Skip to content

Commit a027821

Browse files
author
Jerjou Cheng
committed
Infer project from env
1 parent 0199a4d commit a027821

File tree

20 files changed

+68
-40
lines changed

20 files changed

+68
-40
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# java-docs-samples
22

3-
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
3+
[![Travis Build Status](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/java-docs-samples)
4+
[![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)
45
[![ghit.me](https://ghit.me/badge.svg?repo=GoogleCloudPlatform/java-docs-samples)](https://ghit.me/repo/GoogleCloudPlatform/java-docs-samples)
56
[![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples)
67

bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
package com.google.cloud.bigquery.samples.test;
1818

1919
public class Constants {
20-
public static final String PROJECT_ID = "cloud-samples-tests";
20+
public static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
21+
public static final String BUCKET = PROJECT_ID;
2122
public static final String DATASET_ID = "test_dataset_java";
2223
public static final String CURRENT_TABLE_ID = "test_table_java";
2324
public static final String NEW_TABLE_ID = "test_table_java_2";
24-
public static final String CLOUD_STORAGE_INPUT_URI = "gs://cloud-samples-tests/data.csv";
25-
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://cloud-samples-tests/output.csv";
25+
public static final String CLOUD_STORAGE_INPUT_URI = "gs://" + BUCKET + "/data.csv";
26+
public static final String CLOUD_STORAGE_OUTPUT_URI = "gs://" + BUCKET + "/output.csv";
2627
public static final String QUERY =
2728
"SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;";
2829
}

bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636
@RunWith(JUnit4.class)
3737
public class ListDatasetsProjectsTest {
38+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
3839
private static final PrintStream REAL_OUT = System.out;
3940
private static final PrintStream REAL_ERR = System.err;
4041

@@ -72,6 +73,6 @@ public void testMain() throws Exception {
7273

7374
assertThat(out).named("stdout").contains("Listing all the Projects");
7475
assertThat(out).named("stdout").contains("Project list:");
75-
assertThat(out).named("stdout").containsMatch("Bigquery Samples|cloud-samples-tests");
76+
assertThat(out).named("stdout").containsMatch("Bigquery Samples|" + PROJECT_ID);
7677
}
7778
}

circle.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe"
1212
- sudo apt-get update
1313
- sudo apt-get install -t trusty-backports shellcheck
14+
- sudo apt-get install expect
1415
test:
1516
override:
1617
- bash ./travis.sh

kms/src/test/java/com/example/SnippetsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@SuppressWarnings("checkstyle:abbreviationaswordinname")
4141
public class SnippetsIT {
4242

43-
static final String PROJECT_ID = "java-docs-samples-tests";
43+
static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4444
static final String KEY_RING_ID = "test-snippets-key-ring";
4545
static final String CRYPTO_KEY_ID = "test-snippets-crypto-key";
4646
static final String TEST_USER = "serviceAccount:"

language/analysis/src/test/java/com/google/cloud/language/samples/AnalyzeIT.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
@RunWith(JUnit4.class)
3939
@SuppressWarnings("checkstyle:abbreviationaswordinname")
4040
public class AnalyzeIT {
41+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
42+
private static final String BUCKET = PROJECT_ID;
4143

4244
private Analyze analyzeApp;
4345

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

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

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

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

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

147149
List<Tag> got = token.stream().map(e -> e.getPartOfSpeech().getTag())

logging/src/test/java/ListLogsTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class ListLogsTest {
3232
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
3333
private static final PrintStream REAL_OUT = System.out;
3434
private static final PrintStream REAL_ERR = System.err;
35+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
3536

3637
@Before
3738
public void setUp() {
@@ -53,7 +54,7 @@ public void testUsage() throws Exception {
5354

5455
@Test
5556
public void testListLogs() throws Exception {
56-
ListLogs.main(new String[] {"cloud-samples-tests"});
57+
ListLogs.main(new String[] {PROJECT_ID});
5758
String out = stdout.toString();
5859
// Don't know what logs the test project will have.
5960
assertThat(out, containsPattern("Done\\."));

monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class CloudMonitoringAuthSampleTest {
3333
new ByteArrayOutputStream();
3434
private static final PrintStream REAL_OUT = System.out;
3535
private static final PrintStream REAL_ERR = System.err;
36+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
3637

3738
@Before
3839
public void setUp() {
@@ -56,7 +57,7 @@ public void testUsage() throws Exception {
5657

5758
@Test
5859
public void testListTimeSeries() throws Exception {
59-
CloudMonitoringAuthSample.main(new String[] { "cloud-samples-tests" });
60+
CloudMonitoringAuthSample.main(new String[] { PROJECT_ID });
6061
String out = stdout.toString();
6162
assertThat(out).named("stdout").contains("Timeseries.list raw response:");
6263
assertThat(out)

monitoring/v3/src/test/java/ListResourcesTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ListResourcesTest {
3737
/**
3838
* The project ID of the project created for the integration tests.
3939
*/
40-
public static final String TEST_PROJECT_ID = "cloud-samples-tests";
40+
public static final String TEST_PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
4141

4242
/**
4343
* Google Cloud Monitoring client to integration test.

pubsub/cloud-client/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ the [Google Cloud Client Library for Java][google-cloud-java].
88
[pubsub]: https://cloud.google.com/pubsub/
99
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
1010

11+
For more samples, see the samples in
12+
[google-cloud-java](https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub).
13+
1114
## Quickstart
1215

1316
#### Setup

pubsub/cloud-client/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
<maven.compiler.target>1.8</maven.compiler.target>
3232
<maven.compiler.source>1.8</maven.compiler.source>
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<pubsub.version>0.9.4-alpha</pubsub.version>
3435
</properties>
3536

3637
<dependencies>
3738
<dependency>
3839
<groupId>com.google.cloud</groupId>
3940
<artifactId>google-cloud-pubsub</artifactId>
40-
<version>0.9.4-alpha</version>
41+
<version>${pubsub.version}</version>
4142
</dependency>
4243

4344
<!-- Test dependencies -->

speech/cloud-client/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ You can then run a given `ClassName` via:
3434
### Transcribe a remote audio file (using the recognize sample)
3535
```
3636
mvn exec:java -Dexec.mainClass=com.example.speech.Recognize \
37-
-Dexec.args="syncrecognize 'gs://cloud-samples-tests/speech/brooklyn.flac'"
37+
-Dexec.args="syncrecognize 'gs://java-docs-samples-tests/speech/brooklyn.flac'"
3838
```

speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
@RunWith(JUnit4.class)
3434
@SuppressWarnings("checkstyle:abbreviationaswordinname")
3535
public class RecognizeIT {
36+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
37+
private static final String BUCKET = PROJECT_ID;
38+
3639
private ByteArrayOutputStream bout;
3740
private PrintStream out;
3841

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

4346
@Before
4447
public void setUp() {

speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
*/
3434
@RunWith(JUnit4.class)
3535
public class RecognitionAudioFactoryTest {
36+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
37+
private static final String BUCKET = PROJECT_ID;
3638

3739
@Test
3840
public void verifyBytesInSizeFromLocalFile() throws IOException {
@@ -47,7 +49,7 @@ public void verifyBytesInSizeFromLocalFile() throws IOException {
4749

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

5254
URI uri = URI.create(audioUri);
5355
RecognitionAudio audio = RecognitionAudioFactory.createRecognitionAudio(uri);

storage/json-api/src/test/java/StorageSampleTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import java.util.stream.Collectors;
3131

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

3637
@Test
@@ -43,7 +44,7 @@ public void testListBucket() throws Exception {
4344
public void testGetBucket() throws Exception {
4445
Bucket bucket = StorageSample.getBucket(BUCKET);
4546
assertThat(bucket.getName()).named("bucket name").isEqualTo(BUCKET);
46-
assertThat(bucket.getLocation()).named("bucket location").isEqualTo("US-CENTRAL1");
47+
assertThat(bucket.getLocation()).named("bucket location").startsWith("US");
4748
}
4849

4950
@Test

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@
3030
@RunWith(JUnit4.class)
3131
public class AwsRequesterTest {
3232

33+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
34+
3335
/**
3436
* Tests whether AwsRequester executes a request to create a TransferJob.
3537
*/
3638
@Test
3739
public void testRun() throws Exception {
3840
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
3941
PrintStream outStream = new PrintStream(outBytes);
40-
System.setProperty("projectId", "cloud-samples-tests");
42+
System.setProperty("projectId", PROJECT_ID);
4143
System.setProperty("jobDescription", "Sample transfer job from S3 to GCS.");
4244
System.setProperty("awsSourceBucket", "cloud-samples-tests");
43-
System.setProperty("gcsSinkBucket", "cloud-samples-tests-storagetransfer");
45+
System.setProperty("gcsSinkBucket", PROJECT_ID + "-storagetransfer");
4446
System.setProperty("startDate", "2000-01-01");
4547
System.setProperty("startTime", "00:00:00");
4648

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

5052
assertThat(out).contains("\"description\" : \"Sample transfer job from S3 to GCS.\"");
5153
}
52-
}
54+
}

storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
@RunWith(JUnit4.class)
3131
public class NearlineRequesterTest {
3232

33+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
34+
3335
/**
3436
* Tests whether NearlineRequester executes a request to create a TransferJob.
3537
*/
@@ -38,10 +40,10 @@ public void testRun() throws Exception {
3840

3941
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
4042
PrintStream outStream = new PrintStream(outBytes);
41-
System.setProperty("projectId", "cloud-samples-tests");
43+
System.setProperty("projectId", PROJECT_ID);
4244
System.setProperty("jobDescription", "Sample transfer job from GCS to GCS Nearline.");
43-
System.setProperty("gcsSourceBucket", "cloud-samples-tests-storagetransfer-source");
44-
System.setProperty("gcsNearlineSinkBucket", "cloud-storage-samples-tests-storagetransfer-sink");
45+
System.setProperty("gcsSourceBucket", PROJECT_ID + "-storagetransfer-source");
46+
System.setProperty("gcsNearlineSinkBucket", PROJECT_ID + "-storagetransfer-sink");
4547
System.setProperty("startDate", "2000-01-01");
4648
System.setProperty("startTime", "00:00:00");
4749

storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import org.junit.Test;
2121

2222
public class StorageSampleTest {
23+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
24+
2325
@Test
2426
public void testListBucket() throws Exception {
25-
String listing = StorageSample.listBucket("cloud-samples-tests");
27+
String listing = StorageSample.listBucket(PROJECT_ID);
2628
assertThat(listing)
2729
.containsMatch(
2830
".*<ListBucketResult.*"
29-
+ "<Name>cloud-samples-tests</Name>.*"
31+
+ "<Name>" + PROJECT_ID + "</Name>.*"
3032
+ "</ListBucketResult>.*");
3133
}
3234
}

0 commit comments

Comments
 (0)