Search in sources :

Example 1 with KnowledgeBase

use of com.google.cloud.dialogflow.v2beta1.KnowledgeBase in project java-dialogflow by googleapis.

the class KnowledgeBasesClientTest method listKnowledgeBasesTest2.

@Test
public void listKnowledgeBasesTest2() throws Exception {
    KnowledgeBase responsesElement = KnowledgeBase.newBuilder().build();
    ListKnowledgeBasesResponse expectedResponse = ListKnowledgeBasesResponse.newBuilder().setNextPageToken("").addAllKnowledgeBases(Arrays.asList(responsesElement)).build();
    mockKnowledgeBases.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListKnowledgeBasesPagedResponse pagedListResponse = client.listKnowledgeBases(parent);
    List<KnowledgeBase> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKnowledgeBasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKnowledgeBases.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKnowledgeBasesRequest actualRequest = ((ListKnowledgeBasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListKnowledgeBasesPagedResponse(com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient.ListKnowledgeBasesPagedResponse) Test(org.junit.Test)

Example 2 with KnowledgeBase

use of com.google.cloud.dialogflow.v2beta1.KnowledgeBase in project java-dialogflow by googleapis.

the class KnowledgeBasesClientTest method listKnowledgeBasesTest3.

@Test
public void listKnowledgeBasesTest3() throws Exception {
    KnowledgeBase responsesElement = KnowledgeBase.newBuilder().build();
    ListKnowledgeBasesResponse expectedResponse = ListKnowledgeBasesResponse.newBuilder().setNextPageToken("").addAllKnowledgeBases(Arrays.asList(responsesElement)).build();
    mockKnowledgeBases.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListKnowledgeBasesPagedResponse pagedListResponse = client.listKnowledgeBases(parent);
    List<KnowledgeBase> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKnowledgeBasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKnowledgeBases.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKnowledgeBasesRequest actualRequest = ((ListKnowledgeBasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListKnowledgeBasesPagedResponse(com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient.ListKnowledgeBasesPagedResponse) Test(org.junit.Test)

Example 3 with KnowledgeBase

use of com.google.cloud.dialogflow.v2beta1.KnowledgeBase in project java-dialogflow by googleapis.

the class KnowledgeBasesClientTest method listKnowledgeBasesTest.

@Test
public void listKnowledgeBasesTest() throws Exception {
    KnowledgeBase responsesElement = KnowledgeBase.newBuilder().build();
    ListKnowledgeBasesResponse expectedResponse = ListKnowledgeBasesResponse.newBuilder().setNextPageToken("").addAllKnowledgeBases(Arrays.asList(responsesElement)).build();
    mockKnowledgeBases.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListKnowledgeBasesPagedResponse pagedListResponse = client.listKnowledgeBases(parent);
    List<KnowledgeBase> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getKnowledgeBasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockKnowledgeBases.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListKnowledgeBasesRequest actualRequest = ((ListKnowledgeBasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListKnowledgeBasesPagedResponse(com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient.ListKnowledgeBasesPagedResponse) Test(org.junit.Test)

Example 4 with KnowledgeBase

use of com.google.cloud.dialogflow.v2beta1.KnowledgeBase in project java-dialogflow by googleapis.

the class KnowledgeBaseManagement method createKnowledgeBase.

// Create a Knowledge base
public static void createKnowledgeBase(String projectId, String location, String displayName) throws ApiException, IOException {
    // Instantiates a client
    try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
        KnowledgeBase targetKnowledgeBase = KnowledgeBase.newBuilder().setDisplayName(displayName).build();
        LocationName parent = LocationName.of(projectId, location);
        KnowledgeBase createdKnowledgeBase = knowledgeBasesClient.createKnowledgeBase(parent, targetKnowledgeBase);
        System.out.println("====================");
        System.out.format("Knowledgebase created:\n");
        System.out.format("Display Name: %s\n", createdKnowledgeBase.getDisplayName());
        System.out.format("Name: %s\n", createdKnowledgeBase.getName());
    }
}
Also used : KnowledgeBase(com.google.cloud.dialogflow.v2.KnowledgeBase) KnowledgeBasesClient(com.google.cloud.dialogflow.v2.KnowledgeBasesClient) LocationName(com.google.cloud.dialogflow.v2.LocationName)

Example 5 with KnowledgeBase

use of com.google.cloud.dialogflow.v2beta1.KnowledgeBase in project java-dialogflow by googleapis.

the class CreateDocumentTest method setUp.

@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);
}
Also used : PrintStream(java.io.PrintStream) KnowledgeBase(com.google.cloud.dialogflow.v2beta1.KnowledgeBase) ProjectName(com.google.cloud.dialogflow.v2beta1.ProjectName) KnowledgeBasesClient(com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)4 ListKnowledgeBasesPagedResponse (com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient.ListKnowledgeBasesPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 KnowledgeBase (com.google.cloud.dialogflow.v2beta1.KnowledgeBase)2 KnowledgeBase (com.google.cloud.dialogflow.v2.KnowledgeBase)1 KnowledgeBasesClient (com.google.cloud.dialogflow.v2.KnowledgeBasesClient)1 LocationName (com.google.cloud.dialogflow.v2.LocationName)1 KnowledgeBasesClient (com.google.cloud.dialogflow.v2beta1.KnowledgeBasesClient)1 ProjectName (com.google.cloud.dialogflow.v2beta1.ProjectName)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Before (org.junit.Before)1