Search in sources :

Example 11 with AgentName

use of com.google.cloud.dialogflow.cx.v3beta1.AgentName in project java-dialogflow by googleapis.

the class IntentManagement method listIntents.

// [START dialogflow_list_intents]
/**
 * List intents
 *
 * @param projectId Project/Agent Id.
 * @return Intents found.
 */
public static List<Intent> listIntents(String projectId) throws ApiException, IOException {
    List<Intent> intents = Lists.newArrayList();
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {
        // Set the project agent name using the projectID (my-project-id)
        AgentName parent = AgentName.of(projectId);
        // Performs the list intents request
        for (Intent intent : intentsClient.listIntents(parent).iterateAll()) {
            System.out.println("====================");
            System.out.format("Intent name: '%s'\n", intent.getName());
            System.out.format("Intent display name: '%s'\n", intent.getDisplayName());
            System.out.format("Action: '%s'\n", intent.getAction());
            System.out.format("Root followup intent: '%s'\n", intent.getRootFollowupIntentName());
            System.out.format("Parent followup intent: '%s'\n", intent.getParentFollowupIntentName());
            System.out.format("Input contexts:\n");
            for (String inputContextName : intent.getInputContextNamesList()) {
                System.out.format("\tName: %s\n", inputContextName);
            }
            System.out.format("Output contexts:\n");
            for (Context outputContext : intent.getOutputContextsList()) {
                System.out.format("\tName: %s\n", outputContext.getName());
            }
            intents.add(intent);
        }
    }
    return intents;
}
Also used : Context(com.google.cloud.dialogflow.v2.Context) IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) Intent(com.google.cloud.dialogflow.v2.Intent) AgentName(com.google.cloud.dialogflow.v2.AgentName)

Example 12 with AgentName

use of com.google.cloud.dialogflow.cx.v3beta1.AgentName in project java-dialogflow-cx by googleapis.

the class FlowsClientTest method listFlowsTest.

@Test
public void listFlowsTest() throws Exception {
    Flow responsesElement = Flow.newBuilder().build();
    ListFlowsResponse expectedResponse = ListFlowsResponse.newBuilder().setNextPageToken("").addAllFlows(Arrays.asList(responsesElement)).build();
    mockFlows.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListFlowsPagedResponse pagedListResponse = client.listFlows(parent);
    List<Flow> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFlowsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFlows.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListFlowsRequest actualRequest = ((ListFlowsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListFlowsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse) Test(org.junit.Test)

Example 13 with AgentName

use of com.google.cloud.dialogflow.cx.v3beta1.AgentName in project java-dialogflow-cx by googleapis.

the class IntentsClientTest method listIntentsTest.

@Test
public void listIntentsTest() throws Exception {
    Intent responsesElement = Intent.newBuilder().build();
    ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
    mockIntents.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListIntentsPagedResponse pagedListResponse = client.listIntents(parent);
    List<Intent> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getIntentsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockIntents.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListIntentsRequest actualRequest = ((ListIntentsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListIntentsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient.ListIntentsPagedResponse) Test(org.junit.Test)

Example 14 with AgentName

use of com.google.cloud.dialogflow.cx.v3beta1.AgentName in project java-dialogflow-cx by googleapis.

the class EnvironmentsClientTest method listEnvironmentsTest.

@Test
public void listEnvironmentsTest() throws Exception {
    Environment responsesElement = Environment.newBuilder().build();
    ListEnvironmentsResponse expectedResponse = ListEnvironmentsResponse.newBuilder().setNextPageToken("").addAllEnvironments(Arrays.asList(responsesElement)).build();
    mockEnvironments.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListEnvironmentsPagedResponse pagedListResponse = client.listEnvironments(parent);
    List<Environment> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEnvironmentsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockEnvironments.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEnvironmentsRequest actualRequest = ((ListEnvironmentsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListEnvironmentsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.EnvironmentsClient.ListEnvironmentsPagedResponse) Test(org.junit.Test)

Example 15 with AgentName

use of com.google.cloud.dialogflow.cx.v3beta1.AgentName in project java-dialogflow-cx by googleapis.

the class EntityTypesClientTest method listEntityTypesTest.

@Test
public void listEntityTypesTest() throws Exception {
    EntityType responsesElement = EntityType.newBuilder().build();
    ListEntityTypesResponse expectedResponse = ListEntityTypesResponse.newBuilder().setNextPageToken("").addAllEntityTypes(Arrays.asList(responsesElement)).build();
    mockEntityTypes.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListEntityTypesPagedResponse pagedListResponse = client.listEntityTypes(parent);
    List<EntityType> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEntityTypesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockEntityTypes.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEntityTypesRequest actualRequest = ((ListEntityTypesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListEntityTypesPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.EntityTypesClient.ListEntityTypesPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 AbstractMessage (com.google.protobuf.AbstractMessage)7 ArrayList (java.util.ArrayList)4 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)3 Flow (com.google.cloud.dialogflow.cx.v3beta1.Flow)3 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)3 AgentName (com.google.cloud.dialogflow.v2.AgentName)3 Intent (com.google.cloud.dialogflow.v2.Intent)3 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)3 AgentName (com.google.cloud.dialogflow.cx.v3beta1.AgentName)2 DeleteAgentRequest (com.google.cloud.dialogflow.cx.v3beta1.DeleteAgentRequest)2 EntityType (com.google.cloud.dialogflow.cx.v3beta1.EntityType)2 FlowsClient (com.google.cloud.dialogflow.cx.v3beta1.FlowsClient)2 IntentsClient (com.google.cloud.dialogflow.cx.v3beta1.IntentsClient)2 ListChangelogsPagedResponse (com.google.cloud.dialogflow.cx.v3beta1.ChangelogsClient.ListChangelogsPagedResponse)1 CreateEntityTypeRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest)1 CreateFlowRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest)1 CreateIntentRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest)1 CreatePageRequest (com.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest)1 CreateTransitionRouteGroupRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest)1