From 4e911b54c66b61b75447423fa5e40ba34674c7a7 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:45:19 -0400 Subject: [PATCH] fix: add model signature for batch document translation (#832) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add model signature for batch document translation PiperOrigin-RevId: 403140062 Source-Link: https://github.com/googleapis/googleapis/commit/67e6e0a1dddaa16691d62c99addd3d762e26a7ce Source-Link: https://github.com/googleapis/googleapis-gen/commit/779ead92cdc2433d84ae5ae53418b1600843224e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzc5ZWFkOTJjZGMyNDMzZDg0YWU1YWU1MzQxOGIxNjAwODQzMjI0ZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../v3/TranslationServiceClient.java | 124 +++++++++++++++++ .../cloud/translate/v3/gapic_metadata.json | 2 +- .../v3beta1/TranslationServiceClient.java | 124 +++++++++++++++++ .../translate/v3beta1/gapic_metadata.json | 2 +- .../v3/TranslationServiceClientTest.java | 131 +++++++++++++----- .../v3beta1/TranslationServiceClientTest.java | 131 +++++++++++++----- .../translate/v3/TranslationServiceProto.java | 10 +- .../translate/v3/translation_service.proto | 2 + .../v3beta1/TranslationServiceProto.java | 10 +- .../v3beta1/translation_service.proto | 2 + 10 files changed, 462 insertions(+), 76 deletions(-) diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java index 81e5f3db..bec83605 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java @@ -913,6 +913,130 @@ public final UnaryCallable batchTranslateT return stub.batchTranslateTextCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Translates a large volume of document in asynchronous batch mode. This function provides + * real-time output as the inputs are being processed. If caller cancels a request, the partial + * results (for an input file, it's all or nothing) may still be available on the specified output + * location. + * + *

This call returns immediately and you can use google.longrunning.Operation.name to poll the + * status of the call. + * + *

Sample code: + * + *

{@code
+   * try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String sourceLanguageCode = "sourceLanguageCode1645917472";
+   *   List targetLanguageCodes = new ArrayList<>();
+   *   List inputConfigs = new ArrayList<>();
+   *   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
+   *   BatchTranslateDocumentResponse response =
+   *       translationServiceClient
+   *           .batchTranslateDocumentAsync(
+   *               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
+   *           .get();
+   * }
+   * }
+ * + * @param parent Required. Location to make a regional call. + *

Format: `projects/{project-number-or-id}/locations/{location-id}`. + *

The `global` location is not supported for batch translation. + *

Only AutoML Translation models or glossaries within the same region (have the same + * location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. + * @param sourceLanguageCode Required. The BCP-47 language code of the input document if known, + * for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support + * (https://cloud.google.com/translate/docs/languages). + * @param targetLanguageCodes Required. The BCP-47 language code to use for translation of the + * input document. Specify up to 10 language codes here. + * @param inputConfigs Required. Input configurations. The total number of files matched should be + * <= 100. The total content size to translate should be <= 100M Unicode codepoints. The + * files must use UTF-8 encoding. + * @param outputConfig Required. Output configuration. If 2 input configs match to the same file + * (that is, same input path), we don't generate output for duplicate inputs. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + batchTranslateDocumentAsync( + LocationName parent, + String sourceLanguageCode, + List targetLanguageCodes, + List inputConfigs, + BatchDocumentOutputConfig outputConfig) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setSourceLanguageCode(sourceLanguageCode) + .addAllTargetLanguageCodes(targetLanguageCodes) + .addAllInputConfigs(inputConfigs) + .setOutputConfig(outputConfig) + .build(); + return batchTranslateDocumentAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Translates a large volume of document in asynchronous batch mode. This function provides + * real-time output as the inputs are being processed. If caller cancels a request, the partial + * results (for an input file, it's all or nothing) may still be available on the specified output + * location. + * + *

This call returns immediately and you can use google.longrunning.Operation.name to poll the + * status of the call. + * + *

Sample code: + * + *

{@code
+   * try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
+   *   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
+   *   String sourceLanguageCode = "sourceLanguageCode1645917472";
+   *   List targetLanguageCodes = new ArrayList<>();
+   *   List inputConfigs = new ArrayList<>();
+   *   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
+   *   BatchTranslateDocumentResponse response =
+   *       translationServiceClient
+   *           .batchTranslateDocumentAsync(
+   *               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
+   *           .get();
+   * }
+   * }
+ * + * @param parent Required. Location to make a regional call. + *

Format: `projects/{project-number-or-id}/locations/{location-id}`. + *

The `global` location is not supported for batch translation. + *

Only AutoML Translation models or glossaries within the same region (have the same + * location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. + * @param sourceLanguageCode Required. The BCP-47 language code of the input document if known, + * for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support + * (https://cloud.google.com/translate/docs/languages). + * @param targetLanguageCodes Required. The BCP-47 language code to use for translation of the + * input document. Specify up to 10 language codes here. + * @param inputConfigs Required. Input configurations. The total number of files matched should be + * <= 100. The total content size to translate should be <= 100M Unicode codepoints. The + * files must use UTF-8 encoding. + * @param outputConfig Required. Output configuration. If 2 input configs match to the same file + * (that is, same input path), we don't generate output for duplicate inputs. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + batchTranslateDocumentAsync( + String parent, + String sourceLanguageCode, + List targetLanguageCodes, + List inputConfigs, + BatchDocumentOutputConfig outputConfig) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(parent) + .setSourceLanguageCode(sourceLanguageCode) + .addAllTargetLanguageCodes(targetLanguageCodes) + .addAllInputConfigs(inputConfigs) + .setOutputConfig(outputConfig) + .build(); + return batchTranslateDocumentAsync(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Translates a large volume of document in asynchronous batch mode. This function provides diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/gapic_metadata.json b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/gapic_metadata.json index 0088a1f0..b5190737 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/gapic_metadata.json +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/gapic_metadata.json @@ -11,7 +11,7 @@ "libraryClient": "TranslationServiceClient", "rpcs": { "BatchTranslateDocument": { - "methods": ["batchTranslateDocumentAsync", "batchTranslateDocumentOperationCallable", "batchTranslateDocumentCallable"] + "methods": ["batchTranslateDocumentAsync", "batchTranslateDocumentAsync", "batchTranslateDocumentAsync", "batchTranslateDocumentOperationCallable", "batchTranslateDocumentCallable"] }, "BatchTranslateText": { "methods": ["batchTranslateTextAsync", "batchTranslateTextOperationCallable", "batchTranslateTextCallable"] diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java index 6aa588e2..b9cccb10 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java @@ -692,6 +692,130 @@ public final UnaryCallable batchTranslateT return stub.batchTranslateTextCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Translates a large volume of documents in asynchronous batch mode. This function provides + * real-time output as the inputs are being processed. If caller cancels a request, the partial + * results (for an input file, it's all or nothing) may still be available on the specified output + * location. + * + *

This call returns immediately and you can use google.longrunning.Operation.name to poll the + * status of the call. + * + *

Sample code: + * + *

{@code
+   * try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String sourceLanguageCode = "sourceLanguageCode1645917472";
+   *   List targetLanguageCodes = new ArrayList<>();
+   *   List inputConfigs = new ArrayList<>();
+   *   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
+   *   BatchTranslateDocumentResponse response =
+   *       translationServiceClient
+   *           .batchTranslateDocumentAsync(
+   *               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
+   *           .get();
+   * }
+   * }
+ * + * @param parent Required. Location to make a regional call. + *

Format: `projects/{project-number-or-id}/locations/{location-id}`. + *

The `global` location is not supported for batch translation. + *

Only AutoML Translation models or glossaries within the same region (have the same + * location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. + * @param sourceLanguageCode Required. The BCP-47 language code of the input document if known, + * for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support + * (https://cloud.google.com/translate/docs/languages). + * @param targetLanguageCodes Required. The BCP-47 language code to use for translation of the + * input document. Specify up to 10 language codes here. + * @param inputConfigs Required. Input configurations. The total number of files matched should be + * <= 100. The total content size to translate should be <= 100M Unicode codepoints. The + * files must use UTF-8 encoding. + * @param outputConfig Required. Output configuration. If 2 input configs match to the same file + * (that is, same input path), we don't generate output for duplicate inputs. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + batchTranslateDocumentAsync( + LocationName parent, + String sourceLanguageCode, + List targetLanguageCodes, + List inputConfigs, + BatchDocumentOutputConfig outputConfig) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setSourceLanguageCode(sourceLanguageCode) + .addAllTargetLanguageCodes(targetLanguageCodes) + .addAllInputConfigs(inputConfigs) + .setOutputConfig(outputConfig) + .build(); + return batchTranslateDocumentAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Translates a large volume of documents in asynchronous batch mode. This function provides + * real-time output as the inputs are being processed. If caller cancels a request, the partial + * results (for an input file, it's all or nothing) may still be available on the specified output + * location. + * + *

This call returns immediately and you can use google.longrunning.Operation.name to poll the + * status of the call. + * + *

Sample code: + * + *

{@code
+   * try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
+   *   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
+   *   String sourceLanguageCode = "sourceLanguageCode1645917472";
+   *   List targetLanguageCodes = new ArrayList<>();
+   *   List inputConfigs = new ArrayList<>();
+   *   BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build();
+   *   BatchTranslateDocumentResponse response =
+   *       translationServiceClient
+   *           .batchTranslateDocumentAsync(
+   *               parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig)
+   *           .get();
+   * }
+   * }
+ * + * @param parent Required. Location to make a regional call. + *

Format: `projects/{project-number-or-id}/locations/{location-id}`. + *

The `global` location is not supported for batch translation. + *

Only AutoML Translation models or glossaries within the same region (have the same + * location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned. + * @param sourceLanguageCode Required. The BCP-47 language code of the input document if known, + * for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support + * (https://cloud.google.com/translate/docs/languages). + * @param targetLanguageCodes Required. The BCP-47 language code to use for translation of the + * input document. Specify up to 10 language codes here. + * @param inputConfigs Required. Input configurations. The total number of files matched should be + * <= 100. The total content size to translate should be <= 100M Unicode codepoints. The + * files must use UTF-8 encoding. + * @param outputConfig Required. Output configuration. If 2 input configs match to the same file + * (that is, same input path), we don't generate output for duplicate inputs. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + batchTranslateDocumentAsync( + String parent, + String sourceLanguageCode, + List targetLanguageCodes, + List inputConfigs, + BatchDocumentOutputConfig outputConfig) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(parent) + .setSourceLanguageCode(sourceLanguageCode) + .addAllTargetLanguageCodes(targetLanguageCodes) + .addAllInputConfigs(inputConfigs) + .setOutputConfig(outputConfig) + .build(); + return batchTranslateDocumentAsync(request); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Translates a large volume of documents in asynchronous batch mode. This function provides diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/gapic_metadata.json b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/gapic_metadata.json index e5db2b0a..5cf5bb90 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/gapic_metadata.json +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/gapic_metadata.json @@ -11,7 +11,7 @@ "libraryClient": "TranslationServiceClient", "rpcs": { "BatchTranslateDocument": { - "methods": ["batchTranslateDocumentAsync", "batchTranslateDocumentOperationCallable", "batchTranslateDocumentCallable"] + "methods": ["batchTranslateDocumentAsync", "batchTranslateDocumentAsync", "batchTranslateDocumentAsync", "batchTranslateDocumentOperationCallable", "batchTranslateDocumentCallable"] }, "BatchTranslateText": { "methods": ["batchTranslateTextAsync", "batchTranslateTextOperationCallable", "batchTranslateTextCallable"] diff --git a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientTest.java b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientTest.java index 65a201ce..28a2fe30 100644 --- a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientTest.java +++ b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientTest.java @@ -642,20 +642,17 @@ public void batchTranslateDocumentTest() throws Exception { .build(); mockTranslationService.addResponse(resultOperation); - BatchTranslateDocumentRequest request = - BatchTranslateDocumentRequest.newBuilder() - .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) - .setSourceLanguageCode("sourceLanguageCode1645917472") - .addAllTargetLanguageCodes(new ArrayList()) - .addAllInputConfigs(new ArrayList()) - .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) - .putAllModels(new HashMap()) - .putAllGlossaries(new HashMap()) - .putAllFormatConversions(new HashMap()) - .build(); + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); BatchTranslateDocumentResponse actualResponse = - client.batchTranslateDocumentAsync(request).get(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockTranslationService.getRequests(); @@ -663,15 +660,11 @@ public void batchTranslateDocumentTest() throws Exception { BatchTranslateDocumentRequest actualRequest = ((BatchTranslateDocumentRequest) actualRequests.get(0)); - Assert.assertEquals(request.getParent(), actualRequest.getParent()); - Assert.assertEquals(request.getSourceLanguageCode(), actualRequest.getSourceLanguageCode()); - Assert.assertEquals( - request.getTargetLanguageCodesList(), actualRequest.getTargetLanguageCodesList()); - Assert.assertEquals(request.getInputConfigsList(), actualRequest.getInputConfigsList()); - Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); - Assert.assertEquals(request.getModelsMap(), actualRequest.getModelsMap()); - Assert.assertEquals(request.getGlossariesMap(), actualRequest.getGlossariesMap()); - Assert.assertEquals(request.getFormatConversionsMap(), actualRequest.getFormatConversionsMap()); + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sourceLanguageCode, actualRequest.getSourceLanguageCode()); + Assert.assertEquals(targetLanguageCodes, actualRequest.getTargetLanguageCodesList()); + Assert.assertEquals(inputConfigs, actualRequest.getInputConfigsList()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -684,18 +677,90 @@ public void batchTranslateDocumentExceptionTest() throws Exception { mockTranslationService.addException(exception); try { - BatchTranslateDocumentRequest request = - BatchTranslateDocumentRequest.newBuilder() - .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) - .setSourceLanguageCode("sourceLanguageCode1645917472") - .addAllTargetLanguageCodes(new ArrayList()) - .addAllInputConfigs(new ArrayList()) - .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) - .putAllModels(new HashMap()) - .putAllGlossaries(new HashMap()) - .putAllFormatConversions(new HashMap()) - .build(); - client.batchTranslateDocumentAsync(request).get(); + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void batchTranslateDocumentTest2() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockTranslationService.addResponse(resultOperation); + + String parent = "parent-995424086"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTranslationService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BatchTranslateDocumentRequest actualRequest = + ((BatchTranslateDocumentRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(sourceLanguageCode, actualRequest.getSourceLanguageCode()); + Assert.assertEquals(targetLanguageCodes, actualRequest.getTargetLanguageCodesList()); + Assert.assertEquals(inputConfigs, actualRequest.getInputConfigsList()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void batchTranslateDocumentExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTranslationService.addException(exception); + + try { + String parent = "parent-995424086"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); diff --git a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientTest.java b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientTest.java index c68eaa0e..2a0bcd33 100644 --- a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientTest.java +++ b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientTest.java @@ -496,20 +496,17 @@ public void batchTranslateDocumentTest() throws Exception { .build(); mockTranslationService.addResponse(resultOperation); - BatchTranslateDocumentRequest request = - BatchTranslateDocumentRequest.newBuilder() - .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) - .setSourceLanguageCode("sourceLanguageCode1645917472") - .addAllTargetLanguageCodes(new ArrayList()) - .addAllInputConfigs(new ArrayList()) - .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) - .putAllModels(new HashMap()) - .putAllGlossaries(new HashMap()) - .putAllFormatConversions(new HashMap()) - .build(); + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); BatchTranslateDocumentResponse actualResponse = - client.batchTranslateDocumentAsync(request).get(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockTranslationService.getRequests(); @@ -517,15 +514,11 @@ public void batchTranslateDocumentTest() throws Exception { BatchTranslateDocumentRequest actualRequest = ((BatchTranslateDocumentRequest) actualRequests.get(0)); - Assert.assertEquals(request.getParent(), actualRequest.getParent()); - Assert.assertEquals(request.getSourceLanguageCode(), actualRequest.getSourceLanguageCode()); - Assert.assertEquals( - request.getTargetLanguageCodesList(), actualRequest.getTargetLanguageCodesList()); - Assert.assertEquals(request.getInputConfigsList(), actualRequest.getInputConfigsList()); - Assert.assertEquals(request.getOutputConfig(), actualRequest.getOutputConfig()); - Assert.assertEquals(request.getModelsMap(), actualRequest.getModelsMap()); - Assert.assertEquals(request.getGlossariesMap(), actualRequest.getGlossariesMap()); - Assert.assertEquals(request.getFormatConversionsMap(), actualRequest.getFormatConversionsMap()); + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sourceLanguageCode, actualRequest.getSourceLanguageCode()); + Assert.assertEquals(targetLanguageCodes, actualRequest.getTargetLanguageCodesList()); + Assert.assertEquals(inputConfigs, actualRequest.getInputConfigsList()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -538,18 +531,90 @@ public void batchTranslateDocumentExceptionTest() throws Exception { mockTranslationService.addException(exception); try { - BatchTranslateDocumentRequest request = - BatchTranslateDocumentRequest.newBuilder() - .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) - .setSourceLanguageCode("sourceLanguageCode1645917472") - .addAllTargetLanguageCodes(new ArrayList()) - .addAllInputConfigs(new ArrayList()) - .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) - .putAllModels(new HashMap()) - .putAllGlossaries(new HashMap()) - .putAllFormatConversions(new HashMap()) - .build(); - client.batchTranslateDocumentAsync(request).get(); + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void batchTranslateDocumentTest2() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockTranslationService.addResponse(resultOperation); + + String parent = "parent-995424086"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockTranslationService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BatchTranslateDocumentRequest actualRequest = + ((BatchTranslateDocumentRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(sourceLanguageCode, actualRequest.getSourceLanguageCode()); + Assert.assertEquals(targetLanguageCodes, actualRequest.getTargetLanguageCodesList()); + Assert.assertEquals(inputConfigs, actualRequest.getInputConfigsList()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void batchTranslateDocumentExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockTranslationService.addException(exception); + + try { + String parent = "parent-995424086"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); diff --git a/proto-google-cloud-translate-v3/src/main/java/com/google/cloud/translate/v3/TranslationServiceProto.java b/proto-google-cloud-translate-v3/src/main/java/com/google/cloud/translate/v3/TranslationServiceProto.java index a910f6fb..d0d9cc1a 100644 --- a/proto-google-cloud-translate-v3/src/main/java/com/google/cloud/translate/v3/TranslationServiceProto.java +++ b/proto-google-cloud-translate-v3/src/main/java/com/google/cloud/translate/v3/TranslationServiceProto.java @@ -445,7 +445,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "\0132\032.google.protobuf.Timestamp\"e\n\005State\022\025" + "\n\021STATE_UNSPECIFIED\020\000\022\013\n\007RUNNING\020\001\022\r\n\tSU" + "CCEEDED\020\002\022\n\n\006FAILED\020\003\022\016\n\nCANCELLING\020\004\022\r\n" - + "\tCANCELLED\020\0052\326\023\n\022TranslationService\022\324\002\n\r" + + "\tCANCELLED\020\0052\246\024\n\022TranslationService\022\324\002\n\r" + "TranslateText\0221.google.cloud.translation" + ".v3.TranslateTextRequest\0322.google.cloud." + "translation.v3.TranslateTextResponse\"\333\001\202" @@ -478,12 +478,14 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "uest\032\035.google.longrunning.Operation\"t\202\323\344" + "\223\002;\"6/v3/{parent=projects/*/locations/*}" + ":batchTranslateText:\001*\312A0\n\026BatchTranslat" - + "eResponse\022\026BatchTranslateMetadata\022\376\001\n\026Ba" + + "eResponse\022\026BatchTranslateMetadata\022\316\002\n\026Ba" + "tchTranslateDocument\022:.google.cloud.tran" + "slation.v3.BatchTranslateDocumentRequest" - + "\032\035.google.longrunning.Operation\"\210\001\202\323\344\223\002?" + + "\032\035.google.longrunning.Operation\"\330\001\202\323\344\223\002?" + "\":/v3/{parent=projects/*/locations/*}:ba" - + "tchTranslateDocument:\001*\312A@\n\036BatchTransla" + + "tchTranslateDocument:\001*\332AMparent,source_" + + "language_code,target_language_codes,inpu" + + "t_configs,output_config\312A@\n\036BatchTransla" + "teDocumentResponse\022\036BatchTranslateDocume" + "ntMetadata\022\334\001\n\016CreateGlossary\0222.google.c" + "loud.translation.v3.CreateGlossaryReques" diff --git a/proto-google-cloud-translate-v3/src/main/proto/google/cloud/translate/v3/translation_service.proto b/proto-google-cloud-translate-v3/src/main/proto/google/cloud/translate/v3/translation_service.proto index 070786ce..9f770248 100644 --- a/proto-google-cloud-translate-v3/src/main/proto/google/cloud/translate/v3/translation_service.proto +++ b/proto-google-cloud-translate-v3/src/main/proto/google/cloud/translate/v3/translation_service.proto @@ -123,6 +123,8 @@ service TranslationService { post: "/v3/{parent=projects/*/locations/*}:batchTranslateDocument" body: "*" }; + option (google.api.method_signature) = + "parent,source_language_code,target_language_codes,input_configs,output_config"; option (google.longrunning.operation_info) = { response_type: "BatchTranslateDocumentResponse" metadata_type: "BatchTranslateDocumentMetadata" diff --git a/proto-google-cloud-translate-v3beta1/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceProto.java b/proto-google-cloud-translate-v3beta1/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceProto.java index d20e7a8d..c5d28b95 100644 --- a/proto-google-cloud-translate-v3beta1/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceProto.java +++ b/proto-google-cloud-translate-v3beta1/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceProto.java @@ -450,7 +450,7 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "google.protobuf.Timestamp\"e\n\005State\022\025\n\021ST" + "ATE_UNSPECIFIED\020\000\022\013\n\007RUNNING\020\001\022\r\n\tSUCCEE" + "DED\020\002\022\n\n\006FAILED\020\003\022\016\n\nCANCELLING\020\004\022\r\n\tCAN" - + "CELLED\020\0052\362\023\n\022TranslationService\022\364\001\n\rTran" + + "CELLED\020\0052\302\024\n\022TranslationService\022\364\001\n\rTran" + "slateText\0226.google.cloud.translation.v3b" + "eta1.TranslateTextRequest\0327.google.cloud" + ".translation.v3beta1.TranslateTextRespon" @@ -482,12 +482,14 @@ public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { + "oogle.longrunning.Operation\"y\202\323\344\223\002@\";/v3" + "beta1/{parent=projects/*/locations/*}:ba" + "tchTranslateText:\001*\312A0\n\026BatchTranslateRe" - + "sponse\022\026BatchTranslateMetadata\022\210\002\n\026Batch" + + "sponse\022\026BatchTranslateMetadata\022\330\002\n\026Batch" + "TranslateDocument\022?.google.cloud.transla" + "tion.v3beta1.BatchTranslateDocumentReque" - + "st\032\035.google.longrunning.Operation\"\215\001\202\323\344\223" + + "st\032\035.google.longrunning.Operation\"\335\001\202\323\344\223" + "\002D\"?/v3beta1/{parent=projects/*/location" - + "s/*}:batchTranslateDocument:\001*\312A@\n\036Batch" + + "s/*}:batchTranslateDocument:\001*\332AMparent," + + "source_language_code,target_language_cod" + + "es,input_configs,output_config\312A@\n\036Batch" + "TranslateDocumentResponse\022\036BatchTranslat" + "eDocumentMetadata\022\346\001\n\016CreateGlossary\0227.g" + "oogle.cloud.translation.v3beta1.CreateGl" diff --git a/proto-google-cloud-translate-v3beta1/src/main/proto/google/cloud/translate/v3beta1/translation_service.proto b/proto-google-cloud-translate-v3beta1/src/main/proto/google/cloud/translate/v3beta1/translation_service.proto index 03386518..362d3ef3 100644 --- a/proto-google-cloud-translate-v3beta1/src/main/proto/google/cloud/translate/v3beta1/translation_service.proto +++ b/proto-google-cloud-translate-v3beta1/src/main/proto/google/cloud/translate/v3beta1/translation_service.proto @@ -120,6 +120,8 @@ service TranslationService { post: "/v3beta1/{parent=projects/*/locations/*}:batchTranslateDocument" body: "*" }; + option (google.api.method_signature) = + "parent,source_language_code,target_language_codes,input_configs,output_config"; option (google.longrunning.operation_info) = { response_type: "BatchTranslateDocumentResponse" metadata_type: "BatchTranslateDocumentMetadata"