Search in sources :

Example 1 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent in project java-dialogflow-cx by googleapis.

the class IntentsClientTest method listIntentsTest2.

@Test
public void listIntentsTest2() throws Exception {
    Intent responsesElement = Intent.newBuilder().build();
    ListIntentsResponse expectedResponse = ListIntentsResponse.newBuilder().setNextPageToken("").addAllIntents(Arrays.asList(responsesElement)).build();
    mockIntents.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListIntentsPagedResponse(com.google.cloud.dialogflow.cx.v3.IntentsClient.ListIntentsPagedResponse) Test(org.junit.Test)

Example 2 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent 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.v3.IntentsClient.ListIntentsPagedResponse) Test(org.junit.Test)

Example 3 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent in project java-dialogflow-cx by googleapis.

the class ITSystemTest method getIntentsTest.

@Test
public void getIntentsTest() {
    GetIntentRequest request = GetIntentRequest.newBuilder().setName(intentsName).build();
    Intent intent = intentsClient.getIntent(request);
    assertIntentDetails(intent);
}
Also used : GetIntentRequest(com.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) Test(org.junit.Test)

Example 4 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent in project java-dialogflow-cx by googleapis.

the class ITSystemTest method listIntentsTest.

@Test
public void listIntentsTest() {
    ListIntentsRequest request = ListIntentsRequest.newBuilder().setParent(agentName).build();
    IntentsClient.ListIntentsPagedResponse pagedListResponse = intentsClient.listIntents(request);
    List<Intent> intents = Lists.newArrayList(pagedListResponse.iterateAll());
    boolean isIntentExists = false;
    for (Intent intent : intents) {
        if (intent.getName().equals(intentsName)) {
            assertIntentDetails(intent);
            isIntentExists = true;
        }
    }
    assertTrue(isIntentExists);
}
Also used : IntentsClient(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient) ListIntentsRequest(com.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) Test(org.junit.Test)

Example 5 with Intent

use of com.google.cloud.dialogflow.cx.v3.Intent in project java-dialogflow-cx by googleapis.

the class CreateIntent method createIntent.

// Create an intent of the given intent type.
public static Intent createIntent(String displayName, String projectId, String locationId, String agentId, List<String> trainingPhrasesParts) throws IOException, ApiException {
    IntentsSettings.Builder intentsSettingsBuilder = IntentsSettings.newBuilder();
    if (locationId.equals("global")) {
        intentsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
    } else {
        intentsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
    }
    IntentsSettings intentsSettings = intentsSettingsBuilder.build();
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create(intentsSettings)) {
        // Set the project agent name using the projectID (my-project-id), locationID (global), and
        // agentID (UUID).
        AgentName parent = AgentName.of(projectId, locationId, agentId);
        // Build the trainingPhrases from the trainingPhrasesParts.
        List<TrainingPhrase> trainingPhrases = new ArrayList<>();
        for (String trainingPhrase : trainingPhrasesParts) {
            trainingPhrases.add(TrainingPhrase.newBuilder().addParts(Part.newBuilder().setText(trainingPhrase).build()).setRepeatCount(1).build());
        }
        // Build the intent.
        Intent intent = Intent.newBuilder().setDisplayName(displayName).addAllTrainingPhrases(trainingPhrases).build();
        // Performs the create intent request.
        Intent response = intentsClient.createIntent(parent, intent);
        return response;
    }
}
Also used : IntentsSettings(com.google.cloud.dialogflow.cx.v3beta1.IntentsSettings) TrainingPhrase(com.google.cloud.dialogflow.cx.v3beta1.Intent.TrainingPhrase) IntentsClient(com.google.cloud.dialogflow.cx.v3beta1.IntentsClient) ArrayList(java.util.ArrayList) Intent(com.google.cloud.dialogflow.cx.v3beta1.Intent) AgentName(com.google.cloud.dialogflow.cx.v3beta1.AgentName)

Aggregations

Intent (com.google.cloud.dialogflow.v2.Intent)10 Test (org.junit.Test)10 Intent (com.google.cloud.dialogflow.cx.v3beta1.Intent)7 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)7 AgentName (com.google.cloud.dialogflow.v2.AgentName)4 Intent (com.google.cloud.dialogflow.cx.v3.Intent)3 IntentsClient (com.google.cloud.dialogflow.cx.v3.IntentsClient)3 TrainingPhrase (com.google.cloud.dialogflow.cx.v3beta1.Intent.TrainingPhrase)3 FieldMask (com.google.protobuf.FieldMask)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 ListIntentsPagedResponse (com.google.cloud.dialogflow.cx.v3.IntentsClient.ListIntentsPagedResponse)2 IntentsClient (com.google.cloud.dialogflow.cx.v3beta1.IntentsClient)2 Context (com.google.cloud.dialogflow.v2.Context)2 GetIntentRequest (com.google.cloud.dialogflow.v2.GetIntentRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 BeforeClass (org.junit.BeforeClass)2 Agent (com.google.cloud.dialogflow.cx.v3.Agent)1