use of com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testUpdateCredentialsWOptions.
// Test the updateCredentials operation with a valid options model parameter
@Test
public void testUpdateCredentialsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"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 updateCredentialsPath = "/v1/environments/testString/credentials/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the CredentialDetails model
CredentialDetails credentialDetailsModel = new CredentialDetails.Builder().credentialType("oauth2").clientId("testString").enterpriseId("testString").url("testString").username("testString").organizationUrl("testString").siteCollectionPath("testString").clientSecret("testString").publicKeyId("testString").privateKey("testString").passphrase("testString").password("testString").gatewayId("testString").sourceVersion("online").webApplicationUrl("testString").domain("testString").endpoint("testString").accessKeyId("testString").secretAccessKey("testString").build();
// Construct an instance of the StatusDetails model
StatusDetails statusDetailsModel = new StatusDetails.Builder().authenticated(true).errorMessage("testString").build();
// Construct an instance of the UpdateCredentialsOptions model
UpdateCredentialsOptions updateCredentialsOptionsModel = new UpdateCredentialsOptions.Builder().environmentId("testString").credentialId("testString").sourceType("box").credentialDetails(credentialDetailsModel).status(statusDetailsModel).build();
// Invoke updateCredentials() with a valid options model and verify the result
Response<Credentials> response = discoveryService.updateCredentials(updateCredentialsOptionsModel).execute();
assertNotNull(response);
Credentials 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(), "PUT");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateCredentialsPath);
// 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.UpdateCredentialsOptions in project java-sdk by watson-developer-cloud.
the class Discovery method updateCredentials.
/**
* Update credentials.
*
* <p>Updates an existing set of source credentials.
*
* <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
*
* @param updateCredentialsOptions the {@link UpdateCredentialsOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Credentials}
*/
public ServiceCall<Credentials> updateCredentials(UpdateCredentialsOptions updateCredentialsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateCredentialsOptions, "updateCredentialsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", updateCredentialsOptions.environmentId());
pathParamsMap.put("credential_id", updateCredentialsOptions.credentialId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials/{credential_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateCredentials");
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));
final JsonObject contentJson = new JsonObject();
if (updateCredentialsOptions.sourceType() != null) {
contentJson.addProperty("source_type", updateCredentialsOptions.sourceType());
}
if (updateCredentialsOptions.credentialDetails() != null) {
contentJson.add("credential_details", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCredentialsOptions.credentialDetails()));
}
if (updateCredentialsOptions.status() != null) {
contentJson.add("status", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCredentialsOptions.status()));
}
builder.bodyJson(contentJson);
ResponseConverter<Credentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Credentials>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method updateCredentialsIsSuccessful.
/**
* Update credentials is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void updateCredentialsIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(credentialsResp));
CredentialDetails newDetails = new CredentialDetails.Builder().clientId("new_client_id").clientSecret("new_client_secret").credentialType(CredentialDetails.CredentialType.USERNAME_PASSWORD).enterpriseId("new_enterprise_id").organizationUrl("new_organization_url").passphrase("new_passphrase").password("new_password").privateKey("new_private_key").publicKeyId("new_public_key_id").siteCollectionPath("new_site_collection_path").url("new_url").username("new_username").build();
Credentials newCredentials = new Credentials.Builder().sourceType(Credentials.SourceType.SALESFORCE).credentialDetails(newDetails).build();
UpdateCredentialsOptions options = new UpdateCredentialsOptions.Builder().environmentId(environmentId).credentialId("new_credential_id").sourceType(Credentials.SourceType.SALESFORCE).credentials(newCredentials).credentialDetails(newDetails).build();
Credentials response = discoveryService.updateCredentials(options).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(UPDATE_CREDENTIALS_PATH, request.getPath());
assertEquals(PUT, request.getMethod());
assertEquals(credentialsResp, response);
}
Aggregations