Skip to content

Commit 627b481

Browse files
samples: added list testcase result sample (#315)
* samples: added list testcase result sample * Added agent ids * Lint fix * lint fix * lint fix * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7bce2b7 commit 627b481

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 dialogflow.cx;
18+
19+
// [START dialogflow_cx_list_testcase_result_sample]
20+
21+
import com.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest;
22+
import com.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest.Builder;
23+
import com.google.cloud.dialogflow.cx.v3.TestCaseResult;
24+
import com.google.cloud.dialogflow.cx.v3.TestCasesClient;
25+
import com.google.cloud.dialogflow.cx.v3.TestCasesSettings;
26+
import java.io.IOException;
27+
28+
public class ListTestCaseResults {
29+
30+
public static void main(String[] args) throws IOException {
31+
// TODO(developer): Replace these variables before running the sample.
32+
String projectId = "my-project-id";
33+
String agentId = "my-agent-id";
34+
String testId = "my-test-id";
35+
String location = "my-location";
36+
listTestCaseResults(projectId, agentId, testId, location);
37+
}
38+
39+
public static void listTestCaseResults(
40+
String projectId, String agentId, String testId, String location) throws IOException {
41+
String parent =
42+
"projects/"
43+
+ projectId
44+
+ "/locations/"
45+
+ location
46+
+ "/agents/"
47+
+ agentId
48+
+ "/testCases/"
49+
+ testId;
50+
51+
Builder req = ListTestCaseResultsRequest.newBuilder();
52+
53+
req.setParent(parent);
54+
req.setFilter("environment=draft");
55+
56+
TestCasesSettings testCasesSettings =
57+
TestCasesSettings.newBuilder()
58+
.setEndpoint(location + "-dialogflow.googleapis.com:443")
59+
.build();
60+
TestCasesClient client = TestCasesClient.create(testCasesSettings);
61+
62+
for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) {
63+
System.out.println(element);
64+
}
65+
}
66+
}
67+
// [END dialogflow_cx_list_testcase_result_sample]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 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 dialogflow.cx;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.IOException;
23+
import java.io.PrintStream;
24+
import org.junit.After;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
28+
public class ListTestCaseResultsIT {
29+
30+
private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT");
31+
private static String agentId = "1499b8e1-ab7d-43fd-9b08-30ee57194fc1";
32+
private static String testId = "694a5447-6c40-4752-944e-e3e70580b273";
33+
private static String location = "global";
34+
35+
private ByteArrayOutputStream stdOut;
36+
private static PrintStream originalOut;
37+
38+
@Before
39+
public void setUp() throws IOException {
40+
originalOut = System.out;
41+
stdOut = new ByteArrayOutputStream();
42+
System.setOut(new PrintStream(stdOut));
43+
}
44+
45+
@After
46+
public void tearDown() throws IOException {
47+
System.setOut(originalOut);
48+
}
49+
50+
@Test
51+
public void testListTestCaseResults() throws IOException {
52+
ListTestCaseResults.listTestCaseResults(PROJECT_ID, agentId, testId, location);
53+
assertThat(stdOut.toString()).contains(testId);
54+
}
55+
}

0 commit comments

Comments
 (0)