Search in sources :

Example 1 with TokenDictStatusResponse

use of com.ibm.watson.discovery.v1.model.TokenDictStatusResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryTest method testGetStopwordListStatusWOptions.

// Test the getStopwordListStatus operation with a valid options model parameter
@Test
public void testGetStopwordListStatusWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"status\": \"active\", \"type\": \"type\"}";
    String getStopwordListStatusPath = "/v1/environments/testString/collections/testString/word_lists/stopwords";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetStopwordListStatusOptions model
    GetStopwordListStatusOptions getStopwordListStatusOptionsModel = new GetStopwordListStatusOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke getStopwordListStatus() with a valid options model and verify the result
    Response<TokenDictStatusResponse> response = discoveryService.getStopwordListStatus(getStopwordListStatusOptionsModel).execute();
    assertNotNull(response);
    TokenDictStatusResponse responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getStopwordListStatusPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetStopwordListStatusOptions(com.ibm.watson.discovery.v1.model.GetStopwordListStatusOptions) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse) Test(org.testng.annotations.Test)

Example 2 with TokenDictStatusResponse

use of com.ibm.watson.discovery.v1.model.TokenDictStatusResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryTest method testGetTokenizationDictionaryStatusWOptions.

// Test the getTokenizationDictionaryStatus operation with a valid options model parameter
@Test
public void testGetTokenizationDictionaryStatusWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"status\": \"active\", \"type\": \"type\"}";
    String getTokenizationDictionaryStatusPath = "/v1/environments/testString/collections/testString/word_lists/tokenization_dictionary";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetTokenizationDictionaryStatusOptions model
    GetTokenizationDictionaryStatusOptions getTokenizationDictionaryStatusOptionsModel = new GetTokenizationDictionaryStatusOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke getTokenizationDictionaryStatus() with a valid options model and verify the result
    Response<TokenDictStatusResponse> response = discoveryService.getTokenizationDictionaryStatus(getTokenizationDictionaryStatusOptionsModel).execute();
    assertNotNull(response);
    TokenDictStatusResponse responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getTokenizationDictionaryStatusPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetTokenizationDictionaryStatusOptions(com.ibm.watson.discovery.v1.model.GetTokenizationDictionaryStatusOptions) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse) Test(org.testng.annotations.Test)

Example 3 with TokenDictStatusResponse

use of com.ibm.watson.discovery.v1.model.TokenDictStatusResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method testGetStopwordListStatus.

/**
 * Test get stopword list status.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetStopwordListStatus() throws InterruptedException {
    server.enqueue(jsonResponse(tokenDictStatusResponseStopwords));
    String type = "stopwords";
    GetStopwordListStatusOptions getStopwordListStatusOptions = new GetStopwordListStatusOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    TokenDictStatusResponse response = discoveryService.getStopwordListStatus(getStopwordListStatusOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET, request.getMethod());
    assertEquals(TokenDictStatusResponse.Status.ACTIVE, response.getStatus());
    assertEquals(type, response.getType());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetStopwordListStatusOptions(com.ibm.watson.discovery.v1.model.GetStopwordListStatusOptions) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 4 with TokenDictStatusResponse

use of com.ibm.watson.discovery.v1.model.TokenDictStatusResponse in project java-sdk by watson-developer-cloud.

the class Discovery method createTokenizationDictionary.

/**
 * Create tokenization dictionary.
 *
 * <p>Upload a custom tokenization dictionary to use with the specified collection.
 *
 * @param createTokenizationDictionaryOptions the {@link CreateTokenizationDictionaryOptions}
 *     containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link TokenDictStatusResponse}
 */
public ServiceCall<TokenDictStatusResponse> createTokenizationDictionary(CreateTokenizationDictionaryOptions createTokenizationDictionaryOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createTokenizationDictionaryOptions, "createTokenizationDictionaryOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createTokenizationDictionaryOptions.environmentId());
    pathParamsMap.put("collection_id", createTokenizationDictionaryOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/word_lists/tokenization_dictionary", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createTokenizationDictionary");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createTokenizationDictionaryOptions.tokenizationRules() != null) {
        contentJson.add("tokenization_rules", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createTokenizationDictionaryOptions.tokenizationRules()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<TokenDictStatusResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TokenDictStatusResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)

Example 5 with TokenDictStatusResponse

use of com.ibm.watson.discovery.v1.model.TokenDictStatusResponse in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method testGetTokenizationDictionaryStatus.

/**
 * Test get tokenization dictionary status.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetTokenizationDictionaryStatus() throws InterruptedException {
    server.enqueue(jsonResponse(tokenDictStatusResponse));
    GetTokenizationDictionaryStatusOptions getOptions = new GetTokenizationDictionaryStatusOptions.Builder().environmentId(environmentId).collectionId(collectionId).build();
    TokenDictStatusResponse response = discoveryService.getTokenizationDictionaryStatus(getOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET, request.getMethod());
    assertEquals(tokenDictStatusResponse, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetTokenizationDictionaryStatusOptions(com.ibm.watson.discovery.v1.model.GetTokenizationDictionaryStatusOptions) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

TokenDictStatusResponse (com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)13 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)4 HashMap (java.util.HashMap)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.testng.annotations.Test)4 CreateStopwordListOptions (com.ibm.watson.discovery.v1.model.CreateStopwordListOptions)2 CreateTokenizationDictionaryOptions (com.ibm.watson.discovery.v1.model.CreateTokenizationDictionaryOptions)2 GetStopwordListStatusOptions (com.ibm.watson.discovery.v1.model.GetStopwordListStatusOptions)2 GetTokenizationDictionaryStatusOptions (com.ibm.watson.discovery.v1.model.GetTokenizationDictionaryStatusOptions)2 TokenDictRule (com.ibm.watson.discovery.v1.model.TokenDictRule)2 JsonObject (com.google.gson.JsonObject)1 NoAuthAuthenticator (com.ibm.cloud.sdk.core.security.NoAuthAuthenticator)1 Collection (com.ibm.watson.discovery.v1.model.Collection)1 Configuration (com.ibm.watson.discovery.v1.model.Configuration)1 CreateEventResponse (com.ibm.watson.discovery.v1.model.CreateEventResponse)1 Credentials (com.ibm.watson.discovery.v1.model.Credentials)1 CredentialsList (com.ibm.watson.discovery.v1.model.CredentialsList)1 DeleteCollectionResponse (com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)1