11package io .notifye .botengine .client .test ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .junit .Assert .assertNotNull ;
5+
36import java .util .Arrays ;
7+ import java .util .List ;
8+
9+ import org .junit .After ;
10+ import org .junit .Before ;
11+ import org .junit .Test ;
412
513import io .notifye .botengine .client .BotEngine ;
614import io .notifye .botengine .client .BotEngine .TokenType ;
715import io .notifye .botengine .client .Token ;
816import io .notifye .botengine .client .action .QueryAction ;
917import io .notifye .botengine .client .bots .Bot ;
18+ import io .notifye .botengine .client .bots .ClientBot ;
19+ import io .notifye .botengine .client .bots .DeveloperBot ;
1020import io .notifye .botengine .client .model .Entity ;
1121import io .notifye .botengine .client .model .Entry ;
1222import io .notifye .botengine .client .model .Interaction ;
@@ -24,10 +34,50 @@ public class BotTest {
2434 private static String clientAccessToken = "Bearer e5b129af8161ed369e27804f9a2735fa81a43d2e911e661195c6c7160b70b27b" ;
2535 private static String devAccessToken = "Bearer 9bc76810e6767d68970095e8db817a79134245b096eddcd645d34f19996751a1" ;
2636
27- public static void main (String [] args ) throws Exception {
37+ private List <String > okResponses = Arrays .asList ("Your reservation on $movies has been confirmed" );
38+
39+ private List <String > fallbackResponses = Arrays .asList (
40+ "Eu não entendi, você poderia repetir ?" ,
41+ "Por favor repita" ,
42+ "Desculpe-me, eu ainda estou aprendendo a entender seres humanos. Poderia, por gentileza, repetir o que disse ?" ,
43+ "Porra você já está me enchenco o saco" ,
44+ "Acho que sou burra demais para lhe entender." ,
45+ "Vamos lá, me ajude. Tente de outra forma" );
46+
47+ private Bot developerBot ;
48+ private Entry lordOfTheRingsEntry ;
49+ private Entry startWarsEntry ;
50+
51+ @ Before
52+ public void setup () throws Exception {
53+ // Create Entries
54+ lordOfTheRingsEntry = Entry .builder ()
55+ .value ("The Lord of the Rings" )
56+ .synonyms (Arrays .asList (
57+ Synonym .builder ()
58+ .value ("LOTR" )
59+ .build (),
60+ Synonym .builder ()
61+ .value ("The Fellowship of the Ring" )
62+ .build (),
63+ Synonym .builder ()
64+ .value ("The Lord of the Rings" )
65+ .build ()))
66+ .build ();
67+
68+ startWarsEntry = Entry .builder ()
69+ .value ("Stars Wars" )
70+ .synonyms (Arrays .asList (
71+ Synonym .builder ()
72+ .value ("SW" )
73+ .build (),
74+ Synonym .builder ()
75+ .value ("Stars Wars" )
76+ .build ()))
77+ .build ();
2878
29- // Configure Bot, Story and parametrized Interactions
30- Bot developerBot = BotEngine .ai (
79+ // Configure Bot
80+ developerBot = BotEngine .ai (
3181 Token .builder ()
3282 .token (devAccessToken )
3383 .tokenType (TokenType .DEV )
@@ -39,31 +89,19 @@ public static void main(String[] args) throws Exception {
3989 .build ())
4090 //.del()
4191 .bot ();
92+ }
93+
94+ @ After
95+ public void after () throws Exception {
96+ developerBot .stories ().del ();
97+ }
98+
99+ @ Test
100+ public void botTest () throws Exception {
42101
43- Entry lordOfTheRingsEntry = Entry .builder ()
44- .value ("The Lord of the Rings" )
45- .synonyms (Arrays .asList (
46- Synonym .builder ()
47- .value ("LOTR" )
48- .build (),
49- Synonym .builder ()
50- .value ("The Fellowship of the Ring" )
51- .build (),
52- Synonym .builder ()
53- .value ("The Lord of the Rings" )
54- .build ()))
55- .build ();
56-
57- Entry startWarsEntry = Entry .builder ()
58- .value ("Stars Wars" )
59- .synonyms (Arrays .asList (
60- Synonym .builder ()
61- .value ("SW" )
62- .build (),
63- Synonym .builder ()
64- .value ("Stars Wars" )
65- .build ()))
66- .build ();
102+ assertNotNull (developerBot );
103+ assertThat (developerBot )
104+ .describedAs ("Bot is DeveloperBot instance" ).isInstanceOf (DeveloperBot .class );
67105
68106 developerBot .interactions ()
69107 .add ()
@@ -98,11 +136,10 @@ public static void main(String[] args) throws Exception {
98136 .build ()))
99137 .responses (Arrays .asList (ResponseInteraction .builder ()
100138 .type (ResponseInteractionType .text )
101- .messages (Arrays . asList ( "Your reservation on $movies has been confirmed" ) )
139+ .messages (okResponses )
102140 .build ()))
103141 .build ())
104142
105-
106143 //.interaction(Interaction.builder().build())
107144 .fallback (Interaction .builder ()
108145 .name ("hello" )
@@ -112,13 +149,7 @@ public static void main(String[] args) throws Exception {
112149 .responses (Arrays .asList (
113150 ResponseInteraction .builder ()
114151 .type (ResponseInteractionType .text )
115- .messages (Arrays .asList (
116- "Eu não entendi, você poderia repetir ?" ,
117- "Por favor repita" ,
118- "Desculpe-me, eu ainda estou aprendendo a entender seres humanos. Poderia, por gentileza, repetir o que disse ?" ,
119- "Porra você já está me enchenco o saco" ,
120- "Acho que sou burra demais para lhe entender." ,
121- "Vamos lá, me ajude. Tente de outra forma" ))
152+ .messages (fallbackResponses )
122153 .build ()))
123154 .build ())
124155 .build ();
@@ -131,19 +162,23 @@ public static void main(String[] args) throws Exception {
131162 .build ()
132163 );
133164
165+ assertThat (clientBot )
166+ .describedAs ("Bot is ClientBot instance" ).isInstanceOf (ClientBot .class );
134167
135168 QueryAction conversation = clientBot .query (developerBot .getStory ());
136169
137170 QueryResponse queryResponse = conversation .q ("the would be great to see LOTR" );
171+ assertNotNull (queryResponse );
138172 log .info ("Query Result -> {}" , queryResponse );
139173
140174 QueryResponse fallbackResponse = conversation .q ("E ae 0/" );
175+ assertNotNull (fallbackResponse );
141176 log .info ("Fallback 1 Query Result -> {}" , fallbackResponse );
142177
143178 fallbackResponse = conversation .q ("Nao entendi !!" );
179+ assertNotNull (fallbackResponse );
144180 log .info ("Fallback 2 Query Result -> {}" , fallbackResponse );
145181
146-
147182 }
148183
149184}
0 commit comments