From 380f5cba29b21972872347dc93a72c1093cf1917 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sun, 17 Jul 2022 09:46:37 -0500 Subject: [PATCH 01/25] add try block to clean up resources Change-Id: Ie68f4715646942d2e78189b3477cb9a5a31713b8 --- .../src/main/java/dialogflow/cx/ListTestCaseResults.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java index 3519c5c98..41fd1a7e1 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java @@ -57,10 +57,10 @@ public static void listTestCaseResults( TestCasesSettings.newBuilder() .setEndpoint(location + "-dialogflow.googleapis.com:443") .build(); - TestCasesClient client = TestCasesClient.create(testCasesSettings); - - for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { - System.out.println(element); + try(TestCasesClient client = TestCasesClient.create(testCasesSettings)) { + for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { + System.out.println(element); + } } } } From d3361171b6d1cbd1cef6ac33f9dcb04be6d4b706 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sun, 17 Jul 2022 09:46:37 -0500 Subject: [PATCH 02/25] docs: add try block to clean up resources Change-Id: Ibaa2bd6a9f687b67af61a5f958c37e2faf087434 --- .../src/main/java/dialogflow/cx/ListTestCaseResults.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java index 3519c5c98..41fd1a7e1 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java @@ -57,10 +57,10 @@ public static void listTestCaseResults( TestCasesSettings.newBuilder() .setEndpoint(location + "-dialogflow.googleapis.com:443") .build(); - TestCasesClient client = TestCasesClient.create(testCasesSettings); - - for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { - System.out.println(element); + try(TestCasesClient client = TestCasesClient.create(testCasesSettings)) { + for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { + System.out.println(element); + } } } } From 48173c9c25b5524b6e7e34c6eeb5f2c535b1b270 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sun, 17 Jul 2022 10:08:26 -0500 Subject: [PATCH 03/25] add try block to clean up resources Change-Id: I60fff4d6c83d42b8921b4ed4ce6c0eea76a952c6 --- .../java/dialogflow/cx/PageManagementIT.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index ab1b2ca60..af49b06f9 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -47,21 +47,25 @@ public class PageManagementIT { public static void setUp() throws IOException { stdOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(stdOut)); - Builder build = Agent.newBuilder(); - build.setDefaultLanguageCode("en"); - build.setDisplayName("temp_agent_" + UUID.randomUUID().toString()); - build.setTimeZone("America/Los_Angeles"); - - Agent agent = build.build(); String apiEndpoint = "global-dialogflow.googleapis.com:443"; - String parentPath = "projects/" + PROJECT_ID + "/locations/global"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - AgentsClient client = AgentsClient.create(agentsSettings); + try (AgentsClient client = AgentsClient.create(agentsSettings)) { + + Builder build = Agent.newBuilder(); + build.setDefaultLanguageCode("en"); + build.setDisplayName("temp_agent_" + UUID.randomUUID().toString()); + build.setTimeZone("America/Los_Angeles"); + + Agent agent = build.build(); + String parentPath = "projects/" + PROJECT_ID + "/locations/global"; + + parent = client.createAgent(parentPath, agent).getName(); + + agentID = parent.split("/")[5]; + } - parent = client.createAgent(parentPath, agent).getName(); - agentID = parent.split("/")[5]; } @AfterClass @@ -70,9 +74,9 @@ public static void tearDown() throws IOException, InterruptedException { String parentPath = "projects/" + PROJECT_ID + "/locations/global"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - AgentsClient client = AgentsClient.create(agentsSettings); - - client.deleteAgent(parent); + try (AgentsClient client = AgentsClient.create(agentsSettings)) { + client.deleteAgent(parent); + } // Small delay to prevent reaching quota limit of requests per minute Thread.sleep(250); From 247d799e093fb96485820a89014de4fdcf25dfec Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sun, 17 Jul 2022 10:13:37 -0500 Subject: [PATCH 04/25] add try block to clean up resources Change-Id: I2facb88a81c1d76d5b2316da04cebdffba6634b9 --- .../dialogflow/cx/ListTestCaseResults.java | 2 +- .../java/dialogflow/cx/UpdateIntentTest.java | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java index 41fd1a7e1..3293a8ce2 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java @@ -57,7 +57,7 @@ public static void listTestCaseResults( TestCasesSettings.newBuilder() .setEndpoint(location + "-dialogflow.googleapis.com:443") .build(); - try(TestCasesClient client = TestCasesClient.create(testCasesSettings)) { + try (TestCasesClient client = TestCasesClient.create(testCasesSettings)) { for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { System.out.println(element); } diff --git a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java index 0443ec40c..8a3ce1b83 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java @@ -48,21 +48,24 @@ public void setUp() throws IOException { stdOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(stdOut)); - Builder build = Agent.newBuilder(); - build.setDefaultLanguageCode("en"); - build.setDisplayName("temp_agent_" + UUID.randomUUID().toString()); - build.setTimeZone("America/Los_Angeles"); - - Agent agent = build.build(); - String apiEndpoint = "global-dialogflow.googleapis.com:443"; - String parentPath = "projects/" + PROJECT_ID + "/locations/global"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - AgentsClient client = AgentsClient.create(agentsSettings); + try (AgentsClient agentsClient = AgentsClient.create(agentsSettings)) { + + Builder build = Agent.newBuilder(); - parent = client.createAgent(parentPath, agent).getName(); - UpdateIntentTest.agentID = parent.split("/")[5]; + build.setDefaultLanguageCode("en"); + build.setDisplayName("temp_agent_" + UUID.randomUUID().toString()); + build.setTimeZone("America/Los_Angeles"); + + Agent agent = build.build(); + String parentPath = "projects/" + PROJECT_ID + "/locations/global"; + + parent = agentsClient.createAgent(parentPath, agent).getName(); + + UpdateIntentTest.agentID = parent.split("/")[5]; + } try (IntentsClient intentsClient = IntentsClient.create()) { com.google.cloud.dialogflow.cx.v3.Intent.Builder intent = Intent.newBuilder(); @@ -77,14 +80,14 @@ public void setUp() throws IOException { public void tearDown() throws IOException, InterruptedException { stdOut = null; System.setOut(null); + String apiEndpoint = "global-dialogflow.googleapis.com:443"; - String parentPath = "projects/" + PROJECT_ID + "/locations/global"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - AgentsClient client = AgentsClient.create(agentsSettings); - - client.deleteAgent(parent); - + try(AgentsClient client = AgentsClient.create(agentsSettings)) { + String parentPath = "projects/" + PROJECT_ID + "/locations/global"; + client.deleteAgent(parent); + } // Small delay to prevent reaching quota limit of requests per minute Thread.sleep(250); } From 0377870ea1c42d270b20260a407ee967e84dd3d3 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sun, 17 Jul 2022 10:18:28 -0500 Subject: [PATCH 05/25] add Thread.sleep to try blocks, fix checkstyle Change-Id: I0eab8286ac21a8becf64b541100050581016ca5d --- .../src/test/java/dialogflow/cx/CreateAgentIT.java | 10 +++++----- .../src/test/java/dialogflow/cx/PageManagementIT.java | 6 +++--- .../src/test/java/dialogflow/cx/UpdateIntentTest.java | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java b/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java index 69723e127..aee80c7de 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java @@ -48,12 +48,12 @@ public void tearDown() throws IOException, InterruptedException { String apiEndpoint = "global-dialogflow.googleapis.com:443"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - AgentsClient client = AgentsClient.create(agentsSettings); + try (AgentsClient client = AgentsClient.create(agentsSettings)) { + client.deleteAgent(CreateAgentIT.agentPath); - client.deleteAgent(CreateAgentIT.agentPath); - - // Small delay to prevent reaching quota limit of requests per minute - Thread.sleep(250); + // Small delay to prevent reaching quota limit of requests per minute + Thread.sleep(250); + } } @Test diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index af49b06f9..de3467af7 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -76,10 +76,10 @@ public static void tearDown() throws IOException, InterruptedException { AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); try (AgentsClient client = AgentsClient.create(agentsSettings)) { client.deleteAgent(parent); - } - // Small delay to prevent reaching quota limit of requests per minute - Thread.sleep(250); + // Small delay to prevent reaching quota limit of requests per minute + Thread.sleep(250); + } } @Test diff --git a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java index 8a3ce1b83..afac34e1c 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java @@ -84,12 +84,13 @@ public void tearDown() throws IOException, InterruptedException { String apiEndpoint = "global-dialogflow.googleapis.com:443"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); - try(AgentsClient client = AgentsClient.create(agentsSettings)) { + try (AgentsClient client = AgentsClient.create(agentsSettings)) { String parentPath = "projects/" + PROJECT_ID + "/locations/global"; client.deleteAgent(parent); + + // Small delay to prevent reaching quota limit of requests per minute + Thread.sleep(250); } - // Small delay to prevent reaching quota limit of requests per minute - Thread.sleep(250); } @Test From 330ad0067a222eb303e45bcd44c6be409f73600c Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 10:46:10 -0500 Subject: [PATCH 06/25] add Thread.sleep Change-Id: I94553a4501a6bdfbdcad1360833cd5e4352d9a77 --- ...onfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 1 + .../test/java/dialogflow/cx/WebhookValidateFormParameterIT.java | 1 + 2 files changed, 2 insertions(+) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index b9a051bf7..ca9a76508 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -94,5 +94,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String expectedResponse = gson.toJson(webhookResponse); assertThat(responseOut.toString()).isEqualTo(expectedResponse); + Thread.sleep(200); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index f234c3f3e..7c0652e31 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -101,5 +101,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String expectedResponse = gson.toJson(webhookResponse); assertThat(responseOut.toString()).isEqualTo(expectedResponse); + Thread.sleep(200); } } From 65152dd5d8dc67607f3b9dea2d96fce7b67ccf54 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:06:17 -0500 Subject: [PATCH 07/25] add Thread.sleep Change-Id: I123c577193306dc4625d2d56637e71e13cd06f70 --- .../java/dialogflow/cx/WebhookConfigureSessionParametersIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index 52cd6470d..731fd41c2 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -82,5 +82,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String expectedResponse = gson.toJson(webhookResponse); assertThat(responseOut.toString()).isEqualTo(expectedResponse); + Thread.sleep(200); } } From f334e61de95d14345efb003a2f6625cea7ce4a61 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:09:20 -0500 Subject: [PATCH 08/25] add try block to clean up resources Change-Id: I38d51da44e19b7c50d09d3e32aa6b5378c8fc0e2 --- .../src/test/java/dialogflow/cx/PageManagementIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index de3467af7..8b5c634c6 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -96,7 +96,9 @@ public void testListPages() throws IOException { Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); - ListPages.listPages(PROJECT_ID, agentID, flowID, location); + try { + ListPages.listPages(PROJECT_ID, agentID, flowID, location) + } assertThat(stdOut.toString()).contains(name); } From 07b5ace4bdd5b6346eec14e72538adc901421a22 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:36:48 -0500 Subject: [PATCH 09/25] change fulfillmentInfo tag Change-Id: I8f0b7e31a2283c5dae7c6b377861ee03e8cbe621 --- .../java/dialogflow/cx/WebhookConfigureSessionParametersIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index 731fd41c2..9c1d2a719 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -50,7 +50,7 @@ public class WebhookConfigureSessionParametersIT { public void beforeTest() throws IOException { MockitoAnnotations.initMocks(this); - stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"); + stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameter'}}"); jsonReader = new BufferedReader(stringReader); responseOut = new StringWriter(); From 3a63902435f5954e7193fa53ee0987155c90b93e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:39:53 -0500 Subject: [PATCH 10/25] add try block to clean up resources Change-Id: I3ee67b4c3ce45b18138d9382fd18f5f4646372db --- .../src/test/java/dialogflow/cx/PageManagementIT.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 8b5c634c6..fae735afe 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -84,9 +84,9 @@ public static void tearDown() throws IOException, InterruptedException { @Test public void testCreatePage() throws IOException { - Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); - pageID = p.getName().split("/")[9]; - + try (Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName)) { + pageID = p.getName().split("/")[9]; + } assertThat(p.getDisplayName()).isEqualTo(displayName); } @@ -94,9 +94,7 @@ public void testCreatePage() throws IOException { public void testListPages() throws IOException { String name = "temp_page_" + UUID.randomUUID().toString(); - Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); - - try { + try (Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name)) { ListPages.listPages(PROJECT_ID, agentID, flowID, location) } assertThat(stdOut.toString()).contains(name); From 3282ef210409ae351f168c40c0816812a157c398 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:43:39 -0500 Subject: [PATCH 11/25] add ; Change-Id: I10cb37ff93f4c28c1f94d8e221c893fe4b74835a --- .../snippets/src/test/java/dialogflow/cx/PageManagementIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index fae735afe..35ba0bd60 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -95,7 +95,7 @@ public void testListPages() throws IOException { String name = "temp_page_" + UUID.randomUUID().toString(); try (Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name)) { - ListPages.listPages(PROJECT_ID, agentID, flowID, location) + ListPages.listPages(PROJECT_ID, agentID, flowID, location); } assertThat(stdOut.toString()).contains(name); } From a5d2cac76777cbe91bb11963e9c643ce73697cde Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:45:01 -0500 Subject: [PATCH 12/25] remove try block Change-Id: I9b5f96d7c0ee75745084ed2a277fb9dc8b76a98f --- .../src/test/java/dialogflow/cx/PageManagementIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 35ba0bd60..8de4e900b 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -84,9 +84,9 @@ public static void tearDown() throws IOException, InterruptedException { @Test public void testCreatePage() throws IOException { - try (Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName)) { - pageID = p.getName().split("/")[9]; - } + Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); + pageID = p.getName().split("/")[9]; + assertThat(p.getDisplayName()).isEqualTo(displayName); } From dc15951273c7be79887bdfed141a6466d6c22a22 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 11:45:48 -0500 Subject: [PATCH 13/25] move try block Change-Id: I17eeaf75673cb24682552dd59916c0ad5d68b89a --- .../snippets/src/test/java/dialogflow/cx/PageManagementIT.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 8de4e900b..ba3814e95 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -93,8 +93,9 @@ public void testCreatePage() throws IOException { @Test public void testListPages() throws IOException { String name = "temp_page_" + UUID.randomUUID().toString(); + Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); - try (Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name)) { + try { ListPages.listPages(PROJECT_ID, agentID, flowID, location); } assertThat(stdOut.toString()).contains(name); From 339d56f252449c90beb5f1525d02587c7a6f9d84 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:17:00 -0500 Subject: [PATCH 14/25] remove try block Change-Id: I001e1bd68b5c0953d2c634239828d81bf2576a25 --- .../src/test/java/dialogflow/cx/PageManagementIT.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index ba3814e95..8e9335f8d 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -95,9 +95,7 @@ public void testListPages() throws IOException { String name = "temp_page_" + UUID.randomUUID().toString(); Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); - try { - ListPages.listPages(PROJECT_ID, agentID, flowID, location); - } + ListPages.listPages(PROJECT_ID, agentID, flowID, location); assertThat(stdOut.toString()).contains(name); } From 59479ed9c77b2dd5b39d5f8ba9e8fecf4c308f31 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:27:02 -0500 Subject: [PATCH 15/25] change fulfillmentInfo tag Change-Id: I1454736df9212b36afcd322ef3ce8c677b3500e8 --- ...nfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index ca9a76508..14a381953 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -65,7 +65,7 @@ public void beforeTest() throws IOException { public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = - FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); + FulfillmentInfo.newBuilder().setTag("configure-form-parameters-optional-or-parameter").build(); WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); From a166911e9556ee05d1a9e5e09a3cd05a42a7e654 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:36:03 -0500 Subject: [PATCH 16/25] checkstyle Change-Id: I10d3750668a4acb9ff18f58fdb4f1a19faf6eacc --- ...figureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 14a381953..96b31078a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -65,7 +65,8 @@ public void beforeTest() throws IOException { public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = - FulfillmentInfo.newBuilder().setTag("configure-form-parameters-optional-or-parameter").build(); + FulfillmentInfo.newBuilder() + .setTag("configure-form-parameters-optional-or-parameter").build(); WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); From 72c7080b03fec169fbd7816103a50f3d39ec37c1 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:34:23 -0500 Subject: [PATCH 17/25] add try block to clean up resources Change-Id: I2a56b4f9b558fbebb816fb409fdabff4ee194f2f --- .../main/java/dialogflow/cx/ListPages.java | 19 ++++++++++------- .../java/dialogflow/cx/PageManagementIT.java | 21 ++++++++++++------- .../cx/WebhookValidateFormParameterIT.java | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index f935b6389..f0fd3c926 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -39,11 +39,11 @@ public static void main(String[] args) throws IOException { // Lists all pages from the provided parameters public static void listPages(String projectId, String agentId, String flowId, String location) throws IOException { - PagesClient client = PagesClient.create(); - Builder listRequestBuilder = ListPagesRequest.newBuilder(); + try (PagesClient client = PagesClient.create()) { + Builder listRequestBuilder = ListPagesRequest.newBuilder(); - listRequestBuilder.setParent( - "projects/" + listRequestBuilder.setParent( + "projects/" + projectId + "/locations/" + location @@ -51,12 +51,15 @@ public static void listPages(String projectId, String agentId, String flowId, St + agentId + "/flows/" + flowId); - listRequestBuilder.setLanguageCode("en"); + listRequestBuilder.setLanguageCode("en"); - // Make API request to list all pages in the project - for (Page element : client.listPages(listRequestBuilder.build()).iterateAll()) { - System.out.println(element); + // Make API request to list all pages in the project + for (Page element : client.listPages(listRequestBuilder.build()).iterateAll()) { + System.out.println(element); + } } + + } // [END dialogflow_cx_list_pages] } diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 8e9335f8d..17b729087 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -84,19 +84,24 @@ public static void tearDown() throws IOException, InterruptedException { @Test public void testCreatePage() throws IOException { - Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); - pageID = p.getName().split("/")[9]; - - assertThat(p.getDisplayName()).isEqualTo(displayName); + try { + Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); + pageID = p.getName().split("/")[9]; + assertThat(p.getDisplayName()).isEqualTo(displayName); + } } @Test public void testListPages() throws IOException { String name = "temp_page_" + UUID.randomUUID().toString(); - Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); - - ListPages.listPages(PROJECT_ID, agentID, flowID, location); - assertThat(stdOut.toString()).contains(name); + // Page p + try { + CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, name); + ListPages.listPages(PROJECT_ID, agentID, flowID, location); + assertThat(stdOut.toString()).contains(name); + } catch (Exception e) { + assertThat(e).isEqualTo(""); + } } @Test diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index 7c0652e31..4500e3f94 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -101,6 +101,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String expectedResponse = gson.toJson(webhookResponse); assertThat(responseOut.toString()).isEqualTo(expectedResponse); - Thread.sleep(200); + Thread.sleep(250); } } From 4d9513a5e475cd53d1458af788fb5426de001a15 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:47:23 -0500 Subject: [PATCH 18/25] add catch Change-Id: I7dd46f9543256427e9d86ab4f60b4806bdb8bd9a --- .../snippets/src/test/java/dialogflow/cx/PageManagementIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 17b729087..a29aade72 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -88,6 +88,8 @@ public void testCreatePage() throws IOException { Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); pageID = p.getName().split("/")[9]; assertThat(p.getDisplayName()).isEqualTo(displayName); + } catch (Exception e) { + assertThat(e).isEqualTo(""); } } From f2936a8d61935aa76c709c20f14c27606950586a Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 14:05:36 -0500 Subject: [PATCH 19/25] remove println Change-Id: Idb0f4d75d0e7902a666248c48ed4fc54aeef5e59 --- ...onfigureWebhookToSetFormParametersAsOptionalOrRequired.java | 3 --- .../java/dialogflow/cx/WebhookConfigureSessionParameters.java | 3 --- .../main/java/dialogflow/cx/WebhookValidateFormParameter.java | 2 -- 3 files changed, 8 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 2db56b5de..b94c55242 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -57,9 +57,6 @@ public void service(HttpRequest request, HttpResponse response) throws Exception Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("Response Object: \n"); - System.out.println(jsonResponseObject.toString()); - /* { * "page_info": { * "form_info": { diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index e9c026314..2d59a8ba7 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -49,9 +49,6 @@ public void service(HttpRequest request, HttpResponse response) throws Exception Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("Session Parameter Info: \n"); - System.out.println(jsonResponseObject.toString()); - /** { "session_info": { "parameters": { "order_number": "12345" } } } */ BufferedWriter writer = response.getWriter(); // Sends the webhookResponseObject diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index fadbef573..320b57f3d 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -65,8 +65,6 @@ public void service(HttpRequest request, HttpResponse response) throws Exception Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("Response Object: \n"); - System.out.println(jsonResponseObject.toString()); /** * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", * "required": "true", "state": "INVALID", "value": "123" } ] } }, "session_info": { From d9cbf0af2b3a2c7f699b72f12a1008fce3909681 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Mon, 18 Jul 2022 14:17:40 -0500 Subject: [PATCH 20/25] checkstyle Change-Id: Ie28023c2bf6422a50dc5e09128ede1e49679c95d --- .../test/java/dialogflow/cx/PageManagementIT.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index a29aade72..1eae3e409 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -84,13 +84,13 @@ public static void tearDown() throws IOException, InterruptedException { @Test public void testCreatePage() throws IOException { - try { - Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); - pageID = p.getName().split("/")[9]; - assertThat(p.getDisplayName()).isEqualTo(displayName); - } catch (Exception e) { - assertThat(e).isEqualTo(""); - } + try { + Page p = CreateSimplePage.createPage(PROJECT_ID, agentID, flowID, location, displayName); + pageID = p.getName().split("/")[9]; + assertThat(p.getDisplayName()).isEqualTo(displayName); + } catch (Exception e) { + assertThat(e).isEqualTo(""); + } } @Test From d8fa631698f73196781b08e65d65937d49fd0316 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 18 Jul 2022 19:21:38 +0000 Subject: [PATCH 21/25] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../src/main/java/dialogflow/cx/ListPages.java | 16 +++++++--------- ...oSetFormParametersAsOptionalOrRequiredIT.java | 3 ++- .../java/dialogflow/cx/PageManagementIT.java | 1 - 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index f0fd3c926..68b8d2cd9 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -44,13 +44,13 @@ public static void listPages(String projectId, String agentId, String flowId, St listRequestBuilder.setParent( "projects/" - + projectId - + "/locations/" - + location - + "/agents/" - + agentId - + "/flows/" - + flowId); + + projectId + + "/locations/" + + location + + "/agents/" + + agentId + + "/flows/" + + flowId); listRequestBuilder.setLanguageCode("en"); // Make API request to list all pages in the project @@ -58,8 +58,6 @@ public static void listPages(String projectId, String agentId, String flowId, St System.out.println(element); } } - - } // [END dialogflow_cx_list_pages] } diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 96b31078a..53e30e094 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -66,7 +66,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-form-parameters-optional-or-parameter").build(); + .setTag("configure-form-parameters-optional-or-parameter") + .build(); WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java index 1eae3e409..47c100107 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java @@ -65,7 +65,6 @@ public static void setUp() throws IOException { agentID = parent.split("/")[5]; } - } @AfterClass From 3e2f984a42fd72c0ce3ab1b5db52bbc82101b326 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 19 Jul 2022 09:34:34 -0500 Subject: [PATCH 22/25] add try-with-resources comment to client object creation lines in snippets Change-Id: Ic1acaa6097e972b2db35cca2f5928e826ef08964 --- .../snippets/src/main/java/dialogflow/cx/CreateAgent.java | 3 +++ .../snippets/src/main/java/dialogflow/cx/CreateFlow.java | 5 ++++- .../snippets/src/main/java/dialogflow/cx/CreateIntent.java | 3 +++ .../snippets/src/main/java/dialogflow/cx/CreatePage.java | 3 +++ .../src/main/java/dialogflow/cx/CreateSimplePage.java | 3 +++ .../snippets/src/main/java/dialogflow/cx/DeletePage.java | 4 ++++ .../snippets/src/main/java/dialogflow/cx/DetectIntent.java | 6 +++++- .../src/main/java/dialogflow/cx/DetectIntentAudioInput.java | 4 ++++ .../main/java/dialogflow/cx/DetectIntentDisableWebhook.java | 4 ++++ .../src/main/java/dialogflow/cx/DetectIntentEventInput.java | 4 ++++ .../main/java/dialogflow/cx/DetectIntentIntentInput.java | 4 ++++ .../java/dialogflow/cx/DetectIntentSentimentAnalysis.java | 4 ++++ .../src/main/java/dialogflow/cx/DetectIntentStream.java | 4 ++++ .../dialogflow/cx/DetectIntentStreamingPartialResponse.java | 4 ++++ .../cx/DetectIntentSynthesizeTextToSpeechOutput.java | 4 ++++ .../snippets/src/main/java/dialogflow/cx/ExportAgent.java | 3 +++ samples/snippets/src/main/java/dialogflow/cx/ListPages.java | 3 +++ .../src/main/java/dialogflow/cx/ListTestCaseResults.java | 4 ++++ .../src/main/java/dialogflow/cx/ListTrainingPhrases.java | 4 ++++ .../snippets/src/main/java/dialogflow/cx/UpdateIntent.java | 4 ++++ 20 files changed, 75 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java b/samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java index 2ab019c1e..657abed0e 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java +++ b/samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java @@ -39,6 +39,9 @@ public static Agent createAgent(String parent, String displayName) throws IOExce String apiEndpoint = "global-dialogflow.googleapis.com:443"; AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); + // Note: close() needs to be called on the AgentsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (AgentsClient client = AgentsClient.create(agentsSettings)) { // Set the details of the Agent to create Builder build = Agent.newBuilder(); diff --git a/samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java b/samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java index 3f2b707dd..1719f1526 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java +++ b/samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java @@ -50,7 +50,10 @@ public static Flow createFlow( } FlowsSettings flowsSettings = flowsSettingsBuilder.build(); - // Instantiates a client + // Instantiates a client. + // Note: close() needs to be called on the FlowsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (FlowsClient flowsClient = FlowsClient.create(flowsSettings)) { // Set the project agent name using the projectID (my-project-id), locationID (global), and // agentID (UUID). diff --git a/samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java b/samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java index 603034d8f..3469c1848 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java +++ b/samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java @@ -48,6 +48,9 @@ public static Intent createIntent( IntentsSettings intentsSettings = intentsSettingsBuilder.build(); // Instantiates a client + // Note: close() needs to be called on the IntentsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (IntentsClient intentsClient = IntentsClient.create(intentsSettings)) { // Set the project agent name using the projectID (my-project-id), locationID (global), and // agentID (UUID). diff --git a/samples/snippets/src/main/java/dialogflow/cx/CreatePage.java b/samples/snippets/src/main/java/dialogflow/cx/CreatePage.java index 14162bf8d..b45bc46f8 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/CreatePage.java +++ b/samples/snippets/src/main/java/dialogflow/cx/CreatePage.java @@ -52,6 +52,9 @@ public static Page createPage( PagesSettings pagesSettings = pagesSettingsBuilder.build(); // Instantiates a client + // Note: close() needs to be called on the PagesClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (PagesClient pagesClient = PagesClient.create(pagesSettings)) { // Set the flow name using the projectID (my-project-id), locationID (global), agentID (UUID) // and flowID (UUID). diff --git a/samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java b/samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java index e18b60eeb..26b10e854 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java +++ b/samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java @@ -59,6 +59,9 @@ public static Page createPage( .setPage(pageBuilder); // Make API request to create page + // Note: close() needs to be called on the PagesClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (PagesClient client = PagesClient.create()) { response = client.createPage(createRequestBuilder.build()); System.out.println("Successfully created page!"); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DeletePage.java b/samples/snippets/src/main/java/dialogflow/cx/DeletePage.java index 98bd5e1fd..8403a690a 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DeletePage.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DeletePage.java @@ -40,6 +40,10 @@ public static void main(String[] args) throws IOException { public static void deletePage( String projectId, String agentId, String flowId, String pageId, String location) throws IOException { + + // Note: close() needs to be called on the PagesClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (PagesClient client = PagesClient.create()) { Builder deleteRequestBuilder = DeletePageRequest.newBuilder(); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java index 703f7a773..3109a4fc5 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java @@ -52,7 +52,11 @@ public static Map detectIntent( SessionsSettings sessionsSettings = sessionsSettingsBuilder.build(); Map queryResults = Maps.newHashMap(); - // Instantiates a client + // Instantiates a client. + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { // Set the session name using the projectID (my-project-id), locationID (global), agentID // (UUID), and sessionId (UUID). diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java index e864f381a..36a6a17c7 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java @@ -76,6 +76,10 @@ public static void detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java index c0cf470fe..ee97aabda 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java @@ -68,6 +68,10 @@ public static Map detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java index 5f92199e9..ccd1fe343 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java @@ -62,6 +62,10 @@ public static void detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java index 45af3c567..a0e89547d 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java @@ -62,6 +62,10 @@ public static void detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java index 318242c4f..f69331bbf 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java @@ -68,6 +68,10 @@ public static Map detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java index 96b1799a5..f1d05491e 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java @@ -56,6 +56,10 @@ public static void detectIntentStream( // Instantiates a client by setting the session name. // Format: `projects//locations//agents//sessions/` // Using the same `sessionId` between requests allows continuation of the conversation. + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.of(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java index 81cb534e2..af7258043 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java @@ -56,6 +56,10 @@ public static void detectIntentStreamingPartialResponse( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` // Using the same `sessionId` between requests allows continuation of the conversation. + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.of(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java index d26437eef..74c155f4d 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java +++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java @@ -71,6 +71,10 @@ public static void detectIntent( // Instantiates a client by setting the session name. // Format:`projects//locations//agents//sessions/` + + // Note: close() needs to be called on the SessionsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) { SessionName session = SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java b/samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java index ba908af54..6b431f510 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java @@ -47,6 +47,9 @@ public static void exportAgent(String projectId, String agentId, String location String apiEndpoint = String.format("%s-dialogflow.googleapis.com:443", location); AgentsSettings agentsSettings = AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build(); + // Note: close() needs to be called on the AgentsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (AgentsClient agentsClient = AgentsClient.create(agentsSettings)) { ExportAgentRequest request = ExportAgentRequest.newBuilder() diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index f0fd3c926..3dd413236 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -39,6 +39,9 @@ public static void main(String[] args) throws IOException { // Lists all pages from the provided parameters public static void listPages(String projectId, String agentId, String flowId, String location) throws IOException { + // Note: close() needs to be called on the PagesClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (PagesClient client = PagesClient.create()) { Builder listRequestBuilder = ListPagesRequest.newBuilder(); diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java index 3293a8ce2..2f34d6530 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java @@ -57,6 +57,10 @@ public static void listTestCaseResults( TestCasesSettings.newBuilder() .setEndpoint(location + "-dialogflow.googleapis.com:443") .build(); + + // Note: close() needs to be called on the TestCasesClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (TestCasesClient client = TestCasesClient.create(testCasesSettings)) { for (TestCaseResult element : client.listTestCaseResults(req.build()).iterateAll()) { System.out.println(element); diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java b/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java index 2bd0e73ae..425753051 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java @@ -38,6 +38,10 @@ public static void main(String[] args) throws IOException { // DialogFlow API List Training Phrases sample. public static void listTrainingPhrases( String projectId, String location, String agentId, String intentId) throws IOException { + + // Note: close() needs to be called on the IntentsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (IntentsClient client = IntentsClient.create()) { // Set the intent name IntentName name = IntentName.of(projectId, location, agentId, intentId); diff --git a/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java b/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java index 73a878898..ea16649f6 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java +++ b/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java @@ -41,6 +41,10 @@ public static void main(String[] args) throws IOException { public static void updateIntent( String projectId, String agentId, String intentId, String location, String displayName) throws IOException { + + // Note: close() needs to be called on the IntentsClient object to clean up resources + // such as threads. In the example below, try-with-resources is used, + // which automatically calls close(). try (IntentsClient client = IntentsClient.create()) { String intentPath = "projects/" From 2fbdbf5196e66ab73414d0f3b60ffb383d213c8c Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:24:34 -0500 Subject: [PATCH 23/25] add string.format Change-Id: I25e7e803c8d0b40e6503b6ed8c5fd1c872c4506b --- .../src/main/java/dialogflow/cx/ListPages.java | 16 +++++++--------- .../java/dialogflow/cx/UpdateIntentTest.java | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index f9c8c8a53..5f9a6ff3e 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -45,15 +45,13 @@ public static void listPages(String projectId, String agentId, String flowId, St try (PagesClient client = PagesClient.create()) { Builder listRequestBuilder = ListPagesRequest.newBuilder(); - listRequestBuilder.setParent( - "projects/" - + projectId - + "/locations/" - + location - + "/agents/" - + agentId - + "/flows/" - + flowId); + String parentPath = String + .format("projects/%s/locations/%s/agents/%s/flow/%s", + projectId, + location, + agentId, + flowId); + listRequestBuilder.setParent(parentPath); listRequestBuilder.setLanguageCode("en"); // Make API request to list all pages in the project diff --git a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java index afac34e1c..635b16b78 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java @@ -60,7 +60,7 @@ public void setUp() throws IOException { build.setTimeZone("America/Los_Angeles"); Agent agent = build.build(); - String parentPath = "projects/" + PROJECT_ID + "/locations/global"; + String parentPath = String.format("projects/%s/locations/global", PROJECT_ID); parent = agentsClient.createAgent(parentPath, agent).getName(); From 84a71da5baa9ae96e022959bc111d023228928c4 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:36:20 -0500 Subject: [PATCH 24/25] update parentPath Change-Id: Id387695b0d86c30c74f796e7f57db6e1f8be43bd --- samples/snippets/src/main/java/dialogflow/cx/ListPages.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index 5f9a6ff3e..88d35b504 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -46,7 +46,7 @@ public static void listPages(String projectId, String agentId, String flowId, St Builder listRequestBuilder = ListPagesRequest.newBuilder(); String parentPath = String - .format("projects/%s/locations/%s/agents/%s/flow/%s", + .format("projects/%s/locations/%s/agents/%s/flows/%s", projectId, location, agentId, From 58cdd111b3c3c172cdfede755cdd93f4c0f5115b Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 19 Jul 2022 18:08:31 +0000 Subject: [PATCH 25/25] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../snippets/src/main/java/dialogflow/cx/ListPages.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java index 88d35b504..9a180081f 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ListPages.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ListPages.java @@ -45,12 +45,9 @@ public static void listPages(String projectId, String agentId, String flowId, St try (PagesClient client = PagesClient.create()) { Builder listRequestBuilder = ListPagesRequest.newBuilder(); - String parentPath = String - .format("projects/%s/locations/%s/agents/%s/flows/%s", - projectId, - location, - agentId, - flowId); + String parentPath = + String.format( + "projects/%s/locations/%s/agents/%s/flows/%s", projectId, location, agentId, flowId); listRequestBuilder.setParent(parentPath); listRequestBuilder.setLanguageCode("en");