Skip to content

Commit

Permalink
automl: break tests into individual test files and remove bom from po…
Browse files Browse the repository at this point in the history
…m for v1 library support (#1928)

* automl: break tests into individual files

* remove bom from automl until bom is released with v1 of client library

* Update DeleteModelTest.java

* run code formatter

* Remove file that has been replaced by VisionClassificationDeployModelNodeCountTest

* Update tests to use centralized automl testing project
  • Loading branch information
nnegrey authored Jan 7, 2020
1 parent e3f0654 commit 7507a9b
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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:");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit 7507a9b

Please sign in to comment.