Skip to content

Commit 0c18440

Browse files
nnegreyanguillanneuf
authored andcommitted
samples: automl: break tests into individual test files and remove bom from pom 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
1 parent bd0bd6f commit 0c18440

File tree

8 files changed

+455
-165
lines changed

8 files changed

+455
-165
lines changed
Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,26 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.BeforeClass;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.junit.runner.RunWith;
3332
import org.junit.runners.JUnit4;
3433

35-
// Tests for Automl vision image classification models.
3634
@RunWith(JUnit4.class)
37-
@Ignore
38-
public class VisionClassificationModelManagementIT {
35+
public class DeleteModelTest {
3936
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
40-
private static final String MODEL_ID = System.getenv("VISION_CLASSIFICATION_MODEL_ID");
4137
private ByteArrayOutputStream bout;
4238
private PrintStream out;
4339

4440
private static void requireEnvVar(String varName) {
4541
assertNotNull(
46-
System.getenv(varName),
47-
"Environment variable '%s' is required to perform these tests.".format(varName)
48-
);
42+
System.getenv(varName),
43+
"Environment variable '%s' is required to perform these tests.".format(varName));
4944
}
5045

5146
@BeforeClass
5247
public static void checkRequirements() {
5348
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
5449
requireEnvVar("AUTOML_PROJECT_ID");
55-
requireEnvVar("VISION_CLASSIFICATION_MODEL_ID");
5650
}
5751

5852
@Before
@@ -68,27 +62,16 @@ public void tearDown() {
6862
}
6963

7064
@Test
71-
public void testDeployUndeployModel()
72-
throws IOException, ExecutionException, InterruptedException {
73-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
74-
String got = bout.toString();
75-
assertThat(got).contains("Model undeployment finished");
76-
77-
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
78-
got = bout.toString();
79-
assertThat(got).contains("Model deployment finished");
80-
}
81-
82-
@Test
83-
public void testDeployUndeployModelWithNodeCount()
84-
throws IOException, ExecutionException, InterruptedException {
85-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
86-
String got = bout.toString();
87-
assertThat(got).contains("Model undeployment finished");
88-
89-
VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount(
90-
PROJECT_ID, MODEL_ID);
91-
got = bout.toString();
92-
assertThat(got).contains("Model deployment finished");
65+
public void testDeleteModel() {
66+
// As model creation can take many hours, instead try to delete a
67+
// nonexistent model and confirm that the model was not found, but other
68+
// elements of the request were valid.
69+
try {
70+
DeleteModel.deleteModel(PROJECT_ID, "TRL0000000000000000000");
71+
String got = bout.toString();
72+
assertThat(got).contains("The model does not exist");
73+
} catch (IOException | ExecutionException | InterruptedException e) {
74+
assertThat(e.getMessage()).contains("The model does not exist");
75+
}
9376
}
9477
}

automl/snippets/src/test/java/com/example/automl/GenericModelManagementIT.java

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
import static junit.framework.TestCase.assertNotNull;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.IOException;
24+
import java.io.PrintStream;
25+
26+
import org.junit.After;
27+
import org.junit.Before;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
32+
33+
@RunWith(JUnit4.class)
34+
public class GetModelEvaluationTest {
35+
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
36+
private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID");
37+
private String modelEvaluationId;
38+
private ByteArrayOutputStream bout;
39+
private PrintStream out;
40+
41+
private static void requireEnvVar(String varName) {
42+
assertNotNull(
43+
System.getenv(varName),
44+
"Environment variable '%s' is required to perform these tests.".format(varName));
45+
}
46+
47+
@BeforeClass
48+
public static void checkRequirements() {
49+
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
50+
requireEnvVar("AUTOML_PROJECT_ID");
51+
requireEnvVar("ENTITY_EXTRACTION_MODEL_ID");
52+
}
53+
54+
@Before
55+
public void setUp() throws IOException {
56+
bout = new ByteArrayOutputStream();
57+
out = new PrintStream(bout);
58+
System.setOut(out);
59+
60+
// Get a model evaluation ID from the List request first to be used in the Get call
61+
ListModelEvaluations.listModelEvaluations(PROJECT_ID, MODEL_ID);
62+
String got = bout.toString();
63+
modelEvaluationId = got.split(MODEL_ID + "/modelEvaluations/")[1].split("\n")[0];
64+
assertThat(got).contains("Model Evaluation Name:");
65+
66+
bout = new ByteArrayOutputStream();
67+
out = new PrintStream(bout);
68+
System.setOut(out);
69+
}
70+
71+
@After
72+
public void tearDown() {
73+
System.setOut(null);
74+
}
75+
76+
@Test
77+
public void testGetModelEvaluation() throws IOException {
78+
GetModelEvaluation.getModelEvaluation(PROJECT_ID, MODEL_ID, modelEvaluationId);
79+
String got = bout.toString();
80+
assertThat(got).contains("Model Evaluation Name:");
81+
}
82+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
import static junit.framework.TestCase.assertNotNull;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.IOException;
24+
import java.io.PrintStream;
25+
26+
import org.junit.After;
27+
import org.junit.Before;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.junit.runners.JUnit4;
32+
33+
@RunWith(JUnit4.class)
34+
public class GetModelTest {
35+
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
36+
private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID");
37+
private ByteArrayOutputStream bout;
38+
private PrintStream out;
39+
40+
private static void requireEnvVar(String varName) {
41+
assertNotNull(
42+
System.getenv(varName),
43+
"Environment variable '%s' is required to perform these tests.".format(varName));
44+
}
45+
46+
@BeforeClass
47+
public static void checkRequirements() {
48+
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
49+
requireEnvVar("AUTOML_PROJECT_ID");
50+
requireEnvVar("ENTITY_EXTRACTION_MODEL_ID");
51+
}
52+
53+
@Before
54+
public void setUp() {
55+
bout = new ByteArrayOutputStream();
56+
out = new PrintStream(bout);
57+
System.setOut(out);
58+
}
59+
60+
@After
61+
public void tearDown() {
62+
System.setOut(null);
63+
}
64+
65+
@Test
66+
public void testGetModel() throws IOException {
67+
GetModel.getModel(PROJECT_ID, MODEL_ID);
68+
String got = bout.toString();
69+
assertThat(got).contains("Model id: " + MODEL_ID);
70+
}
71+
}

0 commit comments

Comments
 (0)