use of com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method testConfigurationInEnvironmentWithAllOptionsIsSuccessful.
@Test
public void testConfigurationInEnvironmentWithAllOptionsIsSuccessful() {
Configuration testConfig = createTestConfig();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
TestConfigurationInEnvironmentOptions.Builder builder = new TestConfigurationInEnvironmentOptions.Builder();
builder.environmentId(environmentId);
builder.configurationId(testConfig.getConfigurationId());
builder.step(TestConfigurationInEnvironmentOptions.Step.HTML_OUTPUT);
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
builder.filename("test_file");
builder.metadata(myMetadata.toString());
TestDocument testResponse = discovery.testConfigurationInEnvironment(builder.build()).execute();
assertNotNull(testResponse);
assertEquals(0, testResponse.getNotices().size());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method testConfigurationInEnvironmentIsSuccessful.
// Tests for testConfigurationInEnvironment
@Test
public void testConfigurationInEnvironmentIsSuccessful() {
Configuration testConfig = createTestConfig();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
TestConfigurationInEnvironmentOptions options = new TestConfigurationInEnvironmentOptions.Builder(environmentId).configurationId(testConfig.getConfigurationId()).file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON).filename("test_file").build();
TestDocument testResponse = discovery.testConfigurationInEnvironment(options).execute();
assertNotNull(testResponse);
assertEquals(0, testResponse.getNotices().size());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument in project java-sdk by watson-developer-cloud.
the class Discovery method testConfigurationInEnvironment.
/**
* Test configuration.
*
* Runs a sample document through the default or your configuration and returns diagnostic information designed to
* help you understand how the document was processed. The document is not added to the index.
*
* @param testConfigurationInEnvironmentOptions the {@link TestConfigurationInEnvironmentOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a response type of {@link TestDocument}
*/
public ServiceCall<TestDocument> testConfigurationInEnvironment(TestConfigurationInEnvironmentOptions testConfigurationInEnvironmentOptions) {
Validator.notNull(testConfigurationInEnvironmentOptions, "testConfigurationInEnvironmentOptions cannot be null");
Validator.isTrue((testConfigurationInEnvironmentOptions.configuration() != null) || (testConfigurationInEnvironmentOptions.file() != null) || (testConfigurationInEnvironmentOptions.metadata() != null), "At least one of configuration, file, or metadata must be supplied.");
String[] pathSegments = { "v1/environments", "preview" };
String[] pathParameters = { testConfigurationInEnvironmentOptions.environmentId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (testConfigurationInEnvironmentOptions.step() != null) {
builder.query("step", testConfigurationInEnvironmentOptions.step());
}
if (testConfigurationInEnvironmentOptions.configurationId() != null) {
builder.query("configuration_id", testConfigurationInEnvironmentOptions.configurationId());
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (testConfigurationInEnvironmentOptions.configuration() != null) {
multipartBuilder.addFormDataPart("configuration", testConfigurationInEnvironmentOptions.configuration());
}
if (testConfigurationInEnvironmentOptions.file() != null) {
RequestBody fileBody = RequestUtils.inputStreamBody(testConfigurationInEnvironmentOptions.file(), testConfigurationInEnvironmentOptions.fileContentType());
multipartBuilder.addFormDataPart("file", testConfigurationInEnvironmentOptions.filename(), fileBody);
}
if (testConfigurationInEnvironmentOptions.metadata() != null) {
multipartBuilder.addFormDataPart("metadata", testConfigurationInEnvironmentOptions.metadata());
}
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TestDocument.class));
}
Aggregations