Skip to content

Commit 96e94d2

Browse files
authored
Merge pull request #1202 from watson-developer-cloud/fix-its
test(its): add a way to retrieve properties from config.properties
2 parents 0d25ec0 + 4519c0b commit 96e94d2

File tree

11 files changed

+96
-22
lines changed

11 files changed

+96
-22
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
497497
<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>
498498
<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>
499499
<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>
500+
<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>
500501
</tr>
501502
</table>
502503

assistant/src/test/java/com/ibm/watson/assistant/v1/AssistantServiceTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ public void setUp() throws Exception {
5858
super.setUp();
5959
String apiKey = System.getenv("ASSISTANT_APIKEY");
6060
workspaceId = System.getenv("ASSISTANT_WORKSPACE_ID");
61+
String serviceUrl = System.getenv("ASSISTANT_URL");
6162

62-
Assume.assumeFalse("ASSISTANT_APIKEY is not defined", apiKey == null);
63+
if (apiKey == null) {
64+
apiKey = getProperty("assistant.apikey");
65+
workspaceId = getProperty("assistant.workspace_id");
66+
serviceUrl = getProperty("assistant.url");
67+
}
68+
69+
Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
6370

6471
Authenticator authenticator = new IamAuthenticator(apiKey);
6572
service = new Assistant("2019-02-28", authenticator);
66-
service.setServiceUrl(System.getenv("ASSISTANT_URL"));
73+
service.setServiceUrl(serviceUrl);
6774
service.setDefaultHeaders(getDefaultHeaders());
6875
}
6976

assistant/src/test/java/com/ibm/watson/assistant/v2/AssistantServiceTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ public void setUp() throws Exception {
5858
super.setUp();
5959
String apiKey = System.getenv("ASSISTANT_APIKEY");
6060
assistantId = System.getenv("ASSISTANT_ASSISTANT_ID");
61+
String serviceUrl = System.getenv("ASSISTANT_URL");
6162

62-
Assume.assumeFalse("ASSISTANT_APIKEY is not defined", apiKey == null);
63+
if (apiKey == null) {
64+
apiKey = getProperty("assistant.apikey");
65+
assistantId = getProperty("assistant.assistant_id");
66+
serviceUrl = getProperty("assistant.url");
67+
}
68+
69+
Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
6370

6471
Authenticator authenticator = new IamAuthenticator(apiKey);
6572
service = new Assistant("2019-02-28", authenticator);
66-
service.setServiceUrl(System.getenv("ASSISTANT_URL"));
73+
service.setServiceUrl(serviceUrl);
6774
service.setDefaultHeaders(getDefaultHeaders());
6875
}
6976

discovery/src/test/java/com/ibm/watson/discovery/v1/DiscoveryServiceIT.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ public static void setupClass() throws Exception {
9494
dummyTest = new DiscoveryServiceIT();
9595
String apiKey = System.getenv("DISCOVERY_APIKEY");
9696

97-
assertNotNull("DISCOVERY_APIKEY is not defined", apiKey);
97+
if (apiKey == null) {
98+
apiKey = dummyTest.getProperty("discovery.apikey");
99+
}
100+
101+
assertNotNull("DISCOVERY_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
98102

99103
dummyTest.setup();
100104

@@ -143,10 +147,16 @@ public static void cleanupClass() throws Exception {
143147
public void setup() throws Exception {
144148
super.setUp();
145149
String apiKey = System.getenv("DISCOVERY_APIKEY");
146-
String url = System.getenv("DISCOVERY_URL");
150+
String serviceUrl = System.getenv("DISCOVERY_URL");
151+
152+
if (apiKey == null) {
153+
apiKey = getProperty("discovery.apikey");
154+
serviceUrl = getProperty("discovery.url");
155+
}
156+
147157
Authenticator authenticator = new IamAuthenticator(apiKey);
148158
discovery = new Discovery("2019-04-30", authenticator);
149-
discovery.setServiceUrl(url);
159+
discovery.setServiceUrl(serviceUrl);
150160
discovery.setDefaultHeaders(getDefaultHeaders());
151161

152162
uniqueName = UUID.randomUUID().toString();

discovery/src/test/java/com/ibm/watson/discovery/v2/DiscoveryIT.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ public void setUp() throws Exception {
6565
super.setUp();
6666

6767
String apiKey = System.getenv("DISCOVERY_V2_APIKEY");
68-
assertNotNull("DISCOVERY_V2_APIKEY is not defined", apiKey);
68+
String serviceUrl = System.getenv("DISCOVERY_V2_URL");
69+
70+
if (apiKey == null) {
71+
apiKey = getProperty("discovery_v2.apikey");
72+
serviceUrl = getProperty("discovery_v2.url");
73+
}
74+
75+
assertNotNull("DISCOVERY_V2_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
6976

7077
Authenticator authenticator = new IamAuthenticator(apiKey);
7178
service = new Discovery(VERSION, authenticator);
7279
service.setDefaultHeaders(getDefaultHeaders());
73-
service.setServiceUrl(System.getenv("DISCOVERY_V2_URL"));
80+
service.setServiceUrl(serviceUrl);
7481

7582
HttpConfigOptions configOptions =
7683
new HttpConfigOptions.Builder().disableSslVerification(true).build();

language-translator/src/test/java/com/ibm/watson/language_translator/v3/LanguageTranslatorIT.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ public class LanguageTranslatorIT extends WatsonServiceTest {
6969
public void setUp() throws Exception {
7070
super.setUp();
7171
String iamApiKey = System.getenv("LANGUAGE_TRANSLATOR_APIKEY");
72+
String serviceUrl = System.getenv("LANGUAGE_TRANSLATOR_URL");
7273

73-
assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined", iamApiKey);
74+
if (iamApiKey == null) {
75+
iamApiKey = getProperty("language_translator.apikey");
76+
serviceUrl = getProperty("language_translator.url");
77+
}
78+
79+
assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined and config.properties doesn't have valid credentials.", iamApiKey);
7480

7581
Authenticator authenticator = new IamAuthenticator(iamApiKey);
7682
service = new LanguageTranslator("2018-05-01", authenticator);
77-
service.setServiceUrl(System.getenv("LANGUAGE_TRANSLATOR_URL"));
83+
service.setServiceUrl(serviceUrl);
7884

7985
// issue currently where document translation fails with learning opt-out
8086
Map<String, String> headers = new HashMap<>();

natural-language-classifier/src/test/java/com/ibm/watson/natural_language_classifier/v1/NaturalLanguageClassifierIT.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,23 @@ public class NaturalLanguageClassifierIT extends WatsonServiceTest {
6565
public void setUp() throws Exception {
6666
super.setUp();
6767
String apiKey = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_APIKEY");
68+
String serviceUrl = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_URL");
69+
preCreatedClassifierId = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_ID");
70+
71+
if (apiKey == null) {
72+
apiKey = getProperty("natural_language_classifier.apikey");
73+
serviceUrl = getProperty("natural_language_classifier.url");
74+
preCreatedClassifierId = getProperty("natural_language_classifier.classifier_id");
75+
}
6876

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

7179
Authenticator authenticator = new IamAuthenticator(apiKey);
7280
service = new NaturalLanguageClassifier(authenticator);
7381
service.setDefaultHeaders(getDefaultHeaders());
74-
service.setServiceUrl(System.getenv("NATURAL_LANGUAGE_CLASSIFIER_URL"));
82+
service.setServiceUrl(serviceUrl);
83+
7584

76-
preCreatedClassifierId = System.getenv("NATURAL_LANGUAGE_CLASSIFIER_ID");
7785
}
7886

7987
/**

natural-language-understanding/src/test/java/com/ibm/watson/natural_language_understanding/v1/NaturalLanguageUnderstandingIT.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ public class NaturalLanguageUnderstandingIT extends WatsonServiceTest {
5858
public void setUp() throws Exception {
5959
super.setUp();
6060
String apiKey = System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY");
61+
String serviceUrl = System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_URL");
6162

62-
assertNotNull("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY is not defined", apiKey);
63+
if (apiKey == null) {
64+
apiKey = getProperty("natural_language_understanding.apikey");
65+
serviceUrl = getProperty("natural_language_understanding.url");
66+
}
67+
68+
assertNotNull("NATURAL_LANGUAGE_UNDERSTANDING_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
6369

6470
Authenticator authenticator = new IamAuthenticator(apiKey);
6571
service = new NaturalLanguageUnderstanding("2019-07-12", authenticator);
6672
service.setDefaultHeaders(getDefaultHeaders());
67-
service.setServiceUrl(System.getenv("NATURAL_LANGUAGE_UNDERSTANDING_URL"));
73+
service.setServiceUrl(serviceUrl);
6874
}
6975

7076
/**

speech-to-text/src/test/java/com/ibm/watson/speech_to_text/v1/SpeechToTextIT.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,20 @@ public void setUp() throws Exception {
133133
this.acousticCustomizationId = System.getenv("SPEECH_TO_TEXT_ACOUSTIC_CUSTOM_ID");
134134

135135
String apiKey = System.getenv("SPEECH_TO_TEXT_APIKEY");
136+
String serviceUrl = System.getenv("SPEECH_TO_TEXT_URL");
136137

137-
assertNotNull("SPEECH_TO_TEXT_APIKEY is not defined", apiKey);
138+
if (apiKey == null) {
139+
apiKey = getProperty("speech_to_text.apikey");
140+
this.customizationId = getProperty("speech_to_text.customization_id");
141+
this.acousticCustomizationId = getProperty("speech_to_text.acoustic_customization_id");
142+
serviceUrl = getProperty("speech_to_text.url");
143+
}
144+
145+
assertNotNull("SPEECH_TO_TEXT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
138146

139147
Authenticator authenticator = new IamAuthenticator(apiKey);
140148
service = new SpeechToText(authenticator);
141-
service.setServiceUrl(System.getenv("SPEECH_TO_TEXT_URL"));
149+
service.setServiceUrl(serviceUrl);
142150
service.setDefaultHeaders(getDefaultHeaders());
143151
}
144152

text-to-speech/src/test/java/com/ibm/watson/text_to_speech/v1/CustomizationsIT.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ public class CustomizationsIT extends WatsonServiceTest {
5656
public void setUp() throws Exception {
5757
super.setUp();
5858
String apiKey = System.getenv("TEXT_TO_SPEECH_APIKEY");
59-
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined", apiKey);
59+
String serviceUrl = System.getenv("TEXT_TO_SPEECH_URL");
60+
61+
if (apiKey == null) {
62+
apiKey = getProperty("text_to_speech.apikey");
63+
serviceUrl = getProperty("text_to_speech.url");
64+
}
65+
66+
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
6067

6168
Authenticator authenticator = new IamAuthenticator(apiKey);
6269
service = new TextToSpeech(authenticator);
63-
service.setServiceUrl(System.getenv("TEXT_TO_SPEECH_URL"));
70+
service.setServiceUrl(serviceUrl);
6471
service.setDefaultHeaders(getDefaultHeaders());
6572
}
6673

text-to-speech/src/test/java/com/ibm/watson/text_to_speech/v1/TextToSpeechIT.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,18 @@ public class TextToSpeechIT extends WatsonServiceTest {
9898
public void setUp() throws Exception {
9999
super.setUp();
100100
String apiKey = System.getenv("TEXT_TO_SPEECH_APIKEY");
101-
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined", apiKey);
101+
String serviceUrl = System.getenv("TEXT_TO_SPEECH_URL");
102+
103+
if (apiKey == null) {
104+
apiKey = getProperty("text_to_speech.apikey");
105+
serviceUrl = getProperty("text_to_speech.url");
106+
}
107+
108+
assertNotNull("TEXT_TO_SPEECH_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
102109

103110
Authenticator authenticator = new IamAuthenticator(apiKey);
104111
service = new TextToSpeech(authenticator);
105-
service.setServiceUrl(System.getenv("TEXT_TO_SPEECH_URL"));
112+
service.setServiceUrl(serviceUrl);
106113
service.setDefaultHeaders(getDefaultHeaders());
107114
voiceName = "en-US_MichaelVoice";
108115

0 commit comments

Comments
 (0)