From b09883b2517fb9d4e3ff63d28563cc7ccd777046 Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Mon, 20 Mar 2017 15:38:05 -0700 Subject: [PATCH 1/2] Setup circleci ADC --- circle.yml | 16 ++++++++++++++++ travis.sh | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 00000000000..9acc2954151 --- /dev/null +++ b/circle.yml @@ -0,0 +1,16 @@ +machine: + java: + version: oraclejdk8 + environment: + chromedriver_path: /usr/local/bin/chromedriver +dependencies: + pre: + - sudo mkdir /opt/webdriver/ + - curl -LO https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-linux64.tar.gz + && sudo tar -zxf geckodriver-*.tar.gz -C /opt/webdriver/ + - 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 +test: + override: + - bash ./travis.sh diff --git a/travis.sh b/travis.sh index c99a987dc8a..e2e271ba9a0 100755 --- a/travis.sh +++ b/travis.sh @@ -20,6 +20,14 @@ set -o pipefail shopt -s globstar +# Setup GCP application default credentials +if [[ $GCLOUD_SERVICE_KEY ]]; then + echo "$GCLOUD_SERVICE_KEY" | \ + base64 --decode --ignore-garbage > "${HOME}/google-cloud-service-key.json" + export GOOGLE_APPLICATION_CREDENTIALS="${HOME}/google-cloud-service-key.json" +fi + + SKIP_TESTS=false if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ] ; then SKIP_TESTS=true @@ -28,15 +36,16 @@ fi # Finds the closest parent dir that encompasses all changed files, and has a # pom.xml travis_changed_files_parent() { - [ -z "$TRAVIS_PULL_REQUEST" ] && return 0 # If we're not in a PR, forget it + # If we're not in a PR, forget it + [ -z "${TRAVIS_PULL_REQUEST-CI_PULL_REQUEST}" ] && return 0 ( set +e - changed="$(git diff --name-only "$TRAVIS_COMMIT" "$TRAVIS_BRANCH")" + changed="$(git diff --name-only "${TRAVIS_COMMIT-CIRCLE_SHA1}" "${TRAVIS_BRANCH-CIRCLE_BRANCH}")" if [ $? -ne 0 ]; then # Fall back to git head - changed="$(git diff --name-only "$(git rev-parse HEAD)" "$TRAVIS_BRANCH")" + changed="$(git diff --name-only "$(git rev-parse HEAD)" "${TRAVIS_BRANCH-CIRCLE_BRANCH}")" [ $? -ne 0 ] && return 0 # Give up. Just run everything. fi @@ -67,7 +76,8 @@ common_travis_dir="$(travis_changed_files_parent)" # Give Maven a bit more memory export MAVEN_OPTS='-XX:+PrintFlagsFinal -Xmx800m -Xms400m' -"${TRAVIS_BUILD_DIR}"/mvnw --batch-mode clean verify -e -DskipTests=$SKIP_TESTS | egrep -v "(^\[INFO\] Download|^\[INFO\].*skipping)" +"${TRAVIS_BUILD_DIR-$HOME/$CIRCLE_PROJECT_REPONAME}"/mvnw --batch-mode clean verify -e -DskipTests=$SKIP_TESTS | \ + egrep -v "(^\[INFO\] Download|^\[INFO\].*skipping)" [ -z "$common_travis_dir" ] || popd From 0f1a30844b997aea6f74f92d8a7b7cdd412929df Mon Sep 17 00:00:00 2001 From: Jerjou Cheng Date: Mon, 20 Mar 2017 17:43:42 -0700 Subject: [PATCH 2/2] Infer project from env --- README.md | 3 ++- .../bigquery/samples/test/Constants.java | 7 +++--- .../test/ListDatasetsProjectsTest.java | 3 ++- circle.yml | 1 + kms/src/test/java/com/example/SnippetsIT.java | 2 +- .../cloud/language/samples/AnalyzeIT.java | 12 +++++----- logging/src/test/java/ListLogsTest.java | 3 ++- .../java/CloudMonitoringAuthSampleTest.java | 3 ++- .../v3/src/test/java/ListResourcesTest.java | 2 +- pubsub/cloud-client/README.md | 3 +++ pubsub/cloud-client/pom.xml | 3 ++- speech/cloud-client/README.md | 2 +- .../java/com/example/speech/RecognizeIT.java | 5 ++++- .../speech/RecognitionAudioFactoryTest.java | 4 +++- .../src/test/java/StorageSampleTest.java | 5 +++-- .../samples/test/AwsRequesterTest.java | 8 ++++--- .../samples/test/NearlineRequesterTest.java | 8 ++++--- .../src/test/java/StorageSampleTest.java | 6 +++-- .../java/com/example/vision/DetectIT.java | 22 ++++++++++--------- .../landmarkdetection/DetectLandmarkIT.java | 6 +++-- 20 files changed, 68 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 66c7340b687..683081b9575 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java index 26f9a64d16d..4bddbc34bd1 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/Constants.java @@ -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;"; } diff --git a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java index 6668f9b277a..2bf05e7d3d0 100644 --- a/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java +++ b/bigquery/src/test/java/com/google/cloud/bigquery/samples/test/ListDatasetsProjectsTest.java @@ -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; @@ -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); } } diff --git a/circle.yml b/circle.yml index 9acc2954151..08eab79a2d7 100644 --- a/circle.yml +++ b/circle.yml @@ -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 diff --git a/kms/src/test/java/com/example/SnippetsIT.java b/kms/src/test/java/com/example/SnippetsIT.java index 58f420a5bc2..43c7417c30b 100644 --- a/kms/src/test/java/com/example/SnippetsIT.java +++ b/kms/src/test/java/com/example/SnippetsIT.java @@ -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:" diff --git a/language/analysis/src/test/java/com/google/cloud/language/samples/AnalyzeIT.java b/language/analysis/src/test/java/com/google/cloud/language/samples/AnalyzeIT.java index faa9b0d1f06..4775a4a720a 100644 --- a/language/analysis/src/test/java/com/google/cloud/language/samples/AnalyzeIT.java +++ b/language/analysis/src/test/java/com/google/cloud/language/samples/AnalyzeIT.java @@ -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; @@ -62,7 +64,7 @@ public class AnalyzeIT { @Test public void analyzeEntities_withEntitiesFile_containsGod() throws Exception { // Act List entities = - analyzeApp.analyzeEntitiesFile("gs://cloud-samples-tests/natural-language/gettysburg.txt"); + analyzeApp.analyzeEntitiesFile("gs://" + BUCKET + "/natural-language/gettysburg.txt"); List got = entities.stream().map(e -> e.getName()).collect(Collectors.toList()); // Assert @@ -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 @@ -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 @@ -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 @@ -141,7 +143,7 @@ public class AnalyzeIT { @Test public void analyzeSyntax_partOfSpeechFile() throws Exception { // Act List token = - analyzeApp.analyzeSyntaxFile("gs://cloud-samples-tests/natural-language/" + analyzeApp.analyzeSyntaxFile("gs://" + BUCKET + "/natural-language/" + "sentiment/bladerunner-neutral.txt"); List got = token.stream().map(e -> e.getPartOfSpeech().getTag()) diff --git a/logging/src/test/java/ListLogsTest.java b/logging/src/test/java/ListLogsTest.java index 5f1bd3e26c1..ee94330c394 100644 --- a/logging/src/test/java/ListLogsTest.java +++ b/logging/src/test/java/ListLogsTest.java @@ -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() { @@ -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\\.")); diff --git a/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java b/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java index 878d959e16e..4af0e1c0a1f 100644 --- a/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java +++ b/monitoring/v2/src/test/java/CloudMonitoringAuthSampleTest.java @@ -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() { @@ -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) diff --git a/monitoring/v3/src/test/java/ListResourcesTest.java b/monitoring/v3/src/test/java/ListResourcesTest.java index 46ecfd33488..7a03548b08c 100644 --- a/monitoring/v3/src/test/java/ListResourcesTest.java +++ b/monitoring/v3/src/test/java/ListResourcesTest.java @@ -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. diff --git a/pubsub/cloud-client/README.md b/pubsub/cloud-client/README.md index 1f5232b4bbe..b1c444506e5 100644 --- a/pubsub/cloud-client/README.md +++ b/pubsub/cloud-client/README.md @@ -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 diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml index 37cb102eda8..719e0cfb813 100644 --- a/pubsub/cloud-client/pom.xml +++ b/pubsub/cloud-client/pom.xml @@ -31,13 +31,14 @@ 1.8 1.8 UTF-8 + 0.9.4-alpha com.google.cloud google-cloud-pubsub - 0.9.4-alpha + ${pubsub.version} diff --git a/speech/cloud-client/README.md b/speech/cloud-client/README.md index c0397107edb..e6c5d7b1c9d 100644 --- a/speech/cloud-client/README.md +++ b/speech/cloud-client/README.md @@ -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'" ``` diff --git a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java index 29ec44934f7..d001c410e38 100644 --- a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java +++ b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java @@ -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() { diff --git a/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java b/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java index 0fb30ecfdd0..0f1e01b24c4 100644 --- a/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java +++ b/speech/grpc/src/test/java/com/examples/cloud/speech/RecognitionAudioFactoryTest.java @@ -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 { @@ -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); diff --git a/storage/json-api/src/test/java/StorageSampleTest.java b/storage/json-api/src/test/java/StorageSampleTest.java index 572d88ebe30..55c17aa2830 100644 --- a/storage/json-api/src/test/java/StorageSampleTest.java +++ b/storage/json-api/src/test/java/StorageSampleTest.java @@ -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 @@ -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 diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java index ee1e46c2373..395687d54c8 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/AwsRequesterTest.java @@ -30,6 +30,8 @@ @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. */ @@ -37,10 +39,10 @@ public class AwsRequesterTest { 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"); @@ -49,4 +51,4 @@ public void testRun() throws Exception { assertThat(out).contains("\"description\" : \"Sample transfer job from S3 to GCS.\""); } -} \ No newline at end of file +} diff --git a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java index 4f415ffcc75..21118e80df9 100644 --- a/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java +++ b/storage/storage-transfer/src/test/java/com/google/cloud/storage/storagetransfer/samples/test/NearlineRequesterTest.java @@ -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. */ @@ -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"); diff --git a/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java b/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java index 94b160664e8..8d9343f6c6b 100644 --- a/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java +++ b/storage/xml-api/cmdline-sample/src/test/java/StorageSampleTest.java @@ -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( ".*cloud-samples-tests.*" + + "" + PROJECT_ID + ".*" + ".*"); } } diff --git a/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java b/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java index 6b4b5a91d8e..aeabdc92b21 100644 --- a/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java +++ b/vision/cloud-client/src/test/java/com/example/vision/DetectIT.java @@ -35,6 +35,8 @@ public class DetectIT { private ByteArrayOutputStream bout; private PrintStream out; private Detect app; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String BUCKET = PROJECT_ID; @Before public void setUp() throws IOException { @@ -65,7 +67,7 @@ public void testFaces() throws Exception { @Test public void testFacesGcs() throws Exception { // Act - String[] args = {"faces", "gs://cloud-samples-tests/vision/face_no_surprise.jpg"}; + String[] args = {"faces", "gs://" + BUCKET + "/vision/face_no_surprise.jpg"}; Detect.argsHelper(args, out); // Assert @@ -89,7 +91,7 @@ public void testLabels() throws Exception { @Test public void testLabelsGcs() throws Exception { // Act - String[] args = {"labels", "gs://cloud-samples-tests/vision/wakeupcat.jpg"}; + String[] args = {"labels", "gs://" + BUCKET + "/vision/wakeupcat.jpg"}; Detect.argsHelper(args, out); // Assert @@ -111,7 +113,7 @@ public void testLandmarks() throws Exception { @Test public void testLandmarksGcs() throws Exception { // Act - String[] args = {"landmarks", "gs://cloud-samples-tests/vision/landmark.jpg"}; + String[] args = {"landmarks", "gs://" + BUCKET + "/vision/landmark.jpg"}; Detect.argsHelper(args, out); // Assert @@ -144,7 +146,7 @@ public void testLogos() throws Exception { @Test public void testLogosGcs() throws Exception { // Act - String[] args = {"logos", "gs://cloud-samples-tests/vision/logos.png"}; + String[] args = {"logos", "gs://" + BUCKET + "/vision/logos.png"}; Detect.argsHelper(args, out); // Assert @@ -166,7 +168,7 @@ public void testText() throws Exception { @Test public void testTextGcs() throws Exception { // Act - String[] args = {"text", "gs://cloud-samples-tests/vision/text.jpg"}; + String[] args = {"text", "gs://" + BUCKET + "/vision/text.jpg"}; Detect.argsHelper(args, out); // Assert @@ -188,7 +190,7 @@ public void testSafeSearch() throws Exception { @Test public void testSafeSearchGcs() throws Exception { // Act - String[] args = {"safe-search", "gs://cloud-samples-tests/vision/wakeupcat.jpg"}; + String[] args = {"safe-search", "gs://" + BUCKET + "/vision/wakeupcat.jpg"}; Detect.argsHelper(args, out); // Assert @@ -213,7 +215,7 @@ public void testProperties() throws Exception { @Test public void testPropertiesGcs() throws Exception { // Act - String[] args = {"properties", "gs://cloud-samples-tests/vision/landmark.jpg"}; + String[] args = {"properties", "gs://" + BUCKET + "/vision/landmark.jpg"}; Detect.argsHelper(args, out); // Assert @@ -239,7 +241,7 @@ public void detectWebAnnotations() throws Exception { @Test public void detectWebAnnotationsGcs() throws Exception { // Act - String[] args = {"web", "gs://cloud-samples-tests/vision/landmark.jpg"}; + String[] args = {"web", "gs://" + BUCKET + "/vision/landmark.jpg"}; Detect.argsHelper(args, out); // Assert @@ -264,7 +266,7 @@ public void testCropHints() throws Exception { @Test public void testCropHintsGcs() throws Exception { // Act - String[] args = {"crop", "gs://cloud-samples-tests/vision/wakeupcat.jpg"}; + String[] args = {"crop", "gs://" + BUCKET + "/vision/wakeupcat.jpg"}; Detect.argsHelper(args, out); // Assert @@ -289,7 +291,7 @@ public void testDocumentText() throws Exception { @Test public void testDocumentTextGcs() throws Exception { // Act - String[] args = {"fulltext", "gs://cloud-samples-tests/vision/text.jpg"}; + String[] args = {"fulltext", "gs://" + BUCKET + "/vision/text.jpg"}; Detect.argsHelper(args, out); // Assert diff --git a/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java b/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java index 71ee1c6425d..f0f14c46c30 100644 --- a/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java +++ b/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java @@ -36,9 +36,11 @@ @SuppressWarnings("checkstyle:abbreviationaswordinname") public class DetectLandmarkIT { private static final int MAX_RESULTS = 3; - private static final String LANDMARK_URI = "gs://cloud-samples-tests/vision/water.jpg"; + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String BUCKET = PROJECT_ID; + private static final String LANDMARK_URI = "gs://" + BUCKET + "/vision/water.jpg"; private static final String PRIVATE_LANDMARK_URI = - "gs://cloud-samples-tests/vision/water-private.jpg"; + "gs://" + BUCKET + "/vision/water-private.jpg"; private DetectLandmark appUnderTest;