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");
}
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);
}
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());
}
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);
}
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);
}
Aggregations