use of com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addDocumentFromInputStreamWithFileNameAndMediaTypeIsSuccessful.
@Test
public void addDocumentFromInputStreamWithFileNameAndMediaTypeIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createDocResp));
String fileName = "MyFileName";
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).fileContentType(HttpMediaType.APPLICATION_JSON);
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.developer_cloud.discovery.v1.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method setupTestDocuments.
private synchronized String setupTestDocuments() {
if (collectionId != null) {
return collectionId;
}
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
@SuppressWarnings("unused") List<DocumentAccepted> documentAccepted = createTestDocuments(collectionId, 10);
WaitFor.Condition collectionAvailable = new WaitForCollectionAvailable(environmentId, collectionId);
WaitFor.waitFor(collectionAvailable, 5, TimeUnit.SECONDS, 500);
return collectionId;
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateDocumentIsSuccessful.
@Test
public void updateDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
uniqueName = UUID.randomUUID().toString();
Configuration testConfig = createTestConfig();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.filename("test_file");
// updateBuilder.configurationId(testConfig.getConfigurationId());
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, updateResponse.getDocumentId()).build();
DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
assertTrue(getResponse.getStatus().equals(DocumentStatus.Status.AVAILABLE) || getResponse.getStatus().equals(DocumentStatus.Status.PROCESSING));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateAnotherDocumentIsSuccessful.
@Test
public void updateAnotherDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.metadata(myMetadata.toString());
DocumentAccepted documentAccepted = discovery.addDocument(builder.build()).execute();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.filename("test_file");
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, updateResponse.getDocumentId()).build();
DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
assertTrue(getResponse.getStatus().equals(DocumentStatus.Status.AVAILABLE) || getResponse.getStatus().equals(DocumentStatus.Status.PROCESSING));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted 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());
}
Aggregations