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

Commit

Permalink
test: parametrize GCS Bucket for integration tests (#49)
Browse files Browse the repository at this point in the history
* Parametrize GCS Bucket for integration tests.

* Fix formatting to satisfy maven linter

* Move GCS Bucket selection to static class outside of setUp method
  • Loading branch information
sid-dinesh94 committed Jan 29, 2020
1 parent 8ce97e9 commit d2c3b4b
Showing 1 changed file with 17 additions and 6 deletions.
Expand Up @@ -47,6 +47,17 @@
public class ITSystemTest {

private static LanguageServiceClient client;
private static final String GCS_BUCKET;
private static final String GCS_BUCKET_ENV_VAR = "GOOGLE_CLOUD_TESTS_LANGUAGE_BUCKET";

static {
if (System.getenv(GCS_BUCKET_ENV_VAR) != null) {
GCS_BUCKET = System.getenv(GCS_BUCKET_ENV_VAR);
} else {
GCS_BUCKET = "cloud-samples-data";
}
}

private static final String ANALYZE_TEXT =
"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.";

Expand All @@ -64,7 +75,7 @@ public void tearDown() {
public void analyzeEntitiesFileTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/android.txt")
.setGcsContentUri(String.format("gs://%s/language/android.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
AnalyzeEntitiesRequest request = AnalyzeEntitiesRequest.newBuilder().setDocument(doc).build();
Expand Down Expand Up @@ -104,7 +115,7 @@ public void analyzeEntitiesTextTest() {
public void analyzeEntitySentimentFileTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/president.txt")
.setGcsContentUri(String.format("gs://%s/language/president.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
AnalyzeEntitySentimentRequest request =
Expand Down Expand Up @@ -163,7 +174,7 @@ public void analyzeEntitySentimentTextWithEncodedExpectedResultTest() {
public void analyzeSentimentFileWithReturnPositiveTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/sentiment-positive.txt")
.setGcsContentUri(String.format("gs://%s/language/sentiment-positive.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
AnalyzeSentimentResponse response = client.analyzeSentiment(doc);
Expand All @@ -188,7 +199,7 @@ public void analyzeSentimentTextWithReturnPositiveTest() {
public void analyzeSentimentFileWithReturnNegativeTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/sentiment-negative.txt")
.setGcsContentUri(String.format("gs://%s/language/sentiment-negative.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
Sentiment sentiment = client.analyzeSentiment(doc).getDocumentSentiment();
Expand All @@ -212,7 +223,7 @@ public void analyzeSentimentTextWithReturnNegativeTest() {
public void analyzeSyntaxFileTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/syntax-sentence.txt")
.setGcsContentUri(String.format("gs://%s/language/syntax-sentence.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
AnalyzeSyntaxRequest request =
Expand Down Expand Up @@ -255,7 +266,7 @@ public void analyzeSyntaxTextTest() {
public void classifyFileTest() {
Document doc =
Document.newBuilder()
.setGcsContentUri("gs://cloud-samples-data/language/android.txt")
.setGcsContentUri(String.format("gs://%s/language/android.txt", GCS_BUCKET))
.setType(Type.PLAIN_TEXT)
.build();
ClassifyTextRequest request = ClassifyTextRequest.newBuilder().setDocument(doc).build();
Expand Down

0 comments on commit d2c3b4b

Please sign in to comment.