Search in sources :

Example 26 with Collection

use of li.naska.bgg.resource.v3.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 27 with Collection

use of li.naska.bgg.resource.v3.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 28 with Collection

use of li.naska.bgg.resource.v3.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)

Example 29 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method queryWithNestedAggregationTermIsSuccessful.

@Test
public void queryWithNestedAggregationTermIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    createTestDocument("test_document_1", collectionId);
    createTestDocument("test_document_2", collectionId);
    QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
    StringBuilder sb = new StringBuilder();
    sb.append(AggregationType.TERM);
    sb.append(Operator.OPENING_GROUPING);
    sb.append("field");
    sb.append(Operator.CLOSING_GROUPING);
    sb.append(Operator.NEST_AGGREGATION);
    sb.append(AggregationType.TERM);
    sb.append(Operator.OPENING_GROUPING);
    sb.append("field");
    sb.append(Operator.CLOSING_GROUPING);
    String aggregation = sb.toString();
    queryBuilder.aggregation(aggregation);
    QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
    Term term = (Term) queryResponse.getAggregations().get(0);
    AggregationResult agResults = term.getResults().get(0);
    List<QueryAggregation> aggregations = agResults.getAggregations();
    assertFalse(aggregations.isEmpty());
}
Also used : AggregationResult(com.ibm.watson.developer_cloud.discovery.v1.model.AggregationResult) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Term(com.ibm.watson.developer_cloud.discovery.v1.model.Term) QueryAggregation(com.ibm.watson.developer_cloud.discovery.v1.model.QueryAggregation) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 30 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method updateCollectionIsSuccessful.

@Test
public void updateCollectionIsSuccessful() {
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions createOptions = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).build();
    Collection collection = createCollection(createOptions);
    assertNotNull(collection.getCollectionId());
    Configuration testConfig = createTestConfig();
    String updatedCollectionName = UUID.randomUUID().toString() + "-collection";
    String updatedCollectionDescription = "Description for " + updatedCollectionName;
    UpdateCollectionOptions.Builder updateBuilder = new UpdateCollectionOptions.Builder(environmentId, collection.getCollectionId());
    updateBuilder.name(updatedCollectionName);
    updateBuilder.description(updatedCollectionDescription);
    updateBuilder.configurationId(testConfig.getConfigurationId());
    Collection updatedCollection = discovery.updateCollection(updateBuilder.build()).execute();
    assertEquals(updatedCollectionName, updatedCollection.getName());
    assertEquals(updatedCollectionDescription, updatedCollection.getDescription());
    assertEquals(testConfig.getConfigurationId(), updatedCollection.getConfigurationId());
}
Also used : UpdateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateCollectionOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 JsonObject (com.google.gson.JsonObject)9 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)7 Test (org.testng.annotations.Test)7 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)6 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)5 HashMap (java.util.HashMap)5