Skip to content

Commit cf37185

Browse files
committed
Fixing older automl tests
1 parent de05de5 commit cf37185

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

language/automl/src/main/java/com/google/cloud/language/samples/ModelApi.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
/**
4949
* Google Cloud AutoML Natural Language API sample application. Example usage: mvn package exec:java
50-
* -Dexec.mainClass ='com.google.cloud.vision.samples.automl.ModelApi' -Dexec.args='create_model
50+
* -Dexec.mainClass ='com.google.cloud.language.samples.automl.ModelApi' -Dexec.args='create_model
5151
* [datasetId] test_model'
5252
*/
5353
public class ModelApi {
@@ -168,10 +168,10 @@ public static void getModel(String projectId, String computeRegion, String model
168168
AutoMlClient client = AutoMlClient.create();
169169

170170
// Get the full path of the model.
171-
ModelName modelFullId = ModelName.of(projectId, computeRegion, modelId);
171+
ModelName modelName = ModelName.of(projectId, computeRegion, modelId);
172172

173173
// Get complete detail of the model.
174-
Model model = client.getModel(modelFullId);
174+
Model model = client.getModel(modelName.toString());
175175

176176
// Display the model information.
177177
System.out.println(String.format("Model name: %s", model.getName()));
@@ -183,6 +183,9 @@ public static void getModel(String projectId, String computeRegion, String model
183183
System.out.println(String.format("\tseconds: %s", model.getCreateTime().getSeconds()));
184184
System.out.println(String.format("\tnanos: %s", model.getCreateTime().getNanos()));
185185
System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
186+
187+
// Deploy model so it can be used for Prediction
188+
client.deployModelAsync(modelName.toString());
186189
}
187190
// [END automl_language_get_model]
188191

language/automl/src/test/java/com/google/cloud/language/samples/DatasetApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class DatasetApiIT {
4141
private PrintStream out;
4242
private DatasetApi app;
4343
private String datasetId;
44-
private String getdatasetId = "8477830379477056918";
44+
private String getdatasetId = "TCN8477830379477056918";
4545

4646
@Before
4747
public void setUp() {

language/automl/src/test/java/com/google/cloud/language/samples/ModelApiIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333
public class ModelApiIT {
3434
private static final String PROJECT_ID = "java-docs-samples-testing";
3535
private static final String COMPUTE_REGION = "us-central1";
36+
private static final String MODEL_ID = "TCN342705131419266916";
37+
private static final String MODEL_EVALUATION_ID = "3666189665418739402";
3638
private ByteArrayOutputStream bout;
3739
private PrintStream out;
38-
private ModelApi app;
39-
private String modelId;
40-
private String modelIdGetevaluation = "342705131419266916";
41-
private String modelEvaluationId = "3666189665418739402";
4240

4341
@Before
4442
public void setUp() {
@@ -60,18 +58,17 @@ public void testModelApi() throws Exception {
6058

6159
// Assert
6260
String got = bout.toString();
63-
modelId = got.split("\n")[1].split("/")[got.split("\n")[1].split("/").length - 1];
6461
assertThat(got).contains("Model id:");
6562

6663
// Act
67-
ModelApi.getModel(PROJECT_ID, COMPUTE_REGION, modelId);
64+
ModelApi.getModel(PROJECT_ID, COMPUTE_REGION, MODEL_ID);
6865

6966
// Assert
7067
got = bout.toString();
7168
assertThat(got).contains("Model name:");
7269

7370
// Act
74-
ModelApi.listModelEvaluations(PROJECT_ID, COMPUTE_REGION, modelId, "");
71+
ModelApi.listModelEvaluations(PROJECT_ID, COMPUTE_REGION, MODEL_ID, "");
7572

7673
// Assert
7774
got = bout.toString();
@@ -83,7 +80,7 @@ public void testGetModelEvaluation() throws Exception {
8380

8481
// Act
8582
ModelApi.getModelEvaluation(
86-
PROJECT_ID, COMPUTE_REGION, modelIdGetevaluation, modelEvaluationId);
83+
PROJECT_ID, COMPUTE_REGION, MODEL_ID, MODEL_EVALUATION_ID);
8784

8885
// Assert
8986
String got = bout.toString();

language/automl/src/test/java/com/google/cloud/language/samples/PredictionApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class PredictionApiIT {
3434
private static final String COMPUTE_REGION = "us-central1";
3535
private static final String PROJECT_ID = "java-docs-samples-testing";
36-
private static final String modelId = "342705131419266916";
36+
private static final String modelId = "TCN342705131419266916";
3737
private static final String filePath = "./resources/input.txt";
3838
private ByteArrayOutputStream bout;
3939
private PrintStream out;

0 commit comments

Comments
 (0)