Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automl: break tests into individual test files and remove bom from pom for v1 library support #1928

Merged
merged 7 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions automl/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,17 @@
</parent>

<properties>
<maven.compiler.target>1.11</maven.compiler.target>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!-- [START automl_java_dependencies] -->
<!-- Using libraries-bom to manage versions.
See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- [START automl_java_dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-automl</artifactId>
<version>0.115.1-beta</version>
</dependency>
<!-- [END automl_java_dependencies] -->
<dependency>
Expand All @@ -77,7 +64,5 @@
<version>1.0</version>
<scope>test</scope>
</dependency>
<!-- [START automl_java_dependencies] -->
</dependencies>
<!-- [END automl_java_dependencies] -->
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Google LLC
* Copyright 2020 Google LLC
nnegrey marked this conversation as resolved.
Show resolved Hide resolved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,20 +31,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

// Tests for Automl models.
@RunWith(JUnit4.class)
public class GenericModelManagementIT {
public class DeleteModelTest {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
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)
);
System.getenv(varName),
"Environment variable '%s' is required to perform these tests.".format(varName));
}

@BeforeClass
Expand All @@ -65,59 +61,6 @@ 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
Expand Down
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("GOOGLE_CLOUD_PROJECT");
nnegrey marked this conversation as resolved.
Show resolved Hide resolved
private static final String MODEL_ID = "TEN1974951581904273408";
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("GOOGLE_CLOUD_PROJECT");
}

@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("GOOGLE_CLOUD_PROJECT");
private static final String MODEL_ID = "TEN1974951581904273408";
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("GOOGLE_CLOUD_PROJECT");
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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("GOOGLE_CLOUD_PROJECT");
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("GOOGLE_CLOUD_PROJECT");
}

@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:");
}
}
Loading