Search in sources :

Example 6 with Credentials

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

Example 7 with Credentials

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

the class DiscoveryTest method testGetCredentialsWOptions.

// Test the getCredentials operation with a valid options model parameter
@Test
public void testGetCredentialsWOptions() 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 getCredentialsPath = "/v1/environments/testString/credentials/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetCredentialsOptions model
    GetCredentialsOptions getCredentialsOptionsModel = new GetCredentialsOptions.Builder().environmentId("testString").credentialId("testString").build();
    // Invoke getCredentials() with a valid options model and verify the result
    Response<Credentials> response = discoveryService.getCredentials(getCredentialsOptionsModel).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(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getCredentialsPath);
    // 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) GetCredentialsOptions(com.ibm.watson.discovery.v1.model.GetCredentialsOptions) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) Test(org.testng.annotations.Test)

Example 8 with Credentials

use of com.ibm.watson.discovery.v1.model.Credentials 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 9 with Credentials

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

the class DiscoveryServiceTest method getCredentialsIsSuccessful.

/**
 * Gets the credentials is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getCredentialsIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(credentialsResp));
    GetCredentialsOptions options = new GetCredentialsOptions.Builder().environmentId(environmentId).credentialId("credential_id").build();
    Credentials credentialsResponse = discoveryService.getCredentials(options).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(GET_CREDENTIALS_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(credentialsResp, credentialsResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetCredentialsOptions(com.ibm.watson.discovery.v1.model.GetCredentialsOptions) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 10 with Credentials

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

the class Discovery method getCredentials.

/**
 * View Credentials.
 *
 * <p>Returns details about the specified credentials.
 *
 * <p>**Note:** Secure credential information such as a password or SSH key is never returned and
 * must be obtained from the source system.
 *
 * @param getCredentialsOptions the {@link GetCredentialsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Credentials}
 */
public ServiceCall<Credentials> getCredentials(GetCredentialsOptions getCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCredentialsOptions, "getCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getCredentialsOptions.environmentId());
    pathParamsMap.put("credential_id", getCredentialsOptions.credentialId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials/{credential_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getCredentials");
    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<Credentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Credentials>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Aggregations

DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)12 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 Credentials (com.ibm.watson.discovery.v1.model.Credentials)9 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.testng.annotations.Test)5 CredentialDetails (com.ibm.watson.discovery.v1.model.CredentialDetails)4 CredentialsList (com.ibm.watson.discovery.v1.model.CredentialsList)3 JsonObject (com.google.gson.JsonObject)2 Credentials (com.haleconnect.api.user.v1.model.Credentials)2 CreateCredentialsOptions (com.ibm.watson.discovery.v1.model.CreateCredentialsOptions)2 DeleteCredentialsOptions (com.ibm.watson.discovery.v1.model.DeleteCredentialsOptions)2 GetCredentialsOptions (com.ibm.watson.discovery.v1.model.GetCredentialsOptions)2 ListCredentialsOptions (com.ibm.watson.discovery.v1.model.ListCredentialsOptions)2 StatusDetails (com.ibm.watson.discovery.v1.model.StatusDetails)2 UpdateCredentialsOptions (com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions)2 ApiException (com.haleconnect.api.user.v1.ApiException)1 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)1