diff --git a/.bumpversion.cfg b/.bumpversion.cfg
index cab641a38dd..f01f48a5249 100644
--- a/.bumpversion.cfg
+++ b/.bumpversion.cfg
@@ -1,5 +1,5 @@
[bumpversion]
-current_version = 6.11.1
+current_version = 6.11.2
commit = True
message = [skip ci] docs: Update version numbers from {current_version} -> {new_version}
diff --git a/README.md b/README.md
index c76c3c1f23a..0895a7dce2f 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ All the services:
com.ibm.watson.developer_cloud
java-sdk
- 6.11.1
+ 6.11.2
```
@@ -71,7 +71,7 @@ Only Discovery:
com.ibm.watson.developer_cloud
discovery
- 6.11.1
+ 6.11.2
```
@@ -80,13 +80,13 @@ Only Discovery:
All the services:
```gradle
-'com.ibm.watson.developer_cloud:java-sdk:6.11.1'
+'com.ibm.watson.developer_cloud:java-sdk:6.11.2'
```
Only Assistant:
```gradle
-'com.ibm.watson.developer_cloud:assistant:6.11.1'
+'com.ibm.watson.developer_cloud:assistant:6.11.2'
```
##### Development snapshots
@@ -109,7 +109,7 @@ And then reference the snapshot version on your app module gradle
Only Speech to Text:
```gradle
-'com.ibm.watson.developer_cloud:speech-to-text:6.11.2-SNAPSHOT'
+'com.ibm.watson.developer_cloud:speech-to-text:6.11.3-SNAPSHOT'
```
##### JAR
@@ -348,7 +348,7 @@ Gradle:
```sh
cd java-sdk
-gradle jar # build jar file (build/libs/watson-developer-cloud-6.11.1.jar)
+gradle jar # build jar file (build/libs/watson-developer-cloud-6.11.2.jar)
gradle test # run tests
gradle check # performs quality checks on source files and generates reports
gradle testReport # run tests and generate the aggregated test report (build/reports/allTests)
@@ -401,4 +401,4 @@ or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).
[ibm-cloud-onboarding]: http://console.bluemix.net/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Java
-[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-6.11.1/java-sdk-6.11.1-jar-with-dependencies.jar
+[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-6.11.2/java-sdk-6.11.2-jar-with-dependencies.jar
diff --git a/assistant/README.md b/assistant/README.md
index 7b547da129e..77bdd24b98a 100644
--- a/assistant/README.md
+++ b/assistant/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
assistant
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:assistant:6.11.1'
+'com.ibm.watson.developer_cloud:assistant:6.11.2'
```
## Usage
diff --git a/conversation/README.md b/conversation/README.md
index 969766febaf..6d640616003 100644
--- a/conversation/README.md
+++ b/conversation/README.md
@@ -10,13 +10,13 @@ Conversation will be removed in the next major release. Please migrate to Assist
com.ibm.watson.developer_cloud
conversation
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:conversation:6.11.1'
+'com.ibm.watson.developer_cloud:conversation:6.11.2'
```
## Usage
diff --git a/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java b/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java
index 8ef21f8a614..5fdd439d9cc 100644
--- a/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java
+++ b/core/src/main/java/com/ibm/watson/developer_cloud/service/WatsonService.java
@@ -117,23 +117,31 @@ public abstract class WatsonService {
*/
public WatsonService(final String name) {
this.name = name;
- String iamApiKey = CredentialUtils.getIAMKey(name);
- String iamUrl = CredentialUtils.getIAMUrl(name);
- if (iamApiKey != null) {
+ setCredentialFields(CredentialUtils.getCredentialsFromVcap(name));
+ client = configureHttpClient();
+ }
+
+ /**
+ * Calls appropriate methods to set credential values based on parsed ServiceCredentials object.
+ *
+ * @param serviceCredentials object containing parsed credential values
+ */
+ private void setCredentialFields(CredentialUtils.ServiceCredentials serviceCredentials) {
+ setEndPoint(serviceCredentials.getUrl());
+
+ if ((serviceCredentials.getUsername() != null) && (serviceCredentials.getPassword() != null)) {
+ setUsernameAndPassword(serviceCredentials.getUsername(), serviceCredentials.getPassword());
+ } else if (serviceCredentials.getOldApiKey() != null) {
+ setApiKey(serviceCredentials.getOldApiKey());
+ }
+
+ if (serviceCredentials.getIamApiKey() != null) {
IamOptions iamOptions = new IamOptions.Builder()
- .apiKey(iamApiKey)
- .url(iamUrl)
+ .apiKey(serviceCredentials.getIamApiKey())
+ .url(serviceCredentials.getIamUrl())
.build();
- tokenManager = new IamTokenManager(iamOptions);
+ this.tokenManager = new IamTokenManager(iamOptions);
}
- apiKey = CredentialUtils.getAPIKey(name);
- String url = CredentialUtils.getAPIUrl(name);
- if ((url != null) && !url.isEmpty()) {
- // The VCAP_SERVICES will typically contain a url. If present use it.
- setEndPoint(url);
- }
-
- client = configureHttpClient();
}
/**
@@ -338,6 +346,11 @@ public String getName() {
* @param apiKey the new API key
*/
public void setApiKey(String apiKey) {
+ if (CredentialUtils.hasBadStartOrEndChar(apiKey)) {
+ throw new IllegalArgumentException("The API key shouldn't start or end with curly brackets or quotes. Please "
+ + "remove any surrounding {, }, or \" characters.");
+ }
+
if (this.endPoint.equals(this.defaultEndPoint)) {
this.endPoint = "https://gateway-a.watsonplatform.net/visual-recognition/api";
}
@@ -373,6 +386,11 @@ protected void setAuthentication(final Builder builder) {
* @param endPoint the new end point. Will be ignored if empty or null
*/
public void setEndPoint(final String endPoint) {
+ if (CredentialUtils.hasBadStartOrEndChar(endPoint)) {
+ throw new IllegalArgumentException("The URL shouldn't start or end with curly brackets or quotes. Please "
+ + "remove any surrounding {, }, or \" characters.");
+ }
+
if ((endPoint != null) && !endPoint.isEmpty()) {
String newEndPoint = endPoint.endsWith("/") ? endPoint.substring(0, endPoint.length() - 1) : endPoint;
if (this.endPoint == null) {
@@ -389,6 +407,11 @@ public void setEndPoint(final String endPoint) {
* @param password the password
*/
public void setUsernameAndPassword(final String username, final String password) {
+ if (CredentialUtils.hasBadStartOrEndChar(username) || CredentialUtils.hasBadStartOrEndChar(password)) {
+ throw new IllegalArgumentException("The username and password shouldn't start or end with curly brackets or "
+ + "quotes. Please remove any surrounding {, }, or \" characters.");
+ }
+
// we'll perform the token exchange for users UNLESS they're on ICP
if (username.equals(APIKEY_AS_USERNAME) && !password.startsWith(ICP_PREFIX)) {
IamOptions iamOptions = new IamOptions.Builder()
diff --git a/core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamTokenManager.java b/core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamTokenManager.java
index 3f403a0932c..5db0c865936 100644
--- a/core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamTokenManager.java
+++ b/core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamTokenManager.java
@@ -17,6 +17,7 @@
import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.http.RequestBuilder;
import com.ibm.watson.developer_cloud.http.ResponseConverter;
+import com.ibm.watson.developer_cloud.util.CredentialUtils;
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
import okhttp3.Call;
import okhttp3.FormBody;
@@ -44,7 +45,13 @@ public class IamTokenManager {
private static final String REFRESH_TOKEN = "refresh_token";
public IamTokenManager(IamOptions options) {
- this.apiKey = options.getApiKey();
+ if (options.getApiKey() != null) {
+ if (CredentialUtils.hasBadStartOrEndChar(options.getApiKey())) {
+ throw new IllegalArgumentException("The IAM API key shouldn't start or end with curly brackets or quotes. "
+ + "Please remove any surrounding {, }, or \" characters.");
+ }
+ this.apiKey = options.getApiKey();
+ }
this.url = (options.getUrl() != null) ? options.getUrl() : DEFAULT_IAM_URL;
this.userManagedAccessToken = options.getAccessToken();
tokenData = new IamToken();
diff --git a/core/src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java b/core/src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java
index a1af0bd0018..a8bbdedc643 100644
--- a/core/src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java
+++ b/core/src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java
@@ -26,8 +26,6 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
-import okhttp3.Credentials;
-
/**
* CredentialUtils retrieves service credentials from the environment.
*/
@@ -38,12 +36,30 @@ public final class CredentialUtils {
*
*/
public static class ServiceCredentials {
- private String password;
private String username;
+ private String oldApiKey;
+ private String url;
+ private String iamApiKey;
+ private String iamUrl;
+ private String password;
- private ServiceCredentials(String username, String password) {
+ private ServiceCredentials(String username, String oldApiKey, String url, String iamApiKey, String iamUrl,
+ String password) {
this.username = username;
this.password = password;
+ this.oldApiKey = oldApiKey;
+ this.url = url;
+ this.iamApiKey = iamApiKey;
+ this.iamUrl = iamUrl;
+ }
+
+ /**
+ * Gets the username.
+ *
+ * @return the username
+ */
+ public String getUsername() {
+ return username;
}
/**
@@ -56,20 +72,41 @@ public String getPassword() {
}
/**
- * Gets the username.
+ * Gets the API used for older service instances.
*
- * @return the username
+ * @return the oldApiKey
*/
- public String getUsername() {
- return username;
+ public String getOldApiKey() {
+ return oldApiKey;
+ }
+
+ /**
+ * Gets the API URL.
+ *
+ * @return the url
+ */
+ public String getUrl() {
+ return url;
}
- }
- /** The Constant ALCHEMY_API. */
- private static final String ALCHEMY_API = "alchemy_api";
+ /**
+ * Gets the IAM API key.
+ *
+ * @return the iamApiKey
+ */
+ public String getIamApiKey() {
+ return iamApiKey;
+ }
- /** The Constant VISUAL_RECOGNITION. */
- private static final String VISUAL_RECOGNITION = "watson_vision_combined";
+ /**
+ * Gets the IAM URL.
+ *
+ * @return the iamUrl
+ */
+ public String getIamUrl() {
+ return iamUrl;
+ }
+ }
/** The Constant VCAP_SERVICES. */
private static final String VCAP_SERVICES = "VCAP_SERVICES";
@@ -77,9 +114,6 @@ public String getUsername() {
/** The Constant APIKEY. */
private static final String APIKEY = "apikey";
- /** The Constant IAM_API_KEY_NAME. */
- private static final String IAM_API_KEY_NAME = "iam_apikey_name";
-
/** The Constant CREDENTIALS. */
private static final String CREDENTIALS = "credentials";
@@ -129,6 +163,49 @@ private CredentialUtils() {
// This is a utility class - no instantiation allowed.
}
+ /**
+ * Returns true if the supplied value begins or ends with curly brackets or quotation marks. Returns false for null
+ * inputs.
+ *
+ * @param credentialValue the credential value to check
+ * @return true if the value starts or ends with these characters and is therefore invalid
+ */
+ public static boolean hasBadStartOrEndChar(String credentialValue) {
+ return credentialValue != null
+ && (credentialValue.startsWith("{")
+ || credentialValue.startsWith("\"")
+ || credentialValue.endsWith("}")
+ || credentialValue.endsWith("\""));
+ }
+
+ // VCAP-related methods
+
+ /**
+ * Calls methods to parse VCAP_SERVICES and retrieve credential values. For some values, if VCAP_SERVICES aren't
+ * present, it'll fall back to checking JDNI.
+ *
+ * @param serviceName the service name
+ * @return ServiceCredentials object containing parsed values
+ */
+ public static ServiceCredentials getCredentialsFromVcap(String serviceName) {
+ String username = getVcapValue(serviceName, USERNAME);
+ String password = getVcapValue(serviceName, PASSWORD);
+ String oldApiKey = getVcapValue(serviceName, API_KEY);
+ if (username == null && password == null && oldApiKey == null) {
+ oldApiKey = getJdniValue(serviceName, LOOKUP_NAME_EXTENSION_API_KEY);
+ }
+
+ String url = getVcapValue(serviceName, URL);
+ if (url == null) {
+ url = getJdniValue(serviceName, LOOKUP_NAME_EXTENSION_URL);
+ }
+
+ String iamApiKey = getVcapValue(serviceName, APIKEY);
+ String iamUrl = getVcapValue(serviceName, IAM_URL);
+
+ return new ServiceCredentials(username, password, oldApiKey, url, iamApiKey, iamUrl);
+ }
+
/**
* Builds the lookup name to be searched for in JDNI
* and uses it to call the overloaded JDNI method.
@@ -137,8 +214,8 @@ private CredentialUtils() {
* @param lookupNameExtension Extension to determine which value should be retrieved through JDNI
* @return The encoded desired value
*/
- private static String getJDNIValue(String serviceName, String lookupNameExtension) {
- return getJDNIValue("watson-developer-cloud/" + serviceName + lookupNameExtension);
+ private static String getJdniValue(String serviceName, String lookupNameExtension) {
+ return getJdniValue("watson-developer-cloud/" + serviceName + lookupNameExtension);
}
/**
@@ -149,7 +226,7 @@ private static String getJDNIValue(String serviceName, String lookupNameExtensio
* @param lookupName Key to lookup in JDNI
* @return The encoded desired value
*/
- private static String getJDNIValue(String lookupName) {
+ private static String getJdniValue(String lookupName) {
if (!isClassAvailable("javax.naming.Context") || !isClassAvailable("javax.naming.InitialContext")) {
log.info("JNDI string lookups is not available.");
return null;
@@ -180,7 +257,7 @@ private static boolean isClassAvailable(String className) {
*
* @return the VCAP_SERVICES as a {@link JsonObject}.
*/
- private static JsonObject getVCAPServices() {
+ private static JsonObject getVcapServices() {
final String envServices = services != null ? services : System.getenv(VCAP_SERVICES);
if (envServices == null) {
return null;
@@ -197,122 +274,6 @@ private static JsonObject getVCAPServices() {
return vcapServices;
}
- /**
- * Returns the IAM API key from the VCAP_SERVICES, or null if it doesn't exist.
- *
- * @param serviceName the service name
- * @return the IAM API key or null if the service cannot be found
- */
- public static String getIAMKey(String serviceName) {
- final JsonObject services = getVCAPServices();
-
- if (serviceName == null || services == null) {
- return null;
- }
-
- final JsonObject credentials = getCredentialsObject(services, serviceName, null);
- if (credentials != null && credentials.get(APIKEY) != null && credentials.get(IAM_API_KEY_NAME) != null) {
- return credentials.get(APIKEY).getAsString();
- }
-
- return null;
- }
-
- /**
- * Returns the apiKey from the VCAP_SERVICES or null if doesn't exists.
- *
- * @param serviceName the service name
- * @return the API key or null if the service cannot be found.
- */
- public static String getAPIKey(String serviceName) {
- return getAPIKey(serviceName, null);
- }
-
- /**
- * Returns the apiKey from the VCAP_SERVICES or null if doesn't exists. If plan is specified, then only credentials
- * for the given plan will be returned.
- *
- * @param serviceName the service name
- * @param plan the service plan: standard, free or experimental
- * @return the API key
- */
- public static String getAPIKey(String serviceName, String plan) {
- if ((serviceName == null) || serviceName.isEmpty()) {
- return null;
- }
-
- final JsonObject services = getVCAPServices();
- if (services == null) {
- return getJDNIValue(serviceName, LOOKUP_NAME_EXTENSION_API_KEY);
- }
- if (serviceName.equalsIgnoreCase(ALCHEMY_API)) {
- final JsonObject credentials = getCredentialsObject(services, serviceName, plan);
- if (credentials != null) {
- return credentials.get(APIKEY).getAsString();
- }
- } else if (serviceName.equalsIgnoreCase(VISUAL_RECOGNITION)) {
- final JsonObject credentials = getCredentialsObject(services, serviceName, plan);
- if (credentials != null) {
- return credentials.get(API_KEY).getAsString();
- }
- } else {
- ServiceCredentials credentials = getUserNameAndPassword(serviceName, plan);
- if (credentials != null) {
- return Credentials.basic(credentials.getUsername(), credentials.getPassword());
- }
- }
- return null;
- }
-
- /**
- * Returns the username and password as defined in the VCAP_SERVICES or null if they do not exist or are not
- * accessible. This is a utility method for {@link #getUserNameAndPassword(String, String)}. Invoking this method is
- * identical to calling getUserNameAndPassword(serviceName, null);
- *
- * @param serviceName the name of the service whose credentials are sought
- * @return an object representing the service's credentials
- */
- public static ServiceCredentials getUserNameAndPassword(String serviceName) {
- return getUserNameAndPassword(serviceName, null);
- }
-
- /**
- * Returns the username and password as defined in the VCAP_SERVICES or null if they do not exist or are not
- * accessible. If a plan is provided then only the credentials for that plan (and service) will be returned. Null will
- * be returned if the plan does not exist.
- *
- * @param serviceName the name of the service whose credentials are sought
- * @param plan the plan name
- * @return an object representing the service's credentials
- */
- public static ServiceCredentials getUserNameAndPassword(String serviceName, String plan) {
- if ((serviceName == null) || serviceName.isEmpty()) {
- return null;
- }
-
- final JsonObject services = getVCAPServices();
- if (services == null) {
- return null;
- }
-
- JsonObject jsonCredentials = getCredentialsObject(services, serviceName, plan);
- if (jsonCredentials != null) {
- String username = null;
- if (jsonCredentials.has(USERNAME)) {
- username = jsonCredentials.get(USERNAME).getAsString();
- }
- String password = null;
- if (jsonCredentials.has(PASSWORD)) {
- password = jsonCredentials.get(PASSWORD).getAsString();
- }
- if ((username != null) || (password != null)) {
- // both will be null in the case of Alchemy API
- return new ServiceCredentials(username, password);
- }
- }
- return null;
- }
-
/**
* A helper method to retrieve the appropriate 'credentials' JSON property value from the VCAP_SERVICES.
*
@@ -338,55 +299,35 @@ private static JsonObject getCredentialsObject(JsonObject vcapServices, String s
return null;
}
- /**
- * Gets the API url.
- *
- * @param serviceName the service name
- * @return the API url
- */
-
- public static String getAPIUrl(String serviceName) {
- return getAPIUrl(serviceName, null);
+ static String getVcapValue(String serviceName, String key) {
+ return getVcapValue(serviceName, key, null);
}
/**
- * Returns the API URL from the VCAP_SERVICES, JDNI, or null if doesn't exists. If plan is specified, then only
- * credentials for the given plan will be returned.
+ * Returns the value associated with the provided key from the VCAP_SERVICES, or null if it doesn't exist. In the
+ * case of the API URL, if VCAP_SERVICES aren't present, this method will also search in JDNI.
*
* @param serviceName the service name
- * @param plan the service plan: standard, free or experimental
- * @return the API URL
+ * @param key the key whose value should be returned
+ * @param plan the plan name
+ * @return the value of the provided key
*/
- public static String getAPIUrl(String serviceName, String plan) {
+ static String getVcapValue(String serviceName, String key, String plan) {
if ((serviceName == null) || serviceName.isEmpty()) {
return null;
}
- final JsonObject services = getVCAPServices();
+ final JsonObject services = getVcapServices();
if (services == null) {
- return getJDNIValue(serviceName, LOOKUP_NAME_EXTENSION_URL);
- }
-
- final JsonObject credentials = getCredentialsObject(services, serviceName, plan);
- if ((credentials != null) && credentials.has(URL)) {
- return credentials.get(URL).getAsString();
- }
-
- return null;
- }
-
- public static String getIAMUrl(String serviceName) {
- final JsonObject services = getVCAPServices();
-
- if (serviceName == null || services == null) {
return null;
}
- final JsonObject credentials = getCredentialsObject(services, serviceName, null);
- if (credentials != null && credentials.get(IAM_URL) != null) {
- return credentials.get(IAM_URL).getAsString();
+ JsonObject jsonCredentials = getCredentialsObject(services, serviceName, plan);
+ if (jsonCredentials != null) {
+ if (jsonCredentials.has(key)) {
+ return jsonCredentials.get(key).getAsString();
+ }
}
-
return null;
}
@@ -411,19 +352,4 @@ public static void setContext(Hashtable env) {
log.fine("Error setting up JDNI context: " + e.getMessage());
}
}
-
- /**
- * Method for testing the getAPIUrl method that bypasses the VCAP
- * services to ensure retrieval from JDNI.
- *
- * @param serviceName the service name
- * @return the API URL
- */
- public static String getAPIUrlTest(String serviceName) {
- if ((serviceName == null) || serviceName.isEmpty()) {
- return null;
- }
-
- return getJDNIValue("jdni/watson-developer-cloud/" + serviceName + LOOKUP_NAME_EXTENSION_URL);
- }
}
diff --git a/core/src/test/java/com/ibm/watson/developer_cloud/util/CredentialUtilsTest.java b/core/src/test/java/com/ibm/watson/developer_cloud/util/CredentialUtilsTest.java
index 33b4f4da458..4de4fe5bcef 100644
--- a/core/src/test/java/com/ibm/watson/developer_cloud/util/CredentialUtilsTest.java
+++ b/core/src/test/java/com/ibm/watson/developer_cloud/util/CredentialUtilsTest.java
@@ -13,15 +13,14 @@
package com.ibm.watson.developer_cloud.util;
import com.ibm.watson.developer_cloud.WatsonServiceTest;
-import com.ibm.watson.developer_cloud.util.CredentialUtils.ServiceCredentials;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import java.io.InputStream;
import java.util.Hashtable;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -29,32 +28,16 @@
* The Class CredentialUtilsTest.
*/
public class CredentialUtilsTest extends WatsonServiceTest {
-
- /** The Constant API_KEY_FREE. */
- private static final String API_KEY_FREE = "Basic bm90LWEtZnJlZS11c2VybmFtZTpub3QtYS1mcmVlLXBhc3N3b3Jk";
-
- /** The Constant API_KEY_STANDARD. */
- private static final String API_KEY_STANDARD = "Basic bm90LWEtdXNlcm5hbWU6bm90LWEtcGFzc3dvcmQ=";
-
- /** The Constant SERVICE_NAME. */
private static final String SERVICE_NAME = "personality_insights";
-
- /** The Constant VCAP_SERVICES. */
private static final String VCAP_SERVICES = "vcap_services.json";
-
+ private static final String APIKEY = "apikey";
+ private static final String USERNAME = "username";
+ private static final String OLD_API_KEY = "api_key";
private static final String NOT_A_USERNAME = "not-a-username";
private static final String NOT_A_PASSWORD = "not-a-password";
private static final String NOT_A_FREE_USERNAME = "not-a-free-username";
- private static final String NOT_A_FREE_PASSWORD = "not-a-free-password";
- private static final String PLAN = "standard";
-
private static final String VISUAL_RECOGNITION = "watson_vision_combined";
- private static final String PERSONALITY_INSIGHTS_URL = "https://gateway.watsonplatform.net/personality-insights/api";
-
- private static final String IAM_SERVICE_NAME = "language_translator";
- private static final String IAM_KEY_TEST_VALUE = "123456789";
-
/**
* Setup.
*/
@@ -72,76 +55,46 @@ public void setup() {
CredentialUtils.setContext(env);
}
- /**
- * Test get api key with null or empty service. There are two instances of Personality Insights: ['free', 'standard']
- */
@Test
- public void testGetAPIKeyWithNullOrEmptyService() {
- assertNull(CredentialUtils.getAPIKey(null, null));
- assertNull(CredentialUtils.getAPIKey("", ""));
-
- assertEquals(API_KEY_FREE, CredentialUtils.getAPIKey(SERVICE_NAME, null));
- assertEquals(API_KEY_FREE, CredentialUtils.getAPIKey(SERVICE_NAME, CredentialUtils.PLAN_FREE));
- assertEquals(API_KEY_STANDARD, CredentialUtils.getAPIKey(SERVICE_NAME, CredentialUtils.PLAN_STANDARD));
+ public void testGetVcapValueWithNullOrEmptyService() {
+ assertNull(CredentialUtils.getVcapValue(null, APIKEY));
+ assertNull(CredentialUtils.getVcapValue("", APIKEY));
}
- /**
- * Test get api key for visual recognition.
- */
@Test
- public void testGetApiKeyForVisualRecognition() {
- assertNull(CredentialUtils.getAPIKey(VISUAL_RECOGNITION, NOT_A_PASSWORD));
+ public void testGetVcapValueWithPlan() {
+ assertEquals(NOT_A_USERNAME, CredentialUtils.getVcapValue(SERVICE_NAME, USERNAME, CredentialUtils.PLAN_STANDARD));
}
- /**
- * Test get user name and password without plan.
- */
@Test
- public void testGetUserNameAndPasswordWithoutPlan() {
- assertNull(CredentialUtils.getUserNameAndPassword(null));
- assertNull(CredentialUtils.getUserNameAndPassword(null, null));
-
- ServiceCredentials credentials = CredentialUtils.getUserNameAndPassword(SERVICE_NAME);
- assertTrue(credentials != null);
- assertEquals(credentials.getUsername(), NOT_A_FREE_USERNAME);
- assertEquals(credentials.getPassword(), NOT_A_FREE_PASSWORD);
-
- credentials = CredentialUtils.getUserNameAndPassword(SERVICE_NAME, null);
- assertTrue(credentials != null);
- assertEquals(credentials.getUsername(), NOT_A_FREE_USERNAME);
- assertEquals(credentials.getPassword(), NOT_A_FREE_PASSWORD);
+ public void testGetVcapValueWithoutPlan() {
+ assertEquals(NOT_A_PASSWORD, CredentialUtils.getVcapValue(VISUAL_RECOGNITION, OLD_API_KEY));
}
- /**
- * Test get user credentials with plan.
- */
@Test
- public void testGetUserCredentialsWithPlan() {
- assertNull(CredentialUtils.getUserNameAndPassword(null));
- assertNull(CredentialUtils.getUserNameAndPassword(null, null));
-
- ServiceCredentials credentials = CredentialUtils.getUserNameAndPassword(SERVICE_NAME, PLAN);
- assertTrue(credentials != null);
- assertEquals(credentials.getUsername(), NOT_A_USERNAME);
- assertEquals(credentials.getPassword(), NOT_A_PASSWORD);
+ public void testGetVcapValueWithMultiplePlans() {
+ assertEquals(NOT_A_FREE_USERNAME, CredentialUtils.getVcapValue(SERVICE_NAME, USERNAME));
}
- /**
- * Test getting IAM API key from VCAP_SERVICES.
- */
@Test
- public void testGetIAMKey() {
- String key = CredentialUtils.getIAMKey(IAM_SERVICE_NAME);
- assertEquals(IAM_KEY_TEST_VALUE, key);
- }
+ public void testBadCredentialChar() {
+ // valid
+ assertFalse(CredentialUtils.hasBadStartOrEndChar("this_is_fine"));
- /**
- * Test getting the API URL using JDNI. We ignore this test in Travis because
- * it always fails there.
- */
- @Test
- @Ignore
- public void testGetAPIUrlFromJDNI() {
- assertEquals(CredentialUtils.getAPIUrlTest(SERVICE_NAME), PERSONALITY_INSIGHTS_URL);
+ // starting bracket
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("{bad_username"));
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("{{still_bad"));
+
+ // ending bracket
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("invalid}"));
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("also_invalid}}"));
+
+ // starting quote
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("\"not_allowed_either"));
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("\"\"still_not"));
+
+ // ending quote
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("nope\""));
+ assertTrue(CredentialUtils.hasBadStartOrEndChar("sorry\"\""));
}
}
diff --git a/discovery/README.md b/discovery/README.md
index 1b555b67b77..61fd3ba60eb 100644
--- a/discovery/README.md
+++ b/discovery/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
discovery
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:discovery:6.11.1'
+'com.ibm.watson.developer_cloud:discovery:6.11.2'
```
## Usage
diff --git a/language-translator/README.md b/language-translator/README.md
index 04aea78657a..70bf820c49d 100644
--- a/language-translator/README.md
+++ b/language-translator/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
language-translator
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:language-translator:6.11.1'
+'com.ibm.watson.developer_cloud:language-translator:6.11.2'
```
## Usage
diff --git a/natural-language-classifier/README.md b/natural-language-classifier/README.md
index 5f673da3e29..9f079ff432f 100644
--- a/natural-language-classifier/README.md
+++ b/natural-language-classifier/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
natural-language-classifier
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:natural-language-classifier:6.11.1'
+'com.ibm.watson.developer_cloud:natural-language-classifier:6.11.2'
```
## Usage
diff --git a/natural-language-understanding/README.md b/natural-language-understanding/README.md
index afd40a033a8..ea9ee8e9c80 100644
--- a/natural-language-understanding/README.md
+++ b/natural-language-understanding/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
natural-language-understanding
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:natural-language-understanding:6.11.1'
+'com.ibm.watson.developer_cloud:natural-language-understanding:6.11.2'
```
## Usage
diff --git a/personality-insights/README.md b/personality-insights/README.md
index 3b94012e857..2cdbbe36550 100755
--- a/personality-insights/README.md
+++ b/personality-insights/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
personality-insights
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:personality-insights:6.11.1'
+'com.ibm.watson.developer_cloud:personality-insights:6.11.2'
```
## Usage
diff --git a/speech-to-text/README.md b/speech-to-text/README.md
index 4d0e674fc13..1c306a9f77b 100755
--- a/speech-to-text/README.md
+++ b/speech-to-text/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
speech-to-text
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:speech-to-text:6.11.1'
+'com.ibm.watson.developer_cloud:speech-to-text:6.11.2'
```
## Usage
diff --git a/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java b/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java
index 2501a8ad050..ae980b45546 100755
--- a/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java
+++ b/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextIT.java
@@ -465,7 +465,9 @@ public void testCheckJobWithWrongId() {
/**
* Test check jobs.
*
+ * Ignoring while the endpoint is broken.
*/
+ @Ignore
@Test
public void testCheckJobs() {
RecognitionJobs jobs = service.checkJobs().execute();
diff --git a/text-to-speech/README.md b/text-to-speech/README.md
index 51799fb3953..cdfbb2a2028 100755
--- a/text-to-speech/README.md
+++ b/text-to-speech/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
text-to-speech
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:text-to-speech:6.11.1'
+'com.ibm.watson.developer_cloud:text-to-speech:6.11.2'
```
## Usage
diff --git a/tone-analyzer/README.md b/tone-analyzer/README.md
index db3f2b0abac..5a5222a05ce 100755
--- a/tone-analyzer/README.md
+++ b/tone-analyzer/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
tone-analyzer
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:tone-analyzer:6.11.1'
+'com.ibm.watson.developer_cloud:tone-analyzer:6.11.2'
```
## Usage
diff --git a/visual-recognition/README.md b/visual-recognition/README.md
index 4585ca1cac6..956bb8b53f0 100644
--- a/visual-recognition/README.md
+++ b/visual-recognition/README.md
@@ -7,13 +7,13 @@
com.ibm.watson.developer_cloud
visual-recognition
- 6.11.1
+ 6.11.2
```
##### Gradle
```gradle
-'com.ibm.watson.developer_cloud:visual-recognition:6.11.1'
+'com.ibm.watson.developer_cloud:visual-recognition:6.11.2'
```
## Usage