use of com.ibm.watson.discovery.v1.model.DeleteCredentials in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testDeleteCredentialsWOptions.
// Test the deleteCredentials operation with a valid options model parameter
@Test
public void testDeleteCredentialsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"credential_id\": \"credentialId\", \"status\": \"deleted\"}";
String deleteCredentialsPath = "/v1/environments/testString/credentials/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the DeleteCredentialsOptions model
DeleteCredentialsOptions deleteCredentialsOptionsModel = new DeleteCredentialsOptions.Builder().environmentId("testString").credentialId("testString").build();
// Invoke deleteCredentials() with a valid options model and verify the result
Response<DeleteCredentials> response = discoveryService.deleteCredentials(deleteCredentialsOptionsModel).execute();
assertNotNull(response);
DeleteCredentials 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, deleteCredentialsPath);
// 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.DeleteCredentials in project java-sdk by watson-developer-cloud.
the class Discovery method deleteCredentials.
/**
* Delete credentials.
*
* <p>Deletes a set of stored credentials from your Discovery instance.
*
* @param deleteCredentialsOptions the {@link DeleteCredentialsOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link DeleteCredentials}
*/
public ServiceCall<DeleteCredentials> deleteCredentials(DeleteCredentialsOptions deleteCredentialsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteCredentialsOptions, "deleteCredentialsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", deleteCredentialsOptions.environmentId());
pathParamsMap.put("credential_id", deleteCredentialsOptions.credentialId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials/{credential_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteCredentials");
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<DeleteCredentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteCredentials>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.DeleteCredentials in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method deleteCredentialsIsSuccessful.
/**
* Delete credentials is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void deleteCredentialsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(deleteCredentialsResp));
DeleteCredentialsOptions options = new DeleteCredentialsOptions.Builder().environmentId(environmentId).credentialId("credential_id").build();
DeleteCredentials response = discoveryService.deleteCredentials(options).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(DELETE_CREDENTIALS_PATH, request.getPath());
assertEquals(DELETE, request.getMethod());
assertEquals(deleteCredentialsResp.getCredentialId(), response.getCredentialId());
assertEquals(deleteCredentialsResp.getStatus(), response.getStatus());
}
Aggregations