Search in sources :

Example 1 with Gateway

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

the class DiscoveryTest method testCreateGatewayWOptions.

// Test the createGateway operation with a valid options model parameter
@Test
public void testCreateGatewayWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"gateway_id\": \"gatewayId\", \"name\": \"name\", \"status\": \"connected\", \"token\": \"token\", \"token_id\": \"tokenId\"}";
    String createGatewayPath = "/v1/environments/testString/gateways";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the CreateGatewayOptions model
    CreateGatewayOptions createGatewayOptionsModel = new CreateGatewayOptions.Builder().environmentId("testString").name("testString").build();
    // Invoke createGateway() with a valid options model and verify the result
    Response<Gateway> response = discoveryService.createGateway(createGatewayOptionsModel).execute();
    assertNotNull(response);
    Gateway 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(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createGatewayPath);
    // 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) CreateGatewayOptions(com.ibm.watson.discovery.v1.model.CreateGatewayOptions) Gateway(com.ibm.watson.discovery.v1.model.Gateway) Test(org.testng.annotations.Test)

Example 2 with Gateway

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

the class DiscoveryServiceTest method testGetGateway.

/**
 * Test get gateway.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetGateway() throws InterruptedException {
    server.enqueue(jsonResponse(gatewayResponse));
    String gatewayId = "gateway_id";
    GetGatewayOptions getGatewayOptions = new GetGatewayOptions.Builder().environmentId(environmentId).gatewayId(gatewayId).build();
    Gateway response = discoveryService.getGateway(getGatewayOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET, request.getMethod());
    assertEquals(gatewayResponse, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetGatewayOptions(com.ibm.watson.discovery.v1.model.GetGatewayOptions) Gateway(com.ibm.watson.discovery.v1.model.Gateway) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 3 with Gateway

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

the class DiscoveryServiceTest method testCreateGatewayOptions.

/**
 * Test create gateway options.
 */
@Test
public void testCreateGatewayOptions() {
    String name = "name";
    CreateGatewayOptions createGatewayOptions = new CreateGatewayOptions.Builder().environmentId(environmentId).name(name).build();
    assertEquals(environmentId, createGatewayOptions.environmentId());
    assertEquals(name, createGatewayOptions.name());
}
Also used : CreateGatewayOptions(com.ibm.watson.discovery.v1.model.CreateGatewayOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 4 with Gateway

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

the class Discovery method getGateway.

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

Example 5 with Gateway

use of com.ibm.watson.discovery.v1.model.Gateway 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)

Aggregations

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