Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

Expand All @@ -43,6 +44,9 @@
public class BatchTranslateTextTests {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String INPUT_URI = "gs://cloud-samples-data/translation/text.txt";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -53,7 +57,7 @@ private static void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -102,7 +106,7 @@ public void tearDown() {
public void testBatchTranslateText()
throws InterruptedException, ExecutionException, IOException, TimeoutException {
BatchTranslateText.batchTranslateText(
PROJECT_ID, "en", "es", INPUT_URI, "gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/");
PROJECT_ID, "en", "es", INPUT_URI, OUTPUT_URI);
String got = bout.toString();
assertThat(got).contains("Total Characters: 13");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class BatchTranslateTextWithGlossaryAndModelTests {
private static final String MODEL_ID = "TRL2188848820815848149";
private static final String GLOSSARY_INPUT_URI =
"gs://cloud-samples-data/translation/glossary_ja.csv";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -74,7 +77,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -137,7 +140,7 @@ public void testBatchTranslateTextWithGlossaryAndModel()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
OUTPUT_URI,
GLOSSARY_ID,
MODEL_ID);
String got = bout.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class BatchTranslateTextWithGlossaryTests {
"gs://cloud-samples-data/translation/glossary_ja.csv";
private static final String GLOSSARY_ID =
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -73,7 +76,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -137,7 +140,7 @@ public void testBatchTranslateTextWithGlossary()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
OUTPUT_URI,
GLOSSARY_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 9");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

Expand All @@ -45,6 +46,9 @@ public class BatchTranslateTextWithModelTests {
private static final String INPUT_URI =
"gs://cloud-samples-data/translation/custom_model_text.txt";
private static final String MODEL_ID = "TRL2188848820815848149";
private static final String PREFIX = "BATCH_TRANSLATION_OUTPUT/";
private static final String OUTPUT_URI =
String.format("gs://%s/%s%s/", PROJECT_ID, PREFIX, UUID.randomUUID());

private ByteArrayOutputStream bout;
private PrintStream out;
Expand All @@ -55,7 +59,7 @@ private static final void cleanUpBucket() {
storage.list(
PROJECT_ID,
Storage.BlobListOption.currentDirectory(),
Storage.BlobListOption.prefix("BATCH_TRANSLATION_OUTPUT/"));
Storage.BlobListOption.prefix(PREFIX));

deleteDirectory(storage, blobs);
}
Expand Down Expand Up @@ -108,7 +112,7 @@ public void testBatchTranslateTextWithModel()
"en",
"ja",
INPUT_URI,
"gs://" + PROJECT_ID + "/BATCH_TRANSLATION_OUTPUT/",
OUTPUT_URI,
MODEL_ID);
String got = bout.toString();
assertThat(got).contains("Total Characters: 15");
Expand Down