Skip to content

Commit a2a6d91

Browse files
committed
Vision AutoML
1 parent 3c7d7aa commit a2a6d91

File tree

3 files changed

+260
-0
lines changed

3 files changed

+260
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2018 Google Inc.
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.google.cloud.translate.automl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
import static java.lang.Boolean.FALSE;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.PrintStream;
24+
25+
import org.junit.After;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.JUnit4;
30+
31+
/** Tests for Automl translation "Dataset API" sample. */
32+
@RunWith(JUnit4.class)
33+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
34+
public class DatasetApiIT {
35+
36+
private static final String PROJECT_ID = "java-docs-samples-testing";
37+
private static final String BUCKET = PROJECT_ID + "-vcm";
38+
private static final String COMPUTE_REGION = "us-central1";
39+
private static final String DATASET_NAME = "test_dataset";
40+
private ByteArrayOutputStream bout;
41+
private PrintStream out;
42+
private DatasetApi app;
43+
private String datasetId;
44+
private String getdatasetId = "3946265060617537378";
45+
46+
@Before
47+
public void setUp() {
48+
bout = new ByteArrayOutputStream();
49+
out = new PrintStream(bout);
50+
System.setOut(out);
51+
}
52+
53+
@After
54+
public void tearDown() {
55+
System.setOut(null);
56+
}
57+
58+
@Test
59+
public void testCreateImportDeleteDataset() throws Exception {
60+
// Act
61+
DatasetApi.createDataset(PROJECT_ID, COMPUTE_REGION, DATASET_NAME, "en", "ja");
62+
63+
// Assert
64+
String got = bout.toString();
65+
datasetId =
66+
bout.toString()
67+
.split("\n")[0]
68+
.split("/")[(bout.toString().split("\n")[0]).split("/").length - 1];
69+
assertThat(got).contains("Dataset id:");
70+
71+
// Act
72+
DatasetApi.importData(PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/en-ja.csv");
73+
74+
// Assert
75+
got = bout.toString();
76+
assertThat(got).contains("Dataset id:");
77+
78+
// Act
79+
DatasetApi.deleteDataset(PROJECT_ID, COMPUTE_REGION, datasetId);
80+
81+
// Assert
82+
got = bout.toString();
83+
assertThat(got).contains("Dataset deleted.");
84+
}
85+
86+
@Test
87+
public void testListDataset() throws Exception {
88+
// Act
89+
DatasetApi.listDatasets(PROJECT_ID, COMPUTE_REGION, "translation_dataset_metadata:*");
90+
91+
// Assert
92+
String got = bout.toString();
93+
assertThat(got).contains("Dataset id:");
94+
}
95+
96+
@Test
97+
public void testGetDataset() throws Exception {
98+
99+
// Act
100+
DatasetApi.getDataset(PROJECT_ID, COMPUTE_REGION, getdatasetId);
101+
102+
// Assert
103+
String got = bout.toString();
104+
105+
assertThat(got).contains("Dataset id:");
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2018 Google Inc.
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.google.cloud.translate.automl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.PrintStream;
23+
24+
import org.junit.After;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.junit.runners.JUnit4;
29+
30+
/** Tests for translation "Model API" sample. */
31+
@RunWith(JUnit4.class)
32+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
33+
public class ModelApiIT {
34+
private static final String PROJECT_ID = "java-docs-samples-testing";
35+
private static final String COMPUTE_REGION = "us-central1";
36+
private ByteArrayOutputStream bout;
37+
private PrintStream out;
38+
private ModelApi app;
39+
private String modelId;
40+
private String modelEvaluationId;
41+
42+
@Before
43+
public void setUp() {
44+
45+
bout = new ByteArrayOutputStream();
46+
out = new PrintStream(bout);
47+
System.setOut(out);
48+
}
49+
50+
@After
51+
public void tearDown() {
52+
System.setOut(null);
53+
}
54+
55+
@Test
56+
public void testModelApi() throws Exception {
57+
// Act
58+
ModelApi.listModels(PROJECT_ID, COMPUTE_REGION, "");
59+
60+
// Assert
61+
String got = bout.toString();
62+
modelId = got.split("\n")[1].split("/")[got.split("\n")[1].split("/").length - 1];
63+
assertThat(got).contains("Model id:");
64+
65+
// Act
66+
ModelApi.getModel(PROJECT_ID, COMPUTE_REGION, modelId);
67+
68+
// Assert
69+
got = bout.toString();
70+
assertThat(got).contains("Model name:");
71+
72+
// Act
73+
ModelApi.listModelEvaluations(PROJECT_ID, COMPUTE_REGION, modelId, "");
74+
75+
// Assert
76+
got = bout.toString();
77+
modelEvaluationId = got.split("List of model evaluations:")[1].split("\"")[1].split("/")[7];
78+
assertThat(got).contains("name:");
79+
80+
// Act
81+
ModelApi.getModelEvaluation(PROJECT_ID, COMPUTE_REGION, modelId, modelEvaluationId);
82+
83+
// Assert
84+
got = bout.toString();
85+
assertThat(got).contains("name:");
86+
87+
}
88+
}
89+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2018 Google Inc.
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.google.cloud.translate.automl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
import static java.lang.Boolean.FALSE;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.PrintStream;
24+
25+
import org.junit.After;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
import org.junit.runners.JUnit4;
30+
31+
/** Tests for translation "PredictionAPI" sample. */
32+
@RunWith(JUnit4.class)
33+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
34+
public class PredictionApiIT {
35+
private static final String COMPUTE_REGION = "us-central1";
36+
private static final String PROJECT_ID = "java-docs-samples-testing";
37+
private static final String modelId = "2188848820815848149";
38+
private static final String filePath = "./resources/input.txt";
39+
private ByteArrayOutputStream bout;
40+
private PrintStream out;
41+
private PredictionApi app;
42+
43+
@Before
44+
public void setUp() {
45+
bout = new ByteArrayOutputStream();
46+
out = new PrintStream(bout);
47+
System.setOut(out);
48+
}
49+
50+
@After
51+
public void tearDown() {
52+
System.setOut(null);
53+
}
54+
55+
@Test
56+
public void testPredict() throws Exception {
57+
// Act
58+
PredictionApi.predict(PROJECT_ID, COMPUTE_REGION, modelId, filePath,FALSE);
59+
60+
// Assert
61+
String got = bout.toString();
62+
assertThat(got).contains("Translated Content");
63+
}
64+
}

0 commit comments

Comments
 (0)