use of com.ibm.watson.discovery.v1.model.CredentialsList in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testListCredentialsWOptions.
// Test the listCredentials operation with a valid options model parameter
@Test
public void testListCredentialsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"credentials\": [{\"credential_id\": \"credentialId\", \"source_type\": \"box\", \"credential_details\": {\"credential_type\": \"oauth2\", \"client_id\": \"clientId\", \"enterprise_id\": \"enterpriseId\", \"url\": \"url\", \"username\": \"username\", \"organization_url\": \"organizationUrl\", \"site_collection.path\": \"siteCollectionPath\", \"client_secret\": \"clientSecret\", \"public_key_id\": \"publicKeyId\", \"private_key\": \"privateKey\", \"passphrase\": \"passphrase\", \"password\": \"password\", \"gateway_id\": \"gatewayId\", \"source_version\": \"online\", \"web_application_url\": \"webApplicationUrl\", \"domain\": \"domain\", \"endpoint\": \"endpoint\", \"access_key_id\": \"accessKeyId\", \"secret_access_key\": \"secretAccessKey\"}, \"status\": {\"authenticated\": false, \"error_message\": \"errorMessage\"}}]}";
String listCredentialsPath = "/v1/environments/testString/credentials";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListCredentialsOptions model
ListCredentialsOptions listCredentialsOptionsModel = new ListCredentialsOptions.Builder().environmentId("testString").build();
// Invoke listCredentials() with a valid options model and verify the result
Response<CredentialsList> response = discoveryService.listCredentials(listCredentialsOptionsModel).execute();
assertNotNull(response);
CredentialsList 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, listCredentialsPath);
// 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.CredentialsList in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method listCredentialsIsSuccessful.
/**
* List credentials is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void listCredentialsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(listCredentialsResp));
ListCredentialsOptions options = new ListCredentialsOptions.Builder().environmentId(environmentId).build();
CredentialsList response = discoveryService.listCredentials(options).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(LIST_CREDENTIALS_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(listCredentialsResp, response);
assertTrue(response.getCredentials().size() == 3);
}
use of com.ibm.watson.discovery.v1.model.CredentialsList in project java-sdk by watson-developer-cloud.
the class Discovery method listCredentials.
/**
* List credentials.
*
* <p>List all the source credentials that have been created for this service instance.
*
* <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
*
* @param listCredentialsOptions the {@link ListCredentialsOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link CredentialsList}
*/
public ServiceCall<CredentialsList> listCredentials(ListCredentialsOptions listCredentialsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listCredentialsOptions, "listCredentialsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", listCredentialsOptions.environmentId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCredentials");
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<CredentialsList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CredentialsList>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations