Search in sources :

Example 1 with TestConfigurationInEnvironmentOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions 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 2 with TestConfigurationInEnvironmentOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions 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)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)1 TestConfigurationInEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 Test (org.junit.Test)1