Search in sources :

Example 31 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method getCollectionFieldsIsSuccessful.

@Ignore
@Test
public void getCollectionFieldsIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    createTestDocument("test_document", collectionId);
    ListCollectionFieldsOptions getOptions = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse getResponse = discovery.listCollectionFields(getOptions).execute();
    assertFalse(getResponse.getFields().isEmpty());
}
Also used : ListCollectionFieldsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 32 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method addDocumentWithConfigurationIsSuccessful.

@Test
public void addDocumentWithConfigurationIsSuccessful() {
    Collection collection = createTestCollection();
    uniqueName = UUID.randomUUID().toString();
    String myDocumentJson = "{\"field\":\"value\"}";
    InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
    AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder();
    builder.environmentId(environmentId);
    builder.collectionId(collection.getCollectionId());
    builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
    builder.filename("test_file");
    DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute();
    assertFalse(createResponse.getDocumentId().isEmpty());
    assertNull(createResponse.getNotices());
}
Also used : DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) ByteArrayInputStream(java.io.ByteArrayInputStream) AddDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 33 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method deleteDocumentIsSuccessful.

@Test
public void deleteDocumentIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
    DeleteDocumentOptions deleteOptions = new DeleteDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId()).build();
    discovery.deleteDocument(deleteOptions).execute();
}
Also used : DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) DeleteDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteDocumentOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 34 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method createCollectionIsSuccessful.

// Collection tests
@Test
public void createCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(createCollResp));
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(configurationId);
    Collection response = discoveryService.createCollection(createCollectionBuilder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL1_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(createCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 35 with Collection

use of com.ibm.watson.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method getCollectionIsSuccessful.

@Test
public void getCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollResp));
    GetCollectionOptions getRequest = new GetCollectionOptions.Builder(environmentId, collectionId).build();
    Collection response = discoveryService.getCollection(getRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5