1313package com .ibm .watson .text_to_speech .v1 ;
1414
1515import com .google .common .collect .ImmutableList ;
16+ import com .ibm .cloud .sdk .core .security .Authenticator ;
17+ import com .ibm .cloud .sdk .core .security .IamAuthenticator ;
1618import com .ibm .cloud .sdk .core .service .exception .UnauthorizedException ;
17- import com .ibm .cloud .sdk .core .service .security .IamOptions ;
1819import com .ibm .watson .common .TestUtils ;
1920import com .ibm .watson .common .WatsonServiceTest ;
2021import 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 ())
0 commit comments