Search in sources :

Example 1 with DeleteCollectionResponse

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

the class DiscoveryServiceTest method deleteCollectionIsSuccessful.

/**
 * Delete collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteCollResp));
    DeleteCollectionOptions deleteRequest = new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
    DeleteCollectionResponse response = discoveryService.deleteCollection(deleteRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
    assertEquals(DeleteCollectionResponse.Status.DELETED, response.getStatus());
    assertEquals(deleteCollResp.getCollectionId(), response.getCollectionId());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse) DeleteCollectionOptions(com.ibm.watson.discovery.v1.model.DeleteCollectionOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 2 with DeleteCollectionResponse

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

the class DiscoveryTest method testDeleteCollectionWOptions.

// Test the deleteCollection operation with a valid options model parameter
@Test
public void testDeleteCollectionWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"status\": \"deleted\"}";
    String deleteCollectionPath = "/v1/environments/testString/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteCollectionOptions model
    DeleteCollectionOptions deleteCollectionOptionsModel = new DeleteCollectionOptions.Builder().environmentId("testString").collectionId("testString").build();
    // Invoke deleteCollection() with a valid options model and verify the result
    Response<DeleteCollectionResponse> response = discoveryService.deleteCollection(deleteCollectionOptionsModel).execute();
    assertNotNull(response);
    DeleteCollectionResponse 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(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteCollectionPath);
    // 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) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse) DeleteCollectionOptions(com.ibm.watson.discovery.v1.model.DeleteCollectionOptions) Test(org.testng.annotations.Test)

Example 3 with DeleteCollectionResponse

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

the class Discovery method deleteCollection.

/**
 * Delete a collection.
 *
 * @param deleteCollectionOptions the {@link DeleteCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link DeleteCollectionResponse}
 */
public ServiceCall<DeleteCollectionResponse> deleteCollection(DeleteCollectionOptions deleteCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteCollectionOptions, "deleteCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", deleteCollectionOptions.environmentId());
    pathParamsMap.put("collection_id", deleteCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteCollection");
    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));
    ResponseConverter<DeleteCollectionResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteCollectionResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)

Aggregations

DeleteCollectionResponse (com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)3 DeleteCollectionOptions (com.ibm.watson.discovery.v1.model.DeleteCollectionOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1