From 8c1edfd59844d0190ca88d94bb1c34a6bc261dba Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Tue, 24 Mar 2020 15:54:19 -0700 Subject: [PATCH 01/34] remove unused list_* samples --- .../example/dialogflow/ContextManagement.java | 34 ------------------- .../example/dialogflow/EntityManagement.java | 27 --------------- .../dialogflow/EntityTypeManagement.java | 28 --------------- .../SessionEntityTypeManagement.java | 31 ----------------- 4 files changed, 120 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java index a1658629208..67525dd239a 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java @@ -32,40 +32,6 @@ * DialogFlow API Context sample. */ public class ContextManagement { - // [START dialogflow_list_contexts] - - /** - * Lists contexts - * - * @param sessionId Identifier of the DetectIntent session. - * @param projectId Project/Agent Id. - * @return List of Contexts found. - */ - public static List listContexts(String sessionId, String projectId) throws Exception { - List contexts = Lists.newArrayList(); - // Instantiates a client - try (ContextsClient contextsClient = ContextsClient.create()) { - // Set the session name using the sessionId (UUID) and projectId (my-project-id) - SessionName session = SessionName.of(projectId, sessionId); - - // Performs the list contexts request - for (Context context : contextsClient.listContexts(session).iterateAll()) { - System.out.format("Context name: %s\n", context.getName()); - System.out.format("Lifespan Count: %d\n", context.getLifespanCount()); - System.out.format("Fields:\n"); - for (Entry entry : context.getParameters().getFieldsMap().entrySet()) { - if (entry.getValue().hasStructValue()) { - System.out.format("\t%s: %s\n", entry.getKey(), entry.getValue()); - } - } - - contexts.add(context); - } - } - return contexts; - } - // [END dialogflow_list_contexts] - // [START dialogflow_create_context] /** diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityManagement.java index 0d982693e0d..f2d807048d5 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityManagement.java @@ -31,33 +31,6 @@ * DialogFlow API Entity sample. */ public class EntityManagement { - // [START dialogflow_list_entities] - - /** - * List entities - * - * @param projectId Project/agent id. - * @param entityTypeId The id of the entity_type. - * @return List of found entities. - */ - public static List listEntities(String projectId, String entityTypeId) throws Exception { - // Instantiates a client - try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) { - // Set the entity type name using the projectID (my-project-id) and entityTypeId (KIND_LIST) - EntityTypeName name = EntityTypeName.of(projectId, entityTypeId); - - // Performs the get entity type request - EntityType entityType = entityTypesClient.getEntityType(name); - List entities = entityType.getEntitiesList(); - for (Entity entity : entities) { - System.out.format("Entity value: %s\n", entity.getValue()); - System.out.format("Entity synonyms: %s\n", entity.getSynonymsList().toString()); - } - return entities; - } - } - // [END dialogflow_list_entities] - // [START dialogflow_create_entity] /** diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java index 04740c40b42..106fe2b0fdf 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java @@ -32,34 +32,6 @@ * DialogFlow API EntityType sample. */ public class EntityTypeManagement { - // [START dialogflow_list_entity_types] - - /** - * List entity types - * - * @param projectId Project/agent id. - * @return The EntityTypes found. - */ - public static List listEntityTypes(String projectId) throws Exception { - List entityTypes = Lists.newArrayList(); - // Instantiates a client - try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) { - // Set the project agent name using the projectID (my-project-id) - ProjectAgentName parent = ProjectAgentName.of(projectId); - - // Performs the list entity types request - for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) { - System.out.format("Entity type name %s\n", entityType.getName()); - System.out.format("Entity type display name: %s\n", entityType.getDisplayName()); - System.out.format("Number of entities: %d\n", entityType.getEntitiesCount()); - - entityTypes.add(entityType); - } - } - return entityTypes; - } - // [END dialogflow_list_entity_types] - // [START dialogflow_create_entity_type] /** diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java index aeb28f9f21f..c5f1fec01cd 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java @@ -33,37 +33,6 @@ * DialogFlow API SessionEntityType sample. */ public class SessionEntityTypeManagement { - // [START dialogflow_list_session_entity_types] - - /** - * List session entity types - * - * @param projectId Project/Agent Id. - * @param sessionId Identifier of the DetectIntent session. - * @return SessionEntityTypes found. - */ - public static List listSessionEntityTypes(String projectId, String sessionId) - throws Exception { - List sessionEntityTypes = Lists.newArrayList(); - // Instantiates a client - try (SessionEntityTypesClient sessionEntityTypesClient = SessionEntityTypesClient.create()) { - // Set the session name using the sessionId (UUID) and projectID (my-project-id) - SessionName session = SessionName.of(projectId, sessionId); - - System.out.format("SessionEntityTypes for session %s:\n", session.toString()); - // Performs the list session entity types request - for (SessionEntityType sessionEntityType : - sessionEntityTypesClient.listSessionEntityTypes(session).iterateAll()) { - System.out.format("\tSessionEntityType name: %s\n", sessionEntityType.getName()); - System.out.format("\tNumber of entities: %d\n", sessionEntityType.getEntitiesCount()); - - sessionEntityTypes.add(sessionEntityType); - } - } - return sessionEntityTypes; - } - // [END dialogflow_list_session_entity_types] - // [START dialogflow_create_session_entity_type] /** From 96e34caeb36e61a631e99f2213b25a77e15271ad Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Fri, 3 Apr 2020 11:35:51 -0700 Subject: [PATCH 02/34] dialogflow: delete unused context management samples --- .../example/dialogflow/ContextManagement.java | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java deleted file mode 100644 index 67525dd239a..00000000000 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/ContextManagement.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2018 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; - -// Imports the Google Cloud client library - -import com.google.cloud.dialogflow.v2.Context; -import com.google.cloud.dialogflow.v2.ContextName; -import com.google.cloud.dialogflow.v2.ContextsClient; -import com.google.cloud.dialogflow.v2.SessionName; -import com.google.common.collect.Lists; -import com.google.protobuf.Value; - -import java.util.List; -import java.util.Map.Entry; - -/** - * DialogFlow API Context sample. - */ -public class ContextManagement { - // [START dialogflow_create_context] - - /** - * Create an entity type with the given display name - * - * @param contextId The Id of the context. - * @param sessionId Identifier of the DetectIntent session. - * @param lifespanCount The lifespan count of the context. - * @param projectId Project/Agent Id. - * @return The new Context. - */ - public static Context createContext( - String contextId, - String sessionId, - String projectId, - int lifespanCount) throws Exception { - // Instantiates a client - try (ContextsClient contextsClient = ContextsClient.create()) { - // Set the session name using the sessionId (UUID) and projectID (my-project-id) - SessionName session = SessionName.of(projectId, sessionId); - - // Create the context name with the projectId, sessionId, and contextId - ContextName contextName = ContextName.newBuilder() - .setProject(projectId) - .setSession(sessionId) - .setContext(contextId) - .build(); - - // Create the context with the context name and lifespan count - Context context = Context.newBuilder() - .setName(contextName.toString()) // The unique identifier of the context - .setLifespanCount(lifespanCount) // Number of query requests before the context expires. - .build(); - - // Performs the create context request - Context response = contextsClient.createContext(session, context); - System.out.format("Context created: %s\n", response); - - return response; - } - } - // [END dialogflow_create_context] - - // [START dialogflow_delete_context] - - /** - * Delete entity type with the given entity type name - * - * @param contextId The Id of the context. - * @param sessionId Identifier of the DetectIntent session. - * @param projectId Project/Agent Id. - */ - public static void deleteContext(String contextId, String sessionId, String projectId) - throws Exception { - // Instantiates a client - try (ContextsClient contextsClient = ContextsClient.create()) { - // Create the context name with the projectId, sessionId, and contextId - ContextName contextName = ContextName.of(projectId, sessionId, contextId); - // Performs the delete context request - contextsClient.deleteContext(contextName); - } - } - // [END dialogflow_delete_context] -} From be7df0de7d394fa2adc149c7181da1b737bc188a Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Fri, 3 Apr 2020 11:37:23 -0700 Subject: [PATCH 03/34] dialogflow: delete unused detect intent with model selection samples --- .../DetectIntentWithModelSelection.java | 101 ------------------ 1 file changed, 101 deletions(-) delete mode 100644 dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithModelSelection.java diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithModelSelection.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithModelSelection.java deleted file mode 100644 index f7dd04657ae..00000000000 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithModelSelection.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2018 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; - -import com.google.cloud.dialogflow.v2beta1.AudioEncoding; -import com.google.cloud.dialogflow.v2beta1.DetectIntentRequest; -import com.google.cloud.dialogflow.v2beta1.DetectIntentResponse; -import com.google.cloud.dialogflow.v2beta1.InputAudioConfig; -import com.google.cloud.dialogflow.v2beta1.QueryInput; -import com.google.cloud.dialogflow.v2beta1.QueryResult; -import com.google.cloud.dialogflow.v2beta1.SessionName; -import com.google.cloud.dialogflow.v2beta1.SessionsClient; -import com.google.protobuf.ByteString; - -import java.nio.file.Files; -import java.nio.file.Paths; - -public class DetectIntentWithModelSelection { - // [START dialogflow_detect_intent_with_model_selection] - - /** - * Returns the result of detect intent with an audio file as input. - * - *

Using the same `session_id` between requests allows continuation of the conversation. - * - * @param projectId Project/Agent Id. - * @param audioFilePath Path to the audio file. - * @param sessionId Identifier of the DetectIntent session. - * @param languageCode Language code of the query. - * @return The QueryResult for the audio query. - */ - public static QueryResult detectIntentWithModelSelection( - String projectId, - String audioFilePath, - String sessionId, - String languageCode) throws Exception { - // Instantiates a client - try (SessionsClient sessionsClient = SessionsClient.create()) { - // Set the session name using the sessionId (UUID) and projectID (my-project-id) - SessionName session = SessionName.of(projectId, sessionId); - System.out.println("Session Path: " + session.toString()); - - // Note: hard coding audioEncoding and sampleRateHertz for simplicity. - // Audio encoding of the audio content sent in the query request. - AudioEncoding audioEncoding = AudioEncoding.AUDIO_ENCODING_LINEAR_16; - int sampleRateHertz = 16000; - - // Instructs the speech recognizer how to process the audio content. - InputAudioConfig inputAudioConfig = - InputAudioConfig.newBuilder() - .setAudioEncoding( - audioEncoding) // audioEncoding = AudioEncoding.AUDIO_ENCODING_LINEAR_16 - .setLanguageCode(languageCode) // languageCode = "en-US" - .setSampleRateHertz(sampleRateHertz) // sampleRateHertz = 16000 - .setModel("phone_call") // model = phone call - .build(); - - // Build the query with the InputAudioConfig - QueryInput queryInput = QueryInput.newBuilder().setAudioConfig(inputAudioConfig).build(); - - // Read the bytes from the audio file - byte[] inputAudio = Files.readAllBytes(Paths.get(audioFilePath)); - - // Build the DetectIntentRequest - DetectIntentRequest request = - DetectIntentRequest.newBuilder() - .setSession(session.toString()) - .setQueryInput(queryInput) - .setInputAudio(ByteString.copyFrom(inputAudio)) - .build(); - // Performs the detect intent request - DetectIntentResponse response = sessionsClient.detectIntent(request); - - // Display the query result - QueryResult queryResult = response.getQueryResult(); - System.out.println("===================="); - System.out.format("Query Text: '%s'\n", queryResult.getQueryText()); - System.out.format( - "Detected Intent: %s (confidence: %f)\n", - queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence()); - System.out.format("Fulfillment Text: '%s'\n", queryResult.getFulfillmentText()); - - return queryResult; - } - } - // [END dialogflow_detect_intent_with_model_selection] -} From a9215837d9f7d690f2bb653fb4cb862a8a054cff Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Fri, 3 Apr 2020 11:38:33 -0700 Subject: [PATCH 04/34] dialogflow: delete unused entity type management samples --- .../dialogflow/EntityTypeManagement.java | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java deleted file mode 100644 index 106fe2b0fdf..00000000000 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2018 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; - -// Imports the Google Cloud client library - -import com.google.cloud.dialogflow.v2.EntityType; -import com.google.cloud.dialogflow.v2.EntityType.Kind; -import com.google.cloud.dialogflow.v2.EntityTypeName; -import com.google.cloud.dialogflow.v2.EntityTypesClient; -import com.google.cloud.dialogflow.v2.ProjectAgentName; -import com.google.common.collect.Lists; - -import java.util.ArrayList; -import java.util.List; - -/** - * DialogFlow API EntityType sample. - */ -public class EntityTypeManagement { - // [START dialogflow_create_entity_type] - - /** - * Create an entity type with the given display name - * - * @param displayName The display name of the entity. - * @param projectId Project/agent id. - * @param kind The kind of entity. KIND_MAP (default) or KIND_LIST. - * @return The created EntityType. - */ - public static EntityType createEntityType(String displayName, String projectId, String kind) - throws Exception { - // Instantiates a client - try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) { - // Set the project agent name using the projectID (my-project-id) - ProjectAgentName parent = ProjectAgentName.of(projectId); - - // Entity types serve as a tool for extracting parameter values from natural language queries. - EntityType entityType = EntityType.newBuilder() - .setDisplayName(displayName) - .setKind(Kind.valueOf(kind)) - .build(); - - // Performs the create entity type request - EntityType response = entityTypesClient.createEntityType(parent, entityType); - System.out.println("Entity type created: " + response); - return response; - } - } - // [END dialogflow_create_entity_type] - - // [START dialogflow_delete_entity_type] - - /** - * Delete entity type with the given entity type name - * - * @param entityTypeId The id of the entity_type. - * @param projectId Project/agent id. - */ - public static void deleteEntityType(String entityTypeId, String projectId) throws Exception { - // Instantiates a client - try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) { - // Set the entity type name using the projectID (my-project-id) and entityTypeId (KIND_LIST) - EntityTypeName name = EntityTypeName.of(projectId, entityTypeId); - - // Performs the delete entity type request - entityTypesClient.deleteEntityType(name); - } - } - // [END dialogflow_delete_entity_type] - - /** - * Helper method for testing to get entityTypeId from displayName. - */ - public static List getEntityTypeIds(String displayName, String projectId) - throws Exception { - List entityTypesIds = new ArrayList<>(); - - try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) { - ProjectAgentName parent = ProjectAgentName.of(projectId); - // Performs the list entity types request - for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) { - if (entityType.getDisplayName().equals(displayName)) { - String[] splitName = entityType.getName().split("/"); - entityTypesIds.add(splitName[splitName.length - 1]); - } - } - } - return entityTypesIds; - } -} From acef492afce20170e3b8f61a87ba53b6f8bcc227 Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Fri, 3 Apr 2020 11:43:11 -0700 Subject: [PATCH 05/34] dialogflow: delete unused knowledgebase management samples --- .../dialogflow/KnowledgeBaseManagement.java | 60 +------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java index 1fee645e10e..6eaa53ed802 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java @@ -24,31 +24,6 @@ import java.util.List; public class KnowledgeBaseManagement { - // [START dialogflow_list_knowledge_base] - - /** - * List Knowledge bases - * - * @param projectId Project/agent id. - * @return The KnowledgeBases found in projectId. - */ - public static List listKnowledgeBases(String projectId) throws Exception { - List knowledgeBases = Lists.newArrayList(); - // Instantiates a client - try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) { - // Set the entity type name using the projectID (my-project-id) and entityTypeId (KIND_LIST) - ProjectName projectName = ProjectName.of(projectId); - for (KnowledgeBase knowledgeBase : - knowledgeBasesClient.listKnowledgeBases(projectName).iterateAll()) { - System.out.format(" - Display Name: %s\n", knowledgeBase.getDisplayName()); - System.out.format(" - Knowledge ID: %s\n", knowledgeBase.getName()); - knowledgeBases.add(knowledgeBase); - } - } - return knowledgeBases; - } - // [END dialogflow_list_knowledge_base] - // [START dialogflow_create_knowledge_base] /** @@ -72,37 +47,4 @@ public static KnowledgeBase createKnowledgeBase(String projectId, String display return response; } } - // [END dialogflow_create_knowledge_base] - - // [START dialogflow_get_knowledge_base] - - /** - * @param knowledgeBaseName Knowledge base id. - * @return The retrieved KnowledgeBase. - */ - public static KnowledgeBase getKnowledgeBase(String knowledgeBaseName) throws Exception { - // Instantiates a client - try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) { - KnowledgeBase response = knowledgeBasesClient.getKnowledgeBase(knowledgeBaseName); - System.out.format("Got Knowledge Base:\n"); - System.out.format(" - Display Name: %s\n", response.getDisplayName()); - System.out.format(" - Knowledge ID: %s\n", response.getName()); - return response; - } - } - // [END dialogflow_get_knowledge_base] - - // [START dialogflow_delete_knowledge_base] - - /** - * @param knowledgeBaseName Knowledge base id. - */ - public static void deleteKnowledgeBase(String knowledgeBaseName) throws Exception { - // Instantiates a client - try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) { - knowledgeBasesClient.deleteKnowledgeBase(knowledgeBaseName); - System.out.format("KnowledgeBase has been deleted.\n"); - } - } - // [END dialogflow_delete_knowledge_base] -} + // [END dialogflow_create_knowledge_base] \ No newline at end of file From ca5f614d86b098ab63dc47a0e0e288d19df328bf Mon Sep 17 00:00:00 2001 From: Anthony Wens Date: Fri, 3 Apr 2020 11:43:53 -0700 Subject: [PATCH 06/34] dialogflow: delete unused session entity type management samples --- .../SessionEntityTypeManagement.java | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java deleted file mode 100644 index c5f1fec01cd..00000000000 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2018 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; - -// Imports the Google Cloud client library - -import com.google.cloud.dialogflow.v2.EntityType.Entity; -import com.google.cloud.dialogflow.v2.SessionEntityType; -import com.google.cloud.dialogflow.v2.SessionEntityType.EntityOverrideMode; -import com.google.cloud.dialogflow.v2.SessionEntityTypeName; -import com.google.cloud.dialogflow.v2.SessionEntityTypesClient; -import com.google.cloud.dialogflow.v2.SessionName; -import com.google.common.collect.Lists; - -import java.util.ArrayList; -import java.util.List; - -/** - * DialogFlow API SessionEntityType sample. - */ -public class SessionEntityTypeManagement { - // [START dialogflow_create_session_entity_type] - - /** - * Create an entity type with the given display name - * - * @param projectId Project/Agent Id. - * @param sessionId Identifier of the DetectIntent session. - * @param entityValues The entity values of the session entity type. - * @param entityTypeDisplayName DISPLAY NAME of the entity type to be overridden in the session. - * @param entityOverrideMode ENTITY_OVERRIDE_MODE_OVERRIDE (default) or - * ENTITY_OVERRIDE_MODE_SUPPLEMENT - * @return Created SessionEntityType. - */ - public static SessionEntityType createSessionEntityType( - String projectId, - String sessionId, - List entityValues, - String entityTypeDisplayName, - int entityOverrideMode) throws Exception { - // Instantiates a client - try (SessionEntityTypesClient sessionEntityTypesClient = SessionEntityTypesClient.create()) { - // Set the session name using the sessionId (UUID) and projectID (my-project-id) - SessionName session = SessionName.of(projectId, sessionId); - SessionEntityTypeName name = SessionEntityTypeName.of( - projectId, sessionId, entityTypeDisplayName); - - List entities = new ArrayList<>(); - for (String entityValue : entityValues) { - entities.add(Entity.newBuilder() - .setValue(entityValue) - .addSynonyms(entityValue) - .build()); - } - - // Extends or replaces a developer entity type at the user session level (we refer to the - // entity types defined at the agent level as "developer entity types"). - SessionEntityType sessionEntityType = SessionEntityType.newBuilder() - .setName(name.toString()) - .addAllEntities(entities) - .setEntityOverrideMode(EntityOverrideMode.forNumber(entityOverrideMode)) - .build(); - - // Performs the create session entity type request - SessionEntityType response = sessionEntityTypesClient.createSessionEntityType(session, - sessionEntityType); - System.out.format("SessionEntityType created: %s\n", response); - - return response; - } - } - // [END dialogflow_create_session_entity_type] - - // [START dialogflow_delete_session_entity_type] - - /** - * Delete entity type with the given entity type name - * - * @param projectId Project/Agent Id. - * @param sessionId Identifier of the DetectIntent session. - * @param entityTypeDisplayName DISPLAY NAME of the entity type to be overridden in the session. - */ - public static void deleteSessionEntityType( - String projectId, - String sessionId, - String entityTypeDisplayName) throws Exception { - // Instantiates a client - try (SessionEntityTypesClient sessionEntityTypesClient = SessionEntityTypesClient.create()) { - SessionEntityTypeName name = SessionEntityTypeName.of(projectId, sessionId, - entityTypeDisplayName); - - // Performs the delete session entity type request - sessionEntityTypesClient.deleteSessionEntityType(name); - } - } - // [END dialogflow_delete_session_entity_type] -} From cf6b2f638b9018725a3c6c822663b8346ec2642a Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:40:18 -0600 Subject: [PATCH 07/34] Create CreateDocumentTest --- .../com/example/dialogflow/CreateDocumentTest | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest new file mode 100644 index 00000000000..e75405a0b6f --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest @@ -0,0 +1,100 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBase; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient; +import com.google.cloud.dialogflow.v2beta1.ProjectName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class CreateDocumentTest { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static String KNOWLEDGE_DISPLAY_NAME = UUID.randomUUID().toString(); + private static String DOCUMENT_DISPLAY_NAME = UUID.randomUUID().toString(); + private ByteArrayOutputStream bout; + private PrintStream out; + private String knowledgeBaseName; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() throws IOException { + // Create a knowledge base for the document + try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { + KnowledgeBase knowledgeBase = + KnowledgeBase.newBuilder().setDisplayName(KNOWLEDGE_DISPLAY_NAME).build(); + ProjectName projectName = ProjectName.of(PROJECT_ID); + KnowledgeBase response = client.createKnowledgeBase(projectName, knowledgeBase); + // Save the full name for deletion + knowledgeBaseName = response.getName(); + } + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Delete the created knowledge base + try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { + DeleteKnowledgeBaseRequest request = + DeleteKnowledgeBaseRequest.newBuilder().setName(knowledgeBaseName).setForce(true).build(); + client.deleteKnowledgeBase(request); + } + + System.setOut(null); + } + + @Test + public void testCreateDocument() throws Exception { + DocumentManagement.createDocument( + knowledgeBaseName, + DOCUMENT_DISPLAY_NAME, + "text/html", + "FAQ", + "https://cloud.google.com/storage/docs/faq"); + String got = bout.toString(); + assertThat(got).contains(DOCUMENT_DISPLAY_NAME); + } +} From b31ade6a49d0ae720486f72af1621ec8ab85b82a Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:40:30 -0600 Subject: [PATCH 08/34] Create CreateEntityTest --- .../com/example/dialogflow/CreateEntityTest | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest new file mode 100644 index 00000000000..0bfed56507b --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest @@ -0,0 +1,103 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2.EntityType; +import com.google.cloud.dialogflow.v2.EntityType.Kind; +import com.google.cloud.dialogflow.v2.EntityTypesClient; +import com.google.cloud.dialogflow.v2.ProjectAgentName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class CreateEntityTest { + + private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); + private static String ENTITY_TYPE_DISPLAY_NAME = + "entity_" + UUID.randomUUID().toString().substring(0, 23); + private static String ENTITY_VALUE = UUID.randomUUID().toString(); + private static List SYNONYMS = + Arrays.asList("fake_synonym_for_testing_1", "fake_synonym_for_testing_2"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String entityTypeName; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() throws IOException { + // Create a entity type to hold an entity + try (EntityTypesClient client = EntityTypesClient.create()) { + ProjectAgentName parent = ProjectAgentName.of(PROJECT_ID); + EntityType entityType = + EntityType.newBuilder() + .setDisplayName(ENTITY_TYPE_DISPLAY_NAME) + .setKind(Kind.valueOf("KIND_MAP")) + .build(); + EntityType response = client.createEntityType(parent, entityType); + entityTypeName = response.getName(); + } + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Delete the created entity type + try (EntityTypesClient client = EntityTypesClient.create()) { + client.deleteEntityType(entityTypeName); + } + + System.setOut(null); + } + + @Test + public void testCreateEntity() throws Exception { + String entityTypeId = entityTypeName.split("/")[entityTypeName.split("/").length - 1]; + EntityManagement.createEntity( + PROJECT_ID, entityTypeId, ENTITY_VALUE, Collections.singletonList("")); + String got = bout.toString(); + assertThat(got).contains("Entity created"); + } +} From a3e2baa8f6986a07317802de61de523340bb4313 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:40:40 -0600 Subject: [PATCH 09/34] Delete ContextManagementIT.java --- .../dialogflow/ContextManagementIT.java | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/ContextManagementIT.java diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ContextManagementIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ContextManagementIT.java deleted file mode 100644 index 71026e7410e..00000000000 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ContextManagementIT.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2018 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; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.google.cloud.dialogflow.v2.Context; -import com.google.cloud.dialogflow.v2.ContextName; -import com.google.cloud.dialogflow.v2.ContextsClient; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.List; -import java.util.UUID; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Integration (system) tests for {@link ContextManagement}. - */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class ContextManagementIT { - private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); - private static String SESSION_ID = UUID.randomUUID().toString(); - private static String CONTEXT_ID = UUID.randomUUID().toString(); - - @Before - public void setUp() { - System.setOut(new PrintStream(new ByteArrayOutputStream())); - } - - @After - public void tearDown() throws Exception { - try (ContextsClient contextsClient = ContextsClient.create()) { - // If the Context still exists, delete it. - try { - ContextName contextName = ContextName.of(PROJECT_ID, SESSION_ID, CONTEXT_ID); - Context existing = contextsClient.getContext(contextName); - contextsClient.deleteContext(existing.getName()); - } catch (Exception e) { - // Context doesn't exist, nothing to do. - } - } - System.setOut(null); - } - - @Test - public void testCreateDeleteContext() throws Exception { - // Create the context - Context context = ContextManagement.createContext(CONTEXT_ID, SESSION_ID, PROJECT_ID, 1); - assertThat(context.getName()).contains(CONTEXT_ID); - assertEquals(1, context.getLifespanCount()); - - List contexts = ContextManagement.listContexts(SESSION_ID, PROJECT_ID); - assertTrue(contexts.size() > 0); - assertTrue(contexts.stream().anyMatch(c -> c.getName().contains(SESSION_ID) - && c.getName().contains(CONTEXT_ID))); - - // Delete the context - ContextManagement.deleteContext(CONTEXT_ID, SESSION_ID, PROJECT_ID); - int numContexts = contexts.size(); - contexts = ContextManagement.listContexts(SESSION_ID, PROJECT_ID); - assertEquals(numContexts - 1, contexts.size()); - } -} From 88d4cc0dfa654d4438e4844a233b53936a41b9ab Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:41:00 -0600 Subject: [PATCH 10/34] Create CreateKnowledgeBaseTest --- .../dialogflow/CreateKnowledgeBaseTest | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest new file mode 100644 index 00000000000..5581868f1a7 --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest @@ -0,0 +1,84 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBase; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class CreateKnowledgeBaseTest { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static String KNOWLEDGE_DISPLAY_NAME = UUID.randomUUID().toString(); + private ByteArrayOutputStream bout; + private PrintStream out; + private String knowledgeBaseName; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Delete the created knowledge base + try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { + DeleteKnowledgeBaseRequest request = + DeleteKnowledgeBaseRequest.newBuilder().setName(knowledgeBaseName).setForce(true).build(); + client.deleteKnowledgeBase(request); + } + System.setOut(null); + } + + @Test + public void testCreateKnowledgeBase() throws Exception { + KnowledgeBase knowledgeBase = + KnowledgeBaseManagement.createKnowledgeBase(PROJECT_ID, KNOWLEDGE_DISPLAY_NAME); + knowledgeBaseName = knowledgeBase.getName(); + String got = bout.toString(); + assertThat(got).contains(KNOWLEDGE_DISPLAY_NAME); + } +} From 95294311556fd0a54205053313d822add9df7979 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:41:17 -0600 Subject: [PATCH 11/34] Create DeleteDocumentTest --- .../com/example/dialogflow/DeleteDocumentTest | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest new file mode 100644 index 00000000000..b78b6de3472 --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest @@ -0,0 +1,118 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest; +import com.google.cloud.dialogflow.v2beta1.Document; +import com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType; +import com.google.cloud.dialogflow.v2beta1.DocumentsClient; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBase; +import com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient; +import com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata; +import com.google.cloud.dialogflow.v2beta1.ProjectName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class DeleteDocumentTest { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static String KNOWLEDGE_DISPLAY_NAME = UUID.randomUUID().toString(); + private static String DOCUMENT_DISPLAY_NAME = UUID.randomUUID().toString(); + private ByteArrayOutputStream bout; + private PrintStream out; + private String knowledgeBaseName; + private String documentName; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() + throws IOException, InterruptedException, ExecutionException, TimeoutException { + // Create a knowledge base for the document + try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { + KnowledgeBase knowledgeBase = + KnowledgeBase.newBuilder().setDisplayName(KNOWLEDGE_DISPLAY_NAME).build(); + ProjectName projectName = ProjectName.of(PROJECT_ID); + KnowledgeBase response = client.createKnowledgeBase(projectName, knowledgeBase); + // Save the full name for deletion + knowledgeBaseName = response.getName(); + } + + // Create the Document to delete + try (DocumentsClient documentsClient = DocumentsClient.create()) { + Document document = + Document.newBuilder() + .setDisplayName(DOCUMENT_DISPLAY_NAME) + .setContentUri("https://cloud.google.com/storage/docs/faq") + .setMimeType("text/html") + .addKnowledgeTypes(KnowledgeType.valueOf("FAQ")) + .build(); + CreateDocumentRequest createDocumentRequest = + CreateDocumentRequest.newBuilder() + .setDocument(document) + .setParent(knowledgeBaseName) + .build(); + OperationFuture response = + documentsClient.createDocumentAsync(createDocumentRequest); + Document createdDocument = response.get(180, TimeUnit.SECONDS); + documentName = createdDocument.getName(); + } + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testCreateDocument() throws Exception { + DocumentManagement.deleteDocument(documentName); + String got = bout.toString(); + assertThat(got).contains("The document has been deleted"); + } +} From dbb58c51bdc5c4a6eb683137796d0d4e20b628b7 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:41:30 -0600 Subject: [PATCH 12/34] Create DeleteEntityTest --- .../com/example/dialogflow/DeleteEntityTest | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest new file mode 100644 index 00000000000..5b1853f6ea5 --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest @@ -0,0 +1,107 @@ +/* + * Copyright 2020 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; + +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2.EntityType; +import com.google.cloud.dialogflow.v2.EntityType.Entity; +import com.google.cloud.dialogflow.v2.EntityType.Kind; +import com.google.cloud.dialogflow.v2.EntityTypesClient; +import com.google.cloud.dialogflow.v2.ProjectAgentName; +import com.google.protobuf.Empty; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class DeleteEntityTest { + + private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); + private static String ENTITY_TYPE_DISPLAY_NAME = + "entity_" + UUID.randomUUID().toString().substring(0, 23); + private static String ENTITY_VALUE = UUID.randomUUID().toString(); + private static List SYNONYMS = + Arrays.asList("fake_synonym_for_testing_1", "fake_synonym_for_testing_2"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String entityTypeName; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() throws IOException, ExecutionException, InterruptedException { + // Create a entity type to hold an entity + try (EntityTypesClient client = EntityTypesClient.create()) { + ProjectAgentName parent = ProjectAgentName.of(PROJECT_ID); + EntityType entityType = + EntityType.newBuilder() + .setDisplayName(ENTITY_TYPE_DISPLAY_NAME) + .setKind(Kind.valueOf("KIND_MAP")) + .build(); + EntityType response = client.createEntityType(parent, entityType); + entityTypeName = response.getName(); + + // Create an entity to delete + Entity entity = Entity.newBuilder().setValue(ENTITY_VALUE).addAllSynonyms(SYNONYMS).build(); + Empty empty = + client.batchCreateEntitiesAsync(entityTypeName, Collections.singletonList(entity)).get(); + } + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Delete the created entity type + try (EntityTypesClient client = EntityTypesClient.create()) { + client.deleteEntityType(entityTypeName); + } + + System.setOut(null); + } + + @Test + public void testDeleteEntity() throws Exception { + String entityTypeId = entityTypeName.split("/")[entityTypeName.split("/").length - 1]; + EntityManagement.deleteEntity(PROJECT_ID, entityTypeId, ENTITY_VALUE); + } +} From 8157b0483dbaf2bab717e97263a33f757f48480c Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:42:05 -0600 Subject: [PATCH 13/34] Update and rename KnowledgeBaseManagementIT.java to DetectIntentKnowledgeTest.java --- ...IT.java => DetectIntentKnowledgeTest.java} | 61 +------------------ 1 file changed, 1 insertion(+), 60 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{KnowledgeBaseManagementIT.java => DetectIntentKnowledgeTest.java} (62%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/KnowledgeBaseManagementIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentKnowledgeTest.java similarity index 62% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/KnowledgeBaseManagementIT.java rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentKnowledgeTest.java index d38474673c4..385e5541c53 100644 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/KnowledgeBaseManagementIT.java +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentKnowledgeTest.java @@ -43,7 +43,7 @@ */ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") -public class KnowledgeBaseManagementIT { +public class DetectIntentKnowledgeTest { private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); private static String TEST_KNOWLEDGE_BASE_ID = "MTA4MzE0ODY5NTczMTQzNzU2ODA"; @@ -68,65 +68,6 @@ public void tearDown() { System.setOut(null); } - @Test - public void testKnowledgeBase() throws Exception { - // Create a Knowledge Base - KnowledgeBase knowledgeBase = - KnowledgeBaseManagement.createKnowledgeBase(PROJECT_ID, KNOWLEDGE_BASE_NAME); - assertThat(knowledgeBase.getDisplayName()).contains(KNOWLEDGE_BASE_NAME); - - // Get KnowledgeBase - knowledgeBase = KnowledgeBaseManagement.getKnowledgeBase(knowledgeBase.getName()); - assertThat(knowledgeBase.getDisplayName()).contains(KNOWLEDGE_BASE_NAME); - - // List Knowledge Bases - List knowledgeBases = KnowledgeBaseManagement.listKnowledgeBases(PROJECT_ID); - assertThat(knowledgeBases.size()).isAtLeast(2); - - int found = 0; - for (KnowledgeBase knowledgeBase1 : knowledgeBases) { - if (knowledgeBase1.getDisplayName().equals(KNOWLEDGE_BASE_NAME)) { - found += 1; - } - } - assertThat(found).isEqualTo(1); - - // Delete the Knowledge Base - KnowledgeBaseManagement.deleteKnowledgeBase(knowledgeBase.getName()); - } - - @Test - public void testDocumentManagement() throws Exception { - // Create a Knowledge Base - KnowledgeBase knowledgeBase = - KnowledgeBaseManagement.createKnowledgeBase(PROJECT_ID, KNOWLEDGE_BASE_NAME); - String knowledgeBaseName = knowledgeBase.getName(); - - // Create a Document - Document document = DocumentManagement.createDocument( - knowledgeBaseName, - DOCUMENT_BASE_NAME, - "text/html", - "FAQ", - "https://cloud.google.com/storage/docs/faq"); - assertThat(document.getDisplayName()).contains(DOCUMENT_BASE_NAME); - - // List the Documents - List documents = DocumentManagement.listDocuments(knowledgeBaseName); - assertThat(documents.size()).isEqualTo(1); - assertThat(documents.get(0).getDisplayName()).contains(DOCUMENT_BASE_NAME); - - // Get the Document - document = DocumentManagement.getDocument(document.getName()); - assertThat(document.getDisplayName()).contains(DOCUMENT_BASE_NAME); - - // Delete the Document - DocumentManagement.deleteDocument(document.getName()); - - // Delete the Knowledge Base - KnowledgeBaseManagement.deleteKnowledgeBase(knowledgeBase.getName()); - } - @Test public void testDetectIntentKnowledge() throws Exception { KnowledgeBaseName knowledgeBaseName = KnowledgeBaseName.newBuilder() From 7ed17e023b574224bbc00d56b1470c8aa57b96d0 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:42:37 -0600 Subject: [PATCH 14/34] Update and rename DetectIntentWithAudioAndModelSelectionIT.java to DetectIntentWithAudioIT.java --- ...onIT.java => DetectIntentWithAudioIT.java} | 23 ------------------- 1 file changed, 23 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{DetectIntentWithAudioAndModelSelectionIT.java => DetectIntentWithAudioIT.java} (75%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioIT.java similarity index 75% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioIT.java index 415f36b35aa..7f2c68b0e7a 100644 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioIT.java @@ -37,9 +37,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Integration (system) tests for {@link DetectIntentWithModelSelection}. - */ @RunWith(JUnit4.class) @SuppressWarnings("checkstyle:abbreviationaswordinname") public class DetectIntentWithAudioAndModelSelectionIT { @@ -89,24 +86,4 @@ public void testDetectIntentAudio() throws Exception { assertTrue(result.getAllRequiredParamsPresent()); assertEquals("Choose a room please.", fulfillmentText); } - - @Test - public void testDetectIntentWithModelSelection() throws Exception { - List askedQuestions = Lists.newArrayList(); - QueryResult result = DetectIntentWithModelSelection.detectIntentWithModelSelection( - PROJECT_ID, "resources/book_a_room.wav", SESSION_ID, LANGUAGE_CODE); - String fulfillmentText = result.getFulfillmentText(); - while (!result.getAllRequiredParamsPresent() - && ANSWERS.containsKey(fulfillmentText) - && !askedQuestions.contains(fulfillmentText)) { - askedQuestions.add(result.getFulfillmentText()); - assertEquals("room.reservation", result.getAction()); - assertThat(QUESTIONS).contains(fulfillmentText); - result = DetectIntentWithModelSelection.detectIntentWithModelSelection( - PROJECT_ID, ANSWERS.get(fulfillmentText), SESSION_ID, LANGUAGE_CODE); - fulfillmentText = result.getFulfillmentText(); - } - assertTrue(result.getAllRequiredParamsPresent()); - assertEquals("Choose a room please.", fulfillmentText); - } } From 5c01b08a30ee6b4876925c976a713655a6c7e464 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:43:26 -0600 Subject: [PATCH 15/34] Create GetDocumentTest --- .../com/example/dialogflow/GetDocumentTest | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest new file mode 100644 index 00000000000..cac09729842 --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest @@ -0,0 +1,74 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2beta1.DocumentName; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class GetDocumentTest { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static String TEST_KNOWLEDGE_BASE_ID = "MTA4MzE0ODY5NTczMTQzNzU2ODA"; + private static String TEST_DOCUMENT_ID = "MTUwNjk0ODg1NTU4NzkzMDExMg"; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetDocument() throws Exception { + DocumentName documentName = + DocumentName.of(PROJECT_ID, TEST_KNOWLEDGE_BASE_ID, TEST_DOCUMENT_ID); + DocumentManagement.getDocument(documentName.toString()); + String got = bout.toString(); + assertThat(got).contains(TEST_DOCUMENT_ID); + } +} From 84f687338d822bf017ca7ed3066f07f56facfe1b Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:43:38 -0600 Subject: [PATCH 16/34] Create ListDocumentsTest --- .../com/example/dialogflow/ListDocumentsTest | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest new file mode 100644 index 00000000000..e977d6c8c82 --- /dev/null +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest @@ -0,0 +1,74 @@ +/* + * Copyright 2020 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; + +import static com.google.common.truth.Truth.assertThat; +import static junit.framework.TestCase.assertNotNull; + +import com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class ListDocumentsTest { + + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static String TEST_KNOWLEDGE_BASE_ID = "MTA4MzE0ODY5NTczMTQzNzU2ODA"; + private static String TEST_DOCUMENT_ID = "MTUwNjk0ODg1NTU4NzkzMDExMg"; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static void requireEnvVar(String varName) { + assertNotNull( + "Environment variable '%s' is required to perform these tests.".format(varName), + String.format(varName)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testGetDocument() throws Exception { + KnowledgeBaseName knowledgeBaseName = + KnowledgeBaseName.of(PROJECT_ID, TEST_KNOWLEDGE_BASE_ID); + DocumentManagement.listDocuments(knowledgeBaseName.toString()); + String got = bout.toString(); + assertThat(got).contains(TEST_DOCUMENT_ID); + } +} From b27cbf704c7e5c42690a045498b6b84a1674b6f9 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:43:48 -0600 Subject: [PATCH 17/34] Delete SessionEntityTypeManagementIT.java --- .../SessionEntityTypeManagementIT.java | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/SessionEntityTypeManagementIT.java diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/SessionEntityTypeManagementIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/SessionEntityTypeManagementIT.java deleted file mode 100644 index bcf6d0fb520..00000000000 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/SessionEntityTypeManagementIT.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2018 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; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.google.cloud.dialogflow.v2.EntityType; -import com.google.cloud.dialogflow.v2.EntityType.Kind; -import com.google.cloud.dialogflow.v2.SessionEntityType; -import com.google.cloud.dialogflow.v2.SessionEntityTypesClient; -import com.google.cloud.dialogflow.v2.SessionName; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * Integration (system) tests for {@link SessionEntityTypeManagement}. - */ -@RunWith(JUnit4.class) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class SessionEntityTypeManagementIT { - private static String SESSION_ID = "fake_session_for_testing"; - private static String ENTITY_TYPE_DISPLAY_NAME = - "entity_" + UUID.randomUUID().toString().substring(0, 23); - private static List ENTITY_VALUES = Arrays.asList("fake_entity_value_1", - "fake_entity_value_2"); - private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); - - @Before - public void setUp() { - System.setOut(new PrintStream(new ByteArrayOutputStream())); - } - - @After - public void tearDown() throws Exception { - try (SessionEntityTypesClient sessionEntityTypesClient = SessionEntityTypesClient.create()) { - SessionName session = SessionName.of(PROJECT_ID, SESSION_ID); - - // Performs the list session entity types request - for (SessionEntityType sessionEntityType : - sessionEntityTypesClient.listSessionEntityTypes(session).iterateAll()) { - if (sessionEntityType.getName().equals(ENTITY_TYPE_DISPLAY_NAME)) { - sessionEntityTypesClient.deleteSessionEntityType(sessionEntityType.getName()); - } - } - } - System.setOut(null); - } - - @Test - public void testCreateDeleteSessionEntityType() throws Exception { - // Create session entity type - EntityType entityType = EntityTypeManagement - .createEntityType(ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID, "KIND_MAP"); - assertEquals(Kind.valueOf("KIND_MAP"), entityType.getKind()); - - SessionEntityTypeManagement.createSessionEntityType( - PROJECT_ID, SESSION_ID, ENTITY_VALUES, ENTITY_TYPE_DISPLAY_NAME, 1); - - List sessionEntityTypes = SessionEntityTypeManagement - .listSessionEntityTypes(PROJECT_ID, SESSION_ID); - assertEquals(1, sessionEntityTypes.size()); - SessionEntityType sessionEntityType = sessionEntityTypes.get(0); - assertThat(sessionEntityType.getName()).contains(SESSION_ID); - assertThat(sessionEntityType.getName()).contains(ENTITY_TYPE_DISPLAY_NAME); - - for (String entityValue : ENTITY_VALUES) { - assertTrue(sessionEntityType - .getEntitiesList().stream().anyMatch(e -> e.getValue().equals(entityValue))); - } - - // Delete session entity type - SessionEntityTypeManagement.deleteSessionEntityType( - PROJECT_ID, SESSION_ID, ENTITY_TYPE_DISPLAY_NAME); - - sessionEntityTypes = SessionEntityTypeManagement.listSessionEntityTypes(PROJECT_ID, SESSION_ID); - assertEquals(0, sessionEntityTypes.size()); - - List entityTypesIds = EntityTypeManagement.getEntityTypeIds( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - - for (String entityTypeId : entityTypesIds) { - EntityTypeManagement.deleteEntityType(entityTypeId, PROJECT_ID); - } - } -} From d732880e133093c40d59215118703ea2701d276d Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:44:00 -0600 Subject: [PATCH 18/34] Delete EntityManagementIT.java --- .../dialogflow/EntityManagementIT.java | 131 ------------------ 1 file changed, 131 deletions(-) delete mode 100644 dialogflow/cloud-client/src/test/java/com/example/dialogflow/EntityManagementIT.java diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/EntityManagementIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/EntityManagementIT.java deleted file mode 100644 index 44cfdbc69e7..00000000000 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/EntityManagementIT.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2018 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; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertEquals; - -import com.google.cloud.dialogflow.v2.EntityType; -import com.google.cloud.dialogflow.v2.EntityType.Entity; -import com.google.protobuf.ProtocolStringList; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -import org.junit.After; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.junit.runners.MethodSorters; - -/** - * Integration (system) tests for {@link EntityManagement} and {@link EntityTypeManagement}. - */ -@RunWith(JUnit4.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SuppressWarnings("checkstyle:abbreviationaswordinname") -public class EntityManagementIT { - private static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT"); - private static String ENTITY_TYPE_DISPLAY_NAME = - "entity_" + UUID.randomUUID().toString().substring(0, 23); - private static String ENTITY_VALUE_1 = UUID.randomUUID().toString(); - private static String ENTITY_VALUE_2 = UUID.randomUUID().toString(); - private static List SYNONYMS = Arrays.asList("fake_synonym_for_testing_1", - "fake_synonym_for_testing_2"); - - @Before - public void setUp() { - System.setOut(new PrintStream(new ByteArrayOutputStream())); - } - - @After - public void tearDown() { - System.setOut(null); - } - - @Test - public void testCreateEntityType() throws Exception { - List entityTypeIds = EntityTypeManagement.getEntityTypeIds( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - - assertThat(entityTypeIds.size()).isEqualTo(0); - - EntityType entityType = EntityTypeManagement.createEntityType( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID, "KIND_MAP"); - assertEquals(ENTITY_TYPE_DISPLAY_NAME, entityType.getDisplayName()); - - entityTypeIds = EntityTypeManagement.getEntityTypeIds( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - - assertThat(entityTypeIds.size()).isEqualTo(1); - } - - @Test - public void testCreateEntityWithCreatedEntityType() throws Exception { - List entityTypeIds = EntityTypeManagement.getEntityTypeIds(ENTITY_TYPE_DISPLAY_NAME, - PROJECT_ID); - - EntityManagement.createEntity( - PROJECT_ID, entityTypeIds.get(0), ENTITY_VALUE_1, Collections.singletonList("")); - EntityManagement.createEntity( - PROJECT_ID, entityTypeIds.get(0), ENTITY_VALUE_2, SYNONYMS); - - List entities = EntityManagement.listEntities(PROJECT_ID, entityTypeIds.get(0)); - assertEquals(2, entities.size()); - - int entityOneInd = entities.get(0).getValue().equals(ENTITY_VALUE_1) ? 0 : 1; - int entityTwoInd = entityOneInd == 0 ? 1 : 0; - assertEquals(ENTITY_VALUE_1, entities.get(entityOneInd).getValue()); - assertEquals(ENTITY_VALUE_2, entities.get(entityTwoInd).getValue()); - ProtocolStringList synonyms = entities.get(entityTwoInd).getSynonymsList(); - assertEquals(2, synonyms.size()); - for (String synonym : SYNONYMS) { - assertThat(synonyms).contains(synonym); - } - } - - @Test - public void testDeleteEntity() throws Exception { - List entityTypeIds = EntityTypeManagement.getEntityTypeIds( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - - EntityManagement.deleteEntity(PROJECT_ID, entityTypeIds.get(0), ENTITY_VALUE_1); - EntityManagement.deleteEntity(PROJECT_ID, entityTypeIds.get(0), ENTITY_VALUE_2); - - List entities = EntityManagement.listEntities(PROJECT_ID, entityTypeIds.get(0)); - assertEquals(0, entities.size()); - } - - @Test - public void testDeleteEntityType() throws Exception { - List entityTypeIds = EntityTypeManagement.getEntityTypeIds( - ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - - for (String entityTypeId : entityTypeIds) { - EntityTypeManagement.deleteEntityType(entityTypeId, PROJECT_ID); - } - - entityTypeIds = EntityTypeManagement.getEntityTypeIds(ENTITY_TYPE_DISPLAY_NAME, PROJECT_ID); - assertThat(entityTypeIds.size()).isEqualTo(0); - } -} From 58c41a0d5cc85012eadcd72055627582fe1f8dc6 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:44:46 -0600 Subject: [PATCH 19/34] Update KnowledgeBaseManagement.java --- .../java/com/example/dialogflow/KnowledgeBaseManagement.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java index 6eaa53ed802..3bd479c7540 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/KnowledgeBaseManagement.java @@ -29,7 +29,7 @@ public class KnowledgeBaseManagement { /** * Create a Knowledge base * - * @param projectId Project/agent id. + * @param projectId Project/agent id. * @param displayName Name of the knowledge base. * @return The created KnowledgeBase. */ @@ -47,4 +47,5 @@ public static KnowledgeBase createKnowledgeBase(String projectId, String display return response; } } - // [END dialogflow_create_knowledge_base] \ No newline at end of file + // [END dialogflow_create_knowledge_base] +} From 3eca251a3a92d7dc38af5d310fc2fac113d7ed33 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:45:03 -0600 Subject: [PATCH 20/34] Update DocumentManagement.java --- .../main/java/com/example/dialogflow/DocumentManagement.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java index 797644e2fca..4fd174165e4 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DocumentManagement.java @@ -139,4 +139,6 @@ public static void deleteDocument(String documentName) throws Exception { System.out.format("The document has been deleted."); } } + + // [END dialogflow_delete_document] } From 21c6ef8062aa83c11d8e8d3a44879d80c5125b19 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:45:20 -0600 Subject: [PATCH 21/34] Update DetectIntentWithTextToSpeechResponse.java --- .../dialogflow/DetectIntentWithTextToSpeechResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithTextToSpeechResponse.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithTextToSpeechResponse.java index c7387364334..8b0e0e2c9a0 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithTextToSpeechResponse.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithTextToSpeechResponse.java @@ -25,7 +25,6 @@ import com.google.cloud.dialogflow.v2.SessionName; import com.google.cloud.dialogflow.v2.SessionsClient; import com.google.cloud.dialogflow.v2.TextInput; -import com.google.cloud.dialogflow.v2.TextInput.Builder; import com.google.common.collect.Maps; import java.util.List; @@ -60,7 +59,8 @@ public static Map detectIntentWithTexttoSpeech( // Detect intents for each text input for (String text : texts) { // Set the text (hello) and language code (en-US) for the query - Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode); + TextInput.Builder textInput = + TextInput.newBuilder().setText(text).setLanguageCode(languageCode); // Build the query with the TextInput QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build(); From 485ce50f212bc84db5a30ec6155ba74ab90ae7c8 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:45:31 -0600 Subject: [PATCH 22/34] Update DetectIntentWithSentimentAnalysis.java --- .../example/dialogflow/DetectIntentWithSentimentAnalysis.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithSentimentAnalysis.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithSentimentAnalysis.java index 3005847a1a5..14ffffefd43 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithSentimentAnalysis.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithSentimentAnalysis.java @@ -25,7 +25,6 @@ import com.google.cloud.dialogflow.v2.SessionName; import com.google.cloud.dialogflow.v2.SessionsClient; import com.google.cloud.dialogflow.v2.TextInput; -import com.google.cloud.dialogflow.v2.TextInput.Builder; import com.google.common.collect.Maps; import java.util.List; @@ -60,7 +59,8 @@ public static Map detectIntentSentimentAnalysis( // Detect intents for each text input for (String text : texts) { // Set the text (hello) and language code (en-US) for the query - Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode); + TextInput.Builder textInput = + TextInput.newBuilder().setText(text).setLanguageCode(languageCode); // Build the query with the TextInput QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build(); From 3aef9be5fcf635bcc550957779db3f694f78181e Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:45:48 -0600 Subject: [PATCH 23/34] Update DetectIntentTexts.java --- .../main/java/com/example/dialogflow/DetectIntentTexts.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentTexts.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentTexts.java index 19cad13bb3e..91168122a0d 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentTexts.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentTexts.java @@ -24,7 +24,6 @@ import com.google.cloud.dialogflow.v2.SessionName; import com.google.cloud.dialogflow.v2.SessionsClient; import com.google.cloud.dialogflow.v2.TextInput; -import com.google.cloud.dialogflow.v2.TextInput.Builder; import com.google.common.collect.Maps; import java.util.List; @@ -62,7 +61,8 @@ public static Map detectIntentTexts( // Detect intents for each text input for (String text : texts) { // Set the text (hello) and language code (en-US) for the query - Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode); + TextInput.Builder textInput = + TextInput.newBuilder().setText(text).setLanguageCode(languageCode); // Build the query with the TextInput QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build(); From 2c439b19b097e891b20420cc937c5af6353b1ff5 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:46:00 -0600 Subject: [PATCH 24/34] Update DetectIntentKnowledge.java --- .../java/com/example/dialogflow/DetectIntentKnowledge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java index 5205337bcb7..f6ee2b02cee 100644 --- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java +++ b/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentKnowledge.java @@ -28,7 +28,6 @@ import com.google.cloud.dialogflow.v2beta1.SessionName; import com.google.cloud.dialogflow.v2beta1.SessionsClient; import com.google.cloud.dialogflow.v2beta1.TextInput; -import com.google.cloud.dialogflow.v2beta1.TextInput.Builder; import com.google.common.collect.Maps; import java.util.List; @@ -68,7 +67,8 @@ public static Map detectIntentKnowledge( // Detect intents for each text input for (String text : texts) { // Set the text and language code (en-US) for the query - Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode); + TextInput.Builder textInput = + TextInput.newBuilder().setText(text).setLanguageCode(languageCode); // Build the query with the TextInput QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build(); From 527a987c458208dc4bbe89ab94deda58664c3117 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:48:17 -0600 Subject: [PATCH 25/34] Rename CreateDocumentTest to CreateDocumentTest.java --- .../dialogflow/{CreateDocumentTest => CreateDocumentTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{CreateDocumentTest => CreateDocumentTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest.java From 539ceff292307f64b665cda7f4f375c8f112805d Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:48:31 -0600 Subject: [PATCH 26/34] Rename CreateEntityTest to CreateEntityTest.java --- .../dialogflow/{CreateEntityTest => CreateEntityTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{CreateEntityTest => CreateEntityTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateEntityTest.java From c516e9ae5e7f31f947ab4ca02b2ebdcc98cece39 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:48:51 -0600 Subject: [PATCH 27/34] Rename CreateKnowledgeBaseTest to CreateKnowledgeBaseTest.java --- .../{CreateKnowledgeBaseTest => CreateKnowledgeBaseTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{CreateKnowledgeBaseTest => CreateKnowledgeBaseTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest.java From c8f26649e287ecc48d2cc75cb3a3eaaf7665e4a6 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:49:02 -0600 Subject: [PATCH 28/34] Rename DeleteDocumentTest to DeleteDocumentTest.java --- .../dialogflow/{DeleteDocumentTest => DeleteDocumentTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{DeleteDocumentTest => DeleteDocumentTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java From 08b9cd1ad04a255a5cbd8c1edbd3b89dc4d0483e Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:49:15 -0600 Subject: [PATCH 29/34] Rename DeleteEntityTest to DeleteEntityTest.java --- .../dialogflow/{DeleteEntityTest => DeleteEntityTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{DeleteEntityTest => DeleteEntityTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteEntityTest.java From 8867e887c96f4f2ee4f053b2c52e889016830029 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:49:32 -0600 Subject: [PATCH 30/34] Rename ListDocumentsTest to ListDocumentsTest.java --- .../dialogflow/{ListDocumentsTest => ListDocumentsTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{ListDocumentsTest => ListDocumentsTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/ListDocumentsTest.java From fecc2ed2a9d28fa2cf58967afe15b924e12ad535 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 15:49:44 -0600 Subject: [PATCH 31/34] Rename GetDocumentTest to GetDocumentTest.java --- .../example/dialogflow/{GetDocumentTest => GetDocumentTest.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dialogflow/cloud-client/src/test/java/com/example/dialogflow/{GetDocumentTest => GetDocumentTest.java} (100%) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest.java similarity index 100% rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/GetDocumentTest.java From 53feaefec34fdbb43ad7e311756f3798d254914e Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 16:28:18 -0600 Subject: [PATCH 32/34] Update DeleteDocumentTest.java --- .../java/com/example/dialogflow/DeleteDocumentTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java index b78b6de3472..7bcaf836d31 100644 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java @@ -106,6 +106,12 @@ public void setUp() @After public void tearDown() { + // Delete the created knowledge base + try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { + DeleteKnowledgeBaseRequest request = + DeleteKnowledgeBaseRequest.newBuilder().setName(knowledgeBaseName).setForce(true).build(); + client.deleteKnowledgeBase(request); + } System.setOut(null); } From d12cee051c67f73b3ec33f3b8cbb159987a2b613 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Fri, 3 Apr 2020 16:28:44 -0600 Subject: [PATCH 33/34] Update DeleteDocumentTest.java --- .../test/java/com/example/dialogflow/DeleteDocumentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java index 7bcaf836d31..c04a9e7cbb8 100644 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java @@ -105,7 +105,7 @@ public void setUp() } @After - public void tearDown() { + public void tearDown() throws IOException { // Delete the created knowledge base try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) { DeleteKnowledgeBaseRequest request = From f6ddb010ad6018231e028059b3ed801984408007 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Wed, 8 Apr 2020 09:16:35 -0600 Subject: [PATCH 34/34] Update DeleteDocumentTest.java --- .../src/test/java/com/example/dialogflow/DeleteDocumentTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java index c04a9e7cbb8..d46eede2319 100644 --- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java +++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DeleteDocumentTest.java @@ -21,6 +21,7 @@ import com.google.api.gax.longrunning.OperationFuture; import com.google.cloud.dialogflow.v2beta1.CreateDocumentRequest; +import com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest; import com.google.cloud.dialogflow.v2beta1.Document; import com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType; import com.google.cloud.dialogflow.v2beta1.DocumentsClient;