Search in sources :

Example 1 with Flow

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

the class TransitionRouteGroupsClientTest method listTransitionRouteGroupsTest.

@Test
public void listTransitionRouteGroupsTest() throws Exception {
    TransitionRouteGroup responsesElement = TransitionRouteGroup.newBuilder().build();
    ListTransitionRouteGroupsResponse expectedResponse = ListTransitionRouteGroupsResponse.newBuilder().setNextPageToken("").addAllTransitionRouteGroups(Arrays.asList(responsesElement)).build();
    mockTransitionRouteGroups.addResponse(expectedResponse);
    FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]");
    ListTransitionRouteGroupsPagedResponse pagedListResponse = client.listTransitionRouteGroups(parent);
    List<TransitionRouteGroup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTransitionRouteGroupsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockTransitionRouteGroups.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTransitionRouteGroupsRequest actualRequest = ((ListTransitionRouteGroupsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTransitionRouteGroupsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroupsClient.ListTransitionRouteGroupsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with Flow

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

the class ITSystemTest method getFlowTest.

@Test
public void getFlowTest() {
    GetFlowRequest request = GetFlowRequest.newBuilder().setName(flowName).build();
    Flow flow = flowsClient.getFlow(request);
    assertFlowDetails(flow);
}
Also used : GetFlowRequest(com.google.cloud.dialogflow.cx.v3beta1.GetFlowRequest) Flow(com.google.cloud.dialogflow.cx.v3beta1.Flow) Test(org.junit.Test)

Example 3 with Flow

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

the class ITSystemTest method listFlowsTest.

@Test
public void listFlowsTest() {
    ListFlowsRequest request = ListFlowsRequest.newBuilder().setParent(agentName).build();
    FlowsClient.ListFlowsPagedResponse pagedListResponse = flowsClient.listFlows(request);
    List<Flow> flows = Lists.newArrayList(pagedListResponse.iterateAll());
    boolean isFlowExists = false;
    for (Flow flow : flows) {
        if (flow.getName().equals(flowName)) {
            assertFlowDetails(flow);
            isFlowExists = true;
        }
    }
    assertTrue(isFlowExists);
}
Also used : FlowsClient(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient) ListFlowsRequest(com.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest) Flow(com.google.cloud.dialogflow.cx.v3beta1.Flow) Test(org.junit.Test)

Example 4 with Flow

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

the class PagesClientTest method listPagesTest.

@Test
public void listPagesTest() throws Exception {
    Page responsesElement = Page.newBuilder().build();
    ListPagesResponse expectedResponse = ListPagesResponse.newBuilder().setNextPageToken("").addAllPages(Arrays.asList(responsesElement)).build();
    mockPages.addResponse(expectedResponse);
    FlowName parent = FlowName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[FLOW]");
    ListPagesPagedResponse pagedListResponse = client.listPages(parent);
    List<Page> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getPagesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockPages.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListPagesRequest actualRequest = ((ListPagesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListPagesPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.PagesClient.ListPagesPagedResponse) Test(org.junit.Test)

Example 5 with Flow

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

the class CreatePage method createPage.

// Create a page in the specified agent.
public static Page createPage(String displayName, String projectId, String locationId, String agentId, String flowId, List<String> entryTexts) throws IOException, ApiException {
    PagesSettings.Builder pagesSettingsBuilder = PagesSettings.newBuilder();
    if (locationId.equals("global")) {
        pagesSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
    } else {
        pagesSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
    }
    PagesSettings pagesSettings = pagesSettingsBuilder.build();
    // Instantiates a client
    try (PagesClient pagesClient = PagesClient.create(pagesSettings)) {
        // Set the flow name using the projectID (my-project-id), locationID (global), agentID (UUID)
        // and flowID (UUID).
        FlowName parent = FlowName.of(projectId, locationId, agentId, flowId);
        // Build the entry fulfillment based on entry texts.
        Fulfillment.Builder entryFulfillmentBuilder = Fulfillment.newBuilder();
        for (String entryText : entryTexts) {
            entryFulfillmentBuilder.addMessages(ResponseMessage.newBuilder().setText(Text.newBuilder().addText(entryText).build()).build());
        }
        Fulfillment entryFulfillment = entryFulfillmentBuilder.build();
        // Build the form for the new page.
        // Note: hard coding parameters for simplicity.
        FillBehavior fillBehavior = FillBehavior.newBuilder().setInitialPromptFulfillment(Fulfillment.newBuilder().addMessages(ResponseMessage.newBuilder().setText(Text.newBuilder().addText("What would you like?").build()).build()).build()).build();
        Form form = Form.newBuilder().addParameters(Parameter.newBuilder().setDisplayName("param").setRequired(true).setEntityType("projects/-/locations/-/agents/-/entityTypes/sys.any").setFillBehavior(fillBehavior).build()).build();
        // Build the page.
        Page page = Page.newBuilder().setDisplayName(displayName).setEntryFulfillment(entryFulfillment).setForm(form).build();
        // Performs the create page request.
        Page response = pagesClient.createPage(parent, page);
        // TODO : Uncomment if you want to print response
        // System.out.format("Page created: %s\n", response.toString());
        pagesClient.shutdown();
        return response;
    }
}
Also used : PagesClient(com.google.cloud.dialogflow.cx.v3beta1.PagesClient) Fulfillment(com.google.cloud.dialogflow.cx.v3beta1.Fulfillment) FillBehavior(com.google.cloud.dialogflow.cx.v3beta1.Form.Parameter.FillBehavior) Form(com.google.cloud.dialogflow.cx.v3beta1.Form) FlowName(com.google.cloud.dialogflow.cx.v3beta1.FlowName) Page(com.google.cloud.dialogflow.cx.v3beta1.Page) PagesSettings(com.google.cloud.dialogflow.cx.v3beta1.PagesSettings)

Aggregations

Test (org.junit.Test)9 Flow (com.google.cloud.dialogflow.cx.v3beta1.Flow)6 Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FlowsClient (com.google.cloud.dialogflow.cx.v3beta1.FlowsClient)2 ListFlowsPagedResponse (com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse)2 Page (com.google.cloud.dialogflow.cx.v3beta1.Page)2 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 List (java.util.List)2 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)1 AgentName (com.google.cloud.dialogflow.cx.v3beta1.AgentName)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 CreateVersionRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest)1