use of com.ibm.watson.discovery.v2.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method addDocumentIsSuccessful.
@SuppressWarnings("deprecation")
@Test
public void addDocumentIsSuccessful() {
Collection collection = createTestCollection();
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());
}
use of com.ibm.watson.discovery.v2.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method addDocumentWithMetadataIsSuccessful.
@Ignore
@SuppressWarnings("deprecation")
@Test
public void addDocumentWithMetadataIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
String myDocumentJson = "{\"field\":\"value\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute();
WaitFor.Condition documentAccepted = new WaitForDocumentAccepted(environmentId, collectionId, createResponse.getDocumentId());
WaitFor.waitFor(documentAccepted, 5, TimeUnit.SECONDS, 500);
QueryOptions queryOptions = new QueryOptions.Builder(environmentId, collectionId).build();
QueryResponse queryResponse = discovery.query(queryOptions).execute();
assertTrue(queryResponse.getResults().get(0).getMetadata() != null);
}
use of com.ibm.watson.discovery.v2.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addDocumentWithoutRequiredParametersFails.
@Test(expected = IllegalArgumentException.class)
public void addDocumentWithoutRequiredParametersFails() {
AddDocumentOptions options = new AddDocumentOptions.Builder(environmentId, collectionId).build();
DocumentAccepted response = discoveryService.addDocument(options).execute();
}
use of com.ibm.watson.discovery.v2.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addDocumentFromInputStreamIsSuccessful.
@Test
public void addDocumentFromInputStreamIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createDocResp));
String myDocumentJson = "{\"field\":\"value\"}";
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.file(documentStream);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
DocumentAccepted response = discoveryService.addDocument(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS1_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(createDocResp, response);
}
use of com.ibm.watson.discovery.v2.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method updateDocumentWithoutRequiredParametersFails.
@Test(expected = IllegalArgumentException.class)
public void updateDocumentWithoutRequiredParametersFails() {
UpdateDocumentOptions options = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentId).build();
DocumentAccepted response = discoveryService.updateDocument(options).execute();
}
Aggregations