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");
}
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");
}
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());
}
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);
}
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);
}
Aggregations