diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/DeleteModelTest.java similarity index 55% rename from automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/DeleteModelTest.java index cf1ab01076c..5b422d72046 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/DeleteModelTest.java @@ -27,32 +27,26 @@ import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Tests for Automl vision image classification models. @RunWith(JUnit4.class) -@Ignore -public class VisionClassificationModelManagementIT { +public class DeleteModelTest { private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private static final String MODEL_ID = System.getenv("VISION_CLASSIFICATION_MODEL_ID"); private ByteArrayOutputStream bout; private PrintStream out; private static void requireEnvVar(String varName) { assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); } @BeforeClass public static void checkRequirements() { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("AUTOML_PROJECT_ID"); - requireEnvVar("VISION_CLASSIFICATION_MODEL_ID"); } @Before @@ -68,27 +62,16 @@ public void tearDown() { } @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); - } - - @Test - public void testDeployUndeployModelWithNodeCount() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount( - PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); + public void testDeleteModel() { + // As model creation can take many hours, instead try to delete a + // nonexistent model and confirm that the model was not found, but other + // elements of the request were valid. + try { + DeleteModel.deleteModel(PROJECT_ID, "TRL0000000000000000000"); + 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"); + } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/GenericModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/GenericModelManagementIT.java deleted file mode 100644 index a2facbb6140..00000000000 --- a/automl/cloud-client/src/test/java/com/example/automl/GenericModelManagementIT.java +++ /dev/null @@ -1,134 +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.example.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -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.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for Automl models. -@RunWith(JUnit4.class) -public class GenericModelManagementIT { - private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); - private String modelId; - private String modelEvaluationId; - private ByteArrayOutputStream bout; - private PrintStream out; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("AUTOML_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(null); - } - - @Test - public void testModelApi() throws IOException { - // LIST MODELS - ListModels.listModels(PROJECT_ID); - String got = bout.toString(); - modelId = got.split("Model id: ")[1].split("\n")[0]; - assertThat(got).contains("Model id:"); - - // GET MODEL - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - GetModel.getModel(PROJECT_ID, modelId); - got = bout.toString(); - assertThat(got).contains("Model id: " + modelId); - - // LIST MODEL EVALUATIONS - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - ListModelEvaluations.listModelEvaluations(PROJECT_ID, modelId); - got = bout.toString(); - modelEvaluationId = got.split(modelId + "/modelEvaluations/")[1].split("\n")[0]; - assertThat(got).contains("Model Evaluation Name:"); - - // GET MODEL EVALUATION - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - GetModelEvaluation.getModelEvaluation(PROJECT_ID, modelId, modelEvaluationId); - got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); - } - - @Test - public void testOperationStatus() throws IOException { - // Act - ListOperationStatus.listOperationStatus(PROJECT_ID); - - // Assert - String got = bout.toString(); - String operationId = got.split("\n")[1].split(":")[1].trim(); - assertThat(got).contains("Operation details:"); - - // Act - bout.reset(); - GetOperationStatus.getOperationStatus(operationId); - - // Assert - got = bout.toString(); - assertThat(got).contains("Operation details:"); - } - - @Test - public void testDeleteModel() { - // As model creation can take many hours, instead try to delete a - // nonexistent model and confirm that the model was not found, but other - // elements of the request were valid. - try { - DeleteModel.deleteModel(PROJECT_ID, "TRL0000000000000000000"); - 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"); - } - } -} diff --git a/automl/cloud-client/src/test/java/com/example/automl/GetModelEvaluationTest.java b/automl/cloud-client/src/test/java/com/example/automl/GetModelEvaluationTest.java new file mode 100644 index 00000000000..41c393e402b --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/GetModelEvaluationTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class GetModelEvaluationTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); + private String modelEvaluationId; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); + } + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + + // Get a model evaluation ID from the List request first to be used in the Get call + ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID); + String got = bout.toString(); + modelEvaluationId = got.split(MODEL_ID + "/modelEvaluations/")[1].split("\n")[0]; + assertThat(got).contains("Model Evaluation Name:"); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetModelEvaluation() throws IOException { + GetModelEvaluation.getModelEvaluation(PROJECT_ID, MODEL_ID, modelEvaluationId); + String got = bout.toString(); + assertThat(got).contains("Model Evaluation Name:"); + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/GetModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/GetModelTest.java new file mode 100644 index 00000000000..977c95d076e --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/GetModelTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class GetModelTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetModel() throws IOException { + GetModel.getModel(PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("Model id: " + MODEL_ID); + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/GetOperationStatusTest.java b/automl/cloud-client/src/test/java/com/example/automl/GetOperationStatusTest.java new file mode 100644 index 00000000000..7093cf354cb --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/GetOperationStatusTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class GetOperationStatusTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private String operationId; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + } + + @Before + public void setUp() throws IOException { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + + ListOperationStatus.listOperationStatus(PROJECT_ID); + String got = bout.toString(); + operationId = got.split("\n")[1].split(":")[1].trim(); + assertThat(got).contains("Operation details:"); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetOperationStatus() throws IOException { + GetOperationStatus.getOperationStatus(operationId); + String got = bout.toString(); + assertThat(got).contains("Operation details:"); + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/ListModelEvaluationsTest.java b/automl/cloud-client/src/test/java/com/example/automl/ListModelEvaluationsTest.java new file mode 100644 index 00000000000..d9fd170eef6 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/ListModelEvaluationsTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ListModelEvaluationsTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + requireEnvVar("ENTITY_EXTRACTION_MODEL_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testListModelEvaluations() throws IOException { + ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("Model Evaluation Name:"); + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/ListModelsTest.java b/automl/cloud-client/src/test/java/com/example/automl/ListModelsTest.java new file mode 100644 index 00000000000..eec6778539d --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/ListModelsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ListModelsTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testListModels() throws IOException { + ListModels.listModels(PROJECT_ID); + String got = bout.toString(); + assertThat(got).contains("Model id:"); + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/ListOperationStatusTest.java b/automl/cloud-client/src/test/java/com/example/automl/ListOperationStatusTest.java new file mode 100644 index 00000000000..6e78ae5fb11 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/ListOperationStatusTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2020 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.example.automl; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ListOperationStatusTest { + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testOperationStatus() throws IOException { + ListOperationStatus.listOperationStatus(PROJECT_ID); + String got = bout.toString(); + assertThat(got).contains("Operation details:"); + } +}