Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit d2c3b4b

Browse files
authored
test: parametrize GCS Bucket for integration tests (#49)
* Parametrize GCS Bucket for integration tests. * Fix formatting to satisfy maven linter * Move GCS Bucket selection to static class outside of setUp method
1 parent 8ce97e9 commit d2c3b4b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

google-cloud-language/src/test/java/com/google/cloud/language/it/ITSystemTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
public class ITSystemTest {
4848

4949
private static LanguageServiceClient client;
50+
private static final String GCS_BUCKET;
51+
private static final String GCS_BUCKET_ENV_VAR = "GOOGLE_CLOUD_TESTS_LANGUAGE_BUCKET";
52+
53+
static {
54+
if (System.getenv(GCS_BUCKET_ENV_VAR) != null) {
55+
GCS_BUCKET = System.getenv(GCS_BUCKET_ENV_VAR);
56+
} else {
57+
GCS_BUCKET = "cloud-samples-data";
58+
}
59+
}
60+
5061
private static final String ANALYZE_TEXT =
5162
"Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets.";
5263

@@ -64,7 +75,7 @@ public void tearDown() {
6475
public void analyzeEntitiesFileTest() {
6576
Document doc =
6677
Document.newBuilder()
67-
.setGcsContentUri("gs://cloud-samples-data/language/android.txt")
78+
.setGcsContentUri(String.format("gs://%s/language/android.txt", GCS_BUCKET))
6879
.setType(Type.PLAIN_TEXT)
6980
.build();
7081
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder().setDocument(doc).build();
@@ -104,7 +115,7 @@ public void analyzeEntitiesTextTest() {
104115
public void analyzeEntitySentimentFileTest() {
105116
Document doc =
106117
Document.newBuilder()
107-
.setGcsContentUri("gs://cloud-samples-data/language/president.txt")
118+
.setGcsContentUri(String.format("gs://%s/language/president.txt", GCS_BUCKET))
108119
.setType(Type.PLAIN_TEXT)
109120
.build();
110121
AnalyzeEntitySentimentRequest request =
@@ -163,7 +174,7 @@ public void analyzeEntitySentimentTextWithEncodedExpectedResultTest() {
163174
public void analyzeSentimentFileWithReturnPositiveTest() {
164175
Document doc =
165176
Document.newBuilder()
166-
.setGcsContentUri("gs://cloud-samples-data/language/sentiment-positive.txt")
177+
.setGcsContentUri(String.format("gs://%s/language/sentiment-positive.txt", GCS_BUCKET))
167178
.setType(Type.PLAIN_TEXT)
168179
.build();
169180
AnalyzeSentimentResponse response = client.analyzeSentiment(doc);
@@ -188,7 +199,7 @@ public void analyzeSentimentTextWithReturnPositiveTest() {
188199
public void analyzeSentimentFileWithReturnNegativeTest() {
189200
Document doc =
190201
Document.newBuilder()
191-
.setGcsContentUri("gs://cloud-samples-data/language/sentiment-negative.txt")
202+
.setGcsContentUri(String.format("gs://%s/language/sentiment-negative.txt", GCS_BUCKET))
192203
.setType(Type.PLAIN_TEXT)
193204
.build();
194205
Sentiment sentiment = client.analyzeSentiment(doc).getDocumentSentiment();
@@ -212,7 +223,7 @@ public void analyzeSentimentTextWithReturnNegativeTest() {
212223
public void analyzeSyntaxFileTest() {
213224
Document doc =
214225
Document.newBuilder()
215-
.setGcsContentUri("gs://cloud-samples-data/language/syntax-sentence.txt")
226+
.setGcsContentUri(String.format("gs://%s/language/syntax-sentence.txt", GCS_BUCKET))
216227
.setType(Type.PLAIN_TEXT)
217228
.build();
218229
AnalyzeSyntaxRequest request =
@@ -255,7 +266,7 @@ public void analyzeSyntaxTextTest() {
255266
public void classifyFileTest() {
256267
Document doc =
257268
Document.newBuilder()
258-
.setGcsContentUri("gs://cloud-samples-data/language/android.txt")
269+
.setGcsContentUri(String.format("gs://%s/language/android.txt", GCS_BUCKET))
259270
.setType(Type.PLAIN_TEXT)
260271
.build();
261272
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();

0 commit comments

Comments
 (0)