use of com.ibm.watson.discovery.v2.model.Enrichments in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetCollectionWOptions.
@Test
public void testGetCollectionWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"language\": \"en\", \"enrichments\": [{\"enrichment_id\": \"enrichmentId\", \"fields\": [\"fields\"]}]}";
String getCollectionPath = "/v2/projects/testString/collections/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetCollectionOptions model
GetCollectionOptions getCollectionOptionsModel = new GetCollectionOptions.Builder().projectId("testString").collectionId("testString").build();
// Invoke operation with valid options model (positive test)
Response<CollectionDetails> response = discoveryService.getCollection(getCollectionOptionsModel).execute();
assertNotNull(response);
CollectionDetails responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getCollectionPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichments in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testUpdateEnrichmentWOptions.
@Test
public void testUpdateEnrichmentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"enrichment_id\": \"enrichmentId\", \"name\": \"name\", \"description\": \"description\", \"type\": \"part_of_speech\", \"options\": {\"languages\": [\"languages\"], \"entity_type\": \"entityType\", \"regular_expression\": \"regularExpression\", \"result_field\": \"resultField\"}}";
String updateEnrichmentPath = "/v2/projects/testString/enrichments/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the UpdateEnrichmentOptions model
UpdateEnrichmentOptions updateEnrichmentOptionsModel = new UpdateEnrichmentOptions.Builder().projectId("testString").enrichmentId("testString").name("testString").description("testString").build();
// Invoke operation with valid options model (positive test)
Response<Enrichment> response = discoveryService.updateEnrichment(updateEnrichmentOptionsModel).execute();
assertNotNull(response);
Enrichment responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateEnrichmentPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichments in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testDeleteEnrichmentWOptions.
@Test
public void testDeleteEnrichmentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "";
String deleteEnrichmentPath = "/v2/projects/testString/enrichments/testString";
server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteEnrichmentOptions model
DeleteEnrichmentOptions deleteEnrichmentOptionsModel = new DeleteEnrichmentOptions.Builder().projectId("testString").enrichmentId("testString").build();
// Invoke operation with valid options model (positive test)
Response<Void> response = discoveryService.deleteEnrichment(deleteEnrichmentOptionsModel).execute();
assertNotNull(response);
Void responseObj = response.getResult();
// Response does not have a return type. Check that the result is null.
assertNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteEnrichmentPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichments in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testUpdateCollectionWOptions.
@Test
public void testUpdateCollectionWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"language\": \"en\", \"enrichments\": [{\"enrichment_id\": \"enrichmentId\", \"fields\": [\"fields\"]}]}";
String updateCollectionPath = "/v2/projects/testString/collections/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the CollectionEnrichment model
CollectionEnrichment collectionEnrichmentModel = new CollectionEnrichment.Builder().enrichmentId("testString").fields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Construct an instance of the UpdateCollectionOptions model
UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().projectId("testString").collectionId("testString").name("testString").description("testString").enrichments(new java.util.ArrayList<CollectionEnrichment>(java.util.Arrays.asList(collectionEnrichmentModel))).build();
// Invoke operation with valid options model (positive test)
Response<CollectionDetails> response = discoveryService.updateCollection(updateCollectionOptionsModel).execute();
assertNotNull(response);
CollectionDetails responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateCollectionPath);
}
use of com.ibm.watson.discovery.v2.model.Enrichments in project java-sdk by watson-developer-cloud.
the class Discovery method updateEnrichment.
/**
* Update an enrichment.
*
* <p>Updates an existing enrichment's name and description.
*
* @param updateEnrichmentOptions the {@link UpdateEnrichmentOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Enrichment}
*/
public ServiceCall<Enrichment> updateEnrichment(UpdateEnrichmentOptions updateEnrichmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateEnrichmentOptions, "updateEnrichmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", updateEnrichmentOptions.projectId());
pathParamsMap.put("enrichment_id", updateEnrichmentOptions.enrichmentId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateEnrichment");
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();
contentJson.addProperty("name", updateEnrichmentOptions.name());
if (updateEnrichmentOptions.description() != null) {
contentJson.addProperty("description", updateEnrichmentOptions.description());
}
builder.bodyJson(contentJson);
ResponseConverter<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations