Search in sources :

Example 1 with TestDocument

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());
}
Also used : TestDocument(com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonPrimitive(com.google.gson.JsonPrimitive) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TestConfigurationInEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with TestDocument

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());
}
Also used : TestDocument(com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TestConfigurationInEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with TestDocument

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));
}
Also used : TestDocument(com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) RequestBody(okhttp3.RequestBody)

Aggregations

TestDocument (com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 TestConfigurationInEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1