Skip to content

Commit 65dec98

Browse files
committed
test(conversation): Update tests for new functionality
1 parent 6b41053 commit 65dec98

File tree

2 files changed

+119
-46
lines changed

2 files changed

+119
-46
lines changed

conversation/src/test/java/com/ibm/watson/developer_cloud/conversation/v1/ConversationTest.java

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,7 @@
1212
*/
1313
package 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;
2916
import com.ibm.watson.developer_cloud.conversation.v1.model.Context;
3017
import com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample;
3118
import com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNode;
@@ -51,13 +38,20 @@
5138
import com.ibm.watson.developer_cloud.conversation.v1.model.UpdateValueOptions;
5239
import com.ibm.watson.developer_cloud.conversation.v1.model.UpdateWorkspaceOptions;
5340
import com.ibm.watson.developer_cloud.http.HttpHeaders;
54-
import com.ibm.watson.developer_cloud.WatsonServiceUnitTest;
55-
41+
import okhttp3.mockwebserver.RecordedRequest;
5642
import org.apache.commons.lang3.StringUtils;
5743
import org.junit.Before;
5844
import 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

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,112 @@
11
{
22
"intents": [
33
{
4-
"intent": "get_quote",
5-
"confidence": 0.943643
4+
"intent": "turn_on",
5+
"confidence": 0.9842960834503174
66
}
77
],
88
"entities": [
99
{
10-
"entity": "house",
11-
"value": "home",
10+
"entity": "genre",
1211
"location": [
13-
36,
14-
40
15-
]
12+
26,
13+
30
14+
],
15+
"value": "jazz",
16+
"confidence": 1
17+
},
18+
{
19+
"entity": "genre_bad",
20+
"location": [
21+
31,
22+
36
23+
],
24+
"value": "Soundtrack",
25+
"confidence": 0.7
26+
},
27+
{
28+
"entity": "appliance",
29+
"location": [
30+
31,
31+
36
32+
],
33+
"value": "music",
34+
"confidence": 1
1635
}
1736
],
1837
"input": {
19-
"text": "I'd like to get insurance to for my home"
20-
},
21-
"context": {
38+
"text": "I would love to hear some jazz music."
2239
},
2340
"output": {
2441
"text": [
25-
"Do you want to get a quote?"
26-
]
42+
"Great choice! Playing some jazz for you."
43+
],
44+
"nodes_visited": [
45+
"Entry Point For On Off Commands",
46+
"node_5_1469049934217",
47+
"Genre On Off Check",
48+
"node_3_1484628332751"
49+
],
50+
"action": {
51+
"music_on": "jazz"
52+
},
53+
"nodes_visited_details": [
54+
{
55+
"dialog_node": "Entry Point For On Off Commands",
56+
"title": "Entry Point For On Off Commands",
57+
"conditions": "#turn_on"
58+
},
59+
{
60+
"dialog_node": "node_5_1469049934217",
61+
"title": null,
62+
"conditions": "@genre"
63+
},
64+
{
65+
"dialog_node": "Genre On Off Check",
66+
"title": "Genre On Off Check",
67+
"conditions": "true"
68+
},
69+
{
70+
"dialog_node": "node_3_1484628332751",
71+
"title": null,
72+
"conditions": "$appl_action == \"on\""
73+
}
74+
],
75+
"log_messages": []
76+
},
77+
"context": {
78+
"conversation_id": "ed55c019-83b0-4d24-9d7c-99ee85e4e7a7",
79+
"system": {
80+
"dialog_stack": [
81+
{
82+
"dialog_node": "root"
83+
}
84+
],
85+
"dialog_turn_counter": 2,
86+
"dialog_request_counter": 2,
87+
"_node_output_map": {
88+
"Start And Initialize Context": [
89+
0,
90+
0
91+
],
92+
"node_3_1484628332751": [
93+
0,
94+
0
95+
]
96+
},
97+
"branch_exited": true,
98+
"branch_exited_reason": "completed"
99+
},
100+
"AConoff": "off",
101+
"lightonoff": "off",
102+
"musiconoff": "on",
103+
"appl_action": "on",
104+
"heateronoff": "off",
105+
"volumeonoff": "off",
106+
"wipersonoff": "off",
107+
"default_counter": 0,
108+
"previous_cuisine": "",
109+
"previous_restaurant_date": "",
110+
"previous_restaurant_time": ""
27111
}
28112
}

0 commit comments

Comments
 (0)