Search in sources :

Example 1 with GatewayList

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

the class DiscoveryServiceTest method testListGateways.

/**
 * Test list gateways.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testListGateways() throws InterruptedException {
    server.enqueue(jsonResponse(listGatewaysResponse));
    ListGatewaysOptions listGatewaysOptions = new ListGatewaysOptions.Builder().environmentId(environmentId).build();
    GatewayList response = discoveryService.listGateways(listGatewaysOptions).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET, request.getMethod());
    assertEquals(listGatewaysResponse, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GatewayList(com.ibm.watson.discovery.v1.model.GatewayList) ListGatewaysOptions(com.ibm.watson.discovery.v1.model.ListGatewaysOptions) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 2 with GatewayList

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

the class DiscoveryTest method testListGatewaysWOptions.

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

Example 3 with GatewayList

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

the class Discovery method listGateways.

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

Aggregations

GatewayList (com.ibm.watson.discovery.v1.model.GatewayList)3 ListGatewaysOptions (com.ibm.watson.discovery.v1.model.ListGatewaysOptions)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