Search in sources :

Example 1 with DeleteEnvironmentOptions

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

the class DiscoveryServiceTest method deleteEnvironmentIsSuccessful.

// Deleted test for createEnvironment with null name as this does not fail in the current SDK
@Test
public void deleteEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteEnvResp));
    DeleteEnvironmentOptions deleteRequest = new DeleteEnvironmentOptions.Builder(environmentId).build();
    discoveryService.deleteEnvironment(deleteRequest).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(ENV1_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteEnvironmentOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with DeleteEnvironmentOptions

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

the class DiscoveryTest method testDeleteEnvironmentWOptions.

// Test the deleteEnvironment operation with a valid options model parameter
@Test
public void testDeleteEnvironmentWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"environment_id\": \"environmentId\", \"status\": \"deleted\"}";
    String deleteEnvironmentPath = "/v1/environments/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the DeleteEnvironmentOptions model
    DeleteEnvironmentOptions deleteEnvironmentOptionsModel = new DeleteEnvironmentOptions.Builder().environmentId("testString").build();
    // Invoke deleteEnvironment() with a valid options model and verify the result
    Response<DeleteEnvironmentResponse> response = discoveryService.deleteEnvironment(deleteEnvironmentOptionsModel).execute();
    assertNotNull(response);
    DeleteEnvironmentResponse 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, deleteEnvironmentPath);
    // 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) DeleteEnvironmentResponse(com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse) DeleteEnvironmentOptions(com.ibm.watson.discovery.v1.model.DeleteEnvironmentOptions) Test(org.testng.annotations.Test)

Example 3 with DeleteEnvironmentOptions

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

the class Discovery method deleteEnvironment.

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

Example 4 with DeleteEnvironmentOptions

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

the class DiscoveryServiceIT method deleteEnvironmentIsSuccessful.

@Test
@Ignore("Only 1 BYOD environment allowed per service instance, so do not delete it")
public void deleteEnvironmentIsSuccessful() {
    String environmentName = uniqueName + "-environment";
    CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder().name(environmentName).size(FREE).build();
    Environment createResponse = createEnvironment(createOptions);
    DeleteEnvironmentOptions deleteOptions = new DeleteEnvironmentOptions.Builder(createResponse.getEnvironmentId()).build();
    deleteEnvironment(deleteOptions);
}
Also used : CreateEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment) DeleteEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteEnvironmentOptions) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with DeleteEnvironmentOptions

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

the class DiscoveryServiceTest method deleteEnvironmentIsSuccessful.

// Deleted test for createEnvironment with null name as this does not fail in the current SDK
/**
 * Delete environment is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void deleteEnvironmentIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(deleteEnvResp));
    DeleteEnvironmentOptions deleteRequest = new DeleteEnvironmentOptions.Builder(environmentId).build();
    DeleteEnvironmentResponse response = discoveryService.deleteEnvironment(deleteRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(ENV1_PATH, request.getPath());
    assertEquals(DELETE, request.getMethod());
    assertEquals(deleteEnvResp.getEnvironmentId(), response.getEnvironmentId());
    assertEquals(deleteEnvResp.getStatus(), response.getStatus());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteEnvironmentResponse(com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse) DeleteEnvironmentOptions(com.ibm.watson.discovery.v1.model.DeleteEnvironmentOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

DeleteEnvironmentResponse (com.ibm.watson.discovery.v1.model.DeleteEnvironmentResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 DeleteEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteEnvironmentOptions)2 DeleteEnvironmentOptions (com.ibm.watson.discovery.v1.model.DeleteEnvironmentOptions)2 Test (org.junit.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)1 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Ignore (org.junit.Ignore)1 Test (org.testng.annotations.Test)1