Search in sources :

Example 1 with CredentialDetails

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

the class DiscoveryServiceTest method createCredentialsIsSuccessful.

/**
 * Creates the credentials is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void createCredentialsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(credentialsResp));
    CredentialDetails details = new CredentialDetails.Builder().credentialType(CredentialDetails.CredentialType.USERNAME_PASSWORD).url("url").username("username").build();
    Credentials credentials = new Credentials.Builder().sourceType(Credentials.SourceType.SALESFORCE).credentialDetails(details).build();
    CreateCredentialsOptions options = new CreateCredentialsOptions.Builder().environmentId(environmentId).sourceType(Credentials.SourceType.SALESFORCE).credentials(credentials).credentialDetails(details).build();
    Credentials credentialsResponse = discoveryService.createCredentials(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(CREATE_CREDENTIALS_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(credentialsResp, credentialsResponse);
    assertEquals(credentialsResp.credentialDetails(), credentialsResponse.credentialDetails());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CreateCredentialsOptions(com.ibm.watson.discovery.v1.model.CreateCredentialsOptions) CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 2 with CredentialDetails

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

the class DiscoveryTest method testCreateCredentialsWOptions.

// Test the createCredentials operation with a valid options model parameter
@Test
public void testCreateCredentialsWOptions() 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 createCredentialsPath = "/v1/environments/testString/credentials";
    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 CreateCredentialsOptions model
    CreateCredentialsOptions createCredentialsOptionsModel = new CreateCredentialsOptions.Builder().environmentId("testString").sourceType("box").credentialDetails(credentialDetailsModel).status(statusDetailsModel).build();
    // Invoke createCredentials() with a valid options model and verify the result
    Response<Credentials> response = discoveryService.createCredentials(createCredentialsOptionsModel).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(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createCredentialsPath);
    // 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) CreateCredentialsOptions(com.ibm.watson.discovery.v1.model.CreateCredentialsOptions) CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) StatusDetails(com.ibm.watson.discovery.v1.model.StatusDetails) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) Test(org.testng.annotations.Test)

Example 3 with CredentialDetails

use of com.ibm.watson.discovery.v1.model.CredentialDetails 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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateCredentialsOptions(com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions) CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) StatusDetails(com.ibm.watson.discovery.v1.model.StatusDetails) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) Test(org.testng.annotations.Test)

Example 4 with CredentialDetails

use of com.ibm.watson.discovery.v1.model.CredentialDetails 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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UpdateCredentialsOptions(com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions) CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 5 with CredentialDetails

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

the class DiscoveryServiceTest method testCredentialDetails.

/**
 * Test credential details.
 */
@Test
public void testCredentialDetails() {
    String clientId = "client_id";
    // pragma: whitelist secret
    String clientSecret = "client_secret";
    String enterpriseId = "enterprise_id";
    String organizationUrl = "organization_url";
    String passphrase = "passphrase";
    // pragma: whitelist secret
    String password = "password";
    String privateKey = "private_key";
    String publicKeyId = "public_key_id";
    String siteCollectionPath = "site_collection_path";
    String url = "url";
    String username = "username";
    String gatewayId = "gateway_id";
    String sourceVersion = "source_version";
    String webApplicationUrl = "web_application_url";
    String domain = "domain";
    String endpoint = "endpoint";
    String accessKeyId = "access_key";
    String secretAccessKey = "secret_access_key";
    CredentialDetails details = new CredentialDetails.Builder().clientId(clientId).clientSecret(clientSecret).credentialType(CredentialDetails.CredentialType.USERNAME_PASSWORD).enterpriseId(enterpriseId).organizationUrl(organizationUrl).passphrase(passphrase).password(password).privateKey(privateKey).publicKeyId(publicKeyId).siteCollectionPath(siteCollectionPath).url(url).username(username).gatewayId(gatewayId).sourceVersion(sourceVersion).webApplicationUrl(webApplicationUrl).domain(domain).endpoint(endpoint).accessKeyId(accessKeyId).secretAccessKey(secretAccessKey).build();
    assertEquals(clientId, details.clientId());
    assertEquals(clientSecret, details.clientSecret());
    assertEquals(CredentialDetails.CredentialType.USERNAME_PASSWORD, details.credentialType());
    assertEquals(enterpriseId, details.enterpriseId());
    assertEquals(organizationUrl, details.organizationUrl());
    assertEquals(passphrase, details.passphrase());
    assertEquals(password, details.password());
    assertEquals(privateKey, details.privateKey());
    assertEquals(publicKeyId, details.publicKeyId());
    assertEquals(siteCollectionPath, details.siteCollectionPath());
    assertEquals(url, details.url());
    assertEquals(username, details.username());
    assertEquals(gatewayId, details.gatewayId());
    assertEquals(sourceVersion, details.sourceVersion());
    assertEquals(webApplicationUrl, details.webApplicationUrl());
    assertEquals(domain, details.domain());
    assertEquals(accessKeyId, details.accessKeyId());
    assertEquals(secretAccessKey, details.secretAccessKey());
}
Also used : CredentialDetails(com.ibm.watson.discovery.v1.model.CredentialDetails) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

CredentialDetails (com.ibm.watson.discovery.v1.model.CredentialDetails)5 Credentials (com.ibm.watson.discovery.v1.model.Credentials)4 DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)3 CreateCredentialsOptions (com.ibm.watson.discovery.v1.model.CreateCredentialsOptions)2 StatusDetails (com.ibm.watson.discovery.v1.model.StatusDetails)2 UpdateCredentialsOptions (com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.testng.annotations.Test)2