diff --git a/automl/snippets/src/main/java/beta/automl/GetModel.java b/automl/snippets/src/main/java/beta/automl/GetModel.java index 4534dfbbec9..710b78053eb 100644 --- a/automl/snippets/src/main/java/beta/automl/GetModel.java +++ b/automl/snippets/src/main/java/beta/automl/GetModel.java @@ -17,7 +17,6 @@ package beta.automl; // [START automl_get_model_beta] -// [START automl_tables_get_model] import com.google.cloud.automl.v1beta1.AutoMlClient; import com.google.cloud.automl.v1beta1.Model; import com.google.cloud.automl.v1beta1.ModelName; @@ -60,5 +59,4 @@ static void getModel(String projectId, String modelId) } } } -// [END automl_tables_get_model] // [END automl_get_model_beta] diff --git a/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java b/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java index 39352aab793..fa03c6fd50a 100644 --- a/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java +++ b/automl/snippets/src/main/java/com/google/cloud/translate/automl/DatasetApi.java @@ -18,13 +18,9 @@ // Imports the Google Cloud client library import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.Dataset; import com.google.cloud.automl.v1beta1.DatasetName; import com.google.cloud.automl.v1beta1.GcsSource; import com.google.cloud.automl.v1beta1.InputConfig; -import com.google.cloud.automl.v1beta1.ListDatasetsRequest; -import com.google.cloud.automl.v1beta1.LocationName; -import com.google.cloud.automl.v1beta1.TranslationDatasetMetadata; import com.google.protobuf.Empty; import java.io.IOException; import java.io.PrintStream; @@ -43,156 +39,6 @@ */ public class DatasetApi { - // [START automl_translate_create_dataset] - /** - * Demonstrates using the AutoML client to create a dataset - * - * @param projectId the Google Cloud Project ID. - * @param computeRegion the Region name. (e.g., "us-central1"). - * @param datasetName the name of the dataset to be created. - * @param source the Source language - * @param target the Target language - */ - public static void createDataset( - String projectId, String computeRegion, String datasetName, String source, String target) - throws IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, computeRegion); - - // Specify the source and target language. - TranslationDatasetMetadata translationDatasetMetadata = - TranslationDatasetMetadata.newBuilder() - .setSourceLanguageCode(source) - .setTargetLanguageCode(target) - .build(); - - // Set dataset name and dataset metadata. - Dataset myDataset = - Dataset.newBuilder() - .setDisplayName(datasetName) - .setTranslationDatasetMetadata(translationDatasetMetadata) - .build(); - - // Create a dataset with the dataset metadata in the region. - Dataset dataset = client.createDataset(projectLocation, myDataset); - - // Display the dataset information. - System.out.println(String.format("Dataset name: %s", dataset.getName())); - System.out.println( - String.format( - "Dataset id: %s", - dataset.getName().split("/")[dataset.getName().split("/").length - 1])); - System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName())); - System.out.println("Translation dataset Metadata:"); - System.out.println( - String.format( - "\tSource language code: %s", - dataset.getTranslationDatasetMetadata().getSourceLanguageCode())); - System.out.println( - String.format( - "\tTarget language code: %s", - dataset.getTranslationDatasetMetadata().getTargetLanguageCode())); - System.out.println("Dataset create time:"); - System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds())); - System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos())); - } - } - // [END automl_translate_create_dataset] - - // [START automl_translate_list_datasets] - /** - * Demonstrates using the AutoML client to list all datasets. - * - * @param projectId the Google Cloud Project ID. - * @param computeRegion the Region name. (e.g., "us-central1"). - * @param filter the Filter expression. - */ - public static void listDatasets(String projectId, String computeRegion, String filter) - throws IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, computeRegion); - - ListDatasetsRequest request = - ListDatasetsRequest.newBuilder() - .setParent(projectLocation.toString()) - .setFilter(filter) - .build(); - - // List all the datasets available in the region by applying filter. - System.out.println("List of datasets:"); - for (Dataset dataset : client.listDatasets(request).iterateAll()) { - // Display the dataset information - System.out.println(String.format("\nDataset name: %s", dataset.getName())); - System.out.println( - String.format( - "Dataset id: %s", - dataset.getName().split("/")[dataset.getName().split("/").length - 1])); - System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName())); - System.out.println("Translation dataset metadata:"); - System.out.println( - String.format( - "\tSource language code: %s", - dataset.getTranslationDatasetMetadata().getSourceLanguageCode())); - System.out.println( - String.format( - "\tTarget language code: %s", - dataset.getTranslationDatasetMetadata().getTargetLanguageCode())); - System.out.println("Dataset create time:"); - System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds())); - System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos())); - } - } - } - // [END automl_translate_list_datasets] - - // [START automl_translate_get_dataset] - /** - * Demonstrates using the AutoML client to get a dataset by ID. - * - * @param projectId the Google Cloud Project ID. - * @param computeRegion the Region name. (e.g., "us-central1"). - * @param datasetId the Id of the dataset. - */ - public static void getDataset(String projectId, String computeRegion, String datasetId) - throws IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the complete path of the dataset. - DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId); - - // Get all the information about a given dataset. - Dataset dataset = client.getDataset(datasetFullId); - - // Display the dataset information - System.out.println(String.format("Dataset name: %s", dataset.getName())); - System.out.println( - String.format( - "Dataset id: %s", - dataset.getName().split("/")[dataset.getName().split("/").length - 1])); - System.out.println(String.format("Dataset display name: %s", dataset.getDisplayName())); - System.out.println("Translation dataset metadata:"); - System.out.println( - String.format( - "\tSource language code: %s", - dataset.getTranslationDatasetMetadata().getSourceLanguageCode())); - System.out.println( - String.format( - "\tTarget language code: %s", - dataset.getTranslationDatasetMetadata().getTargetLanguageCode())); - System.out.println("Dataset create time:"); - System.out.println(String.format("\tseconds: %s", dataset.getCreateTime().getSeconds())); - System.out.println(String.format("\tnanos: %s", dataset.getCreateTime().getNanos())); - } - } - // [END automl_translate_get_dataset] - // [START automl_translate_import_data] /** * Import sentence pairs to the dataset. @@ -262,17 +108,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { ArgumentParser parser = ArgumentParsers.newFor("").build(); Subparsers subparsers = parser.addSubparsers().dest("command"); - Subparser createDatasetParser = subparsers.addParser("create_dataset"); - createDatasetParser.addArgument("datasetName"); - createDatasetParser.addArgument("source"); - createDatasetParser.addArgument("target"); - - Subparser listDatasetParser = subparsers.addParser("list_datasets"); - listDatasetParser.addArgument("filter").nargs("?").setDefault("translation_dataset_metadata:*"); - - Subparser getDatasetParser = subparsers.addParser("get_dataset"); - getDatasetParser.addArgument("datasetId"); - Subparser importDataParser = subparsers.addParser("import_data"); importDataParser.addArgument("datasetId"); importDataParser.addArgument("path"); @@ -286,20 +121,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { Namespace ns; try { ns = parser.parseArgs(args); - if (ns.get("command").equals("create_dataset")) { - createDataset( - projectId, - computeRegion, - ns.getString("datasetName"), - ns.getString("source"), - ns.getString("target")); - } - if (ns.get("command").equals("list_datasets")) { - listDatasets(projectId, computeRegion, ns.getString("filter")); - } - if (ns.get("command").equals("get_dataset")) { - getDataset(projectId, computeRegion, ns.getString("datasetId")); - } if (ns.get("command").equals("import_data")) { importData(projectId, computeRegion, ns.getString("datasetId"), ns.getString("path")); } diff --git a/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java b/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java index e309432fc43..900fd4f09ea 100644 --- a/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java +++ b/automl/snippets/src/main/java/com/google/cloud/translate/automl/ModelApi.java @@ -17,17 +17,11 @@ package com.google.cloud.translate.automl; // Imports the Google Cloud client library -import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.automl.v1beta1.AutoMlClient; -import com.google.cloud.automl.v1beta1.ListModelEvaluationsRequest; import com.google.cloud.automl.v1beta1.ListModelsRequest; import com.google.cloud.automl.v1beta1.LocationName; import com.google.cloud.automl.v1beta1.Model; -import com.google.cloud.automl.v1beta1.ModelEvaluation; -import com.google.cloud.automl.v1beta1.ModelEvaluationName; import com.google.cloud.automl.v1beta1.ModelName; -import com.google.cloud.automl.v1beta1.OperationMetadata; -import com.google.cloud.automl.v1beta1.TranslationModelMetadata; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import java.io.IOException; @@ -47,48 +41,6 @@ */ public class ModelApi { - // [START automl_translate_create_model] - /** - * Demonstrates using the AutoML client to create a model. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param dataSetId the Id of the dataset to which model is created. - * @param modelName the Name of the model. - */ - public static void createModel( - String projectId, String computeRegion, String dataSetId, String modelName) - throws IOException, InterruptedException, ExecutionException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // A resource that represents Google Cloud Platform location. - LocationName projectLocation = LocationName.of(projectId, computeRegion); - - // Set model metadata. - TranslationModelMetadata translationModelMetadata = - TranslationModelMetadata.newBuilder().setBaseModel("").build(); - - // Set model name, dataset and metadata. - Model myModel = - Model.newBuilder() - .setDisplayName(modelName) - .setDatasetId(dataSetId) - .setTranslationModelMetadata(translationModelMetadata) - .build(); - - // Create a model with the model metadata in the region. - OperationFuture response = - client.createModelAsync(projectLocation, myModel); - - System.out.println( - String.format( - "Training operation name: %s", response.getInitialFuture().get().getName())); - System.out.println("Training started..."); - } - } - // [END automl_translate_create_model] - // [START automl_translate_list_models] /** * Demonstrates using the AutoML client to list all models. @@ -165,69 +117,6 @@ public static void getModel(String projectId, String computeRegion, String model } // [END automl_translate_get_model] - // [START automl_translate_list_model_evaluations] - /** - * Demonstrates using the AutoML client to list model evaluations. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param modelId the Id of the model. - * @param filter the filter expression. - * @throws IOException on Input/Output errors. - */ - public static void listModelEvaluations( - String projectId, String computeRegion, String modelId, String filter) throws IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId); - - // Create list model evaluations request - ListModelEvaluationsRequest modelEvaluationsrequest = - ListModelEvaluationsRequest.newBuilder() - .setParent(modelFullId.toString()) - .setFilter(filter) - .build(); - - // List all the model evaluations in the model by applying filter. - System.out.println("List of model evaluations:"); - for (ModelEvaluation element : - client.listModelEvaluations(modelEvaluationsrequest).iterateAll()) { - System.out.println(element); - } - } - } - // [END automl_translate_list_model_evaluations] - - // [START automl_translate_get_model_evaluation] - /** - * Demonstrates using the AutoML client to get model evaluations. - * - * @param projectId the Id of the project. - * @param computeRegion the Region name. - * @param modelId the Id of the model. - * @param modelEvaluationId the Id of your model evaluation. - * @throws IOException on Input/Output errors. - */ - public static void getModelEvaluation( - String projectId, String computeRegion, String modelId, String modelEvaluationId) - throws IOException { - // Instantiates a client - try (AutoMlClient client = AutoMlClient.create()) { - - // Get the full path of the model evaluation. - ModelEvaluationName modelEvaluationFullId = - ModelEvaluationName.of(projectId, computeRegion, modelId, modelEvaluationId); - - // Get complete detail of the model evaluation. - ModelEvaluation response = client.getModelEvaluation(modelEvaluationFullId); - - System.out.println(response); - } - } - // [END automl_translate_get_model_evaluation] - // [START automl_translate_delete_model] /** * Demonstrates using the AutoML client to delete a model. @@ -287,24 +176,12 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { .description("Model API operations"); Subparsers subparsers = parser.addSubparsers().dest("command"); - Subparser createModelParser = subparsers.addParser("create_model"); - createModelParser.addArgument("datasetId"); - createModelParser.addArgument("modelName"); - Subparser listModelParser = subparsers.addParser("list_models"); listModelParser.addArgument("filter").nargs("?").setDefault(""); Subparser getModelParser = subparsers.addParser("get_model"); getModelParser.addArgument("modelId"); - Subparser listModelEvaluationsParser = subparsers.addParser("list_model_evaluations"); - listModelEvaluationsParser.addArgument("modelId"); - listModelEvaluationsParser.addArgument("filter").nargs("?").setDefault(""); - - Subparser getModelEvaluationParser = subparsers.addParser("get_model_evaluation"); - getModelEvaluationParser.addArgument("modelId"); - getModelEvaluationParser.addArgument("modelEvaluationId"); - Subparser deleteModelParser = subparsers.addParser("delete_model"); deleteModelParser.addArgument("modelId"); @@ -317,23 +194,12 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception { Namespace ns = null; try { ns = parser.parseArgs(args); - if (ns.get("command").equals("create_model")) { - createModel(projectId, computeRegion, ns.getString("datasetId"), ns.getString("modelName")); - } if (ns.get("command").equals("list_models")) { listModels(projectId, computeRegion, ns.getString("filter")); } if (ns.get("command").equals("get_model")) { getModel(projectId, computeRegion, ns.getString("modelId")); } - if (ns.get("command").equals("list_model_evaluations")) { - listModelEvaluations( - projectId, computeRegion, ns.getString("modelId"), ns.getString("filter")); - } - if (ns.get("command").equals("get_model_evaluation")) { - getModelEvaluation( - projectId, computeRegion, ns.getString("modelId"), ns.getString("modelEvaluationId")); - } if (ns.get("command").equals("delete_model")) { deleteModel(projectId, computeRegion, ns.getString("modelId")); } diff --git a/automl/snippets/src/main/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCount.java b/automl/snippets/src/main/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCount.java deleted file mode 100644 index 829f3199c5f..00000000000 --- a/automl/snippets/src/main/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCount.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.vision; - -// [START automl_vision_object_detection_deploy_model_node_count] -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.automl.v1.AutoMlClient; -import com.google.cloud.automl.v1.DeployModelRequest; -import com.google.cloud.automl.v1.ImageObjectDetectionModelDeploymentMetadata; -import com.google.cloud.automl.v1.ModelName; -import com.google.cloud.automl.v1.OperationMetadata; -import com.google.protobuf.Empty; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -class ObjectDetectionDeployModelNodeCount { - - static void objectDetectionDeployModelNodeCount(String projectId, String modelId) - throws IOException, ExecutionException, InterruptedException { - // String projectId = "YOUR_PROJECT_ID"; - // String modelId = "YOUR_MODEL_ID"; - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (AutoMlClient client = AutoMlClient.create()) { - // Get the full path of the model. - ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId); - - // Set how many nodes the model is deployed on - ImageObjectDetectionModelDeploymentMetadata deploymentMetadata = - ImageObjectDetectionModelDeploymentMetadata.newBuilder().setNodeCount(2).build(); - - DeployModelRequest request = - DeployModelRequest.newBuilder() - .setName(modelFullId.toString()) - .setImageObjectDetectionModelDeploymentMetadata(deploymentMetadata) - .build(); - // Deploy the model - OperationFuture future = client.deployModelAsync(request); - future.get(); - System.out.println("Model deployment on 2 nodes finished"); - } - } -} -// [END automl_vision_object_detection_deploy_model_node_count] diff --git a/automl/snippets/src/test/java/com/google/cloud/translate/automl/DatasetApiIT.java b/automl/snippets/src/test/java/com/google/cloud/translate/automl/DatasetApiIT.java index b6dd3035b75..4dd9dc7fb43 100644 --- a/automl/snippets/src/test/java/com/google/cloud/translate/automl/DatasetApiIT.java +++ b/automl/snippets/src/test/java/com/google/cloud/translate/automl/DatasetApiIT.java @@ -18,10 +18,11 @@ import static com.google.common.truth.Truth.assertThat; +import com.google.api.gax.rpc.NotFoundException; +import io.grpc.StatusRuntimeException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; -import java.util.UUID; import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; @@ -40,9 +41,7 @@ public class DatasetApiIT { private ByteArrayOutputStream bout; private PrintStream out; private PrintStream originalPrintStream; - private DatasetApi app; - private String datasetId; - private String getdatasetId = "TRL3946265060617537378"; + private String datasetId = "TEN0000000000000000000"; @Before public void setUp() { @@ -61,59 +60,14 @@ public void tearDown() { @Test public void testCreateImportDeleteDataset() - throws IOException, ExecutionException, InterruptedException { - // Create a random dataset name with a length of 32 characters (max allowed by AutoML) - // To prevent name collisions when running tests in multiple java versions at once. - // AutoML doesn't allow "-", but accepts "_" - String datasetName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); - - // Act - DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, datasetName, "en", "ja"); - - // Assert - String got = bout.toString(); - datasetId = - bout.toString() - .split("\n")[0] - .split("/")[(bout.toString().split("\n")[0]).split("/").length - 1]; - assertThat(got).contains("Dataset id:"); - - // Act - DatasetApi.importData( - PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/en-ja-short.csv"); - - // Assert - got = bout.toString(); - assertThat(got).contains("Dataset id:"); - - // Act - DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId); - - // Assert - got = bout.toString(); - assertThat(got).contains("Dataset deleted."); - } - - @Test - public void testListDataset() throws IOException { - // Act - DatasetApi.listDatasets(PROJECT_ID, COMPUTE_REGION, "translation_dataset_metadata:*"); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Dataset id:"); - } - - @Test - public void testGetDataset() throws IOException { - - // Act - DatasetApi.getDataset(PROJECT_ID, COMPUTE_REGION, getdatasetId); - - // Assert - String got = bout.toString(); - - assertThat(got).contains("Dataset id:"); + throws IOException, InterruptedException { + try { + DatasetApi.importData( + PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/en-ja-short.csv"); + String got = bout.toString(); + assertThat(got).contains("The Dataset doesn't exist "); + } catch (NotFoundException | ExecutionException | StatusRuntimeException ex) { + assertThat(ex.getMessage()).contains("The Dataset doesn't exist"); + } } } diff --git a/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java b/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java index ba8c293419a..214a4a5a221 100644 --- a/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java +++ b/automl/snippets/src/test/java/com/google/cloud/translate/automl/ModelApiIT.java @@ -35,9 +35,7 @@ public class ModelApiIT { private ByteArrayOutputStream bout; private PrintStream out; private PrintStream originalPrintStream; - private ModelApi app; private String modelId; - private String modelEvaluationId; @Before public void setUp() { @@ -71,20 +69,5 @@ public void testModelApi() throws Exception { // Assert got = bout.toString(); assertThat(got).contains("Model name:"); - - // Act - ModelApi.listModelEvaluations(PROJECT_ID, COMPUTE_REGION, modelId, ""); - - // Assert - got = bout.toString(); - modelEvaluationId = got.split("List of model evaluations:")[1].split("\"")[1].split("/")[7]; - assertThat(got).contains("name:"); - - // Act - ModelApi.getModelEvaluation(PROJECT_ID, COMPUTE_REGION, modelId, modelEvaluationId); - - // Assert - got = bout.toString(); - assertThat(got).contains("name:"); } } diff --git a/automl/snippets/src/test/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCountIT.java b/automl/snippets/src/test/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCountIT.java deleted file mode 100644 index 80e0254caf2..00000000000 --- a/automl/snippets/src/test/java/com/google/cloud/vision/ObjectDetectionDeployModelNodeCountIT.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.vision; - -import static com.google.common.truth.Truth.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for vision "Deploy Model Node Count" sample. */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ObjectDetectionDeployModelNodeCountIT { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "0000000000000000000000"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() { - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testObjectDetectionDeployModelNodeCountApi() { - // As model deployment can take a long time, instead try to deploy a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - ObjectDetectionDeployModelNodeCount.objectDetectionDeployModelNodeCount(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("The model does not exist"); - } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("The model does not exist"); - } - } -}