Search in sources :

Example 1 with DeleteGatewayOptions

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

the class DiscoveryTest method testDeleteGatewayWOptions.

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

Example 2 with DeleteGatewayOptions

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

the class Discovery method deleteGateway.

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

Example 3 with DeleteGatewayOptions

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

the class DiscoveryServiceTest method testDeleteGateway.

/**
 * Test delete gateway.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testDeleteGateway() throws InterruptedException {
    server.enqueue(jsonResponse(deleteGatewayResponse));
    String gatewayId = "gateway_id";
    DeleteGatewayOptions deleteGatewayOptions = new DeleteGatewayOptions.Builder().environmentId(environmentId).gatewayId(gatewayId).build();
    GatewayDelete response = discoveryService.deleteGateway(deleteGatewayOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(DELETE, request.getMethod());
    assertEquals(deleteGatewayResponse.getGatewayId(), response.getGatewayId());
    assertEquals(deleteGatewayResponse.getStatus(), response.getStatus());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) DeleteGatewayOptions(com.ibm.watson.discovery.v1.model.DeleteGatewayOptions) GatewayDelete(com.ibm.watson.discovery.v1.model.GatewayDelete) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 4 with DeleteGatewayOptions

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

the class DiscoveryServiceTest method testDeleteGatewayOptions.

/**
 * Test delete gateway options.
 */
@Test
public void testDeleteGatewayOptions() {
    String gatewayId = "gateway_id";
    DeleteGatewayOptions deleteGatewayOptions = new DeleteGatewayOptions.Builder().environmentId(environmentId).gatewayId(gatewayId).build();
    assertEquals(environmentId, deleteGatewayOptions.environmentId());
    assertEquals(gatewayId, deleteGatewayOptions.gatewayId());
}
Also used : DeleteGatewayOptions(com.ibm.watson.discovery.v1.model.DeleteGatewayOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

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