Skip to content

Commit 873369f

Browse files
committed
test(Text to Speech): Update tests
1 parent 7b7b138 commit 873369f

File tree

4 files changed

+67
-78
lines changed

4 files changed

+67
-78
lines changed

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

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
package com.ibm.watson.text_to_speech.v1;
1414

1515
import com.google.common.collect.ImmutableList;
16+
import com.ibm.cloud.sdk.core.security.Authenticator;
17+
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
1618
import com.ibm.cloud.sdk.core.service.exception.UnauthorizedException;
17-
import com.ibm.cloud.sdk.core.service.security.IamOptions;
1819
import com.ibm.watson.common.TestUtils;
1920
import com.ibm.watson.common.WatsonServiceTest;
2021
import com.ibm.watson.text_to_speech.v1.model.AddWordOptions;
@@ -76,34 +77,35 @@ public void setUp() throws Exception {
7677
String apiKey = getProperty("text_to_speech.apikey");
7778
Assume.assumeFalse("config.properties doesn't have valid credentials.", apiKey == null);
7879

79-
service = new TextToSpeech();
80-
IamOptions iamOptions = new IamOptions.Builder()
81-
.apiKey(apiKey)
82-
.build();
83-
service.setIamCredentials(iamOptions);
80+
Authenticator authenticator = new IamAuthenticator(apiKey);
81+
service = new TextToSpeech(authenticator);
8482
service.setEndPoint(getProperty("text_to_speech.url"));
8583
service.setDefaultHeaders(getDefaultHeaders());
8684
}
8785

8886
private List<Word> instantiateWords() {
89-
Word word1 = new Word();
90-
word1.setWord("hodor");
91-
word1.setTranslation("hold the door");
92-
Word word2 = new Word();
93-
word2.setWord("shocking");
94-
word2.setTranslation("<phoneme alphabet='ibm' ph='.1Sa.0kIG'></phoneme>");
87+
Word word1 = new Word.Builder()
88+
.word("hodor")
89+
.translation("hold the door")
90+
.build();
91+
Word word2 = new Word.Builder()
92+
.word("shocking")
93+
.translation("<phoneme alphabet='ibm' ph='.1Sa.0kIG'></phoneme>")
94+
.build();
9595
return ImmutableList.of(word1, word2);
9696
}
9797

9898
private List<Word> instantiateWordsJapanese() {
99-
Word word1 = new Word();
100-
word1.setWord("hodor");
101-
word1.setTranslation("hold the door");
102-
word1.setPartOfSpeech(Word.PartOfSpeech.JOSI);
103-
Word word2 = new Word();
104-
word2.setWord("clodor");
105-
word2.setTranslation("close the door");
106-
word2.setPartOfSpeech(Word.PartOfSpeech.HOKA);
99+
Word word1 = new Word.Builder()
100+
.word("hodor")
101+
.translation("hold the door")
102+
.partOfSpeech(Word.PartOfSpeech.JOSI)
103+
.build();
104+
Word word2 = new Word.Builder()
105+
.word("clodor")
106+
.translation("close the door")
107+
.partOfSpeech(Word.PartOfSpeech.HOKA)
108+
.build();
107109
return ImmutableList.of(word1, word2);
108110
}
109111

@@ -359,8 +361,8 @@ public void testAddWord() {
359361
final Word expected = instantiateWords().get(0);
360362

361363
AddWordOptions addOptions = new AddWordOptions.Builder()
362-
.word(expected.getWord())
363-
.translation(expected.getTranslation())
364+
.word(expected.word())
365+
.translation(expected.translation())
364366
.customizationId(model.getCustomizationId())
365367
.build();
366368
service.addWord(addOptions).execute().getResult();
@@ -369,12 +371,12 @@ public void testAddWord() {
369371
.customizationId(model.getCustomizationId())
370372
.build();
371373
final Words results = service.listWords(listOptions).execute().getResult();
372-
assertEquals(1, results.getWords().size());
374+
assertEquals(1, results.words().size());
373375

374-
final Word result = results.getWords().get(0);
376+
final Word result = results.words().get(0);
375377
assertEquals(expected, result);
376-
assertEquals(expected.getWord(), result.getWord());
377-
assertEquals(expected.getTranslation(), result.getTranslation());
378+
assertEquals(expected.word(), result.word());
379+
assertEquals(expected.translation(), result.translation());
378380
}
379381

380382
/**
@@ -396,7 +398,7 @@ public void testAddWords() {
396398
.customizationId(model.getCustomizationId())
397399
.build();
398400
final Words words = service.listWords(listOptions).execute().getResult();
399-
assertEquals(expected.size(), words.getWords().size());
401+
assertEquals(expected.size(), words.words().size());
400402
}
401403

402404
/**
@@ -418,7 +420,7 @@ public void testAddWordsJapanese() {
418420
.customizationId(model.getCustomizationId())
419421
.build();
420422
final Words words = service.listWords(listOptions).execute().getResult();
421-
assertEquals(expected.size(), words.getWords().size());
423+
assertEquals(expected.size(), words.words().size());
422424
}
423425

424426
/**
@@ -438,10 +440,10 @@ public void testGetWord() {
438440

439441
GetWordOptions getOptions = new GetWordOptions.Builder()
440442
.customizationId(model.getCustomizationId())
441-
.word(expected.get(0).getWord())
443+
.word(expected.get(0).word())
442444
.build();
443445
final Translation translation = service.getWord(getOptions).execute().getResult();
444-
assertEquals(expected.get(0).getTranslation(), translation.getTranslation());
446+
assertEquals(expected.get(0).translation(), translation.translation());
445447
}
446448

447449
/**
@@ -461,11 +463,11 @@ public void testGetWordJapanese() {
461463

462464
GetWordOptions getOptions = new GetWordOptions.Builder()
463465
.customizationId(model.getCustomizationId())
464-
.word(expected.get(0).getWord())
466+
.word(expected.get(0).word())
465467
.build();
466468
final Translation translation = service.getWord(getOptions).execute().getResult();
467-
assertEquals(expected.get(0).getTranslation(), translation.getTranslation());
468-
assertEquals(expected.get(0).getPartOfSpeech(), translation.getPartOfSpeech());
469+
assertEquals(expected.get(0).translation(), translation.translation());
470+
assertEquals(expected.get(0).partOfSpeech(), translation.partOfSpeech());
469471
}
470472

471473
/**
@@ -478,22 +480,22 @@ public void testDeleteWord() {
478480
final Word expected = instantiateWords().get(0);
479481

480482
AddWordOptions addOptions = new AddWordOptions.Builder()
481-
.word(expected.getWord())
482-
.translation(expected.getTranslation())
483+
.word(expected.word())
484+
.translation(expected.translation())
483485
.customizationId(model.getCustomizationId())
484486
.build();
485487
service.addWord(addOptions).execute().getResult();
486488
DeleteWordOptions deleteOptions = new DeleteWordOptions.Builder()
487489
.customizationId(model.getCustomizationId())
488-
.word(expected.getWord())
490+
.word(expected.word())
489491
.build();
490492
service.deleteWord(deleteOptions).execute();
491493

492494
ListWordsOptions listOptions = new ListWordsOptions.Builder()
493495
.customizationId(model.getCustomizationId())
494496
.build();
495497
final Words results = service.listWords(listOptions).execute().getResult();
496-
assertEquals(0, results.getWords().size());
498+
assertEquals(0, results.words().size());
497499
}
498500

499501
/**
@@ -508,19 +510,19 @@ public void testSynthesize() throws IOException {
508510
final Word expected = instantiateWords().get(0);
509511

510512
AddWordOptions addOptions = new AddWordOptions.Builder()
511-
.word(expected.getWord())
512-
.translation(expected.getTranslation())
513+
.word(expected.word())
514+
.translation(expected.translation())
513515
.customizationId(model.getCustomizationId())
514516
.build();
515517
service.addWord(addOptions).execute().getResult();
516518
SynthesizeOptions synthesizeOptions1 = new SynthesizeOptions.Builder()
517-
.text(expected.getWord())
519+
.text(expected.word())
518520
.voice(SynthesizeOptions.Voice.EN_US_MICHAELVOICE)
519521
.accept(SynthesizeOptions.Accept.AUDIO_WAV)
520522
.build();
521523
final InputStream stream1 = service.synthesize(synthesizeOptions1).execute().getResult();
522524
SynthesizeOptions synthesizeOptions2 = new SynthesizeOptions.Builder()
523-
.text(expected.getWord())
525+
.text(expected.word())
524526
.voice(SynthesizeOptions.Voice.EN_US_MICHAELVOICE)
525527
.accept(SynthesizeOptions.Accept.AUDIO_WAV)
526528
.customizationId(model.getCustomizationId())

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import com.google.common.collect.ImmutableList;
1616
import com.google.common.collect.ImmutableMap;
17-
import com.ibm.cloud.sdk.core.security.basicauth.BasicAuthConfig;
17+
import com.ibm.cloud.sdk.core.security.NoAuthAuthenticator;
1818
import com.ibm.watson.common.WatsonServiceUnitTest;
1919
import com.ibm.watson.text_to_speech.v1.model.AddWordOptions;
2020
import com.ibm.watson.text_to_speech.v1.model.AddWordsOptions;
@@ -82,11 +82,7 @@ public class CustomizationsTest extends WatsonServiceUnitTest {
8282
public void setUp() throws Exception {
8383
super.setUp();
8484

85-
BasicAuthConfig authConfig = new BasicAuthConfig.Builder()
86-
.username("")
87-
.password("")
88-
.build();
89-
service = new TextToSpeech(authConfig);
85+
service = new TextToSpeech(new NoAuthAuthenticator());
9086
service.setEndPoint(getMockWebServerUrl());
9187

9288
voiceModel = loadFixture("src/test/resources/text_to_speech/voice_model.json", VoiceModel.class);
@@ -95,18 +91,15 @@ public void setUp() throws Exception {
9591
voice = loadFixture("src/test/resources/text_to_speech/voice.json", Voice.class);
9692
}
9793

98-
private static List<Word> instantiateWords() {
99-
Word word = new Word();
100-
word.setWord("hodor");
101-
word.setTranslation("hold the door");
102-
return ImmutableList.of(word);
94+
private static Word instantiateWord() {
95+
return new Word.Builder()
96+
.word("hodor")
97+
.translation("hold the door")
98+
.build();
10399
}
104100

105-
private static Word instantiateWord() {
106-
Word word = new Word();
107-
word.setWord("hodor");
108-
word.setTranslation("hold the door");
109-
return word;
101+
private static List<Word> instantiateWords() {
102+
return ImmutableList.of(instantiateWord());
110103
}
111104

112105
/**
@@ -366,7 +359,7 @@ public void testListWords() throws InterruptedException {
366359

367360
assertEquals(String.format(WORDS_PATH, CUSTOMIZATION_ID), request.getPath());
368361
assertEquals("GET", request.getMethod());
369-
assertEquals(expected, result.getWords());
362+
assertEquals(expected, result.words());
370363
}
371364

372365
/**
@@ -378,17 +371,17 @@ public void testListWords() throws InterruptedException {
378371
public void testGetWord() throws InterruptedException {
379372
final Word expected = instantiateWords().get(0);
380373

381-
server.enqueue(jsonResponse(ImmutableMap.of(TRANSLATION, expected.getTranslation())));
374+
server.enqueue(jsonResponse(ImmutableMap.of(TRANSLATION, expected.translation())));
382375
GetWordOptions getOptions = new GetWordOptions.Builder()
383376
.customizationId(CUSTOMIZATION_ID)
384-
.word(expected.getWord())
377+
.word(expected.word())
385378
.build();
386379
final Translation result = service.getWord(getOptions).execute().getResult();
387380
final RecordedRequest request = server.takeRequest();
388381

389-
assertEquals(String.format(WORDS_PATH, CUSTOMIZATION_ID) + "/" + expected.getWord(), request.getPath());
382+
assertEquals(String.format(WORDS_PATH, CUSTOMIZATION_ID) + "/" + expected.word(), request.getPath());
390383
assertEquals("GET", request.getMethod());
391-
assertEquals(expected.getTranslation(), result.getTranslation());
384+
assertEquals(expected.translation(), result.translation());
392385
}
393386

394387
/**
@@ -424,13 +417,13 @@ public void testAddWord() throws InterruptedException {
424417
server.enqueue(new MockResponse().setResponseCode(201));
425418
AddWordOptions addOptions = new AddWordOptions.Builder()
426419
.customizationId(CUSTOMIZATION_ID)
427-
.word(expected.getWord())
428-
.translation(expected.getTranslation())
420+
.word(expected.word())
421+
.translation(expected.translation())
429422
.build();
430423
service.addWord(addOptions).execute().getResult();
431424
RecordedRequest request = server.takeRequest();
432425

433-
assertEquals(String.format(WORD_PATH, CUSTOMIZATION_ID, expected.getWord()), request.getPath());
426+
assertEquals(String.format(WORD_PATH, CUSTOMIZATION_ID, expected.word()), request.getPath());
434427
assertEquals("PUT", request.getMethod());
435428
}
436429

@@ -441,7 +434,7 @@ public void testAddWord() throws InterruptedException {
441434
*/
442435
@Test
443436
public void testDeleteWord() throws InterruptedException {
444-
final String expected = instantiateWords().get(0).getWord();
437+
final String expected = instantiateWords().get(0).word();
445438

446439
server.enqueue(new MockResponse().setResponseCode(204));
447440
DeleteWordOptions deleteOptions = new DeleteWordOptions.Builder()

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
package com.ibm.watson.text_to_speech.v1;
1414

1515

16-
import com.ibm.cloud.sdk.core.service.security.IamOptions;
16+
import com.ibm.cloud.sdk.core.security.Authenticator;
17+
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
1718
import com.ibm.watson.common.RetryRunner;
1819
import com.ibm.watson.common.WatsonServiceTest;
1920
import com.ibm.watson.text_to_speech.v1.model.DeleteUserDataOptions;
@@ -78,11 +79,8 @@ public void setUp() throws Exception {
7879
String apiKey = getProperty("text_to_speech.apikey");
7980
Assume.assumeFalse("config.properties doesn't have valid credentials.", apiKey == null);
8081

81-
service = new TextToSpeech();
82-
IamOptions iamOptions = new IamOptions.Builder()
83-
.apiKey(apiKey)
84-
.build();
85-
service.setIamCredentials(iamOptions);
82+
Authenticator authenticator = new IamAuthenticator(apiKey);
83+
service = new TextToSpeech(authenticator);
8684
service.setEndPoint(getProperty("text_to_speech.url"));
8785
service.setDefaultHeaders(getDefaultHeaders());
8886
voiceName = getProperty("text_to_speech.voice_name");

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import com.google.common.io.Files;
1616
import com.google.gson.Gson;
1717
import com.ibm.cloud.sdk.core.http.HttpMediaType;
18-
import com.ibm.cloud.sdk.core.security.basicauth.BasicAuthConfig;
18+
import com.ibm.cloud.sdk.core.security.NoAuthAuthenticator;
1919
import com.ibm.cloud.sdk.core.util.GsonSingleton;
2020
import com.ibm.watson.common.TestUtils;
2121
import com.ibm.watson.common.WatsonServiceUnitTest;
@@ -105,11 +105,7 @@ private static void writeInputStreamToOutputStream(InputStream inputStream, Outp
105105
public void setUp() throws Exception {
106106
super.setUp();
107107

108-
BasicAuthConfig authConfig = new BasicAuthConfig.Builder()
109-
.username("")
110-
.password("")
111-
.build();
112-
service = new TextToSpeech(authConfig);
108+
service = new TextToSpeech(new NoAuthAuthenticator());
113109
service.setEndPoint(getMockWebServerUrl());
114110

115111
getVoiceResponse = loadFixture("src/test/resources/text_to_speech/get_voice_response.json", Voice.class);

0 commit comments

Comments
 (0)