Skip to content

Commit

Permalink
Merge pull request #1202 from watson-developer-cloud/fix-its
Browse files Browse the repository at this point in the history
test(its): add a way to retrieve properties from config.properties
  • Loading branch information
kevinkowa authored Jan 14, 2022
2 parents 0d25ec0 + 4519c0b commit 96e94d2
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://www.linkedin.com/in/logan-patino/"><img src="https://avatars2.githubusercontent.com/u/8710772?v=4" width="100px;" alt=""/><br /><sub><b>Logan Patino</b></sub></a><br /><a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=lpatino10" title="Code">💻</a> <a href="#design-lpatino10" title="Design">🎨</a> <a href="https://github.com/watson-developer-cloud/java-sdk/issues?q=author%3Alpatino10" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/mediumTaj"><img src="https://avatars1.githubusercontent.com/u/4381558?v=4" width="100px;" alt=""/><br /><sub><b>Ajiemar Santiago</b></sub></a><br /><a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=mediumTaj" title="Code">💻</a> <a href="#design-mediumTaj" title="Design">🎨</a> <a href="https://github.com/watson-developer-cloud/java-sdk/issues?q=author%3AmediumTaj" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://germanattanasio.com"><img src="https://avatars3.githubusercontent.com/u/313157?v=4" width="100px;" alt=""/><br /><sub><b>German Attanasio</b></sub></a><br /><a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=germanattanasio" title="Code">💻</a> <a href="#design-germanattanasio" title="Design">🎨</a> <a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=germanattanasio" title="Documentation">📖</a> <a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=germanattanasio" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/kevinkowa"><img src="https://avatars.githubusercontent.com/u/15097482?v=4" width="100px;" alt=""/><br /><sub><b>Kevin Kowalski</b></sub></a><br /><a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=kevinkowa" title="Code">💻</a> <a href="#design-kevinkowa" title="Design">🎨</a> <a href="https://github.com/watson-developer-cloud/java-sdk/issues?q=author%3Akevinkowa+" title="Bug reports">🐛</a> <a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=kevinkowa" title="Documentation">📖</a> <a href="https://github.com/watson-developer-cloud/java-sdk/commits?author=kevinkowa" title="Tests">⚠️</a> <a href="https://github.com/watson-developer-cloud/java-sdk/issues?q=mentions%3Akevinkowa+is%3Aclosed+" title="questions">💬️</a></td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("ASSISTANT_APIKEY");
workspaceId = System.getenv("ASSISTANT_WORKSPACE_ID");
String serviceUrl = System.getenv("ASSISTANT_URL");

Assume.assumeFalse("ASSISTANT_APIKEY is not defined", apiKey == null);
if (apiKey == null) {
apiKey = getProperty("assistant.apikey");
workspaceId = getProperty("assistant.workspace_id");
serviceUrl = getProperty("assistant.url");
}

Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Assistant("2019-02-28", authenticator);
service.setServiceUrl(System.getenv("ASSISTANT_URL"));
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("ASSISTANT_APIKEY");
assistantId = System.getenv("ASSISTANT_ASSISTANT_ID");
String serviceUrl = System.getenv("ASSISTANT_URL");

Assume.assumeFalse("ASSISTANT_APIKEY is not defined", apiKey == null);
if (apiKey == null) {
apiKey = getProperty("assistant.apikey");
assistantId = getProperty("assistant.assistant_id");
serviceUrl = getProperty("assistant.url");
}

Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Assistant("2019-02-28", authenticator);
service.setServiceUrl(System.getenv("ASSISTANT_URL"));
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ public static void setupClass() throws Exception {
dummyTest = new DiscoveryServiceIT();
String apiKey = System.getenv("DISCOVERY_APIKEY");

assertNotNull("DISCOVERY_APIKEY is not defined", apiKey);
if (apiKey == null) {
apiKey = dummyTest.getProperty("discovery.apikey");
}

assertNotNull("DISCOVERY_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

dummyTest.setup();

Expand Down Expand Up @@ -143,10 +147,16 @@ public static void cleanupClass() throws Exception {
public void setup() throws Exception {
super.setUp();
String apiKey = System.getenv("DISCOVERY_APIKEY");
String url = System.getenv("DISCOVERY_URL");
String serviceUrl = System.getenv("DISCOVERY_URL");

if (apiKey == null) {
apiKey = getProperty("discovery.apikey");
serviceUrl = getProperty("discovery.url");
}

Authenticator authenticator = new IamAuthenticator(apiKey);
discovery = new Discovery("2019-04-30", authenticator);
discovery.setServiceUrl(url);
discovery.setServiceUrl(serviceUrl);
discovery.setDefaultHeaders(getDefaultHeaders());

uniqueName = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ public void setUp() throws Exception {
super.setUp();

String apiKey = System.getenv("DISCOVERY_V2_APIKEY");
assertNotNull("DISCOVERY_V2_APIKEY is not defined", apiKey);
String serviceUrl = System.getenv("DISCOVERY_V2_URL");

if (apiKey == null) {
apiKey = getProperty("discovery_v2.apikey");
serviceUrl = getProperty("discovery_v2.url");
}

assertNotNull("DISCOVERY_V2_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new Discovery(VERSION, authenticator);
service.setDefaultHeaders(getDefaultHeaders());
service.setServiceUrl(System.getenv("DISCOVERY_V2_URL"));
service.setServiceUrl(serviceUrl);

HttpConfigOptions configOptions =
new HttpConfigOptions.Builder().disableSslVerification(true).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ public class LanguageTranslatorIT extends WatsonServiceTest {
public void setUp() throws Exception {
super.setUp();
String iamApiKey = System.getenv("LANGUAGE_TRANSLATOR_APIKEY");
String serviceUrl = System.getenv("LANGUAGE_TRANSLATOR_URL");

assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined", iamApiKey);
if (iamApiKey == null) {
iamApiKey = getProperty("language_translator.apikey");
serviceUrl = getProperty("language_translator.url");
}

assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined and config.properties doesn't have valid credentials.", iamApiKey);

Authenticator authenticator = new IamAuthenticator(iamApiKey);
service = new LanguageTranslator("2018-05-01", authenticator);
service.setServiceUrl(System.getenv("LANGUAGE_TRANSLATOR_URL"));
service.setServiceUrl(serviceUrl);

// issue currently where document translation fails with learning opt-out
Map<String, String> headers = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ public class NaturalLanguageClassifierIT extends WatsonServiceTest {
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_APIKEY");
String serviceUrl = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_URL");
preCreatedClassifierId = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_ID");

if (apiKey == null) {
apiKey = getProperty("natural_language_classifier.apikey");
serviceUrl = getProperty("natural_language_classifier.url");
preCreatedClassifierId = getProperty("natural_language_classifier.classifier_id");
}

assertNotNull("NATURAL_LANGUAGE_CLASSIFIER_APIKEY is not defined", apiKey);
assertNotNull("NATURAL_LANGUAGE_CLASSIFIER_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new NaturalLanguageClassifier(authenticator);
service.setDefaultHeaders(getDefaultHeaders());
service.setServiceUrl(System.getenv("NATURAL_LANGUAGE_CLASSIFIER_URL"));
service.setServiceUrl(serviceUrl);


preCreatedClassifierId = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_ID");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ public class NaturalLanguageUnderstandingIT extends WatsonServiceTest {
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY");
String serviceUrl = System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_URL");

assertNotNull("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY is not defined", apiKey);
if (apiKey == null) {
apiKey = getProperty("natural_language_understanding.apikey");
serviceUrl = getProperty("natural_language_understanding.url");
}

assertNotNull("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new NaturalLanguageUnderstanding("2019-07-12", authenticator);
service.setDefaultHeaders(getDefaultHeaders());
service.setServiceUrl(System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_URL"));
service.setServiceUrl(serviceUrl);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,20 @@ public void setUp() throws Exception {
this.acousticCustomizationId = System.getenv("SPEECH_TO_TEXT_ACOUSTIC_CUSTOM_ID");

String apiKey = System.getenv("SPEECH_TO_TEXT_APIKEY");
String serviceUrl = System.getenv("SPEECH_TO_TEXT_URL");

assertNotNull("SPEECH_TO_TEXT_APIKEY is not defined", apiKey);
if (apiKey == null) {
apiKey = getProperty("speech_to_text.apikey");
this.customizationId = getProperty("speech_to_text.customization_id");
this.acousticCustomizationId = getProperty("speech_to_text.acoustic_customization_id");
serviceUrl = getProperty("speech_to_text.url");
}

assertNotNull("SPEECH_TO_TEXT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new SpeechToText(authenticator);
service.setServiceUrl(System.getenv("SPEECH_TO_TEXT_URL"));
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ public class CustomizationsIT extends WatsonServiceTest {
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("TEXT_TO_SPEECH_APIKEY");
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined", apiKey);
String serviceUrl = System.getenv("TEXT_TO_SPEECH_URL");

if (apiKey == null) {
apiKey = getProperty("text_to_speech.apikey");
serviceUrl = getProperty("text_to_speech.url");
}

assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new TextToSpeech(authenticator);
service.setServiceUrl(System.getenv("TEXT_TO_SPEECH_URL"));
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ public class TextToSpeechIT extends WatsonServiceTest {
public void setUp() throws Exception {
super.setUp();
String apiKey = System.getenv("TEXT_TO_SPEECH_APIKEY");
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined", apiKey);
String serviceUrl = System.getenv("TEXT_TO_SPEECH_URL");

if (apiKey == null) {
apiKey = getProperty("text_to_speech.apikey");
serviceUrl = getProperty("text_to_speech.url");
}

assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);

Authenticator authenticator = new IamAuthenticator(apiKey);
service = new TextToSpeech(authenticator);
service.setServiceUrl(System.getenv("TEXT_TO_SPEECH_URL"));
service.setServiceUrl(serviceUrl);
service.setDefaultHeaders(getDefaultHeaders());
voiceName = "en-US_MichaelVoice";

Expand Down

0 comments on commit 96e94d2

Please sign in to comment.