Skip to content

Commit

Permalink
Infer project from env
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerjou Cheng committed Mar 21, 2017
1 parent 0199a4d commit a027821
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 40 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# java-docs-samples

[![Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
[![Travis Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
[![Circle-CI Build Status](https://circleci.com/gh/GoogleCloudPlatform/java-docs-samples.svg?style=shield&circle-token=117b41ead030b212fc7d519519ee9262c4f3480b)](https://circleci.com/gh/GoogleCloudPlatform/java-docs-samples)
[![ghit.me](https://ghit.me/badge.svg?repo=GoogleCloudPlatform/java-docs-samples)](https://ghit.me/repo/GoogleCloudPlatform/java-docs-samples)
[![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package com.google.cloud.bigquery.samples.test;

public class Constants {
public static final String PROJECT_ID = "cloud-samples-tests";
public static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
public static final String BUCKET = PROJECT_ID;
public static final String DATASET_ID = "test_dataset_java";
public static final String CURRENT_TABLE_ID = "test_table_java";
public static final String NEW_TABLE_ID = "test_table_java_2";
public static final String CLOUD_STORAGE_INPUT_URI = "gs://cloud-samples-tests/data.csv";
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://cloud-samples-tests/output.csv";
public static final String CLOUD_STORAGE_INPUT_URI = "gs://" + BUCKET + "/data.csv";
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://" + BUCKET + "/output.csv";
public static final String QUERY =
"SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/
@RunWith(JUnit4.class)
public class ListDatasetsProjectsTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;

Expand Down Expand Up @@ -72,6 +73,6 @@ public void testMain() throws Exception {

assertThat(out).named("stdout").contains("Listing all the Projects");
assertThat(out).named("stdout").contains("Project list:");
assertThat(out).named("stdout").containsMatch("Bigquery Samples|cloud-samples-tests");
assertThat(out).named("stdout").containsMatch("Bigquery Samples|" + PROJECT_ID);
}
}
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe"
- sudo apt-get update
- sudo apt-get install -t trusty-backports shellcheck
- sudo apt-get install expect
test:
override:
- bash ./travis.sh
2 changes: 1 addition & 1 deletion kms/src/test/java/com/example/SnippetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class SnippetsIT {

static final String PROJECT_ID = "java-docs-samples-tests";
static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
static final String KEY_RING_ID = "test-snippets-key-ring";
static final String CRYPTO_KEY_ID = "test-snippets-crypto-key";
static final String TEST_USER = "serviceAccount:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class AnalyzeIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

private Analyze analyzeApp;

Expand All @@ -62,7 +64,7 @@ public class AnalyzeIT {
@Test public void analyzeEntities_withEntitiesFile_containsGod() throws Exception {
// Act
List<Entity> entities =
analyzeApp.analyzeEntitiesFile("gs://cloud-samples-tests/natural-language/gettysburg.txt");
analyzeApp.analyzeEntitiesFile("gs://" + BUCKET + "/natural-language/gettysburg.txt");
List<String> got = entities.stream().map(e -> e.getName()).collect(Collectors.toList());

// Assert
Expand All @@ -83,7 +85,7 @@ public class AnalyzeIT {
@Test public void analyzeSentimentFile_returnPositiveFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-pos.txt");

// Assert
Expand All @@ -105,7 +107,7 @@ public class AnalyzeIT {
@Test public void analyzeSentiment_returnNegativeFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neg.txt");

// Assert
Expand All @@ -116,7 +118,7 @@ public class AnalyzeIT {
@Test public void analyzeSentiment_returnNeutralFile() throws Exception {
// Act
Sentiment sentiment =
analyzeApp.analyzeSentimentFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSentimentFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neutral.txt");

// Assert
Expand All @@ -141,7 +143,7 @@ public class AnalyzeIT {
@Test public void analyzeSyntax_partOfSpeechFile() throws Exception {
// Act
List<Token> token =
analyzeApp.analyzeSyntaxFile("gs://cloud-samples-tests/natural-language/"
analyzeApp.analyzeSyntaxFile("gs://" + BUCKET + "/natural-language/"
+ "sentiment/bladerunner-neutral.txt");

List<Tag> got = token.stream().map(e -> e.getPartOfSpeech().getTag())
Expand Down
3 changes: 2 additions & 1 deletion logging/src/test/java/ListLogsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ListLogsTest {
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Before
public void setUp() {
Expand All @@ -53,7 +54,7 @@ public void testUsage() throws Exception {

@Test
public void testListLogs() throws Exception {
ListLogs.main(new String[] {"cloud-samples-tests"});
ListLogs.main(new String[] {PROJECT_ID});
String out = stdout.toString();
// Don't know what logs the test project will have.
assertThat(out, containsPattern("Done\\."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CloudMonitoringAuthSampleTest {
new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Before
public void setUp() {
Expand All @@ -56,7 +57,7 @@ public void testUsage() throws Exception {

@Test
public void testListTimeSeries() throws Exception {
CloudMonitoringAuthSample.main(new String[] { "cloud-samples-tests" });
CloudMonitoringAuthSample.main(new String[] { PROJECT_ID });
String out = stdout.toString();
assertThat(out).named("stdout").contains("Timeseries.list raw response:");
assertThat(out)
Expand Down
2 changes: 1 addition & 1 deletion monitoring/v3/src/test/java/ListResourcesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ListResourcesTest {
/**
* The project ID of the project created for the integration tests.
*/
public static final String TEST_PROJECT_ID = "cloud-samples-tests";
public static final String TEST_PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Google Cloud Monitoring client to integration test.
Expand Down
3 changes: 3 additions & 0 deletions pubsub/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ the [Google Cloud Client Library for Java][google-cloud-java].
[pubsub]: https://cloud.google.com/pubsub/
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java

For more samples, see the samples in
[google-cloud-java](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub).

## Quickstart

#### Setup
Expand Down
3 changes: 2 additions & 1 deletion pubsub/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pubsub.version>0.9.4-alpha</pubsub.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>0.9.4-alpha</version>
<version>${pubsub.version}</version>
</dependency>

<!-- Test dependencies -->
Expand Down
2 changes: 1 addition & 1 deletion speech/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ You can then run a given `ClassName` via:
### Transcribe a remote audio file (using the recognize sample)
```
mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \
-Dexec.args="syncrecognize 'gs://cloud-samples-tests/speech/brooklyn.flac'"
-Dexec.args="syncrecognize 'gs://java-docs-samples-tests/speech/brooklyn.flac'"
```
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class RecognizeIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

private ByteArrayOutputStream bout;
private PrintStream out;

// The path to the audio file to transcribe
private String fileName = "./resources/audio.raw";
private String gcsPath = "gs://cloud-samples-tests/speech/brooklyn.flac";
private String gcsPath = "gs://" + BUCKET + "/speech/brooklyn.flac";

@Before
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
@RunWith(JUnit4.class)
public class RecognitionAudioFactoryTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;

@Test
public void verifyBytesInSizeFromLocalFile() throws IOException {
Expand All @@ -47,7 +49,7 @@ public void verifyBytesInSizeFromLocalFile() throws IOException {

@Test
public void verifyBytesInSizeFromGoogleStorageFile() throws IOException {
String audioUri = "gs://cloud-samples-tests/speech/audio.raw";
String audioUri = "gs://" + BUCKET + "/speech/audio.raw";

URI uri = URI.create(audioUri);
RecognitionAudio audio = RecognitionAudioFactory.createRecognitionAudio(uri);
Expand Down
5 changes: 3 additions & 2 deletions storage/json-api/src/test/java/StorageSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import java.util.stream.Collectors;

public class StorageSampleTest {
private static final String BUCKET = "cloud-samples-test";
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String BUCKET = PROJECT_ID;
private static final String TEST_OBJECT = "storage-sample-test-upload.txt";

@Test
Expand All @@ -43,7 +44,7 @@ public void testListBucket() throws Exception {
public void testGetBucket() throws Exception {
Bucket bucket = StorageSample.getBucket(BUCKET);
assertThat(bucket.getName()).named("bucket name").isEqualTo(BUCKET);
assertThat(bucket.getLocation()).named("bucket location").isEqualTo("US-CENTRAL1");
assertThat(bucket.getLocation()).named("bucket location").startsWith("US");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
@RunWith(JUnit4.class)
public class AwsRequesterTest {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Tests whether AwsRequester executes a request to create a TransferJob.
*/
@Test
public void testRun() throws Exception {
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(outBytes);
System.setProperty("projectId", "cloud-samples-tests");
System.setProperty("projectId", PROJECT_ID);
System.setProperty("jobDescription", "Sample transfer job from S3 to GCS.");
System.setProperty("awsSourceBucket", "cloud-samples-tests");
System.setProperty("gcsSinkBucket", "cloud-samples-tests-storagetransfer");
System.setProperty("gcsSinkBucket", PROJECT_ID + "-storagetransfer");
System.setProperty("startDate", "2000-01-01");
System.setProperty("startTime", "00:00:00");

Expand All @@ -49,4 +51,4 @@ public void testRun() throws Exception {

assertThat(out).contains("\"description\" : \"Sample transfer job from S3 to GCS.\"");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
@RunWith(JUnit4.class)
public class NearlineRequesterTest {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

/**
* Tests whether NearlineRequester executes a request to create a TransferJob.
*/
Expand All @@ -38,10 +40,10 @@ public void testRun() throws Exception {

ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
PrintStream outStream = new PrintStream(outBytes);
System.setProperty("projectId", "cloud-samples-tests");
System.setProperty("projectId", PROJECT_ID);
System.setProperty("jobDescription", "Sample transfer job from GCS to GCS Nearline.");
System.setProperty("gcsSourceBucket", "cloud-samples-tests-storagetransfer-source");
System.setProperty("gcsNearlineSinkBucket", "cloud-storage-samples-tests-storagetransfer-sink");
System.setProperty("gcsSourceBucket", PROJECT_ID + "-storagetransfer-source");
System.setProperty("gcsNearlineSinkBucket", PROJECT_ID + "-storagetransfer-sink");
System.setProperty("startDate", "2000-01-01");
System.setProperty("startTime", "00:00:00");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import org.junit.Test;

public class StorageSampleTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");

@Test
public void testListBucket() throws Exception {
String listing = StorageSample.listBucket("cloud-samples-tests");
String listing = StorageSample.listBucket(PROJECT_ID);
assertThat(listing)
.containsMatch(
".*<ListBucketResult.*"
+ "<Name>cloud-samples-tests</Name>.*"
+ "<Name>" + PROJECT_ID + "</Name>.*"
+ "</ListBucketResult>.*");
}
}
Expand Down
Loading

0 comments on commit a027821

Please sign in to comment.