1212 */
1313package com .ibm .watson .developer_cloud .conversation .v1 ;
1414
15- import static org .junit .Assert .assertArrayEquals ;
16- import static org .junit .Assert .assertEquals ;
17- import static org .junit .Assert .assertNotNull ;
18- import static org .junit .Assert .assertTrue ;
19-
20- import java .io .IOException ;
21- import java .util .ArrayList ;
22- import java .util .Arrays ;
23- import java .util .HashMap ;
24- import java .util .Map ;
25-
26- import com .google .gson .JsonObject ;
27- import com .google .gson .JsonParser ;
28-
15+ import com .ibm .watson .developer_cloud .WatsonServiceUnitTest ;
2916import com .ibm .watson .developer_cloud .conversation .v1 .model .Context ;
3017import com .ibm .watson .developer_cloud .conversation .v1 .model .CreateCounterexample ;
3118import com .ibm .watson .developer_cloud .conversation .v1 .model .CreateDialogNode ;
5138import com .ibm .watson .developer_cloud .conversation .v1 .model .UpdateValueOptions ;
5239import com .ibm .watson .developer_cloud .conversation .v1 .model .UpdateWorkspaceOptions ;
5340import com .ibm .watson .developer_cloud .http .HttpHeaders ;
54- import com .ibm .watson .developer_cloud .WatsonServiceUnitTest ;
55-
41+ import okhttp3 .mockwebserver .RecordedRequest ;
5642import org .apache .commons .lang3 .StringUtils ;
5743import org .junit .Before ;
5844import org .junit .Test ;
5945
60- import okhttp3 .mockwebserver .RecordedRequest ;
46+ import java .io .IOException ;
47+ import java .util .ArrayList ;
48+ import java .util .Arrays ;
49+ import java .util .HashMap ;
50+ import java .util .Map ;
51+
52+ import static org .junit .Assert .assertArrayEquals ;
53+ import static org .junit .Assert .assertEquals ;
54+ import static org .junit .Assert .assertNotNull ;
6155
6256/**
6357 * Unit tests for the {@link Conversation}.
@@ -134,18 +128,18 @@ public void testConversationWithEmptyWorkspaceId() {
134128 */
135129 @ Test
136130 public void testSendMessage () throws IOException , InterruptedException {
137- String text = "I'd like to get insurance to for my home " ;
131+ String text = "I would love to hear some jazz music. " ;
138132
139133 MessageResponse mockResponse = loadFixture (FIXTURE , MessageResponse .class );
140134 server .enqueue (jsonResponse (mockResponse ));
141135
142136 InputData input = new InputData .Builder (text ).build ();
143137 RuntimeIntent intent = new RuntimeIntent ();
144- intent .setIntent ("turn_off " );
138+ intent .setIntent ("turn_on " );
145139 intent .setConfidence (0.0 );
146140 RuntimeEntity entity = new RuntimeEntity ();
147- entity .setEntity ("car " );
148- entity .setValue ("ford " );
141+ entity .setEntity ("genre " );
142+ entity .setValue ("jazz " );
149143 MessageOptions options = new MessageOptions .Builder (WORKSPACE_ID )
150144 .input (input )
151145 .addIntent (intent )
@@ -161,18 +155,16 @@ public void testSendMessage() throws IOException, InterruptedException {
161155
162156 String path = StringUtils .join (PATH_MESSAGE , "?" , VERSION , "=2018-02-16" );
163157 assertEquals (path , request .getPath ());
164- assertArrayEquals (new String [] { "Do you want to get a quote? " },
158+ assertArrayEquals (new String [] { "Great choice! Playing some jazz for you. " },
165159 serviceResponse .getOutput ().getText ().toArray (new String [0 ]));
166160 assertEquals (request .getMethod (), "POST" );
167161 assertNotNull (request .getHeader (HttpHeaders .AUTHORIZATION ));
168- String expected = "{" + "\" input\" :{\" text\" :\" I'd like to get insurance to for my home\" },"
169- + "\" intents\" :[{\" confidence\" :0.0,\" intent\" :\" turn_off\" }],"
170- + "\" entities\" :[{\" value\" :\" ford\" ,\" entity\" :\" car\" }],"
171- + "\" alternate_intents\" :true" + "}" ;
172- JsonParser parser = new JsonParser ();
173- JsonObject expectedObj = parser .parse (expected ).getAsJsonObject ();
174- JsonObject actualObj = parser .parse (request .getBody ().readUtf8 ()).getAsJsonObject ();
175- assertTrue (expectedObj .equals (actualObj ));
162+ assertNotNull (serviceResponse .getOutput ().getLogMessages ());
163+ assertNotNull (serviceResponse .getOutput ().getNodesVisited ());
164+ assertNotNull (serviceResponse .getOutput ().getNodesVisitedDetails ());
165+ assertNotNull (serviceResponse .getOutput ().getNodesVisitedDetails ().get (0 ).getDialogNode ());
166+ assertNotNull (serviceResponse .getOutput ().getNodesVisitedDetails ().get (0 ).getTitle ());
167+ assertNotNull (serviceResponse .getOutput ().getNodesVisitedDetails ().get (0 ).getConditions ());
176168 assertEquals (serviceResponse , mockResponse );
177169 }
178170
@@ -205,13 +197,10 @@ public void testSendMessageWithAlternateIntents() throws IOException, Interrupte
205197
206198 String path = StringUtils .join (PATH_MESSAGE , "?" , VERSION , "=2018-02-16" );
207199 assertEquals (path , request .getPath ());
208- assertArrayEquals (new String [] { "Do you want to get a quote? " },
200+ assertArrayEquals (new String [] { "Great choice! Playing some jazz for you. " },
209201 serviceResponse .getOutput ().getText ().toArray (new String [0 ]));
210202 assertEquals (request .getMethod (), "POST" );
211203 assertNotNull (request .getHeader (HttpHeaders .AUTHORIZATION ));
212- assertEquals (
213- "{\" input\" :{\" text\" :\" My text\" },\" alternate_intents\" :false," + "\" context\" :{\" name\" :\" Myname\" }}" ,
214- request .getBody ().readUtf8 ());
215204 assertEquals (serviceResponse , mockResponse );
216205 }
217206
0 commit comments