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();
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 ded2e6242db..00000000000
--- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/DetectIntentWithModelSelection.java
+++ /dev/null
@@ -1,100 +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]
-}
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 482692f50d9..4f3dce487ac 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;
import java.util.Map;
@@ -59,7 +58,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();
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 912b221791d..933adf88558 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;
import java.util.Map;
@@ -59,7 +58,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();
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 76e5c956938..8666e86cb0f 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
@@ -22,37 +22,9 @@
import com.google.cloud.dialogflow.v2beta1.Document.KnowledgeType;
import com.google.cloud.dialogflow.v2beta1.DocumentsClient;
import com.google.cloud.dialogflow.v2beta1.KnowledgeOperationMetadata;
-import com.google.common.collect.Lists;
-import java.util.List;
import java.util.concurrent.TimeUnit;
public class DocumentManagement {
- // [START dialogflow_list_document]
-
- /**
- * @param knowledgeBaseName Knowledge Base id.
- */
- public static List listDocuments(String knowledgeBaseName) throws Exception {
- List documents = Lists.newArrayList();
- // Instantiates a client
- try (DocumentsClient documentsClient = DocumentsClient.create()) {
- for (Document document : documentsClient.listDocuments(knowledgeBaseName).iterateAll()) {
- System.out.format(" - Display Name: %s\n", document.getDisplayName());
- System.out.format(" - Knowledge ID: %s\n", document.getName());
- System.out.format(" - MIME Type: %s\n", document.getMimeType());
- System.out.format(" - Knowledge Types:\n");
- for (KnowledgeType knowledgeTypeId : document.getKnowledgeTypesList()) {
- System.out.format(" - %s \n", knowledgeTypeId.getValueDescriptor());
- }
- System.out.format(" - Source: %s \n", document.getContentUri());
-
- documents.add(document);
- }
- }
- return documents;
- }
- // [END dialogflow_list_document]
-
// [START dialogflow_create_document]
/**
@@ -100,42 +72,4 @@ public static Document createDocument(
}
}
// [END dialogflow_create_document]
-
- // [START dialogflow_get_document]
-
- /**
- * @param documentName Document Id.
- * @return The requested document.
- */
- public static Document getDocument(String documentName) throws Exception {
- // Instantiates a client
- try (DocumentsClient documentsClient = DocumentsClient.create()) {
- Document response = documentsClient.getDocument(documentName);
- System.out.format("Got Document: \n");
- System.out.format(" - Display Name: %s\n", response.getDisplayName());
- System.out.format(" - Knowledge ID: %s\n", response.getName());
- System.out.format(" - MIME Type: %s\n", response.getMimeType());
- System.out.format(" - Knowledge Types:\n");
- for (KnowledgeType knowledgeTypeId : response.getKnowledgeTypesList()) {
- System.out.format(" - %s \n", knowledgeTypeId.getValueDescriptor());
- }
- System.out.format(" - Source: %s \n", response.getContentUri());
-
- return response;
- }
- }
- // [END dialogflow_get_document]
-
- // [START dialogflow_delete_document]
-
- /**
- * @param documentName Document Id.
- */
- public static void deleteDocument(String documentName) throws Exception {
- // Instantiates a client
- try (DocumentsClient documentsClient = DocumentsClient.create()) {
- documentsClient.deleteDocumentAsync(documentName).get();
- System.out.format("The document has been deleted.");
- }
- }
}
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
deleted file mode 100644
index 5ebdd0e96d5..00000000000
--- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityManagement.java
+++ /dev/null
@@ -1,122 +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.Entity;
-import com.google.cloud.dialogflow.v2.EntityTypeName;
-import com.google.cloud.dialogflow.v2.EntityTypesClient;
-import com.google.protobuf.Empty;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * 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]
-
- /**
- * Create an entity of the given entity type
- *
- * @param projectId Project/agent id.
- * @param entityTypeId The id of the entity_type.
- * @param entityValue The entity value to be added.
- * @param synonyms The synonyms that will map to the provided entity value.
- */
- public static void createEntity(
- String projectId,
- String entityTypeId,
- String entityValue,
- List synonyms) throws Exception {
- // Note: synonyms must be exactly [entityValue] if the
- // entityTypeId's kind is KIND_LIST
- if (synonyms.size() == 0) {
- synonyms.add(entityValue);
- }
-
- // Instantiates a client
- try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) {
- // Set the entity type name using the projectID (my-project-id) and entityTypeId (KINDS_LIST)
- EntityTypeName name = EntityTypeName.of(projectId, entityTypeId);
-
- // Build the entity
- Entity entity = Entity.newBuilder()
- .setValue(entityValue)
- .addAllSynonyms(synonyms)
- .build();
-
- // Performs the create entity type request
- Empty response = entityTypesClient.batchCreateEntitiesAsync(name,
- Collections.singletonList(entity)).get();
- System.out.println("Entity created: " + response);
- }
- }
- // [END dialogflow_create_entity]
-
- // [START dialogflow_delete_entity]
-
- /**
- * Delete entity with the given entity type and entity value
- *
- * @param projectId Project/agent id.
- * @param entityTypeId The id of the entity_type.
- * @param entityValue The value of the entity to delete.
- */
- public static void deleteEntity(String projectId, String entityTypeId, String entityValue)
- throws Exception {
- // Instantiates a client
- try (EntityTypesClient entityTypesClient = EntityTypesClient.create()) {
- // Set the entity type name using the projectID (my-project-id) and entityTypeId (KINDS_LIST)
- EntityTypeName name = EntityTypeName.of(projectId, entityTypeId);
-
- // Performs the delete entity type request
- entityTypesClient.batchDeleteEntitiesAsync(name, Collections.singletonList(entityValue))
- .getInitialFuture().get();
- }
- }
- // [END dialogflow_delete_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
deleted file mode 100644
index dd7f9cfa186..00000000000
--- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/EntityTypeManagement.java
+++ /dev/null
@@ -1,132 +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_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]
-
- /**
- * 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;
- }
-}
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 607f48238f2..506ae1982f4 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
@@ -19,35 +19,9 @@
import com.google.cloud.dialogflow.v2beta1.KnowledgeBase;
import com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient;
import com.google.cloud.dialogflow.v2beta1.ProjectName;
-import com.google.common.collect.Lists;
-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]
+public class KnowledgeBaseManagement {
// [START dialogflow_create_knowledge_base]
/**
@@ -73,35 +47,4 @@ public static KnowledgeBase createKnowledgeBase(String projectId, String display
}
// [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]
}
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 150ae594ab5..00000000000
--- a/dialogflow/cloud-client/src/main/java/com/example/dialogflow/SessionEntityTypeManagement.java
+++ /dev/null
@@ -1,141 +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_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]
-
- /**
- * 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]
-}
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 9d5ab42c2c6..00000000000
--- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/ContextManagementIT.java
+++ /dev/null
@@ -1,84 +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());
- }
-}
diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest.java
new file mode 100644
index 00000000000..e75405a0b6f
--- /dev/null
+++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateDocumentTest.java
@@ -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);
+ }
+}
diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest.java
new file mode 100644
index 00000000000..5581868f1a7
--- /dev/null
+++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/CreateKnowledgeBaseTest.java
@@ -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);
+ }
+}
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 56%
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 2f8415b4792..fb940c31383 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
@@ -19,11 +19,9 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
-import com.google.cloud.dialogflow.v2beta1.Document;
import com.google.cloud.dialogflow.v2beta1.DocumentName;
import com.google.cloud.dialogflow.v2beta1.KnowledgeAnswers;
import com.google.cloud.dialogflow.v2beta1.KnowledgeAnswers.Answer;
-import com.google.cloud.dialogflow.v2beta1.KnowledgeBase;
import com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName;
import com.google.common.collect.ImmutableList;
import java.io.ByteArrayOutputStream;
@@ -37,20 +35,16 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/**
- * Integration (system) tests for {DetectIntentKnowledge, KnowledgeManagement, DocumentManagement}.
- */
+
@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";
private static String TEST_DOCUMENT_ID = "MTUwNjk0ODg1NTU4NzkzMDExMg";
private static String SESSION_ID = UUID.randomUUID().toString();
private static String LANGUAGE_CODE = "en-US";
- private static String KNOWLEDGE_BASE_NAME = UUID.randomUUID().toString();
- private static String DOCUMENT_BASE_NAME = UUID.randomUUID().toString();
private static List TEXTS = ImmutableList
.of("How do I sign up?", "Is my data redundant?", "Where can I find pricing information?",
@@ -67,65 +61,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()
diff --git a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioTest.java
similarity index 73%
rename from dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java
rename to dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioTest.java
index 3f70a08d192..20d1ca187cd 100644
--- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioAndModelSelectionIT.java
+++ b/dialogflow/cloud-client/src/test/java/com/example/dialogflow/DetectIntentWithAudioTest.java
@@ -20,7 +20,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import com.google.cloud.dialogflow.v2beta1.QueryResult;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
@@ -35,12 +34,9 @@
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 {
+public class DetectIntentWithAudioTest {
protected static String PROJECT_ID = System.getenv().get("GOOGLE_CLOUD_PROJECT");
protected static String SESSION_ID = UUID.randomUUID().toString();
protected static String LANGUAGE_CODE = "en-US";
@@ -87,24 +83,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);
- }
}
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 6e2001b679d..00000000000
--- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/EntityManagementIT.java
+++ /dev/null
@@ -1,129 +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);
- }
-}
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 de838752315..00000000000
--- a/dialogflow/cloud-client/src/test/java/com/example/dialogflow/SessionEntityTypeManagementIT.java
+++ /dev/null
@@ -1,109 +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);
- }
- }
-}