From 27217aa74ef28ceea333f5b6a36ce8ade663a4c7 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Wed, 18 May 2022 17:17:45 -0700 Subject: [PATCH 01/72] docs:add configure webhook to set form parameter as optional or required sample and test Change-Id: I75bed489bd8abefca60263acb266501810c0e856 --- ...SetFormParametersAsOptionalOrRequired.java | 64 +++++++++++++++++ ...ormParametersAsOptionalOrRequiredTest.java | 72 +++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java new file mode 100644 index 000000000..e792c8ad8 --- /dev/null +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -0,0 +1,64 @@ +/* + * Copyright 2022 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 dialogflow.cx; + +// The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook + +// [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] + +// TODO: Change class name to Example +// TODO: add GSON dependency to Pom file +// (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) +// TODO: Uncomment the line bellow before running cloud function +// package com.example; + +import com.google.cloud.functions.HttpFunction; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.BufferedWriter; + +public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements HttpFunction { + @Override + public void service(HttpRequest request, HttpResponse response) throws Exception { + JsonParser parser = new JsonParser(); + Gson gson = new GsonBuilder().create(); + JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); + + // For more information on the structure of this object, visit https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment + JsonObject responseObject = null; + + // Constructing the response jsonObject + responseObject = + parser + .parse( + "{\"page_info\":{\"form_info\":{\"parameter_info\":[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}") + .getAsJsonObject(); + BufferedWriter writer = response.getWriter(); + + System.out.println("Parameter Info: \n"); + System.out.println(responseObject.toString()); + // System.out.println(responseObject.pageInfo.formInfo.parameterInfo[0]); + + //Sends the responseObject + writer.write(responseObject.toString()); + } +} +// [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java new file mode 100644 index 000000000..74e28a00f --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2022 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 dialogflow.cx; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { + + @Mock private HttpRequest request; + @Mock private HttpResponse response; + + private BufferedWriter writerOut; + private StringWriter responseOut; + private static final Gson gson = new Gson(); + + @Before + public void beforeTest() throws IOException { + MockitoAnnotations.initMocks(this); + + // use an empty string as the default request content + BufferedReader reader = new BufferedReader(new StringReader("")); + when(request.getReader()).thenReturn(reader); + + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + when(response.getWriter()).thenReturn(writerOut); + } + + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; + + BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + + when(request.getReader()).thenReturn(jsonReader); + + new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); + writerOut.flush(); + + String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + + assertThat(responseOut.toString()).isEqualTo(expectedResponse); + } +} \ No newline at end of file From 9ec52bf2add90b93cd1cd648307146c23385dceb Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Wed, 18 May 2022 17:23:38 -0700 Subject: [PATCH 02/72] docs: fix checkstyle Change-Id: I18be2a5c1d46ac9838cf4a15ab87dcf331ee26ee --- ...onfigureWebhookToSetFormParametersAsOptionalOrRequired.java | 3 ++- ...gureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index e792c8ad8..3bbcdb4cd 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -49,7 +49,8 @@ public void service(HttpRequest request, HttpResponse response) throws Exception responseObject = parser .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}") + "{\"page_info\":{\"form_info\":{\"parameter_info\": + [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 74e28a00f..232ef94f2 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -65,7 +65,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\": + [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From 47d91ad58953cfd89e0b928c2294d6452201b6a7 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Wed, 18 May 2022 17:44:18 -0700 Subject: [PATCH 03/72] fix checkstyle Change-Id: Ia85899f678ef1382718c2443a682770417340af2 --- ...nfigureWebhookToSetFormParametersAsOptionalOrRequired.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 3bbcdb4cd..56758535e 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -50,13 +50,13 @@ public void service(HttpRequest request, HttpResponse response) throws Exception parser .parse( "{\"page_info\":{\"form_info\":{\"parameter_info\": - [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}") + [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"} + ]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); System.out.println("Parameter Info: \n"); System.out.println(responseObject.toString()); - // System.out.println(responseObject.pageInfo.formInfo.parameterInfo[0]); //Sends the responseObject writer.write(responseObject.toString()); From fec80c60dce126d34a98cd0c05d4f2b1af250895 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:14:51 -0700 Subject: [PATCH 04/72] fix checkstyle Change-Id: I4dd56107a3197027f287980fa87a15e962154783 --- ...SetFormParametersAsOptionalOrRequired.java | 6 +- .../cx/WebhookConfigureSessionParameters.java | 76 +++++++++++++++++++ ...eSessionParametersEnableAgentResponse.java | 76 +++++++++++++++++++ ...ureSessionParametersTriggerTransition.java | 76 +++++++++++++++++++ .../cx/WebhookValidateFormParameter.java | 76 +++++++++++++++++++ .../cx/WebhookConfigureSessionParameters.java | 74 ++++++++++++++++++ ...eSessionParametersEnableAgentResponse.java | 74 ++++++++++++++++++ ...ureSessionParametersTriggerTransition.java | 74 ++++++++++++++++++ .../cx/WebhookValidateFormParameter.java | 74 ++++++++++++++++++ 9 files changed, 603 insertions(+), 3 deletions(-) create mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java create mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java create mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java create mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 56758535e..184aaaeec 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -49,9 +49,9 @@ public void service(HttpRequest request, HttpResponse response) throws Exception responseObject = parser .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\": - [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"} - ]}}}") + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}" + + "]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java new file mode 100644 index 000000000..bb8527e7b --- /dev/null +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -0,0 +1,76 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook + +// // [START dialogflow_webhook] + +// // TODO: Change class name to Example +// // TODO: add GSON dependency to Pom file +// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) +// // TODO: Uncomment the line bellow before running cloud function +// // package com.example; + +// import com.google.cloud.functions.HttpFunction; +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import com.google.gson.GsonBuilder; +// import com.google.gson.JsonObject; +// import com.google.gson.JsonParser; +// import java.io.BufferedWriter; + +// public class BasicWebhook implements HttpFunction { +// @Override +// public void service(HttpRequest request, HttpResponse response) throws Exception { +// JsonParser parser = new JsonParser(); +// Gson gson = new GsonBuilder().create(); +// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); + +// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") +// .getAsJsonPrimitive("tag").toString(); +// JsonObject responseObject = null; +// String defaultIntent = "\"Default Welcome Intent\""; +// String secondIntent = "\"get-agent-name\""; +// String responseText = ""; + +// // Compares the Intent Tag to provide the correct response +// if (requestTag.equals(defaultIntent)) { +// responseText = "\"Hello from a Java GCF Webhook\""; +// } else if (requestTag.equals(secondIntent)) { +// responseText = "\"My name is Flowhook\""; +// } else { +// responseText = "\"Sorry I didn't get that\""; +// } + +// // Constructing the response jsonObject +// responseObject = +// parser +// .parse( +// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" +// + responseText +// + "] } } ] } }") +// .getAsJsonObject(); +// BufferedWriter writer = response.getWriter(); + +// //Sends the responseObject +// writer.write(responseObject.toString()); +// } +// } +// // [END dialogflow_webhook] \ No newline at end of file diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java new file mode 100644 index 000000000..bb8527e7b --- /dev/null +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -0,0 +1,76 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook + +// // [START dialogflow_webhook] + +// // TODO: Change class name to Example +// // TODO: add GSON dependency to Pom file +// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) +// // TODO: Uncomment the line bellow before running cloud function +// // package com.example; + +// import com.google.cloud.functions.HttpFunction; +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import com.google.gson.GsonBuilder; +// import com.google.gson.JsonObject; +// import com.google.gson.JsonParser; +// import java.io.BufferedWriter; + +// public class BasicWebhook implements HttpFunction { +// @Override +// public void service(HttpRequest request, HttpResponse response) throws Exception { +// JsonParser parser = new JsonParser(); +// Gson gson = new GsonBuilder().create(); +// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); + +// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") +// .getAsJsonPrimitive("tag").toString(); +// JsonObject responseObject = null; +// String defaultIntent = "\"Default Welcome Intent\""; +// String secondIntent = "\"get-agent-name\""; +// String responseText = ""; + +// // Compares the Intent Tag to provide the correct response +// if (requestTag.equals(defaultIntent)) { +// responseText = "\"Hello from a Java GCF Webhook\""; +// } else if (requestTag.equals(secondIntent)) { +// responseText = "\"My name is Flowhook\""; +// } else { +// responseText = "\"Sorry I didn't get that\""; +// } + +// // Constructing the response jsonObject +// responseObject = +// parser +// .parse( +// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" +// + responseText +// + "] } } ] } }") +// .getAsJsonObject(); +// BufferedWriter writer = response.getWriter(); + +// //Sends the responseObject +// writer.write(responseObject.toString()); +// } +// } +// // [END dialogflow_webhook] \ No newline at end of file diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java new file mode 100644 index 000000000..bb8527e7b --- /dev/null +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -0,0 +1,76 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook + +// // [START dialogflow_webhook] + +// // TODO: Change class name to Example +// // TODO: add GSON dependency to Pom file +// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) +// // TODO: Uncomment the line bellow before running cloud function +// // package com.example; + +// import com.google.cloud.functions.HttpFunction; +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import com.google.gson.GsonBuilder; +// import com.google.gson.JsonObject; +// import com.google.gson.JsonParser; +// import java.io.BufferedWriter; + +// public class BasicWebhook implements HttpFunction { +// @Override +// public void service(HttpRequest request, HttpResponse response) throws Exception { +// JsonParser parser = new JsonParser(); +// Gson gson = new GsonBuilder().create(); +// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); + +// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") +// .getAsJsonPrimitive("tag").toString(); +// JsonObject responseObject = null; +// String defaultIntent = "\"Default Welcome Intent\""; +// String secondIntent = "\"get-agent-name\""; +// String responseText = ""; + +// // Compares the Intent Tag to provide the correct response +// if (requestTag.equals(defaultIntent)) { +// responseText = "\"Hello from a Java GCF Webhook\""; +// } else if (requestTag.equals(secondIntent)) { +// responseText = "\"My name is Flowhook\""; +// } else { +// responseText = "\"Sorry I didn't get that\""; +// } + +// // Constructing the response jsonObject +// responseObject = +// parser +// .parse( +// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" +// + responseText +// + "] } } ] } }") +// .getAsJsonObject(); +// BufferedWriter writer = response.getWriter(); + +// //Sends the responseObject +// writer.write(responseObject.toString()); +// } +// } +// // [END dialogflow_webhook] \ No newline at end of file diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java new file mode 100644 index 000000000..bb8527e7b --- /dev/null +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -0,0 +1,76 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook + +// // [START dialogflow_webhook] + +// // TODO: Change class name to Example +// // TODO: add GSON dependency to Pom file +// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) +// // TODO: Uncomment the line bellow before running cloud function +// // package com.example; + +// import com.google.cloud.functions.HttpFunction; +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import com.google.gson.GsonBuilder; +// import com.google.gson.JsonObject; +// import com.google.gson.JsonParser; +// import java.io.BufferedWriter; + +// public class BasicWebhook implements HttpFunction { +// @Override +// public void service(HttpRequest request, HttpResponse response) throws Exception { +// JsonParser parser = new JsonParser(); +// Gson gson = new GsonBuilder().create(); +// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); + +// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") +// .getAsJsonPrimitive("tag").toString(); +// JsonObject responseObject = null; +// String defaultIntent = "\"Default Welcome Intent\""; +// String secondIntent = "\"get-agent-name\""; +// String responseText = ""; + +// // Compares the Intent Tag to provide the correct response +// if (requestTag.equals(defaultIntent)) { +// responseText = "\"Hello from a Java GCF Webhook\""; +// } else if (requestTag.equals(secondIntent)) { +// responseText = "\"My name is Flowhook\""; +// } else { +// responseText = "\"Sorry I didn't get that\""; +// } + +// // Constructing the response jsonObject +// responseObject = +// parser +// .parse( +// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" +// + responseText +// + "] } } ] } }") +// .getAsJsonObject(); +// BufferedWriter writer = response.getWriter(); + +// //Sends the responseObject +// writer.write(responseObject.toString()); +// } +// } +// // [END dialogflow_webhook] \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java new file mode 100644 index 000000000..75b59d58d --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -0,0 +1,74 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// import static com.google.common.truth.Truth.assertThat; +// import static org.mockito.Mockito.when; + +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import java.io.BufferedReader; +// import java.io.BufferedWriter; +// import java.io.IOException; +// import java.io.StringReader; +// import java.io.StringWriter; +// import org.junit.Before; +// import org.junit.Test; +// import org.mockito.Mock; +// import org.mockito.MockitoAnnotations; + +// public class BasicWebhookIT { + +// @Mock private HttpRequest request; +// @Mock private HttpResponse response; + +// private BufferedWriter writerOut; +// private StringWriter responseOut; +// private static final Gson gson = new Gson(); + +// @Before +// public void beforeTest() throws IOException { +// MockitoAnnotations.initMocks(this); + +// // use an empty string as the default request content +// BufferedReader reader = new BufferedReader(new StringReader("")); +// when(request.getReader()).thenReturn(reader); + +// responseOut = new StringWriter(); +// writerOut = new BufferedWriter(responseOut); +// when(response.getWriter()).thenReturn(writerOut); +// } + +// @Test +// public void helloHttp_bodyParamsPost() throws IOException, Exception { +// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; + +// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + +// when(request.getReader()).thenReturn(jsonReader); + +// new BasicWebhook().service(request, response); +// writerOut.flush(); + +// String expectedResponse = +// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" +// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; + +// assertThat(responseOut.toString()).isEqualTo(expectedResponse); +// } +// } \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java new file mode 100644 index 000000000..75b59d58d --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -0,0 +1,74 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// import static com.google.common.truth.Truth.assertThat; +// import static org.mockito.Mockito.when; + +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import java.io.BufferedReader; +// import java.io.BufferedWriter; +// import java.io.IOException; +// import java.io.StringReader; +// import java.io.StringWriter; +// import org.junit.Before; +// import org.junit.Test; +// import org.mockito.Mock; +// import org.mockito.MockitoAnnotations; + +// public class BasicWebhookIT { + +// @Mock private HttpRequest request; +// @Mock private HttpResponse response; + +// private BufferedWriter writerOut; +// private StringWriter responseOut; +// private static final Gson gson = new Gson(); + +// @Before +// public void beforeTest() throws IOException { +// MockitoAnnotations.initMocks(this); + +// // use an empty string as the default request content +// BufferedReader reader = new BufferedReader(new StringReader("")); +// when(request.getReader()).thenReturn(reader); + +// responseOut = new StringWriter(); +// writerOut = new BufferedWriter(responseOut); +// when(response.getWriter()).thenReturn(writerOut); +// } + +// @Test +// public void helloHttp_bodyParamsPost() throws IOException, Exception { +// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; + +// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + +// when(request.getReader()).thenReturn(jsonReader); + +// new BasicWebhook().service(request, response); +// writerOut.flush(); + +// String expectedResponse = +// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" +// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; + +// assertThat(responseOut.toString()).isEqualTo(expectedResponse); +// } +// } \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java new file mode 100644 index 000000000..75b59d58d --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -0,0 +1,74 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// import static com.google.common.truth.Truth.assertThat; +// import static org.mockito.Mockito.when; + +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import java.io.BufferedReader; +// import java.io.BufferedWriter; +// import java.io.IOException; +// import java.io.StringReader; +// import java.io.StringWriter; +// import org.junit.Before; +// import org.junit.Test; +// import org.mockito.Mock; +// import org.mockito.MockitoAnnotations; + +// public class BasicWebhookIT { + +// @Mock private HttpRequest request; +// @Mock private HttpResponse response; + +// private BufferedWriter writerOut; +// private StringWriter responseOut; +// private static final Gson gson = new Gson(); + +// @Before +// public void beforeTest() throws IOException { +// MockitoAnnotations.initMocks(this); + +// // use an empty string as the default request content +// BufferedReader reader = new BufferedReader(new StringReader("")); +// when(request.getReader()).thenReturn(reader); + +// responseOut = new StringWriter(); +// writerOut = new BufferedWriter(responseOut); +// when(response.getWriter()).thenReturn(writerOut); +// } + +// @Test +// public void helloHttp_bodyParamsPost() throws IOException, Exception { +// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; + +// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + +// when(request.getReader()).thenReturn(jsonReader); + +// new BasicWebhook().service(request, response); +// writerOut.flush(); + +// String expectedResponse = +// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" +// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; + +// assertThat(responseOut.toString()).isEqualTo(expectedResponse); +// } +// } \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java new file mode 100644 index 000000000..75b59d58d --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -0,0 +1,74 @@ +// /* +// * Copyright 2022 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.dialogflow.cx; + +// import static com.google.common.truth.Truth.assertThat; +// import static org.mockito.Mockito.when; + +// import com.google.cloud.functions.HttpRequest; +// import com.google.cloud.functions.HttpResponse; +// import com.google.gson.Gson; +// import java.io.BufferedReader; +// import java.io.BufferedWriter; +// import java.io.IOException; +// import java.io.StringReader; +// import java.io.StringWriter; +// import org.junit.Before; +// import org.junit.Test; +// import org.mockito.Mock; +// import org.mockito.MockitoAnnotations; + +// public class BasicWebhookIT { + +// @Mock private HttpRequest request; +// @Mock private HttpResponse response; + +// private BufferedWriter writerOut; +// private StringWriter responseOut; +// private static final Gson gson = new Gson(); + +// @Before +// public void beforeTest() throws IOException { +// MockitoAnnotations.initMocks(this); + +// // use an empty string as the default request content +// BufferedReader reader = new BufferedReader(new StringReader("")); +// when(request.getReader()).thenReturn(reader); + +// responseOut = new StringWriter(); +// writerOut = new BufferedWriter(responseOut); +// when(response.getWriter()).thenReturn(writerOut); +// } + +// @Test +// public void helloHttp_bodyParamsPost() throws IOException, Exception { +// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; + +// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + +// when(request.getReader()).thenReturn(jsonReader); + +// new BasicWebhook().service(request, response); +// writerOut.flush(); + +// String expectedResponse = +// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" +// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; + +// assertThat(responseOut.toString()).isEqualTo(expectedResponse); +// } +// } \ No newline at end of file From 782689312807dc2e0f682a42b2dd6f02af21a794 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:25:35 -0700 Subject: [PATCH 05/72] fix multiline string Change-Id: I8dcdb0dcaad486a2fb69e0737df99bda49b28839 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 232ef94f2..59aca1b1b 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -65,8 +65,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\": - [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From b0ea8846b8f6b254d5059511f1413f3644aa2c71 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:29:52 -0700 Subject: [PATCH 06/72] fix checkstyle violations Change-Id: I5f4521b3e50660f30f9f73da3d939da213084d28 --- .../cx/WebhookConfigureSessionParameters.java | 2 +- ...eSessionParametersEnableAgentResponse.java | 2 +- ...ureSessionParametersTriggerTransition.java | 2 +- .../cx/WebhookValidateFormParameter.java | 38 +++++++------------ .../cx/WebhookConfigureSessionParameters.java | 2 +- ...eSessionParametersEnableAgentResponse.java | 2 +- ...ureSessionParametersTriggerTransition.java | 2 +- ... => WebhookValidateFormParameterTest.java} | 13 +++---- 8 files changed, 26 insertions(+), 37 deletions(-) rename samples/snippets/src/test/java/dialogflow/cx/{WebhookValidateFormParameter.java => WebhookValidateFormParameterTest.java} (84%) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index bb8527e7b..a1a81a409 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java index bb8527e7b..a1a81a409 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java index bb8527e7b..a1a81a409 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index bb8527e7b..fb5c5320b 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,11 +14,11 @@ // * limitations under the License. // */ -// package com.example.dialogflow.cx; +// package dialogflow.cx; // // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook -// // [START dialogflow_webhook] +// // [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] // // TODO: Change class name to Example // // TODO: add GSON dependency to Pom file @@ -35,42 +35,32 @@ // import com.google.gson.JsonParser; // import java.io.BufferedWriter; -// public class BasicWebhook implements HttpFunction { +// public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements HttpFunction { // @Override // public void service(HttpRequest request, HttpResponse response) throws Exception { // JsonParser parser = new JsonParser(); // Gson gson = new GsonBuilder().create(); // JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); -// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment -// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") -// .getAsJsonPrimitive("tag").toString(); +// // For more information on the structure of this object, visit https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment // JsonObject responseObject = null; -// String defaultIntent = "\"Default Welcome Intent\""; -// String secondIntent = "\"get-agent-name\""; -// String responseText = ""; - -// // Compares the Intent Tag to provide the correct response -// if (requestTag.equals(defaultIntent)) { -// responseText = "\"Hello from a Java GCF Webhook\""; -// } else if (requestTag.equals(secondIntent)) { -// responseText = "\"My name is Flowhook\""; -// } else { -// responseText = "\"Sorry I didn't get that\""; -// } // // Constructing the response jsonObject + +// String responseString = String.join("{\"page_info\":{\"form_info\":{\"parameter_info\":", +// "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}", +// "]}}}"); // responseObject = // parser -// .parse( -// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" -// + responseText -// + "] } } ] } }") +// .parse(responseString); // .getAsJsonObject(); // BufferedWriter writer = response.getWriter(); +// System.out.println("Parameter Info: \n"); +// System.out.println(responseObject.toString()); + // //Sends the responseObject // writer.write(responseObject.toString()); // } // } -// // [END dialogflow_webhook] \ No newline at end of file +// // [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 75b59d58d..d068de36a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java index 75b59d58d..d068de36a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java index 75b59d58d..d068de36a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java similarity index 84% rename from samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java rename to samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 75b59d58d..6bf00cba2 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -14,7 +14,7 @@ // * limitations under the License. // */ -// package com.example.dialogflow.cx; +// package dialogflow.cx; // import static com.google.common.truth.Truth.assertThat; // import static org.mockito.Mockito.when; @@ -32,7 +32,7 @@ // import org.mockito.Mock; // import org.mockito.MockitoAnnotations; -// public class BasicWebhookIT { +// public class WebhookValidateFormParameter { // @Mock private HttpRequest request; // @Mock private HttpResponse response; @@ -56,18 +56,17 @@ // @Test // public void helloHttp_bodyParamsPost() throws IOException, Exception { -// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; +// String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; // BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); // when(request.getReader()).thenReturn(jsonReader); -// new BasicWebhook().service(request, response); +// new WebhookValidateFormParameter().service(request, response); // writerOut.flush(); -// String expectedResponse = -// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" -// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; +// String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\": +// [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; // assertThat(responseOut.toString()).isEqualTo(expectedResponse); // } From acd66593cd4ba3f190177dbc7762e1e4e5508120 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:31:56 -0700 Subject: [PATCH 07/72] fix checkstyle violations Change-Id: I39dedfba1b62be5cb4580a42dde270146f3b6f97 --- ...igureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 59aca1b1b..0e4fe94dc 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -66,7 +66,7 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { writerOut.flush(); String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From d9fb52271ae28614504a539389655140c1f5bb6e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:38:31 -0700 Subject: [PATCH 08/72] remove unused variable Change-Id: Ic54ae0d1f091079661f3fa67097cdcd2e888dc90 --- ...figureWebhookToSetFormParametersAsOptionalOrRequired.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 184aaaeec..6d388d654 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -21,8 +21,6 @@ // [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] // TODO: Change class name to Example -// TODO: add GSON dependency to Pom file -// (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) // TODO: Uncomment the line bellow before running cloud function // package com.example; @@ -30,7 +28,6 @@ import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.BufferedWriter; @@ -39,8 +36,6 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements @Override public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - Gson gson = new GsonBuilder().create(); - JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); // For more information on the structure of this object, visit https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment JsonObject responseObject = null; From fedcc6b6849e025e63b2c987dc5c04d233916aef Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 19 May 2022 10:39:42 -0700 Subject: [PATCH 09/72] fix checkstyle violations Change-Id: Ifd303b7395844240dca0b29cde9b791112fcabe5 --- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 6bf00cba2..380266662 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -1,4 +1,4 @@ -// /* +/* // * Copyright 2022 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); From 3b3d65ff0a39cac9bbb86566d1c59666e07d12d4 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 19 May 2022 17:49:02 +0000 Subject: [PATCH 10/72] =?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 --- README.md | 5 +++++ ...bhookToSetFormParametersAsOptionalOrRequired.java | 12 ++++++------ .../cx/WebhookConfigureSessionParameters.java | 5 +++-- ...onfigureSessionParametersEnableAgentResponse.java | 5 +++-- ...kConfigureSessionParametersTriggerTransition.java | 5 +++-- .../dialogflow/cx/WebhookValidateFormParameter.java | 3 ++- ...kToSetFormParametersAsOptionalOrRequiredTest.java | 7 ++++--- .../cx/WebhookConfigureSessionParameters.java | 4 ++-- ...onfigureSessionParametersEnableAgentResponse.java | 4 ++-- ...kConfigureSessionParametersTriggerTransition.java | 4 ++-- .../cx/WebhookValidateFormParameterTest.java | 2 +- 11 files changed, 33 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ca21094a7..c64f82679 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-dialogflow-cx | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | +| Configure Webhook To Set Form Parameters As Optional Or Required | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java) | | Create Agent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/CreateAgent.java) | | Create Flow | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/CreateFlow.java) | | Create Intent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/CreateIntent.java) | @@ -92,6 +93,10 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-dialogflow-cx | List Test Case Results | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java) | | List Training Phrases | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java) | | Update Intent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java) | +| Webhook Configure Session Parameters | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java) | +| Webhook Configure Session Parameters Enable Agent Response | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java) | +| Webhook Configure Session Parameters Trigger Transition | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java) | +| Webhook Validate Form Parameter | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java) | diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 6d388d654..95169fc84 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -27,7 +27,6 @@ import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.BufferedWriter; @@ -37,23 +36,24 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - // For more information on the structure of this object, visit https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment + // For more information on the structure of this object, visit + // https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment JsonObject responseObject = null; // Constructing the response jsonObject responseObject = parser .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}" - + "]}}}") + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}" + + "]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); System.out.println("Parameter Info: \n"); System.out.println(responseObject.toString()); - //Sends the responseObject + // Sends the responseObject writer.write(responseObject.toString()); } } diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index a1a81a409..f53cb59d6 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -42,7 +42,8 @@ // Gson gson = new GsonBuilder().create(); // JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); -// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// // For more information on the structure of this object +// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment // String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") // .getAsJsonPrimitive("tag").toString(); // JsonObject responseObject = null; @@ -73,4 +74,4 @@ // writer.write(responseObject.toString()); // } // } -// // [END dialogflow_webhook] \ No newline at end of file +// // [END dialogflow_webhook] diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java index a1a81a409..f53cb59d6 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -42,7 +42,8 @@ // Gson gson = new GsonBuilder().create(); // JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); -// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// // For more information on the structure of this object +// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment // String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") // .getAsJsonPrimitive("tag").toString(); // JsonObject responseObject = null; @@ -73,4 +74,4 @@ // writer.write(responseObject.toString()); // } // } -// // [END dialogflow_webhook] \ No newline at end of file +// // [END dialogflow_webhook] diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java index a1a81a409..f53cb59d6 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -42,7 +42,8 @@ // Gson gson = new GsonBuilder().create(); // JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); -// // For more information on the structure of this object https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// // For more information on the structure of this object +// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment // String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") // .getAsJsonPrimitive("tag").toString(); // JsonObject responseObject = null; @@ -73,4 +74,4 @@ // writer.write(responseObject.toString()); // } // } -// // [END dialogflow_webhook] \ No newline at end of file +// // [END dialogflow_webhook] diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index fb5c5320b..8ed51a5e4 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -42,7 +42,8 @@ // Gson gson = new GsonBuilder().create(); // JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); -// // For more information on the structure of this object, visit https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment +// // For more information on the structure of this object, visit +// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment // JsonObject responseObject = null; // // Constructing the response jsonObject diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 0e4fe94dc..f0d56e83c 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -65,9 +65,10 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + String expectedResponse = + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java index d068de36a..9f86fd0f5 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -65,10 +65,10 @@ // new BasicWebhook().service(request, response); // writerOut.flush(); -// String expectedResponse = +// String expectedResponse = // "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" // + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; // assertThat(responseOut.toString()).isEqualTo(expectedResponse); // } -// } \ No newline at end of file +// } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java index d068de36a..9f86fd0f5 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java @@ -65,10 +65,10 @@ // new BasicWebhook().service(request, response); // writerOut.flush(); -// String expectedResponse = +// String expectedResponse = // "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" // + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; // assertThat(responseOut.toString()).isEqualTo(expectedResponse); // } -// } \ No newline at end of file +// } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java index d068de36a..9f86fd0f5 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java @@ -65,10 +65,10 @@ // new BasicWebhook().service(request, response); // writerOut.flush(); -// String expectedResponse = +// String expectedResponse = // "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" // + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; // assertThat(responseOut.toString()).isEqualTo(expectedResponse); // } -// } \ No newline at end of file +// } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 380266662..adc80500e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -70,4 +70,4 @@ // assertThat(responseOut.toString()).isEqualTo(expectedResponse); // } -// } \ No newline at end of file +// } From aec26afd535e71c2dd9670038aa8bdfd5242a431 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Wed, 8 Jun 2022 12:24:56 -0500 Subject: [PATCH 11/72] fix checkstyle violations Change-Id: I59e45da9f9e57b327a527f1405816ac1275fe1c8 --- ...onfigureWebhookToSetFormParametersAsOptionalOrRequired.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 6d388d654..baa37bb58 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -45,7 +45,8 @@ public void service(HttpRequest request, HttpResponse response) throws Exception parser .parse( "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"VALID\"}" + "]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); From 4428653c158183c45e49ba39610518e7d318b603 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Wed, 8 Jun 2022 12:33:31 -0500 Subject: [PATCH 12/72] fix checkstyle violations Change-Id: I70ff4118cc8b3111a3ed55a2fae32258d3f6819c --- ...igureWebhookToSetFormParametersAsOptionalOrRequired.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 7ba522f13..8f124d8b1 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -44,16 +44,10 @@ public void service(HttpRequest request, HttpResponse response) throws Exception responseObject = parser .parse( -<<<<<<< HEAD "{\"page_info\":{\"form_info\":{\"parameter_info\":" + "[{\"display_name\":\"order-number\",\"required\":" + "\"true\",\"state\":\"VALID\"}" + "]}}}") -======= - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}" - + "]}}}") ->>>>>>> 3b3d65ff0a39cac9bbb86566d1c59666e07d12d4 .getAsJsonObject(); BufferedWriter writer = response.getWriter(); From f6d9d1dd4fda8942386db4eacfffb48b75d97a9b Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 8 Jun 2022 17:37:02 +0000 Subject: [PATCH 13/72] =?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 --- README.md | 6 +++--- ...ureWebhookToSetFormParametersAsOptionalOrRequired.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c64f82679..5f0c7dbcc 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-dialogflow-cx - 0.12.1 + 0.13.0 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.12.1' +implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.13.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.12.1" +libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.13.0" ``` ## Authentication diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 8f124d8b1..19feced91 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -44,10 +44,10 @@ public void service(HttpRequest request, HttpResponse response) throws Exception responseObject = parser .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"VALID\"}" - + "]}}}") + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"VALID\"}" + + "]}}}") .getAsJsonObject(); BufferedWriter writer = response.getWriter(); From fe9b21222ec1b3d402cf9160e682cdda6fe3e654 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:22:20 -0500 Subject: [PATCH 14/72] remove unnecessary samples Change-Id: I395dd5abc9a48733126ab0ecdc2a974fbf9eb471 --- ...SetFormParametersAsOptionalOrRequired.java | 5 +- .../cx/WebhookConfigureSessionParameters.java | 133 ++++++++---------- ...eSessionParametersEnableAgentResponse.java | 77 ---------- ...ureSessionParametersTriggerTransition.java | 77 ---------- .../cx/WebhookConfigureSessionParameters.java | 74 ---------- ...eSessionParametersEnableAgentResponse.java | 74 ---------- ...WebhookConfigureSessionParametersTest.java | 76 ++++++++++ ...ureSessionParametersTriggerTransition.java | 74 ---------- 8 files changed, 134 insertions(+), 456 deletions(-) delete mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java delete mode 100644 samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java delete mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java delete mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java delete mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 19feced91..107412214 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -21,7 +21,7 @@ // [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] // TODO: Change class name to Example -// TODO: Uncomment the line bellow before running cloud function +// TODO: Uncomment the line below before running cloud function // package com.example; import com.google.cloud.functions.HttpFunction; @@ -35,9 +35,6 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements @Override public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - - // For more information on the structure of this object, visit - // https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment JsonObject responseObject = null; // Constructing the response jsonObject diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index f53cb59d6..7484b80b3 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -1,77 +1,58 @@ /* -// * Copyright 2022 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.dialogflow.cx; - -// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook - -// // [START dialogflow_webhook] - -// // TODO: Change class name to Example -// // TODO: add GSON dependency to Pom file -// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) -// // TODO: Uncomment the line bellow before running cloud function -// // package com.example; - -// import com.google.cloud.functions.HttpFunction; -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import com.google.gson.GsonBuilder; -// import com.google.gson.JsonObject; -// import com.google.gson.JsonParser; -// import java.io.BufferedWriter; - -// public class BasicWebhook implements HttpFunction { -// @Override -// public void service(HttpRequest request, HttpResponse response) throws Exception { -// JsonParser parser = new JsonParser(); -// Gson gson = new GsonBuilder().create(); -// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); - -// // For more information on the structure of this object -// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment -// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") -// .getAsJsonPrimitive("tag").toString(); -// JsonObject responseObject = null; -// String defaultIntent = "\"Default Welcome Intent\""; -// String secondIntent = "\"get-agent-name\""; -// String responseText = ""; - -// // Compares the Intent Tag to provide the correct response -// if (requestTag.equals(defaultIntent)) { -// responseText = "\"Hello from a Java GCF Webhook\""; -// } else if (requestTag.equals(secondIntent)) { -// responseText = "\"My name is Flowhook\""; -// } else { -// responseText = "\"Sorry I didn't get that\""; -// } - -// // Constructing the response jsonObject -// responseObject = -// parser -// .parse( -// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" -// + responseText -// + "] } } ] } }") -// .getAsJsonObject(); -// BufferedWriter writer = response.getWriter(); - -// //Sends the responseObject -// writer.write(responseObject.toString()); -// } -// } -// // [END dialogflow_webhook] + * Copyright 2022 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 dialogflow.cx; + +// The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook +// Configures a webhook to set a session parameter + +// [START dialogflow_cx_v3_webhook_configure_session_parameters] + +// TODO: Change class name to Example +// TODO: Uncomment the line below before running cloud function +// package com.example; + +import com.google.cloud.functions.HttpFunction; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.BufferedWriter; + +public class WebhookConfigureSessionParameters implements HttpFunction { + @Override + public void service(HttpRequest request, HttpResponse response) throws Exception { + JsonParser parser = new JsonParser(); + JSONObject responseObject = null; + + // Constructing the response jsonObject + responseObject = + parser + .parse( + "{\"session_info\":{\"parameters\":" + + "{\"order-number\":\"12345\"}" + + "}}") + .getAsJsonObject(); + BufferedWriter writer = response.getWriter(); + + System.out.println("Parameter Info: \n"); + System.out.println(responseObject.toString()); + + // Sends the responseObject + writer.write(responseObject.toString()); + } +} +// [END dialogflow_cx_v3_webhook_configure_session_parameters] \ No newline at end of file diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java deleted file mode 100644 index f53cb59d6..000000000 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -// * Copyright 2022 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.dialogflow.cx; - -// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook - -// // [START dialogflow_webhook] - -// // TODO: Change class name to Example -// // TODO: add GSON dependency to Pom file -// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) -// // TODO: Uncomment the line bellow before running cloud function -// // package com.example; - -// import com.google.cloud.functions.HttpFunction; -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import com.google.gson.GsonBuilder; -// import com.google.gson.JsonObject; -// import com.google.gson.JsonParser; -// import java.io.BufferedWriter; - -// public class BasicWebhook implements HttpFunction { -// @Override -// public void service(HttpRequest request, HttpResponse response) throws Exception { -// JsonParser parser = new JsonParser(); -// Gson gson = new GsonBuilder().create(); -// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); - -// // For more information on the structure of this object -// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment -// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") -// .getAsJsonPrimitive("tag").toString(); -// JsonObject responseObject = null; -// String defaultIntent = "\"Default Welcome Intent\""; -// String secondIntent = "\"get-agent-name\""; -// String responseText = ""; - -// // Compares the Intent Tag to provide the correct response -// if (requestTag.equals(defaultIntent)) { -// responseText = "\"Hello from a Java GCF Webhook\""; -// } else if (requestTag.equals(secondIntent)) { -// responseText = "\"My name is Flowhook\""; -// } else { -// responseText = "\"Sorry I didn't get that\""; -// } - -// // Constructing the response jsonObject -// responseObject = -// parser -// .parse( -// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" -// + responseText -// + "] } } ] } }") -// .getAsJsonObject(); -// BufferedWriter writer = response.getWriter(); - -// //Sends the responseObject -// writer.write(responseObject.toString()); -// } -// } -// // [END dialogflow_webhook] diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java deleted file mode 100644 index f53cb59d6..000000000 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -// * Copyright 2022 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.dialogflow.cx; - -// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook - -// // [START dialogflow_webhook] - -// // TODO: Change class name to Example -// // TODO: add GSON dependency to Pom file -// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) -// // TODO: Uncomment the line bellow before running cloud function -// // package com.example; - -// import com.google.cloud.functions.HttpFunction; -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import com.google.gson.GsonBuilder; -// import com.google.gson.JsonObject; -// import com.google.gson.JsonParser; -// import java.io.BufferedWriter; - -// public class BasicWebhook implements HttpFunction { -// @Override -// public void service(HttpRequest request, HttpResponse response) throws Exception { -// JsonParser parser = new JsonParser(); -// Gson gson = new GsonBuilder().create(); -// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); - -// // For more information on the structure of this object -// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment -// String requestTag = parsedRequest.getAsJsonObject("fulfillmentInfo") -// .getAsJsonPrimitive("tag").toString(); -// JsonObject responseObject = null; -// String defaultIntent = "\"Default Welcome Intent\""; -// String secondIntent = "\"get-agent-name\""; -// String responseText = ""; - -// // Compares the Intent Tag to provide the correct response -// if (requestTag.equals(defaultIntent)) { -// responseText = "\"Hello from a Java GCF Webhook\""; -// } else if (requestTag.equals(secondIntent)) { -// responseText = "\"My name is Flowhook\""; -// } else { -// responseText = "\"Sorry I didn't get that\""; -// } - -// // Constructing the response jsonObject -// responseObject = -// parser -// .parse( -// "{ \"fulfillment_response\": { \"messages\": [ { \"text\": { \"text\": [" -// + responseText -// + "] } } ] } }") -// .getAsJsonObject(); -// BufferedWriter writer = response.getWriter(); - -// //Sends the responseObject -// writer.write(responseObject.toString()); -// } -// } -// // [END dialogflow_webhook] diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java deleted file mode 100644 index 9f86fd0f5..000000000 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -// * Copyright 2022 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.dialogflow.cx; - -// import static com.google.common.truth.Truth.assertThat; -// import static org.mockito.Mockito.when; - -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import java.io.BufferedReader; -// import java.io.BufferedWriter; -// import java.io.IOException; -// import java.io.StringReader; -// import java.io.StringWriter; -// import org.junit.Before; -// import org.junit.Test; -// import org.mockito.Mock; -// import org.mockito.MockitoAnnotations; - -// public class BasicWebhookIT { - -// @Mock private HttpRequest request; -// @Mock private HttpResponse response; - -// private BufferedWriter writerOut; -// private StringWriter responseOut; -// private static final Gson gson = new Gson(); - -// @Before -// public void beforeTest() throws IOException { -// MockitoAnnotations.initMocks(this); - -// // use an empty string as the default request content -// BufferedReader reader = new BufferedReader(new StringReader("")); -// when(request.getReader()).thenReturn(reader); - -// responseOut = new StringWriter(); -// writerOut = new BufferedWriter(responseOut); -// when(response.getWriter()).thenReturn(writerOut); -// } - -// @Test -// public void helloHttp_bodyParamsPost() throws IOException, Exception { -// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; - -// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - -// when(request.getReader()).thenReturn(jsonReader); - -// new BasicWebhook().service(request, response); -// writerOut.flush(); - -// String expectedResponse = -// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" -// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; - -// assertThat(responseOut.toString()).isEqualTo(expectedResponse); -// } -// } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java deleted file mode 100644 index 9f86fd0f5..000000000 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -// * Copyright 2022 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.dialogflow.cx; - -// import static com.google.common.truth.Truth.assertThat; -// import static org.mockito.Mockito.when; - -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import java.io.BufferedReader; -// import java.io.BufferedWriter; -// import java.io.IOException; -// import java.io.StringReader; -// import java.io.StringWriter; -// import org.junit.Before; -// import org.junit.Test; -// import org.mockito.Mock; -// import org.mockito.MockitoAnnotations; - -// public class BasicWebhookIT { - -// @Mock private HttpRequest request; -// @Mock private HttpResponse response; - -// private BufferedWriter writerOut; -// private StringWriter responseOut; -// private static final Gson gson = new Gson(); - -// @Before -// public void beforeTest() throws IOException { -// MockitoAnnotations.initMocks(this); - -// // use an empty string as the default request content -// BufferedReader reader = new BufferedReader(new StringReader("")); -// when(request.getReader()).thenReturn(reader); - -// responseOut = new StringWriter(); -// writerOut = new BufferedWriter(responseOut); -// when(response.getWriter()).thenReturn(writerOut); -// } - -// @Test -// public void helloHttp_bodyParamsPost() throws IOException, Exception { -// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; - -// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - -// when(request.getReader()).thenReturn(jsonReader); - -// new BasicWebhook().service(request, response); -// writerOut.flush(); - -// String expectedResponse = -// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" -// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; - -// assertThat(responseOut.toString()).isEqualTo(expectedResponse); -// } -// } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java new file mode 100644 index 000000000..313f783a1 --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2022 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 dialogflow.cx; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class WebhookConfigureSessionParametersTest { + + @Mock private HttpRequest request; + @Mock private HttpResponse response; + + private BufferedWriter writerOut; + private StringWriter responseOut; + private static final Gson gson = new Gson(); + + @Before + public void beforeTest() throws IOException { + MockitoAnnotations.initMocks(this); + + // use an empty string as the default request content + BufferedReader reader = new BufferedReader(new StringReader("")); + when(request.getReader()).thenReturn(reader); + + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + when(response.getWriter()).thenReturn(writerOut); + } + + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + String jsonString = "{'fulfillmentInfo': {'tag': 'configure-session-parameter'}}"; + + BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + + when(request.getReader()).thenReturn(jsonReader); + + new WebhookConfigureSessionParameters().service(request, response); + writerOut.flush(); + + String expectedResponse = + "{\"session_info\":{\"parameters\":" + + "{\"order-number\":\"12345\"}" + + "}}"; + + System.out.println(responseOut.toString()); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); + } +} diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java deleted file mode 100644 index 9f86fd0f5..000000000 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -// * Copyright 2022 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.dialogflow.cx; - -// import static com.google.common.truth.Truth.assertThat; -// import static org.mockito.Mockito.when; - -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import java.io.BufferedReader; -// import java.io.BufferedWriter; -// import java.io.IOException; -// import java.io.StringReader; -// import java.io.StringWriter; -// import org.junit.Before; -// import org.junit.Test; -// import org.mockito.Mock; -// import org.mockito.MockitoAnnotations; - -// public class BasicWebhookIT { - -// @Mock private HttpRequest request; -// @Mock private HttpResponse response; - -// private BufferedWriter writerOut; -// private StringWriter responseOut; -// private static final Gson gson = new Gson(); - -// @Before -// public void beforeTest() throws IOException { -// MockitoAnnotations.initMocks(this); - -// // use an empty string as the default request content -// BufferedReader reader = new BufferedReader(new StringReader("")); -// when(request.getReader()).thenReturn(reader); - -// responseOut = new StringWriter(); -// writerOut = new BufferedWriter(responseOut); -// when(response.getWriter()).thenReturn(writerOut); -// } - -// @Test -// public void helloHttp_bodyParamsPost() throws IOException, Exception { -// String jsonString = "{'fulfillmentInfo': {'tag': 'Default Welcome Intent'}}"; - -// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - -// when(request.getReader()).thenReturn(jsonReader); - -// new BasicWebhook().service(request, response); -// writerOut.flush(); - -// String expectedResponse = -// "{\"fulfillment_response\":{\"messages\":[{\"text\":{\"text\":[" -// + "\"Hello from a Java GCF Webhook\"" + "]}}]}}"; - -// assertThat(responseOut.toString()).isEqualTo(expectedResponse); -// } -// } From 77ba0852d5adb33cb4520dd4f941d9d53b06a2be Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:28:24 -0500 Subject: [PATCH 15/72] add webhook configure session parameter sample and test Change-Id: Ia599ab7f4d432477d9952b4e12c709845f1ad97b --- .../java/dialogflow/cx/WebhookConfigureSessionParameters.java | 2 +- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 7484b80b3..23ed17d7d 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -36,7 +36,7 @@ public class WebhookConfigureSessionParameters implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - JSONObject responseObject = null; + JsonObject responseObject = null; // Constructing the response jsonObject responseObject = diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 313f783a1..7bc7ed734 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -21,7 +21,6 @@ import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -39,7 +38,6 @@ public class WebhookConfigureSessionParametersTest { private BufferedWriter writerOut; private StringWriter responseOut; - private static final Gson gson = new Gson(); @Before public void beforeTest() throws IOException { From 16ab5b8f3857e0ce4c30c98035d518cf811fd983 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:43:35 -0500 Subject: [PATCH 16/72] add webhook validate form parameter sample and test Change-Id: I8cdf93fd9e21161757d198b1338c5ab77bb3a236 --- .../cx/WebhookValidateFormParameter.java | 74 +++++++--------- .../cx/WebhookValidateFormParameterTest.java | 86 +++++++++---------- 2 files changed, 76 insertions(+), 84 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index 8ed51a5e4..d5ad25ff2 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -14,54 +14,46 @@ // * limitations under the License. // */ -// package dialogflow.cx; +package dialogflow.cx; -// // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook +// The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook -// // [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] +// [START dialogflow_cx_v3_webhook_validate_form_parameter] -// // TODO: Change class name to Example -// // TODO: add GSON dependency to Pom file -// // (https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5) -// // TODO: Uncomment the line bellow before running cloud function -// // package com.example; +// TODO: Change class name to Example +// TODO: Uncomment the line bellow before running cloud function +// package com.example; -// import com.google.cloud.functions.HttpFunction; -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import com.google.gson.GsonBuilder; -// import com.google.gson.JsonObject; -// import com.google.gson.JsonParser; -// import java.io.BufferedWriter; +import com.google.cloud.functions.HttpFunction; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; -// public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements HttpFunction { -// @Override -// public void service(HttpRequest request, HttpResponse response) throws Exception { -// JsonParser parser = new JsonParser(); -// Gson gson = new GsonBuilder().create(); -// JsonObject parsedRequest = gson.fromJson(request.getReader(), JsonObject.class); +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.BufferedWriter; -// // For more information on the structure of this object, visit -// https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/Fulfillment -// JsonObject responseObject = null; +public class WebhookValidateFormParameter implements HttpFunction { + @Override + public void service(HttpRequest request, HttpResponse response) throws Exception { + JsonParser parser = new JsonParser(); + JsonObject responseObject = null; -// // Constructing the response jsonObject + // Constructing the response jsonObject + responseObject = + parser.parse( + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" + + "]}}}") + .getAsJsonObject(); -// String responseString = String.join("{\"page_info\":{\"form_info\":{\"parameter_info\":", -// "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}", -// "]}}}"); -// responseObject = -// parser -// .parse(responseString); -// .getAsJsonObject(); -// BufferedWriter writer = response.getWriter(); + BufferedWriter writer = response.getWriter(); -// System.out.println("Parameter Info: \n"); -// System.out.println(responseObject.toString()); + System.out.println("Parameter Info: \n"); + System.out.println(responseObject.toString()); -// //Sends the responseObject -// writer.write(responseObject.toString()); -// } -// } -// // [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] + //Sends the responseObject + writer.write(responseObject.toString()); + } +} +// [END dialogflow_cx_v3_webhook_validate_form_parameter] diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index adc80500e..a89985e84 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -14,60 +14,60 @@ // * limitations under the License. // */ -// package dialogflow.cx; +package dialogflow.cx; -// import static com.google.common.truth.Truth.assertThat; -// import static org.mockito.Mockito.when; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; -// import com.google.cloud.functions.HttpRequest; -// import com.google.cloud.functions.HttpResponse; -// import com.google.gson.Gson; -// import java.io.BufferedReader; -// import java.io.BufferedWriter; -// import java.io.IOException; -// import java.io.StringReader; -// import java.io.StringWriter; -// import org.junit.Before; -// import org.junit.Test; -// import org.mockito.Mock; -// import org.mockito.MockitoAnnotations; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; -// public class WebhookValidateFormParameter { +public class WebhookValidateFormParameterTest { -// @Mock private HttpRequest request; -// @Mock private HttpResponse response; + @Mock private HttpRequest request; + @Mock private HttpResponse response; -// private BufferedWriter writerOut; -// private StringWriter responseOut; -// private static final Gson gson = new Gson(); + private BufferedWriter writerOut; + private StringWriter responseOut; + private static final Gson gson = new Gson(); -// @Before -// public void beforeTest() throws IOException { -// MockitoAnnotations.initMocks(this); + @Before + public void beforeTest() throws IOException { + MockitoAnnotations.initMocks(this); -// // use an empty string as the default request content -// BufferedReader reader = new BufferedReader(new StringReader("")); -// when(request.getReader()).thenReturn(reader); + // use an empty string as the default request content + BufferedReader reader = new BufferedReader(new StringReader("")); + when(request.getReader()).thenReturn(reader); -// responseOut = new StringWriter(); -// writerOut = new BufferedWriter(responseOut); -// when(response.getWriter()).thenReturn(writerOut); -// } + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + when(response.getWriter()).thenReturn(writerOut); + } -// @Test -// public void helloHttp_bodyParamsPost() throws IOException, Exception { -// String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + String jsonString = "{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"; -// BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); + BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); -// when(request.getReader()).thenReturn(jsonReader); + when(request.getReader()).thenReturn(jsonReader); -// new WebhookValidateFormParameter().service(request, response); -// writerOut.flush(); + new WebhookValidateFormParameter().service(request, response); + writerOut.flush(); -// String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\": -// [{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"INVALID\",\"value\":\"123\"}]}}}"; -// assertThat(responseOut.toString()).isEqualTo(expectedResponse); -// } -// } + assertThat(responseOut.toString()).isEqualTo(expectedResponse); + } +} From 7bf63a07fe808ce3630accc31a0766a07c276c3c Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:51:18 -0500 Subject: [PATCH 17/72] fix checkstyle violations Change-Id: I90f1f626588fd59c116d119348054c914945cd1d --- .../cx/WebhookConfigureSessionParameters.java | 2 +- .../dialogflow/cx/WebhookValidateFormParameter.java | 11 +++++------ .../cx/WebhookConfigureSessionParametersTest.java | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 23ed17d7d..df6e0a274 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -36,7 +36,7 @@ public class WebhookConfigureSessionParameters implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - JsonObject responseObject = null; + JsonObject responseObject = null; // Constructing the response jsonObject responseObject = diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index d5ad25ff2..8e26f8e8a 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -27,7 +27,6 @@ import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; - import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.BufferedWriter; @@ -41,11 +40,11 @@ public void service(HttpRequest request, HttpResponse response) throws Exception // Constructing the response jsonObject responseObject = parser.parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" - + "]}}}") - .getAsJsonObject(); + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" + + "]}}}") + .getAsJsonObject(); BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 7bc7ed734..43a8929df 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -65,8 +65,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String expectedResponse = "{\"session_info\":{\"parameters\":" - + "{\"order-number\":\"12345\"}" - + "}}"; + + "{\"order-number\":\"12345\"}" + + "}}"; System.out.println(responseOut.toString()); assertThat(responseOut.toString()).isEqualTo(expectedResponse); From 5176e43a27f3ee22a9c23363ffb53b5f5eb6aec8 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 14 Jun 2022 11:40:06 -0500 Subject: [PATCH 18/72] fix checkstyle violations Change-Id: I5ff686ab2ffc94b358bdf87b8dfc3d00f5e45657 --- .../cx/WebhookConfigureSessionParameters.java | 14 ++++++-------- .../cx/WebhookValidateFormParameter.java | 10 +++++----- .../cx/WebhookConfigureSessionParametersTest.java | 2 +- .../cx/WebhookValidateFormParameterTest.java | 3 ++- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index df6e0a274..1d0eaf766 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -36,16 +36,14 @@ public class WebhookConfigureSessionParameters implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { JsonParser parser = new JsonParser(); - JsonObject responseObject = null; + JsonObject responseObject = null; // Constructing the response jsonObject - responseObject = - parser - .parse( - "{\"session_info\":{\"parameters\":" - + "{\"order-number\":\"12345\"}" - + "}}") - .getAsJsonObject(); + responseObject = parser.parse( + "{\"session_info\":{\"parameters\":" + + "{\"order-number\":\"12345\"}" + + "}}") + .getAsJsonObject(); BufferedWriter writer = response.getWriter(); System.out.println("Parameter Info: \n"); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index 8e26f8e8a..17365bd34 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -40,11 +40,11 @@ public void service(HttpRequest request, HttpResponse response) throws Exception // Constructing the response jsonObject responseObject = parser.parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" - + "]}}}") - .getAsJsonObject(); + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" + + "]}}}") + .getAsJsonObject(); BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 43a8929df..9ce484c18 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -64,7 +64,7 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { writerOut.flush(); String expectedResponse = - "{\"session_info\":{\"parameters\":" + "{\"session_info\":{\"parameters\":" + "{\"order-number\":\"12345\"}" + "}}"; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index a89985e84..f71f6d9c2 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -66,7 +66,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { writerOut.flush(); String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"INVALID\",\"value\":\"123\"}]}}}"; + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":" + + "\"INVALID\",\"value\":\"123\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From 9d65836c4f80e9411e2d493f55edc297307e847c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 14 Jun 2022 16:52:52 +0000 Subject: [PATCH 19/72] =?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 --- README.md | 2 -- .../cx/WebhookConfigureSessionParameters.java | 11 +++++------ .../cx/WebhookValidateFormParameter.java | 15 ++++++++------- .../cx/WebhookConfigureSessionParametersTest.java | 4 +--- .../cx/WebhookValidateFormParameterTest.java | 7 ++++--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5f0c7dbcc..87fed314a 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,6 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-dialogflow-cx | List Training Phrases | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ListTrainingPhrases.java) | | Update Intent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/UpdateIntent.java) | | Webhook Configure Session Parameters | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java) | -| Webhook Configure Session Parameters Enable Agent Response | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersEnableAgentResponse.java) | -| Webhook Configure Session Parameters Trigger Transition | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParametersTriggerTransition.java) | | Webhook Validate Form Parameter | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java) | diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 1d0eaf766..da150ead5 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -39,11 +39,10 @@ public void service(HttpRequest request, HttpResponse response) throws Exception JsonObject responseObject = null; // Constructing the response jsonObject - responseObject = parser.parse( - "{\"session_info\":{\"parameters\":" - + "{\"order-number\":\"12345\"}" - + "}}") - .getAsJsonObject(); + responseObject = + parser + .parse("{\"session_info\":{\"parameters\":" + "{\"order-number\":\"12345\"}" + "}}") + .getAsJsonObject(); BufferedWriter writer = response.getWriter(); System.out.println("Parameter Info: \n"); @@ -53,4 +52,4 @@ public void service(HttpRequest request, HttpResponse response) throws Exception writer.write(responseObject.toString()); } } -// [END dialogflow_cx_v3_webhook_configure_session_parameters] \ No newline at end of file +// [END dialogflow_cx_v3_webhook_configure_session_parameters] diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index 17365bd34..e72de786b 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -39,19 +39,20 @@ public void service(HttpRequest request, HttpResponse response) throws Exception // Constructing the response jsonObject responseObject = - parser.parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" - + "]}}}") - .getAsJsonObject(); + parser + .parse( + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":" + + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" + + "]}}}") + .getAsJsonObject(); BufferedWriter writer = response.getWriter(); System.out.println("Parameter Info: \n"); System.out.println(responseObject.toString()); - //Sends the responseObject + // Sends the responseObject writer.write(responseObject.toString()); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 9ce484c18..9fe83ae98 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -64,9 +64,7 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { writerOut.flush(); String expectedResponse = - "{\"session_info\":{\"parameters\":" - + "{\"order-number\":\"12345\"}" - + "}}"; + "{\"session_info\":{\"parameters\":" + "{\"order-number\":\"12345\"}" + "}}"; System.out.println(responseOut.toString()); assertThat(responseOut.toString()).isEqualTo(expectedResponse); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index f71f6d9c2..3aae7d31e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -65,9 +65,10 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookValidateFormParameter().service(request, response); writerOut.flush(); - String expectedResponse = "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":" - + "\"INVALID\",\"value\":\"123\"}]}}}"; + String expectedResponse = + "{\"page_info\":{\"form_info\":{\"parameter_info\":" + + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":" + + "\"INVALID\",\"value\":\"123\"}]}}}"; assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From 8eaff7da622d16cec7ae1522bbcbde26cb466b3b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 18:01:06 -0500 Subject: [PATCH 20/72] update to use gson Change-Id: I6f645ff225e42a3485773af1b63e7b3378f95bb2 --- .../cx/WebhookConfigureSessionParameters.java | 34 +++++++++++-------- ...WebhookConfigureSessionParametersTest.java | 30 +++++++++++++--- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index da150ead5..281d82473 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -25,31 +25,37 @@ // TODO: Uncomment the line below before running cloud function // package com.example; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.io.BufferedWriter; public class WebhookConfigureSessionParameters implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - JsonParser parser = new JsonParser(); - JsonObject responseObject = null; - - // Constructing the response jsonObject - responseObject = - parser - .parse("{\"session_info\":{\"parameters\":" + "{\"order-number\":\"12345\"}" + "}}") - .getAsJsonObject(); + // Creates webhook response object + JsonObject webhookResponse = new JsonObject(); + JsonObject parameterObject = new JsonObject(); + JsonObject orderParameter = new JsonObject(); + orderParameter.addProperty("order_number", "12345"); + parameterObject.add("parameters", orderParameter); + webhookResponse.add("session_info", parameterObject); + + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonResponseObject = gson.toJson(webhookResponse); + System.out.println("JSON response: " + jsonResponseObject); + BufferedWriter writer = response.getWriter(); - System.out.println("Parameter Info: \n"); - System.out.println(responseObject.toString()); + System.out.println("Session Parameter Info: \n"); + System.out.println(jsonResponseObject.toString()); - // Sends the responseObject - writer.write(responseObject.toString()); + // Sends the webhookResponseObject + writer.write(jsonResponseObject.toString()); } } // [END dialogflow_cx_v3_webhook_configure_session_parameters] diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 9fe83ae98..88568a918 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -19,6 +19,16 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; + +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookResponse; +import com.google.cloud.dialogflow.cx.v3beta1.SessionInfo; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.protobuf.Value; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import java.io.BufferedReader; @@ -54,8 +64,14 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'configure-session-parameter'}}"; + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + + WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonString = gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); @@ -63,10 +79,14 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); - String expectedResponse = - "{\"session_info\":{\"parameters\":" + "{\"order-number\":\"12345\"}" + "}}"; + JsonObject webhookResponse = new JsonObject(); + JsonObject parameterObject = new JsonObject(); + JsonObject orderParameter = new JsonObject(); + orderParameter.addProperty("order_number", "12345"); + parameterObject.add("parameters", orderParameter); + webhookResponse.add("session_info", parameterObject); + String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println(responseOut.toString()); - assertThat(responseOut.toString()).isEqualTo(expectedResponse); + assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); } } From cdc0857afdfb5346b82a803673e3cbe0575cb78a Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 18:04:27 -0500 Subject: [PATCH 21/72] update to use gson Change-Id: I155a40ae8def8472b3e08551fc3dc112b06c68ec --- .../cx/WebhookConfigureSessionParameters.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 281d82473..b9c1331cf 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -47,13 +47,21 @@ public void service(HttpRequest request, HttpResponse response) throws Exception Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("JSON response: " + jsonResponseObject); - - BufferedWriter writer = response.getWriter(); 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 writer.write(jsonResponseObject.toString()); } From c0d615b8b0025c29a59dbae43d3e509bb0d5e6b8 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:14:17 -0500 Subject: [PATCH 22/72] update webhook-optional-or-required to use gson Change-Id: I6b4c19023982668c9c5d0c901bb72c41d3ca7457 --- ...SetFormParametersAsOptionalOrRequired.java | 50 ++++++++++++------- ...ormParametersAsOptionalOrRequiredTest.java | 34 ++++++++++--- ...WebhookConfigureSessionParametersTest.java | 1 - 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 107412214..59db01828 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -24,35 +24,51 @@ // TODO: Uncomment the line below before running cloud function // package com.example; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.io.BufferedWriter; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - JsonParser parser = new JsonParser(); - JsonObject responseObject = null; - - // Constructing the response jsonObject - responseObject = - parser - .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"VALID\"}" - + "]}}}") - .getAsJsonObject(); - BufferedWriter writer = response.getWriter(); + // Constructs the webhook response object + JsonObject webhookResponse = new JsonObject(); + JsonObject formInfo = new JsonObject(); + JsonObject parameterInfoObject = new JsonObject(); + JsonArray parameterInfoList = new JsonArray(); + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "VALID"); + + parameterInfoList.add(parameterObject); + parameterInfoObject.add("parameter_info", parameterInfoList); + formInfo.add("form_info", parameterInfoObject); + webhookResponse.add("page_info", formInfo); + // responseObject = + // parser + // .parse( + // "{\"page_info\":{\"form_info\":{\"parameter_info\":" + // + "[{\"display_name\":\"order-number\",\"required\":" + // + "\"true\",\"state\":\"VALID\"}" + // + "]}}}") + // .getAsJsonObject(); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonResponseObject = gson.toJson(webhookResponse); System.out.println("Parameter Info: \n"); - System.out.println(responseObject.toString()); + System.out.println(jsonResponseObject.toString()); + + BufferedWriter writer = response.getWriter(); // Sends the responseObject - writer.write(responseObject.toString()); + writer.write(jsonResponseObject.toString()); } } // [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index f0d56e83c..0ea301e85 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -19,9 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -56,8 +61,13 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + + WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonString = gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); @@ -65,10 +75,22 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - String expectedResponse = - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":\"VALID\"}]}}}"; + JsonObject webhookResponse = new JsonObject(); + JsonObject formInfo = new JsonObject(); + JsonObject parameterInfoObject = new JsonObject(); + JsonArray parameterInfoList = new JsonArray(); + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "VALID"); + + parameterInfoList.add(parameterObject); + parameterInfoObject.add("parameter_info", parameterInfoList); + formInfo.add("form_info", parameterInfoObject); + webhookResponse.add("page_info", formInfo); + + String jsonResponseObject = gson.toJson(webhookResponse); - assertThat(responseOut.toString()).isEqualTo(expectedResponse); + assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 88568a918..58d745590 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -27,7 +27,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.google.protobuf.Value; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; From 6ceacda966846679df39e0b79da424a2f8335d0e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:16:14 -0500 Subject: [PATCH 23/72] update test Change-Id: I43ce833251dadfbc9e6c3e652ff1f278a2f7c2f2 --- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 58d745590..647a493dd 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -22,12 +22,9 @@ import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookResponse; -import com.google.cloud.dialogflow.cx.v3beta1.SessionInfo; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import com.google.protobuf.Value; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import java.io.BufferedReader; From 56b356976b642831613d625771a64ec1b84b9a4f Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:37:45 -0500 Subject: [PATCH 24/72] update to use gson Change-Id: I509e163dcb69161ad8c18147bd2116b7014d4aef --- ...SetFormParametersAsOptionalOrRequired.java | 8 -- .../cx/WebhookValidateFormParameter.java | 85 +++++++++++-------- .../cx/WebhookValidateFormParameterTest.java | 72 +++++++++++----- 3 files changed, 102 insertions(+), 63 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 59db01828..90be8a230 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -50,14 +50,6 @@ public void service(HttpRequest request, HttpResponse response) throws Exception parameterInfoObject.add("parameter_info", parameterInfoList); formInfo.add("form_info", parameterInfoObject); webhookResponse.add("page_info", formInfo); - // responseObject = - // parser - // .parse( - // "{\"page_info\":{\"form_info\":{\"parameter_info\":" - // + "[{\"display_name\":\"order-number\",\"required\":" - // + "\"true\",\"state\":\"VALID\"}" - // + "]}}}") - // .getAsJsonObject(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index e72de786b..9e047bd5d 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -1,59 +1,76 @@ /* -// * Copyright 2022 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. -// */ + * Copyright 2022 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 dialogflow.cx; // The following snippet is used in https://cloud.google.com/dialogflow/cx/docs/concept/webhook -// [START dialogflow_cx_v3_webhook_validate_form_parameter] +// [START dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] // TODO: Change class name to Example -// TODO: Uncomment the line bellow before running cloud function +// TODO: Uncomment the line below before running cloud function // package com.example; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.io.BufferedWriter; public class WebhookValidateFormParameter implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - JsonParser parser = new JsonParser(); - JsonObject responseObject = null; - - // Constructing the response jsonObject - responseObject = - parser - .parse( - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":" - + "\"true\",\"state\":\"INVALID\",\"value\":\"123\"}" - + "]}}}") - .getAsJsonObject(); + // Constructs the webhook response object + JsonObject webhookResponse = new JsonObject(); - BufferedWriter writer = response.getWriter(); + JsonObject sessionInfo = new JsonObject(); + JsonObject sessionParameter = new JsonObject(); + + sessionParameter.addProperty("order_number", "null"); + sessionInfo.add("parameters", sessionParameter); + + JsonObject pageInfo = new JsonObject(); + JsonObject parameterInfoObject = new JsonObject(); + JsonArray parameterInfoList = new JsonArray(); + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "INVALID"); + parameterObject.addProperty("value", "123"); + + parameterInfoList.add(parameterObject); + parameterInfoObject.add("parameter_info", parameterInfoList); + pageInfo.add("form_info", parameterInfoObject); + webhookResponse.add("page_info", pageInfo); + webhookResponse.add("session_info", sessionInfo); + + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String jsonResponseObject = gson.toJson(webhookResponse); System.out.println("Parameter Info: \n"); - System.out.println(responseObject.toString()); + System.out.println(jsonResponseObject.toString()); + + BufferedWriter writer = response.getWriter(); // Sends the responseObject - writer.write(responseObject.toString()); + writer.write(jsonResponseObject.toString()); } } -// [END dialogflow_cx_v3_webhook_validate_form_parameter] +// [END dialogflow_cx_v3_configure_webhooks_to_set_form_parameter_as_optional_or_required] diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 3aae7d31e..4e19417d1 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -1,27 +1,32 @@ /* -// * Copyright 2022 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. -// */ + * Copyright 2022 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 dialogflow.cx; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonArray; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -56,8 +61,13 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"; + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + String jsonString = gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); @@ -65,11 +75,31 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookValidateFormParameter().service(request, response); writerOut.flush(); - String expectedResponse = - "{\"page_info\":{\"form_info\":{\"parameter_info\":" - + "[{\"display_name\":\"order-number\",\"required\":\"true\",\"state\":" - + "\"INVALID\",\"value\":\"123\"}]}}}"; + JsonObject webhookResponse = new JsonObject(); + + JsonObject sessionInfo = new JsonObject(); + JsonObject sessionParameter = new JsonObject(); + + sessionParameter.addProperty("order_number", "null"); + sessionInfo.add("parameters", sessionParameter); + + JsonObject formInfo = new JsonObject(); + JsonObject parameterInfoObject = new JsonObject(); + JsonArray parameterInfoList = new JsonArray(); + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "INVALID"); + parameterObject.addProperty("value", "123"); + + parameterInfoList.add(parameterObject); + parameterInfoObject.add("parameter_info", parameterInfoList); + formInfo.add("form_info", parameterInfoObject); + webhookResponse.add("page_info", formInfo); + webhookResponse.add("session_info", sessionInfo); + + String jsonResponseObject = gson.toJson(webhookResponse); - assertThat(responseOut.toString()).isEqualTo(expectedResponse); + assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); } } From 34f6ca736c09b2b045027f3db21987a8349289e3 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:59:14 -0500 Subject: [PATCH 25/72] fix checkstyle violations Change-Id: I2f882c298379630b71dbb533173ec3cc9ca4aee1 --- ...SetFormParametersAsOptionalOrRequired.java | 39 +++++++++++---- .../cx/WebhookConfigureSessionParameters.java | 14 +++--- .../cx/WebhookValidateFormParameter.java | 47 ++++++++++++++----- ...ormParametersAsOptionalOrRequiredTest.java | 22 +++++---- ...WebhookConfigureSessionParametersTest.java | 10 ++-- .../cx/WebhookValidateFormParameterTest.java | 27 ++++++----- 6 files changed, 105 insertions(+), 54 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 90be8a230..4b6cff21f 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -24,39 +24,58 @@ // TODO: Uncomment the line below before running cloud function // package com.example; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.google.gson.JsonArray; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import java.io.BufferedWriter; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequired implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - // Constructs the webhook response object - JsonObject webhookResponse = new JsonObject(); - JsonObject formInfo = new JsonObject(); - JsonObject parameterInfoObject = new JsonObject(); - JsonArray parameterInfoList = new JsonArray(); JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); parameterObject.addProperty("state", "VALID"); + JsonArray parameterInfoList = new JsonArray(); parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject formInfo = new JsonObject(); formInfo.add("form_info", parameterInfoObject); + + // Constructs the webhook response object + JsonObject webhookResponse = new JsonObject(); webhookResponse.add("page_info", formInfo); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("Parameter Info: \n"); + System.out.println("Response Object: \n"); System.out.println(jsonResponseObject.toString()); + /** + * { + "page_info": { + "form_info": { + "parameter_info": [ + { + "display_name": "order_number", + "required": "true", + "state": "VALID" + } + ] + } + } + } + */ + BufferedWriter writer = response.getWriter(); // Sends the responseObject diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index b9c1331cf..4e53c5001 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -25,23 +25,25 @@ // TODO: Uncomment the line below before running cloud function // package com.example; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import java.io.BufferedWriter; public class WebhookConfigureSessionParameters implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - // Creates webhook response object - JsonObject webhookResponse = new JsonObject(); - JsonObject parameterObject = new JsonObject(); JsonObject orderParameter = new JsonObject(); orderParameter.addProperty("order_number", "12345"); + + JsonObject parameterObject = new JsonObject(); parameterObject.add("parameters", orderParameter); + + // Creates webhook response object + JsonObject webhookResponse = new JsonObject(); webhookResponse.add("session_info", parameterObject); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index 9e047bd5d..262e1b5c2 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -24,48 +24,71 @@ // TODO: Uncomment the line below before running cloud function // package com.example; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.google.gson.JsonArray; import com.google.cloud.functions.HttpFunction; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import java.io.BufferedWriter; public class WebhookValidateFormParameter implements HttpFunction { @Override public void service(HttpRequest request, HttpResponse response) throws Exception { - // Constructs the webhook response object - JsonObject webhookResponse = new JsonObject(); - JsonObject sessionInfo = new JsonObject(); JsonObject sessionParameter = new JsonObject(); sessionParameter.addProperty("order_number", "null"); sessionInfo.add("parameters", sessionParameter); - JsonObject pageInfo = new JsonObject(); - JsonObject parameterInfoObject = new JsonObject(); - JsonArray parameterInfoList = new JsonArray(); JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); parameterObject.addProperty("state", "INVALID"); parameterObject.addProperty("value", "123"); + JsonArray parameterInfoList = new JsonArray(); parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject pageInfo = new JsonObject(); pageInfo.add("form_info", parameterInfoObject); + + // Constructs the webhook response object + JsonObject webhookResponse = new JsonObject(); webhookResponse.add("page_info", pageInfo); webhookResponse.add("session_info", sessionInfo); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonResponseObject = gson.toJson(webhookResponse); - System.out.println("Parameter Info: \n"); + 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": { + "parameters": { + "order_number": "null" + } + } + } + */ + BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 0ea301e85..18e03980a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -21,12 +21,12 @@ import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.google.gson.JsonArray; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; +import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -62,9 +62,10 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + .setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = gson.toJson(webhookRequest); @@ -75,18 +76,21 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - JsonObject webhookResponse = new JsonObject(); - JsonObject formInfo = new JsonObject(); - JsonObject parameterInfoObject = new JsonObject(); - JsonArray parameterInfoList = new JsonArray(); JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); parameterObject.addProperty("state", "VALID"); + JsonArray parameterInfoList = new JsonArray(); parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject formInfo = new JsonObject(); formInfo.add("form_info", parameterInfoObject); + + JsonObject webhookResponse = new JsonObject(); webhookResponse.add("page_info", formInfo); String jsonResponseObject = gson.toJson(webhookResponse); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 647a493dd..43958206a 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -19,14 +19,13 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; - import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -61,9 +60,10 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + .setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 4e19417d1..7358d2419 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -21,12 +21,12 @@ import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import com.google.gson.JsonArray; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; +import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -62,9 +62,10 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + .setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = gson.toJson(webhookRequest); @@ -75,26 +76,28 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookValidateFormParameter().service(request, response); writerOut.flush(); - JsonObject webhookResponse = new JsonObject(); - - JsonObject sessionInfo = new JsonObject(); JsonObject sessionParameter = new JsonObject(); - sessionParameter.addProperty("order_number", "null"); + + JsonObject sessionInfo = new JsonObject(); sessionInfo.add("parameters", sessionParameter); - JsonObject formInfo = new JsonObject(); - JsonObject parameterInfoObject = new JsonObject(); - JsonArray parameterInfoList = new JsonArray(); JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); parameterObject.addProperty("state", "INVALID"); parameterObject.addProperty("value", "123"); + JsonArray parameterInfoList = new JsonArray(); parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject formInfo = new JsonObject(); formInfo.add("form_info", parameterInfoObject); + + JsonObject webhookResponse = new JsonObject(); webhookResponse.add("page_info", formInfo); webhookResponse.add("session_info", sessionInfo); From bfe788a5ab5e365f695e0a715221b6c0aa40058c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 29 Jun 2022 01:07:11 +0000 Subject: [PATCH 26/72] =?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 --- ...SetFormParametersAsOptionalOrRequired.java | 16 ++----------- .../cx/WebhookConfigureSessionParameters.java | 12 +--------- .../cx/WebhookValidateFormParameter.java | 24 +++---------------- ...ormParametersAsOptionalOrRequiredTest.java | 8 +++---- ...WebhookConfigureSessionParametersTest.java | 8 +++---- .../cx/WebhookValidateFormParameterTest.java | 8 +++---- 6 files changed, 18 insertions(+), 58 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 4b6cff21f..a6f1eb206 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -61,21 +61,9 @@ public void service(HttpRequest request, HttpResponse response) throws Exception System.out.println(jsonResponseObject.toString()); /** - * { - "page_info": { - "form_info": { - "parameter_info": [ - { - "display_name": "order_number", - "required": "true", - "state": "VALID" - } - ] - } - } - } + * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", + * "required": "true", "state": "VALID" } ] } } } */ - BufferedWriter writer = response.getWriter(); // Sends the responseObject diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java index 4e53c5001..e9c026314 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookConfigureSessionParameters.java @@ -46,23 +46,13 @@ public void service(HttpRequest request, HttpResponse response) throws Exception JsonObject webhookResponse = new JsonObject(); webhookResponse.add("session_info", parameterObject); - 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" - } - } - } - */ - + /** { "session_info": { "parameters": { "order_number": "12345" } } } */ BufferedWriter writer = response.getWriter(); // Sends the webhookResponseObject writer.write(jsonResponseObject.toString()); diff --git a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java index 262e1b5c2..fadbef573 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java +++ b/samples/snippets/src/main/java/dialogflow/cx/WebhookValidateFormParameter.java @@ -68,28 +68,10 @@ public void service(HttpRequest request, HttpResponse response) throws Exception 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": { - "parameters": { - "order_number": "null" - } - } - } + * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", + * "required": "true", "state": "INVALID", "value": "123" } ] } }, "session_info": { + * "parameters": { "order_number": "null" } } } */ - - BufferedWriter writer = response.getWriter(); // Sends the responseObject diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 18e03980a..05ed52309 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -61,11 +61,11 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = gson.toJson(webhookRequest); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 43958206a..377c3f9fc 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -59,11 +59,11 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 7358d2419..a3cbb3672 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -61,11 +61,11 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = gson.toJson(webhookRequest); From c6e5c95c7fef5b7ebdf53dad154df7722413104b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 30 Jun 2022 11:54:13 -0500 Subject: [PATCH 27/72] v3beta1 to v3 Change-Id: If9d465d862ca5c7ae7f5e1fb03a5b09c878997a8 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 ++-- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 4 ++-- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 18e03980a..c7feedbc3 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 43958206a..bfacbbd89 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 7358d2419..afb4ac8f6 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -19,8 +19,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import com.google.gson.Gson; From a6340fe0ade1d28e8c814c2cc6ad8137d9fc162b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:45:12 -0500 Subject: [PATCH 28/72] add flag to kokoro build script Change-Id: Ib5c9ccd81e1e6fabe1ed79fe6d3c96f455480c16 --- .kokoro/build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 7fc69f67c..443dd81db 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,7 +101,8 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify + verify \ + -e RETURN_CODE=$? popd else From e183c779806fbea17c34eea53a6bd96874ed8d6e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:00:33 -0500 Subject: [PATCH 29/72] remove flag Change-Id: Ie1fc788f64c6dc14763f0c2df3ac9327ee7a1044 --- .kokoro/build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 443dd81db..7fc69f67c 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,8 +101,7 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify \ - -e + verify RETURN_CODE=$? popd else From b8810dafbd55abf69e5a280c9f76ad6ab6a82daf Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:48:24 -0500 Subject: [PATCH 30/72] add flag to kokoro build script Change-Id: Ie7821b49ea0b954fdcf6ad7f0a5efd57c865c20c --- .kokoro/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 7fc69f67c..3814d84d5 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,7 +101,9 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify + verify \ + -e \ + -X RETURN_CODE=$? popd else From b76ad6462ed97d5bee75bdace5cc23cbc2fd1981 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 30 Jun 2022 16:23:44 -0500 Subject: [PATCH 31/72] remove flag Change-Id: I3ae6982f6a4f8dc3b2b4e5a404e5e46c8c8d6aaa --- .kokoro/build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 3814d84d5..7fc69f67c 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,9 +101,7 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify \ - -e \ - -X + verify RETURN_CODE=$? popd else From c3e19c79c60752f7c097f37d155b2a3dca58b604 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 07:40:31 -0500 Subject: [PATCH 32/72] add kokoro flag Change-Id: Id7a7aae81cd43d920fa1fe750fb259b0d2ea0581 --- .kokoro/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 7fc69f67c..3814d84d5 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,7 +101,9 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify + verify \ + -e \ + -X RETURN_CODE=$? popd else From 403f2b6c7eafcf5482eb812953651239061e733c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 12 Jul 2022 12:45:22 +0000 Subject: [PATCH 33/72] =?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 --- .kokoro/build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 3814d84d5..7fc69f67c 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,9 +101,7 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify \ - -e \ - -X + verify RETURN_CODE=$? popd else From 52c3411d8631932fa6b1be4c9e911202b08fc653 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 08:01:31 -0500 Subject: [PATCH 34/72] add kokoro flag Change-Id: I3a4733a05b86a135642c4667a52ab7b09f462559 --- .kokoro/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 7fc69f67c..2054545c1 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,7 +101,9 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify + verify \ + -e \ + -X RETURN_CODE=$? popd else From 7b3a3f99c5e44086ec571c8a0f34c7c65b45eaf5 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:22:20 -0500 Subject: [PATCH 35/72] fix formatting Change-Id: I491c924ed2fc6dff078f1d7944a3590a24b7530f --- ...okToSetFormParametersAsOptionalOrRequired.java | 15 +++++++++++++-- ...SetFormParametersAsOptionalOrRequiredTest.java | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index a6f1eb206..0fb200db5 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -61,8 +61,19 @@ public void service(HttpRequest request, HttpResponse response) throws Exception System.out.println(jsonResponseObject.toString()); /** - * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", - * "required": "true", "state": "VALID" } ] } } } + * { + * "page_info": { + * "form_info": { + * "parameter_info": [ + * { + * "display_name": "order_number", + * "required": "true", + * "state": "VALID" + * } + * ] + * } + * } + * } */ BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 46f7347c6..6dfa871a5 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -66,6 +66,7 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { WebhookRequest webhookRequest = WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = gson.toJson(webhookRequest); @@ -74,7 +75,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { when(request.getReader()).thenReturn(jsonReader); new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); - writerOut.flush(); JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); @@ -95,6 +95,9 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String jsonResponseObject = gson.toJson(webhookResponse); + writerOut.flush(); + + assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); } } From 564673ac0ec31adfa484fb92b904d84d167eaf77 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 12 Jul 2022 16:03:41 +0000 Subject: [PATCH 36/72] =?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 --- .kokoro/build.sh | 4 +--- README.md | 6 +++--- ...okToSetFormParametersAsOptionalOrRequired.java | 15 ++------------- ...SetFormParametersAsOptionalOrRequiredTest.java | 1 - 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 2054545c1..7fc69f67c 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,9 +101,7 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify \ - -e \ - -X + verify RETURN_CODE=$? popd else diff --git a/README.md b/README.md index 09351c249..c5d3c44d7 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-dialogflow-cx - 0.14.0 + 0.14.1 ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.0' +implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.1' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.0" +libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.1" ``` ## Authentication diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index 0fb200db5..a6f1eb206 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -61,19 +61,8 @@ public void service(HttpRequest request, HttpResponse response) throws Exception System.out.println(jsonResponseObject.toString()); /** - * { - * "page_info": { - * "form_info": { - * "parameter_info": [ - * { - * "display_name": "order_number", - * "required": "true", - * "state": "VALID" - * } - * ] - * } - * } - * } + * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", + * "required": "true", "state": "VALID" } ] } } } */ BufferedWriter writer = response.getWriter(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 6dfa871a5..e6b5bee3f 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -97,7 +97,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { writerOut.flush(); - assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); } } From 775704b7fbfab112f6b01e560a73a2689c38069a Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 11:07:18 -0500 Subject: [PATCH 37/72] remove extra gson Change-Id: I7f6b52e600a8b2513f59560fe3e727dd5d822319 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 6dfa871a5..ac303cbdb 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -44,7 +44,6 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { private BufferedWriter writerOut; private StringWriter responseOut; - private static final Gson gson = new Gson(); @Before public void beforeTest() throws IOException { @@ -69,7 +68,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String jsonString = gson.toJson(webhookRequest); + String jsonString = webhookRequest.toString(); + // gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); From dada2ce642fb6bb46a327395c2a3d8115a4877a9 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 11:12:14 -0500 Subject: [PATCH 38/72] fix formatting Change-Id: Icb1ff15957d93fab961b49f05492282c4363fdcd --- ...ToSetFormParametersAsOptionalOrRequired.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java index a6f1eb206..2db56b5de 100644 --- a/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java +++ b/samples/snippets/src/main/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequired.java @@ -60,10 +60,21 @@ public void service(HttpRequest request, HttpResponse response) throws Exception System.out.println("Response Object: \n"); System.out.println(jsonResponseObject.toString()); - /** - * { "page_info": { "form_info": { "parameter_info": [ { "display_name": "order_number", - * "required": "true", "state": "VALID" } ] } } } + /* { + * "page_info": { + * "form_info": { + * "parameter_info": [ + * { + * "display_name": "order_number", + * "required": "true", + * "state": "VALID" + * } + * ] + * } + * } + * } */ + BufferedWriter writer = response.getWriter(); // Sends the responseObject From 94c721935a08e55fd2d87815870ebd263f2fa0a0 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 12:08:54 -0500 Subject: [PATCH 39/72] fix formatting Change-Id: Iabb1e248e03bd5300b9aad10e0504d8d96ea564b --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 80d4e3bcd..3f1468311 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -74,8 +74,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { when(request.getReader()).thenReturn(jsonReader); - new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); - JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); @@ -95,6 +93,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { String jsonResponseObject = gson.toJson(webhookResponse); + new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); + writerOut.flush(); assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); From 105ffedc1af194cc9d1793aa5d8df19ed372007c Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 12:09:14 -0500 Subject: [PATCH 40/72] fix formatting Change-Id: Icd6976bd8fc1795accfda722e00270aebf69fa43 --- ...figureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 3f1468311..9373de068 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -69,7 +69,6 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonString = webhookRequest.toString(); - // gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); From abb1f30bdae54285f177aa02d01c9337d371c311 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 15:21:04 -0500 Subject: [PATCH 41/72] restructure json format Change-Id: I1e919a48b857e4bb4e33fb26265ec7320b1ece24 --- .../configure_session_parameters.json | 7 +++++ ...WebhookConfigureSessionParametersTest.java | 31 +++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 samples/snippets/resources/configure_session_parameters.json diff --git a/samples/snippets/resources/configure_session_parameters.json b/samples/snippets/resources/configure_session_parameters.json new file mode 100644 index 000000000..8fbb052f1 --- /dev/null +++ b/samples/snippets/resources/configure_session_parameters.json @@ -0,0 +1,7 @@ +{ + "session_info": { + "parameters": { + "order_number": "12345" + } + } +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 1eee85bcd..e0506196f 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -23,14 +23,14 @@ import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -57,17 +57,16 @@ public void beforeTest() throws IOException { when(response.getWriter()).thenReturn(writerOut); } - @Test - public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = - FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); + private static String fromFile(String fileName) throws IOException { + Path absolutePath = Paths.get("resources", fileName); - WebhookRequest webhookRequest = - WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + return new String(Files.readAllBytes(absolutePath)); + } - Gson gson = new GsonBuilder().setPrettyPrinting().create(); + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + String jsonString = "{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}"; - String jsonString = gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); @@ -75,14 +74,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); - JsonObject webhookResponse = new JsonObject(); - JsonObject parameterObject = new JsonObject(); - JsonObject orderParameter = new JsonObject(); - orderParameter.addProperty("order_number", "12345"); - parameterObject.add("parameters", orderParameter); - webhookResponse.add("session_info", parameterObject); - String jsonResponseObject = gson.toJson(webhookResponse); + String expectedResponse = fromFile("configure_session_parameters.json"); - assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } From f9142a7420767758b1d7b0cf63b434dc37848361 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 15:27:09 -0500 Subject: [PATCH 42/72] restructure json format Change-Id: Ib36de1d54869dad920e1743834be56a84d8398ba --- ...orm_parameter_as_optional_or_required.json | 13 ++++++ ...ormParametersAsOptionalOrRequiredTest.java | 43 ++++++------------- 2 files changed, 25 insertions(+), 31 deletions(-) create mode 100644 samples/snippets/resources/set_form_parameter_as_optional_or_required.json diff --git a/samples/snippets/resources/set_form_parameter_as_optional_or_required.json b/samples/snippets/resources/set_form_parameter_as_optional_or_required.json new file mode 100644 index 000000000..9a658fbe2 --- /dev/null +++ b/samples/snippets/resources/set_form_parameter_as_optional_or_required.json @@ -0,0 +1,13 @@ +{ + "page_info": { + "form_info": { + "parameter_info": [ + { + "display_name": "order_number", + "required": "true", + "state": "VALID" + } + ] + } + } +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 9373de068..0a38897be 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -23,15 +23,14 @@ import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -58,44 +57,26 @@ public void beforeTest() throws IOException { when(response.getWriter()).thenReturn(writerOut); } - @Test - public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = - FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); + private static String fromFile(String fileName) throws IOException { + Path absolutePath = Paths.get("resources", fileName); - WebhookRequest webhookRequest = - WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); + return new String(Files.readAllBytes(absolutePath)); + } - Gson gson = new GsonBuilder().setPrettyPrinting().create(); + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; - String jsonString = webhookRequest.toString(); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); - JsonObject parameterObject = new JsonObject(); - parameterObject.addProperty("display_name", "order_number"); - parameterObject.addProperty("required", "true"); - parameterObject.addProperty("state", "VALID"); - - JsonArray parameterInfoList = new JsonArray(); - parameterInfoList.add(parameterObject); - - JsonObject parameterInfoObject = new JsonObject(); - parameterInfoObject.add("parameter_info", parameterInfoList); - - JsonObject formInfo = new JsonObject(); - formInfo.add("form_info", parameterInfoObject); - - JsonObject webhookResponse = new JsonObject(); - webhookResponse.add("page_info", formInfo); - - String jsonResponseObject = gson.toJson(webhookResponse); + String expectedResponse = fromFile("set_form_parameter_as_optional_or_required.json"); new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } From 17742f3cd9f5aa7ef99db1a44cda1711339ebb26 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Tue, 12 Jul 2022 15:32:59 -0500 Subject: [PATCH 43/72] restructure json format Change-Id: I5c7be6894f91e26a8b59a46635a65953728ae591 --- .../resources/validate_form_parameter.json | 19 +++++++ .../cx/WebhookValidateFormParameterTest.java | 51 +++++-------------- 2 files changed, 31 insertions(+), 39 deletions(-) create mode 100644 samples/snippets/resources/validate_form_parameter.json diff --git a/samples/snippets/resources/validate_form_parameter.json b/samples/snippets/resources/validate_form_parameter.json new file mode 100644 index 000000000..e918beea3 --- /dev/null +++ b/samples/snippets/resources/validate_form_parameter.json @@ -0,0 +1,19 @@ +{ + "page_info": { + "form_info": { + "parameter_info": [ + { + "display_name": "order_number", + "required": "true", + "state": "INVALID", + "value": "123" + } + ] + } + }, + "session_info": { + "parameters": { + "order_number": "null" + } + } +} \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index d576f53b4..4b63ff17e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -23,15 +23,14 @@ import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -44,7 +43,6 @@ public class WebhookValidateFormParameterTest { private BufferedWriter writerOut; private StringWriter responseOut; - private static final Gson gson = new Gson(); @Before public void beforeTest() throws IOException { @@ -59,16 +57,16 @@ public void beforeTest() throws IOException { when(response.getWriter()).thenReturn(writerOut); } + private static String fromFile(String fileName) throws IOException { + Path absolutePath = Paths.get("resources", fileName); + + return new String(Files.readAllBytes(absolutePath)); + } + @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = - FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); + String jsonString = "{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"; - WebhookRequest webhookRequest = - WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - String jsonString = gson.toJson(webhookRequest); BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(jsonReader); @@ -76,33 +74,8 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { new WebhookValidateFormParameter().service(request, response); writerOut.flush(); - JsonObject sessionParameter = new JsonObject(); - sessionParameter.addProperty("order_number", "null"); - - JsonObject sessionInfo = new JsonObject(); - sessionInfo.add("parameters", sessionParameter); - - JsonObject parameterObject = new JsonObject(); - parameterObject.addProperty("display_name", "order_number"); - parameterObject.addProperty("required", "true"); - parameterObject.addProperty("state", "INVALID"); - parameterObject.addProperty("value", "123"); - - JsonArray parameterInfoList = new JsonArray(); - parameterInfoList.add(parameterObject); - - JsonObject parameterInfoObject = new JsonObject(); - parameterInfoObject.add("parameter_info", parameterInfoList); - - JsonObject formInfo = new JsonObject(); - formInfo.add("form_info", parameterInfoObject); - - JsonObject webhookResponse = new JsonObject(); - webhookResponse.add("page_info", formInfo); - webhookResponse.add("session_info", sessionInfo); - - String jsonResponseObject = gson.toJson(webhookResponse); + String expectedResponse = fromFile("validate_form_parameter.json"); - assertThat(responseOut.toString()).isEqualTo(jsonResponseObject.toString()); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } From 9fdab1155ef97eb31585f4484bcc577d17efa6b3 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 11:41:33 -0500 Subject: [PATCH 44/72] restructure mockito stubbing Change-Id: Id67943d85113ba436844fe5b6a39593a030a89cb --- ...ormParametersAsOptionalOrRequiredTest.java | 31 ++++++++--------- ...WebhookConfigureSessionParametersTest.java | 29 ++++++++++------ .../cx/WebhookValidateFormParameterTest.java | 34 +++++++++++++------ 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 0a38897be..4f2172448 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -17,7 +17,9 @@ package dialogflow.cx; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doAnswer; import com.google.cloud.dialogflow.cx.v3.WebhookRequest; import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; @@ -34,27 +36,31 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { - @Mock private HttpRequest request; - @Mock private HttpResponse response; + private HttpRequest request; + private HttpResponse response; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + + BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); + doReturn(jsonReader).when(request).getReader(); - // use an empty string as the default request content - BufferedReader reader = new BufferedReader(new StringReader("")); - when(request.getReader()).thenReturn(reader); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(response.getWriter()).thenReturn(writerOut); + + doReturn(writerOut).when(response).getWriter(); } private static String fromFile(String fileName) throws IOException { @@ -65,18 +71,11 @@ private static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'optional-or-required'}}"; - - BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - - when(request.getReader()).thenReturn(jsonReader); - - String expectedResponse = fromFile("set_form_parameter_as_optional_or_required.json"); - new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); - writerOut.flush(); + String expectedResponse = fromFile("set_form_parameter_as_optional_or_required.json"); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index e0506196f..fbff3f760 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -17,6 +17,9 @@ package dialogflow.cx; import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import com.google.cloud.dialogflow.cx.v3.WebhookRequest; @@ -34,27 +37,36 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.stubbing.Answer; + public class WebhookConfigureSessionParametersTest { - @Mock private HttpRequest request; - @Mock private HttpResponse response; + private HttpRequest request; + private HttpResponse response; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); + + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // use an empty string as the default request content - BufferedReader reader = new BufferedReader(new StringReader("")); - when(request.getReader()).thenReturn(reader); + BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + doReturn(jsonReader).when(request).getReader(); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(response.getWriter()).thenReturn(writerOut); + + doReturn(writerOut).when(response).getWriter(); + // when(response.getWriter()).thenReturn(writerOut); + } private static String fromFile(String fileName) throws IOException { @@ -65,11 +77,6 @@ private static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}"; - - BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - - when(request.getReader()).thenReturn(jsonReader); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 4b63ff17e..76344a501 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -17,6 +17,8 @@ package dialogflow.cx; import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import com.google.cloud.dialogflow.cx.v3.WebhookRequest; @@ -34,27 +36,39 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterTest { - @Mock private HttpRequest request; - @Mock private HttpResponse response; + // @Mock private HttpRequest request; + // @Mock private HttpResponse response; + + private HttpRequest request; + private HttpResponse response; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); + + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - // use an empty string as the default request content - BufferedReader reader = new BufferedReader(new StringReader("")); - when(request.getReader()).thenReturn(reader); + BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); + // System.out.println("READER" + jsonReader); + doReturn(jsonReader).when(request).getReader(); + // when(request.getReader()).thenReturn(jsonReader); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(response.getWriter()).thenReturn(writerOut); + + // doReturn(jsonReader).when(request).getReader(); + + doReturn(writerOut).when(response).getWriter(); + // when(response.getWriter()).thenReturn(writerOut); } private static String fromFile(String fileName) throws IOException { @@ -65,11 +79,11 @@ private static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - String jsonString = "{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"; - BufferedReader jsonReader = new BufferedReader(new StringReader(jsonString)); - when(request.getReader()).thenReturn(jsonReader); + // when(request.getReader()).thenReturn(jsonReader); + // when(response.getWriter()).thenReturn(writerOut); + new WebhookValidateFormParameter().service(request, response); writerOut.flush(); From cfb1a261c4037dfd0fe523195638bf299867015b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:08:22 -0500 Subject: [PATCH 45/72] restructure mockito stubbing Change-Id: Ib1df6375ec71353f4ab62bf83c6ff7712da59acb --- ...ormParametersAsOptionalOrRequiredTest.java | 25 +++++++++++----- ...WebhookConfigureSessionParametersTest.java | 23 +++++++++----- .../cx/WebhookValidateFormParameterTest.java | 30 ++++++++++++------- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 4f2172448..358ef2412 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -35,32 +35,40 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { + @InjectMocks + WebhookValidateFormParameter webhookValidateFormParameter; - private HttpRequest request; - private HttpResponse response; + @Mock + HttpRequest httpRequest; + + @Mock + HttpResponse httpResponse; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + MockitoAnnotations.openMocks(this); + + // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); - doReturn(jsonReader).when(request).getReader(); + // doReturn(jsonReader).when(request).getReader(); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - doReturn(writerOut).when(response).getWriter(); + + // doReturn(writerOut).when(response).getWriter(); } private static String fromFile(String fileName) throws IOException { @@ -71,6 +79,9 @@ private static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); + new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index fbff3f760..cf1d11fe5 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -36,6 +36,7 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -43,28 +44,34 @@ public class WebhookConfigureSessionParametersTest { + @InjectMocks + WebhookValidateFormParameter webhookValidateFormParameter; - private HttpRequest request; - private HttpResponse response; + @Mock + HttpRequest httpRequest; + + @Mock + HttpResponse httpResponse; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // use an empty string as the default request content BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - doReturn(jsonReader).when(request).getReader(); + // when(request.getReader()).thenReturn(jsonReader); + // doReturn(jsonReader).when(request).getReader(); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - doReturn(writerOut).when(response).getWriter(); + // doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); } @@ -77,6 +84,8 @@ private static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 76344a501..82dec0db1 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -35,31 +35,39 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterTest { + @InjectMocks + WebhookValidateFormParameter webhookValidateFormParameter; - // @Mock private HttpRequest request; - // @Mock private HttpResponse response; + @Mock + HttpRequest httpRequest; - private HttpRequest request; - private HttpResponse response; + @Mock + HttpResponse httpResponse; + + // private HttpRequest request; + // private HttpResponse response; private BufferedWriter writerOut; private StringWriter responseOut; @Before public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); + + // when(request.getReader()).thenReturn(jsonReader); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); // System.out.println("READER" + jsonReader); - doReturn(jsonReader).when(request).getReader(); + // doReturn(jsonReader).when(request).getReader(); // when(request.getReader()).thenReturn(jsonReader); responseOut = new StringWriter(); @@ -67,7 +75,7 @@ public void beforeTest() throws IOException { // doReturn(jsonReader).when(request).getReader(); - doReturn(writerOut).when(response).getWriter(); + // doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); } @@ -81,8 +89,8 @@ private static String fromFile(String fileName) throws IOException { public void helloHttp_bodyParamsPost() throws IOException, Exception { - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); new WebhookValidateFormParameter().service(request, response); From 7876884814c7f96d540d39f9f285e85456bbf0c6 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:20:35 -0500 Subject: [PATCH 46/72] restructure mockito stubbing Change-Id: I3243a7b5b70010d9f181039983bdeb35098c72b2 --- ...reWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 2 +- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 2 +- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 358ef2412..47f0d1695 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -71,7 +71,7 @@ public void beforeTest() throws IOException { // doReturn(writerOut).when(response).getWriter(); } - private static String fromFile(String fileName) throws IOException { + public static String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index cf1d11fe5..a45ce3439 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -76,7 +76,7 @@ public void beforeTest() throws IOException { } - private static String fromFile(String fileName) throws IOException { + public static String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 82dec0db1..e95d10965 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -60,6 +60,9 @@ public class WebhookValidateFormParameterTest { public void beforeTest() throws IOException { MockitoAnnotations.openMocks(this); + request = mock(HttpRequest.class); + response = mock(HttpResponse.class); + // when(request.getReader()).thenReturn(jsonReader); // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); @@ -79,7 +82,7 @@ public void beforeTest() throws IOException { // when(response.getWriter()).thenReturn(writerOut); } - private static String fromFile(String fileName) throws IOException { + public static String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); From 0f414eb132eb8c2f0fa8495773d8040caad6a62b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:28:32 -0500 Subject: [PATCH 47/72] restructure mockito stubbing Change-Id: Idd80a7b9a29f0daaabc866b35b685efff1a80f94 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 3 ++- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 3 ++- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 47f0d1695..57ec1fa4b 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -50,6 +50,7 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Mock HttpResponse httpResponse; + private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; @@ -60,7 +61,7 @@ public void beforeTest() throws IOException { // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); // doReturn(jsonReader).when(request).getReader(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index a45ce3439..4882d4dc4 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -53,6 +53,7 @@ public class WebhookConfigureSessionParametersTest { @Mock HttpResponse httpResponse; + private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; @@ -64,7 +65,7 @@ public void beforeTest() throws IOException { // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // use an empty string as the default request content - BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); // when(request.getReader()).thenReturn(jsonReader); // doReturn(jsonReader).when(request).getReader(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index e95d10965..ef75b3a4b 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -53,9 +53,11 @@ public class WebhookValidateFormParameterTest { // private HttpRequest request; // private HttpResponse response; + private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; + @Before public void beforeTest() throws IOException { MockitoAnnotations.openMocks(this); @@ -68,7 +70,7 @@ public void beforeTest() throws IOException { // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - BufferedReader jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); // System.out.println("READER" + jsonReader); // doReturn(jsonReader).when(request).getReader(); // when(request.getReader()).thenReturn(jsonReader); From 2af0833d48979d49f59333b54d638a5cebdccf4b Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:51:05 -0500 Subject: [PATCH 48/72] restructure mocks and variables Change-Id: I2faa86d33aaf5d0b8a9941779f2b17934e848c74 --- ...eWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 6 +++--- .../cx/WebhookConfigureSessionParametersTest.java | 6 +++--- .../dialogflow/cx/WebhookValidateFormParameterTest.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 57ec1fa4b..36077a482 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -56,10 +56,10 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.openMocks(this); + MockitoAnnotations.initMocks(this); - // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); // doReturn(jsonReader).when(request).getReader(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 4882d4dc4..3e7ac1024 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -59,10 +59,10 @@ public class WebhookConfigureSessionParametersTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.openMocks(this); + MockitoAnnotations.initMocks(this); - // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // use an empty string as the default request content jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index ef75b3a4b..4b094261c 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -60,10 +60,10 @@ public class WebhookValidateFormParameterTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.openMocks(this); + MockitoAnnotations.initMocks(this); - request = mock(HttpRequest.class); - response = mock(HttpResponse.class); + request = Mockito.mock(HttpRequest.class); + response = Mockito.mock(HttpResponse.class); // when(request.getReader()).thenReturn(jsonReader); From d4b84cc2f4d48eaf3bade60d4892a9c10d1f3068 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 14:01:47 -0500 Subject: [PATCH 49/72] restructure mocks and variables Change-Id: I9accbd7282c92b409c619e717cc05aa694d6e3e7 --- ...bhookToSetFormParametersAsOptionalOrRequiredTest.java | 9 ++++++--- .../cx/WebhookConfigureSessionParametersTest.java | 6 ++++-- .../dialogflow/cx/WebhookValidateFormParameterTest.java | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 36077a482..e54b5c3c3 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -61,13 +61,17 @@ public void beforeTest() throws IOException { request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); // doReturn(jsonReader).when(request).getReader(); - + when(request.getReader()).thenReturn(jsonReader); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); + when(response.getWriter()).thenReturn(writerOut); + + // doReturn(writerOut).when(response).getWriter(); } @@ -80,8 +84,7 @@ public static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); + new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 3e7ac1024..57430b9f3 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -64,6 +64,7 @@ public void beforeTest() throws IOException { request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + // use an empty string as the default request content jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); // when(request.getReader()).thenReturn(jsonReader); @@ -71,6 +72,8 @@ public void beforeTest() throws IOException { responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); // doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); @@ -85,8 +88,7 @@ public static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); + new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 4b094261c..4d4cf1d32 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -78,6 +78,9 @@ public void beforeTest() throws IOException { responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); + // doReturn(jsonReader).when(request).getReader(); // doReturn(writerOut).when(response).getWriter(); @@ -94,8 +97,6 @@ public static String fromFile(String fileName) throws IOException { public void helloHttp_bodyParamsPost() throws IOException, Exception { - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); new WebhookValidateFormParameter().service(request, response); From 40b0839d8f570f29f97e5d2b7dbf2f37acb545d7 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 14:11:13 -0500 Subject: [PATCH 50/72] restructure mocks and variables Change-Id: I03bdc68502f8deff333e68cd3fb36d080a9f44ca --- ...ormParametersAsOptionalOrRequiredTest.java | 13 ++++------- ...WebhookConfigureSessionParametersTest.java | 20 ++++++---------- .../cx/WebhookValidateFormParameterTest.java | 23 ++++++------------- 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index e54b5c3c3..a87007fbd 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -56,24 +56,21 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); - // doReturn(jsonReader).when(request).getReader(); - when(request.getReader()).thenReturn(jsonReader); + doReturn(jsonReader).when(request).getReader(); + // when(request.getReader()).thenReturn(jsonReader); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(response.getWriter()).thenReturn(writerOut); - - - - // doReturn(writerOut).when(response).getWriter(); + // when(response.getWriter()).thenReturn(writerOut); + doReturn(writerOut).when(response).getWriter(); } public static String fromFile(String fileName) throws IOException { diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 57430b9f3..17a5f05eb 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -44,14 +44,8 @@ public class WebhookConfigureSessionParametersTest { - @InjectMocks - WebhookValidateFormParameter webhookValidateFormParameter; - - @Mock - HttpRequest httpRequest; - - @Mock - HttpResponse httpResponse; + private HttpRequest httpRequest; + private HttpResponse httpResponse; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -59,7 +53,7 @@ public class WebhookConfigureSessionParametersTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); @@ -68,14 +62,14 @@ public void beforeTest() throws IOException { // use an empty string as the default request content jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); // when(request.getReader()).thenReturn(jsonReader); - // doReturn(jsonReader).when(request).getReader(); + doReturn(jsonReader).when(request).getReader(); responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); + // when(request.getReader()).thenReturn(jsonReader); + // when(response.getWriter()).thenReturn(writerOut); - // doReturn(writerOut).when(response).getWriter(); + doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 4d4cf1d32..5ee960b52 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -41,17 +41,8 @@ import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterTest { - @InjectMocks - WebhookValidateFormParameter webhookValidateFormParameter; - - @Mock - HttpRequest httpRequest; - - @Mock - HttpResponse httpResponse; - - // private HttpRequest request; - // private HttpResponse response; + private HttpRequest httpRequest; + private HttpResponse httpResponse; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -60,10 +51,10 @@ public class WebhookValidateFormParameterTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class); - response = Mockito.mock(HttpResponse.class); + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // when(request.getReader()).thenReturn(jsonReader); @@ -72,7 +63,7 @@ public void beforeTest() throws IOException { jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); // System.out.println("READER" + jsonReader); - // doReturn(jsonReader).when(request).getReader(); + doReturn(jsonReader).when(request).getReader(); // when(request.getReader()).thenReturn(jsonReader); responseOut = new StringWriter(); @@ -83,7 +74,7 @@ public void beforeTest() throws IOException { // doReturn(jsonReader).when(request).getReader(); - // doReturn(writerOut).when(response).getWriter(); + doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); } From 5c23b7bea2d6a5796277ebb49560a086886aa97e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 15:16:13 -0500 Subject: [PATCH 51/72] fix variable names Change-Id: Ic196c389141e834c4d7cc54531de808b0c941801 --- ...ebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 ++-- .../cx/WebhookConfigureSessionParametersTest.java | 4 ++-- .../dialogflow/cx/WebhookValidateFormParameterTest.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index a87007fbd..f6ef7a1ed 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -45,10 +45,10 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { WebhookValidateFormParameter webhookValidateFormParameter; @Mock - HttpRequest httpRequest; + HttpRequest request; @Mock - HttpResponse httpResponse; + HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 17a5f05eb..26da47eda 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -44,8 +44,8 @@ public class WebhookConfigureSessionParametersTest { - private HttpRequest httpRequest; - private HttpResponse httpResponse; + private HttpRequest request; + private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 5ee960b52..663515177 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -41,8 +41,8 @@ import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterTest { - private HttpRequest httpRequest; - private HttpResponse httpResponse; + private HttpRequest request; + private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -53,8 +53,8 @@ public class WebhookValidateFormParameterTest { public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + httpRequest = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + httpResponse = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // when(request.getReader()).thenReturn(jsonReader); From b915194b4d2d16a319435f8e969df18e8cb61c36 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 15:23:23 -0500 Subject: [PATCH 52/72] fix variable names Change-Id: I5d4ce6132bfdfb1d709e589eaff060520da8fcc0 --- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 663515177..bd29e19c2 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -53,8 +53,8 @@ public class WebhookValidateFormParameterTest { public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - httpRequest = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - httpResponse = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // when(request.getReader()).thenReturn(jsonReader); From ef7fce8f9568865543d037602bf603bb8fc4e05a Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:29:04 -0500 Subject: [PATCH 53/72] remove unnecessary mock Change-Id: Ibff1531d1a6e6de27fee6e409d005d657ad2c86d --- ...ToSetFormParametersAsOptionalOrRequiredTest.java | 3 --- .../cx/WebhookConfigureSessionParametersTest.java | 10 +++++----- .../cx/WebhookValidateFormParameterTest.java | 13 +++++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index f6ef7a1ed..d808e5b50 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -41,9 +41,6 @@ import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { - @InjectMocks - WebhookValidateFormParameter webhookValidateFormParameter; - @Mock HttpRequest request; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 26da47eda..f7f472bce 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -44,8 +44,11 @@ public class WebhookConfigureSessionParametersTest { - private HttpRequest request; - private HttpResponse response; + @Mock + HttpRequest request; + + @Mock + HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -54,7 +57,6 @@ public class WebhookConfigureSessionParametersTest { @Before public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); @@ -82,8 +84,6 @@ public static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - - new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index bd29e19c2..cd3934a1e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -41,8 +41,11 @@ import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterTest { - private HttpRequest request; - private HttpResponse response; + @Mock + HttpRequest request; + + @Mock + HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -69,8 +72,8 @@ public void beforeTest() throws IOException { responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); + // when(request.getReader()).thenReturn(jsonReader); + // when(response.getWriter()).thenReturn(writerOut); // doReturn(jsonReader).when(request).getReader(); @@ -88,8 +91,6 @@ public static String fromFile(String fileName) throws IOException { public void helloHttp_bodyParamsPost() throws IOException, Exception { - - new WebhookValidateFormParameter().service(request, response); writerOut.flush(); From a5f53a7926f45393732bb5504c7a87028fb4c50e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:57:01 -0500 Subject: [PATCH 54/72] remove static Change-Id: Ie67fd74d024957fc8584794f30ccc1f953fb39e4 --- ...eWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 6 ++---- .../cx/WebhookConfigureSessionParametersTest.java | 2 +- .../dialogflow/cx/WebhookValidateFormParameterTest.java | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index d808e5b50..fa27afc16 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -53,7 +53,7 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Before public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); + MockitoAnnotations.initMocks(this); request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); @@ -70,7 +70,7 @@ public void beforeTest() throws IOException { doReturn(writerOut).when(response).getWriter(); } - public static String fromFile(String fileName) throws IOException { + public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); @@ -78,8 +78,6 @@ public static String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - - new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index f7f472bce..01f085cc0 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -76,7 +76,7 @@ public void beforeTest() throws IOException { } - public static String fromFile(String fileName) throws IOException { + public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index cd3934a1e..5619f30f4 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -81,7 +81,7 @@ public void beforeTest() throws IOException { // when(response.getWriter()).thenReturn(writerOut); } - public static String fromFile(String fileName) throws IOException { + public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); return new String(Files.readAllBytes(absolutePath)); From 5a02f34fd2c073c3496c66bfd5cea344eb968a0f Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 17:18:48 -0500 Subject: [PATCH 55/72] add annotations Change-Id: I727e43c0b98c4641414d950658e78c5c30b66506 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 4 +++- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 3 ++- .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index fa27afc16..deee777f1 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -39,7 +39,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Mock HttpRequest request; @@ -53,7 +55,7 @@ public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { @Before public void beforeTest() throws IOException { - MockitoAnnotations.initMocks(this); + // MockitoAnnotations.initMocks(this); request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 01f085cc0..813cf12c0 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -40,9 +40,10 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; - +@RunWith(MockitoJUnitRunner.class) public class WebhookConfigureSessionParametersTest { @Mock HttpRequest request; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 5619f30f4..261712ca6 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -39,7 +39,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class WebhookValidateFormParameterTest { @Mock HttpRequest request; From 3ffb3c775271aa71b42af4ef2e2b5b8d4622eb4c Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Thu, 14 Jul 2022 17:32:58 -0500 Subject: [PATCH 56/72] add annotations Change-Id: Ib594629756b704a701739188e2d59c0273d68a8f --- ...figureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 1 + .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 1 + .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 1 + 3 files changed, 3 insertions(+) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index deee777f1..4a751c010 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; +import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 813cf12c0..daa0bfcd4 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -35,6 +35,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; +import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 261712ca6..e923f7ba1 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; +import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; From a793ca443169e4dfc3c4aafd3cdb24ee40198249 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:09:16 -0500 Subject: [PATCH 57/72] add runwith import Change-Id: I32b0746e89b2131106ef965b1712981633b8488f --- ...figureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 1 + .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 1 + .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 1 + 3 files changed, 3 insertions(+) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 4a751c010..4884f32cc 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -40,6 +40,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index daa0bfcd4..9fed020aa 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -41,6 +41,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index e923f7ba1..9e15b21f9 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -40,6 +40,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) From 3be535773e061898d4d3ac8163a25eba8845f5d5 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:45:46 -0500 Subject: [PATCH 58/72] restructure test and mocks Change-Id: I5bdf09bd4c262c20ec84ad4255170b084c0caa69 --- ...ormParametersAsOptionalOrRequiredTest.java | 33 ++++++------ ...WebhookConfigureSessionParametersTest.java | 51 +++++++++++------- .../cx/WebhookValidateFormParameterTest.java | 54 ++++++++++++------- 3 files changed, 83 insertions(+), 55 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 4884f32cc..668d84e9f 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -43,20 +43,29 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; -@RunWith(MockitoJUnitRunner.class) public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { - @Mock - HttpRequest request; + private HttpRequest request; - @Mock - HttpResponse response; + // @Mock + private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; - @Before - public void beforeTest() throws IOException { + // @Before + // public void beforeTest() throws IOException { + + // } + + public String fromFile(String fileName) throws IOException { + Path absolutePath = Paths.get("resources", fileName); + + return new String(Files.readAllBytes(absolutePath)); + } + + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { // MockitoAnnotations.initMocks(this); request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); @@ -72,16 +81,6 @@ public void beforeTest() throws IOException { // when(response.getWriter()).thenReturn(writerOut); doReturn(writerOut).when(response).getWriter(); - } - - public String fromFile(String fileName) throws IOException { - Path absolutePath = Paths.get("resources", fileName); - - return new String(Files.readAllBytes(absolutePath)); - } - - @Test - public void helloHttp_bodyParamsPost() throws IOException, Exception { new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 9fed020aa..79befc749 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -47,37 +47,37 @@ @RunWith(MockitoJUnitRunner.class) public class WebhookConfigureSessionParametersTest { - @Mock - HttpRequest request; + // @Mock + private HttpRequest request; - @Mock - HttpResponse response; + // @Mock + private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; - @Before - public void beforeTest() throws IOException { + // @Before + // public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - // use an empty string as the default request content - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - // when(request.getReader()).thenReturn(jsonReader); - doReturn(jsonReader).when(request).getReader(); + // // use an empty string as the default request content + // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + // // when(request.getReader()).thenReturn(jsonReader); + // doReturn(jsonReader).when(request).getReader(); - responseOut = new StringWriter(); - writerOut = new BufferedWriter(responseOut); - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); + // responseOut = new StringWriter(); + // writerOut = new BufferedWriter(responseOut); + // // when(request.getReader()).thenReturn(jsonReader); + // // when(response.getWriter()).thenReturn(writerOut); - doReturn(writerOut).when(response).getWriter(); + // doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); - } + // } public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); @@ -87,6 +87,21 @@ public String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + + + // use an empty string as the default request content + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + // when(request.getReader()).thenReturn(jsonReader); + doReturn(jsonReader).when(request).getReader(); + + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + // when(request.getReader()).thenReturn(jsonReader); + // when(response.getWriter()).thenReturn(writerOut); + + doReturn(writerOut).when(response).getWriter(); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 9e15b21f9..afcf24892 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -45,45 +45,43 @@ @RunWith(MockitoJUnitRunner.class) public class WebhookValidateFormParameterTest { - @Mock - HttpRequest request; + // @Mock + private HttpRequest request; - @Mock - HttpResponse response; + // @Mock + private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; private StringWriter responseOut; - @Before - public void beforeTest() throws IOException { + // @Before + // public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - + // when(request.getReader()).thenReturn(jsonReader); // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); - // System.out.println("READER" + jsonReader); - doReturn(jsonReader).when(request).getReader(); - // when(request.getReader()).thenReturn(jsonReader); + // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); + // // System.out.println("READER" + jsonReader); + // doReturn(jsonReader).when(request).getReader(); + // // when(request.getReader()).thenReturn(jsonReader); - responseOut = new StringWriter(); - writerOut = new BufferedWriter(responseOut); + // responseOut = new StringWriter(); + // writerOut = new BufferedWriter(responseOut); - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); + // // when(request.getReader()).thenReturn(jsonReader); + // // when(response.getWriter()).thenReturn(writerOut); - // doReturn(jsonReader).when(request).getReader(); + // // doReturn(jsonReader).when(request).getReader(); - doReturn(writerOut).when(response).getWriter(); + // doReturn(writerOut).when(response).getWriter(); // when(response.getWriter()).thenReturn(writerOut); - } + // } public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); @@ -93,7 +91,23 @@ public String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); + // System.out.println("READER" + jsonReader); + doReturn(jsonReader).when(request).getReader(); + // when(request.getReader()).thenReturn(jsonReader); + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + + // when(request.getReader()).thenReturn(jsonReader); + // when(response.getWriter()).thenReturn(writerOut); + + // doReturn(jsonReader).when(request).getReader(); + + doReturn(writerOut).when(response).getWriter(); new WebhookValidateFormParameter().service(request, response); writerOut.flush(); From 313bb7545809ea941ccb57a2af257883e26c3c11 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 10:20:55 -0500 Subject: [PATCH 59/72] fix imports Change-Id: I48b1628e4f60372a767c354dcd78e9c1b3e0f415 --- ...figureWebhookToSetFormParametersAsOptionalOrRequiredTest.java | 1 - .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 1 - .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 1 - 3 files changed, 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index 668d84e9f..ee3214651 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -40,7 +40,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 79befc749..06c2a3f33 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -41,7 +41,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index afcf24892..08a2d7439 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -40,7 +40,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) From 56633b2516edb50fd7fe0ae3ed8e96b2131026b2 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:33:21 -0500 Subject: [PATCH 60/72] fix imports Change-Id: Icbc59fc1d313a7224c2d472b49ca144f217bbf77 --- .../dialogflow/cx/WebhookConfigureSessionParametersTest.java | 1 - .../java/dialogflow/cx/WebhookValidateFormParameterTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 06c2a3f33..63fa3132c 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -44,7 +44,6 @@ import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; -@RunWith(MockitoJUnitRunner.class) public class WebhookConfigureSessionParametersTest { // @Mock private HttpRequest request; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 08a2d7439..7fbd9b149 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -42,7 +42,6 @@ import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; -@RunWith(MockitoJUnitRunner.class) public class WebhookValidateFormParameterTest { // @Mock private HttpRequest request; From e711e37e27023333377023fe95869bbf746be9b2 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:04:46 -0500 Subject: [PATCH 61/72] fix imports Change-Id: I2591dbdd32e3f97e7f61f38d88e222ed11418c25 --- ...ormParametersAsOptionalOrRequiredTest.java | 1 - ...WebhookConfigureSessionParametersTest.java | 47 +++++++++---------- .../cx/WebhookValidateFormParameterTest.java | 1 - 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java index ee3214651..7f2a19758 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java @@ -34,7 +34,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; -import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java index 63fa3132c..c38647d84 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java @@ -35,7 +35,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; -import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -55,27 +54,27 @@ public class WebhookConfigureSessionParametersTest { private BufferedWriter writerOut; private StringWriter responseOut; - // @Before - // public void beforeTest() throws IOException { + @Before + public void beforeTest() throws IOException { // MockitoAnnotations.initMocks(this); - // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - + request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - // // use an empty string as the default request content - // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - // // when(request.getReader()).thenReturn(jsonReader); - // doReturn(jsonReader).when(request).getReader(); - // responseOut = new StringWriter(); - // writerOut = new BufferedWriter(responseOut); - // // when(request.getReader()).thenReturn(jsonReader); - // // when(response.getWriter()).thenReturn(writerOut); + // use an empty string as the default request content + jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + // when(request.getReader()).thenReturn(jsonReader); + doReturn(jsonReader).when(request).getReader(); - // doReturn(writerOut).when(response).getWriter(); + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + // when(request.getReader()).thenReturn(jsonReader); // when(response.getWriter()).thenReturn(writerOut); - // } + doReturn(writerOut).when(response).getWriter(); + when(response.getWriter()).thenReturn(writerOut); + + } public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); @@ -85,21 +84,21 @@ public String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); + // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); + // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); // use an empty string as the default request content - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - // when(request.getReader()).thenReturn(jsonReader); - doReturn(jsonReader).when(request).getReader(); + // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); + // // when(request.getReader()).thenReturn(jsonReader); + // doReturn(jsonReader).when(request).getReader(); - responseOut = new StringWriter(); - writerOut = new BufferedWriter(responseOut); + // responseOut = new StringWriter(); + // writerOut = new BufferedWriter(responseOut); // when(request.getReader()).thenReturn(jsonReader); // when(response.getWriter()).thenReturn(writerOut); - doReturn(writerOut).when(response).getWriter(); + // doReturn(writerOut).when(response).getWriter(); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java index 7fbd9b149..4b066fc30 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java @@ -34,7 +34,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; -import org.junit.runner.Runwith; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; From d5feb4c6b67007ed45a7e83254dad4a080be654e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 13:19:36 -0500 Subject: [PATCH 62/72] rename test files Change-Id: Ifcd47fd1d94f7064a0fa178a36fe3e803a8bb234 --- ...FormParametersAsOptionalOrRequiredIT.java} | 56 ++++----- ... WebhookConfigureSessionParametersIT.java} | 47 ++----- .../cx/WebhookValidateFormParameterIT.java | 79 ++++++++++++ .../cx/WebhookValidateFormParameterTest.java | 116 ------------------ 4 files changed, 108 insertions(+), 190 deletions(-) rename samples/snippets/src/test/java/dialogflow/cx/{ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java => ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java} (62%) rename samples/snippets/src/test/java/dialogflow/cx/{WebhookConfigureSessionParametersTest.java => WebhookConfigureSessionParametersIT.java} (52%) create mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java delete mode 100644 samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java similarity index 62% rename from samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java rename to samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 7f2a19758..6c9e05292 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -17,12 +17,8 @@ package dialogflow.cx; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.doAnswer; -import com.google.cloud.dialogflow.cx.v3.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import java.io.BufferedReader; @@ -36,25 +32,33 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; -public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredTest { - private HttpRequest request; +public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT { + @Mock + HttpRequest request; - // @Mock - private HttpResponse response; + @Mock + HttpResponse response; - private BufferedReader jsonReader; - private BufferedWriter writerOut; - private StringWriter responseOut; + BufferedReader jsonReader; + StringReader stringReader; + BufferedWriter writerOut; + StringWriter responseOut; - // @Before - // public void beforeTest() throws IOException { - - // } + @Before + public void beforeTest() throws IOException { + MockitoAnnotations.initMocks(this); + + stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"); + jsonReader = new BufferedReader(stringReader); + + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); + } public String fromFile(String fileName) throws IOException { Path absolutePath = Paths.get("resources", fileName); @@ -64,26 +68,10 @@ public String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - // MockitoAnnotations.initMocks(this); - - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - - - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'optional-or-required'}}")); - doReturn(jsonReader).when(request).getReader(); - // when(request.getReader()).thenReturn(jsonReader); - - responseOut = new StringWriter(); - writerOut = new BufferedWriter(responseOut); - - // when(response.getWriter()).thenReturn(writerOut); - doReturn(writerOut).when(response).getWriter(); new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); String expectedResponse = fromFile("set_form_parameter_as_optional_or_required.json"); - assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java similarity index 52% rename from samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java rename to samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index c38647d84..c0ebe1433 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersTest.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -17,13 +17,8 @@ package dialogflow.cx; import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; -import com.google.cloud.dialogflow.cx.v3.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; import java.io.BufferedReader; @@ -38,16 +33,13 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -public class WebhookConfigureSessionParametersTest { - // @Mock +public class WebhookConfigureSessionParametersIT { + @Mock private HttpRequest request; - // @Mock + @Mock private HttpResponse response; private BufferedReader jsonReader; @@ -56,22 +48,13 @@ public class WebhookConfigureSessionParametersTest { @Before public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - + MockitoAnnotations.initMocks(this); - // use an empty string as the default request content - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - // when(request.getReader()).thenReturn(jsonReader); - doReturn(jsonReader).when(request).getReader(); - - responseOut = new StringWriter(); + stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"); + jsonReader = new BufferedReader(stringReader); writerOut = new BufferedWriter(responseOut); - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); - doReturn(writerOut).when(response).getWriter(); + when(request.getReader()).thenReturn(jsonReader); when(response.getWriter()).thenReturn(writerOut); } @@ -84,26 +67,10 @@ public String fromFile(String fileName) throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - - - // use an empty string as the default request content - // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'configure-session-parameters'}}")); - // // when(request.getReader()).thenReturn(jsonReader); - // doReturn(jsonReader).when(request).getReader(); - - // responseOut = new StringWriter(); - // writerOut = new BufferedWriter(responseOut); - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); - - // doReturn(writerOut).when(response).getWriter(); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); String expectedResponse = fromFile("configure_session_parameters.json"); - assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java new file mode 100644 index 000000000..ed069b808 --- /dev/null +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -0,0 +1,79 @@ +/* + * Copyright 2022 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 dialogflow.cx; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class WebhookValidateFormParameterIT { + @Mock + private HttpRequest request; + + @Mock + private HttpResponse response; + + private BufferedReader jsonReader; + private StringReader stringReader; + private BufferedWriter writerOut; + private StringWriter responseOut; + + + @Before + public void beforeTest() throws IOException { + MockitoAnnotations.initMocks(this); + + stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"); + jsonReader = new BufferedReader(stringReader); + + responseOut = new StringWriter(); + writerOut = new BufferedWriter(responseOut); + + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); + } + + public String fromFile(String fileName) throws IOException { + Path absolutePath = Paths.get("resources", fileName); + + return new String(Files.readAllBytes(absolutePath)); + } + + @Test + public void helloHttp_bodyParamsPost() throws IOException, Exception { + new WebhookValidateFormParameter().service(request, response); + writerOut.flush(); + + String expectedResponse = fromFile("validate_form_parameter.json"); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); + } +} diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java deleted file mode 100644 index 4b066fc30..000000000 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2022 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 dialogflow.cx; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.when; - -import com.google.cloud.dialogflow.cx.v3.WebhookRequest; -import com.google.cloud.dialogflow.cx.v3.WebhookRequest.FulfillmentInfo; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnitRunner; - -public class WebhookValidateFormParameterTest { - // @Mock - private HttpRequest request; - - // @Mock - private HttpResponse response; - - private BufferedReader jsonReader; - private BufferedWriter writerOut; - private StringWriter responseOut; - - - // @Before - // public void beforeTest() throws IOException { - // MockitoAnnotations.initMocks(this); - - - // when(request.getReader()).thenReturn(jsonReader); - - // request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - // response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - - // jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); - // // System.out.println("READER" + jsonReader); - // doReturn(jsonReader).when(request).getReader(); - // // when(request.getReader()).thenReturn(jsonReader); - - // responseOut = new StringWriter(); - // writerOut = new BufferedWriter(responseOut); - - // // when(request.getReader()).thenReturn(jsonReader); - // // when(response.getWriter()).thenReturn(writerOut); - - // // doReturn(jsonReader).when(request).getReader(); - - // doReturn(writerOut).when(response).getWriter(); - // when(response.getWriter()).thenReturn(writerOut); - // } - - public String fromFile(String fileName) throws IOException { - Path absolutePath = Paths.get("resources", fileName); - - return new String(Files.readAllBytes(absolutePath)); - } - - @Test - public void helloHttp_bodyParamsPost() throws IOException, Exception { - request = Mockito.mock(HttpRequest.class, Mockito.withSettings().verboseLogging()); - response = Mockito.mock(HttpResponse.class, Mockito.withSettings().verboseLogging()); - - jsonReader = new BufferedReader(new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}")); - // System.out.println("READER" + jsonReader); - doReturn(jsonReader).when(request).getReader(); - // when(request.getReader()).thenReturn(jsonReader); - - responseOut = new StringWriter(); - writerOut = new BufferedWriter(responseOut); - - // when(request.getReader()).thenReturn(jsonReader); - // when(response.getWriter()).thenReturn(writerOut); - - // doReturn(jsonReader).when(request).getReader(); - - doReturn(writerOut).when(response).getWriter(); - - new WebhookValidateFormParameter().service(request, response); - writerOut.flush(); - - String expectedResponse = fromFile("validate_form_parameter.json"); - - assertThat(responseOut.toString()).isEqualTo(expectedResponse); - } -} From 4e73b3dfc0962f1c034c723fb3ae191225677987 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 15 Jul 2022 18:26:25 +0000 Subject: [PATCH 63/72] =?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 --- README.md | 6 +++--- ...eWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 7 ++----- .../cx/WebhookConfigureSessionParametersIT.java | 8 ++------ .../dialogflow/cx/WebhookValidateFormParameterIT.java | 8 ++------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c5d3c44d7..b64dd3bb7 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-dialogflow-cx - 0.14.1 + 0.14.2 ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.1' +implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.1" +libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.2" ``` ## Authentication diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 6c9e05292..3bb606f4b 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -31,15 +31,12 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT { - @Mock - HttpRequest request; + @Mock HttpRequest request; - @Mock - HttpResponse response; + @Mock HttpResponse response; BufferedReader jsonReader; StringReader stringReader; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index c0ebe1433..52261efdf 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -31,16 +31,13 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class WebhookConfigureSessionParametersIT { - @Mock - private HttpRequest request; + @Mock private HttpRequest request; - @Mock - private HttpResponse response; + @Mock private HttpResponse response; private BufferedReader jsonReader; private BufferedWriter writerOut; @@ -56,7 +53,6 @@ public void beforeTest() throws IOException { when(request.getReader()).thenReturn(jsonReader); when(response.getWriter()).thenReturn(writerOut); - } public String fromFile(String fileName) throws IOException { diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index ed069b808..855307b86 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -31,23 +31,19 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterIT { - @Mock - private HttpRequest request; + @Mock private HttpRequest request; - @Mock - private HttpResponse response; + @Mock private HttpResponse response; private BufferedReader jsonReader; private StringReader stringReader; private BufferedWriter writerOut; private StringWriter responseOut; - @Before public void beforeTest() throws IOException { MockitoAnnotations.initMocks(this); From d6df8d386897b26df0fedaf22e2b80bc7761ad62 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 13:44:31 -0500 Subject: [PATCH 64/72] fix imports Change-Id: I65c7c53359c87b0c00afe02871f5405ce629d996 --- ...nfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 2 +- .../java/dialogflow/cx/WebhookConfigureSessionParametersIT.java | 1 - .../test/java/dialogflow/cx/WebhookValidateFormParameterIT.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 6c9e05292..7f7d7741d 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -31,7 +31,7 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT { diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index c0ebe1433..95733b890 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -31,7 +31,6 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index ed069b808..3551d2922 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -31,7 +31,6 @@ import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; From abf222e0962ef944f6d1516fdbb4ecc8cdbb37ff Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 14:53:55 -0500 Subject: [PATCH 65/72] add variable Change-Id: I140b08fdb80654140055e292057c0ddc74d23921 --- .../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 52261efdf..31c688865 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -40,6 +40,7 @@ public class WebhookConfigureSessionParametersIT { @Mock private HttpResponse response; private BufferedReader jsonReader; + private StringReader stringReader; private BufferedWriter writerOut; private StringWriter responseOut; From 750a308e233f192314781f37521be60368467d9f Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:57:29 -0500 Subject: [PATCH 66/72] remove json files and fix checkstyle Change-Id: Idf77efee6e42f430efab1c9aae662756d4feb92c --- .../configure_session_parameters.json | 7 --- ...orm_parameter_as_optional_or_required.json | 13 ----- .../resources/validate_form_parameter.json | 19 ------- ...tFormParametersAsOptionalOrRequiredIT.java | 45 ++++++++++++---- .../WebhookConfigureSessionParametersIT.java | 33 ++++++++---- .../cx/WebhookValidateFormParameterIT.java | 54 +++++++++++++++---- 6 files changed, 100 insertions(+), 71 deletions(-) delete mode 100644 samples/snippets/resources/configure_session_parameters.json delete mode 100644 samples/snippets/resources/set_form_parameter_as_optional_or_required.json delete mode 100644 samples/snippets/resources/validate_form_parameter.json diff --git a/samples/snippets/resources/configure_session_parameters.json b/samples/snippets/resources/configure_session_parameters.json deleted file mode 100644 index 8fbb052f1..000000000 --- a/samples/snippets/resources/configure_session_parameters.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "session_info": { - "parameters": { - "order_number": "12345" - } - } -} \ No newline at end of file diff --git a/samples/snippets/resources/set_form_parameter_as_optional_or_required.json b/samples/snippets/resources/set_form_parameter_as_optional_or_required.json deleted file mode 100644 index 9a658fbe2..000000000 --- a/samples/snippets/resources/set_form_parameter_as_optional_or_required.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "page_info": { - "form_info": { - "parameter_info": [ - { - "display_name": "order_number", - "required": "true", - "state": "VALID" - } - ] - } - } -} \ No newline at end of file diff --git a/samples/snippets/resources/validate_form_parameter.json b/samples/snippets/resources/validate_form_parameter.json deleted file mode 100644 index e918beea3..000000000 --- a/samples/snippets/resources/validate_form_parameter.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "page_info": { - "form_info": { - "parameter_info": [ - { - "display_name": "order_number", - "required": "true", - "state": "INVALID", - "value": "123" - } - ] - } - }, - "session_info": { - "parameters": { - "order_number": "null" - } - } -} \ No newline at end of file diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 1f441c95a..c5bad9c18 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -19,24 +19,27 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT { - @Mock HttpRequest request; + @Mock HttpRequest request; @Mock HttpResponse response; BufferedReader jsonReader; @@ -58,18 +61,38 @@ public void beforeTest() throws IOException { when(response.getWriter()).thenReturn(writerOut); } - public String fromFile(String fileName) throws IOException { - Path absolutePath = Paths.get("resources", fileName); - - return new String(Files.readAllBytes(absolutePath)); - } - @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); + new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - String expectedResponse = fromFile("set_form_parameter_as_optional_or_required.json"); + + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "VALID"); + + JsonArray parameterInfoList = new JsonArray(); + parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); + parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject formInfo = new JsonObject(); + formInfo.add("form_info", parameterInfoObject); + + JsonObject webhookResponse = new JsonObject(); + webhookResponse.add("page_info", formInfo); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String expectedResponse = gson.toJson(webhookResponse); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index 31c688865..d61527030 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -19,16 +19,18 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -50,24 +52,35 @@ public void beforeTest() throws IOException { stringReader = new StringReader("{'fulfillmentInfo': {'tag': 'validate-form-parameter'}}"); jsonReader = new BufferedReader(stringReader); + + responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); when(request.getReader()).thenReturn(jsonReader); when(response.getWriter()).thenReturn(writerOut); } - public String fromFile(String fileName) throws IOException { - Path absolutePath = Paths.get("resources", fileName); - - return new String(Files.readAllBytes(absolutePath)); - } - @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); + new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); - String expectedResponse = fromFile("configure_session_parameters.json"); + JsonObject webhookResponse = new JsonObject(); + JsonObject parameterObject = new JsonObject(); + JsonObject orderParameter = new JsonObject(); + orderParameter.addProperty("order_number", "12345"); + parameterObject.add("parameters", orderParameter); + webhookResponse.add("session_info", parameterObject); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String expectedResponse = gson.toJson(webhookResponse); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index 855307b86..e64a1271e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -19,16 +19,19 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest; +import com.google.cloud.dialogflow.cx.v3beta1.WebhookRequest.FulfillmentInfo; import com.google.cloud.functions.HttpRequest; import com.google.cloud.functions.HttpResponse; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -36,13 +39,13 @@ public class WebhookValidateFormParameterIT { @Mock private HttpRequest request; - @Mock private HttpResponse response; private BufferedReader jsonReader; private StringReader stringReader; private BufferedWriter writerOut; private StringWriter responseOut; + private static final Gson gson = new Gson(); @Before public void beforeTest() throws IOException { @@ -58,18 +61,47 @@ public void beforeTest() throws IOException { when(response.getWriter()).thenReturn(writerOut); } - public String fromFile(String fileName) throws IOException { - Path absolutePath = Paths.get("resources", fileName); - - return new String(Files.readAllBytes(absolutePath)); - } - @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() + .setTag("configure-session-parameters").build(); + + WebhookRequest webhookRequest = WebhookRequest.newBuilder() + .setFulfillmentInfo(fulfillmentInfo).build(); + new WebhookValidateFormParameter().service(request, response); writerOut.flush(); - String expectedResponse = fromFile("validate_form_parameter.json"); + JsonObject sessionParameter = new JsonObject(); + sessionParameter.addProperty("order_number", "null"); + + JsonObject sessionInfo = new JsonObject(); + sessionInfo.add("parameters", sessionParameter); + + JsonObject parameterObject = new JsonObject(); + parameterObject.addProperty("display_name", "order_number"); + parameterObject.addProperty("required", "true"); + parameterObject.addProperty("state", "INVALID"); + parameterObject.addProperty("value", "123"); + + JsonArray parameterInfoList = new JsonArray(); + parameterInfoList.add(parameterObject); + + JsonObject parameterInfoObject = new JsonObject(); + parameterInfoObject.add("parameter_info", parameterInfoList); + + JsonObject formInfo = new JsonObject(); + formInfo.add("form_info", parameterInfoObject); + + JsonObject webhookResponse = new JsonObject(); + webhookResponse.add("page_info", formInfo); + webhookResponse.add("session_info", sessionInfo); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + String expectedResponse = gson.toJson(webhookResponse); + System.out.println("Response: " + expectedResponse); + assertThat(responseOut.toString()).isEqualTo(expectedResponse); } } From c8a95f6a3cb9b4456dea3f5a00f03a79ec676d9e Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 16:12:17 -0500 Subject: [PATCH 67/72] make public Change-Id: I6bfaf4c002f513b3e517394d745c1548f886de77 --- .../cx/WebhookConfigureSessionParametersIT.java | 13 ++++++------- .../cx/WebhookValidateFormParameterIT.java | 15 +++++++-------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index d61527030..b59536033 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -37,14 +37,13 @@ import org.mockito.MockitoAnnotations; public class WebhookConfigureSessionParametersIT { - @Mock private HttpRequest request; + @Mock HttpRequest request; + @Mock HttpResponse response; - @Mock private HttpResponse response; - - private BufferedReader jsonReader; - private StringReader stringReader; - private BufferedWriter writerOut; - private StringWriter responseOut; + BufferedReader jsonReader; + StringReader stringReader; + BufferedWriter writerOut; + StringWriter responseOut; @Before public void beforeTest() throws IOException { diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index e64a1271e..2b19a44a9 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -38,14 +38,13 @@ import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterIT { - @Mock private HttpRequest request; - @Mock private HttpResponse response; - - private BufferedReader jsonReader; - private StringReader stringReader; - private BufferedWriter writerOut; - private StringWriter responseOut; - private static final Gson gson = new Gson(); + @Mock HttpRequest request; + @Mock HttpResponse response; + + BufferedReader jsonReader; + StringReader stringReader; + BufferedWriter writerOut; + StringWriter responseOut; @Before public void beforeTest() throws IOException { From 3b2f15877e2e4b7a9b1506a919d3d658f74906f3 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Fri, 15 Jul 2022 16:28:07 -0500 Subject: [PATCH 68/72] remove print Change-Id: Iff827980844223c3323db37df587a075c1f226c5 --- .../dialogflow/cx/WebhookConfigureSessionParametersIT.java | 1 + .../java/dialogflow/cx/WebhookValidateFormParameterIT.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index b59536033..0940ed921 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -37,6 +37,7 @@ import org.mockito.MockitoAnnotations; public class WebhookConfigureSessionParametersIT { + @Mock HttpRequest request; @Mock HttpResponse response; diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index 2b19a44a9..f14ce1508 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -38,6 +38,7 @@ import org.mockito.MockitoAnnotations; public class WebhookValidateFormParameterIT { + @Mock HttpRequest request; @Mock HttpResponse response; @@ -97,9 +98,7 @@ public void helloHttp_bodyParamsPost() throws IOException, Exception { webhookResponse.add("session_info", sessionInfo); Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String expectedResponse = gson.toJson(webhookResponse); - System.out.println("Response: " + expectedResponse); assertThat(responseOut.toString()).isEqualTo(expectedResponse); } From 6ead0e3d34a710a80cc53d3e8aacbd194bd108ab Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sat, 16 Jul 2022 12:17:00 -0500 Subject: [PATCH 69/72] add flag to kokoro build script Change-Id: I7a2d667a3460a59963b592d1504d0a465cc03565 --- .kokoro/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 7fc69f67c..3814d84d5 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,7 +101,9 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify + verify \ + -e \ + -X RETURN_CODE=$? popd else From 64af3d951187abd43e5ff7c44c358d724763fd04 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sat, 16 Jul 2022 12:23:23 -0500 Subject: [PATCH 70/72] add mock Change-Id: Iec351ef910c551a5a511454ad8edf3da6aec0734 --- ...ureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index c5bad9c18..acf0dcae7 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -56,13 +56,13 @@ public void beforeTest() throws IOException { responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); - - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); } @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); + FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() .setTag("configure-session-parameters").build(); From 9f50683c513f8e82ea4093850fd1a57cccf10833 Mon Sep 17 00:00:00 2001 From: aribray <45905583+aribray@users.noreply.github.com> Date: Sat, 16 Jul 2022 12:30:25 -0500 Subject: [PATCH 71/72] move mocks Change-Id: Ic1b22fd72c7e624bff8f19767ce5b15f44356e7d --- ...gureWebhookToSetFormParametersAsOptionalOrRequiredIT.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index acf0dcae7..0983c682d 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -56,12 +56,13 @@ public void beforeTest() throws IOException { responseOut = new StringWriter(); writerOut = new BufferedWriter(responseOut); + + when(request.getReader()).thenReturn(jsonReader); + when(response.getWriter()).thenReturn(writerOut); } @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - when(request.getReader()).thenReturn(jsonReader); - when(response.getWriter()).thenReturn(writerOut); FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() .setTag("configure-session-parameters").build(); From 323fa00727c78cd64040ec1d8a89b844987814a5 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Sat, 16 Jul 2022 17:42:16 +0000 Subject: [PATCH 72/72] =?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 --- .kokoro/build.sh | 4 +--- README.md | 6 +++--- ...WebhookToSetFormParametersAsOptionalOrRequiredIT.java | 9 ++++----- .../cx/WebhookConfigureSessionParametersIT.java | 8 ++++---- .../dialogflow/cx/WebhookValidateFormParameterIT.java | 8 ++++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 3814d84d5..7fc69f67c 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -101,9 +101,7 @@ samples) -Dclirr.skip=true \ -Denforcer.skip=true \ -fae \ - verify \ - -e \ - -X + verify RETURN_CODE=$? popd else diff --git a/README.md b/README.md index c5d3c44d7..b64dd3bb7 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-dialogflow-cx - 0.14.1 + 0.14.2 ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.1' +implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.1" +libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.2" ``` ## Authentication diff --git a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java index 0983c682d..b9a051bf7 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/ConfigureWebhookToSetFormParametersAsOptionalOrRequiredIT.java @@ -64,16 +64,15 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); new ConfigureWebhookToSetFormParametersAsOptionalOrRequired().service(request, response); writerOut.flush(); - JsonObject parameterObject = new JsonObject(); parameterObject.addProperty("display_name", "order_number"); parameterObject.addProperty("required", "true"); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java index 0940ed921..52cd6470d 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookConfigureSessionParametersIT.java @@ -62,11 +62,11 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); new WebhookConfigureSessionParameters().service(request, response); writerOut.flush(); diff --git a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java index f14ce1508..f234c3f3e 100644 --- a/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java +++ b/samples/snippets/src/test/java/dialogflow/cx/WebhookValidateFormParameterIT.java @@ -63,11 +63,11 @@ public void beforeTest() throws IOException { @Test public void helloHttp_bodyParamsPost() throws IOException, Exception { - FulfillmentInfo fulfillmentInfo = FulfillmentInfo.newBuilder() - .setTag("configure-session-parameters").build(); + FulfillmentInfo fulfillmentInfo = + FulfillmentInfo.newBuilder().setTag("configure-session-parameters").build(); - WebhookRequest webhookRequest = WebhookRequest.newBuilder() - .setFulfillmentInfo(fulfillmentInfo).build(); + WebhookRequest webhookRequest = + WebhookRequest.newBuilder().setFulfillmentInfo(fulfillmentInfo).build(); new WebhookValidateFormParameter().service(request, response); writerOut.flush();