Skip to content

Commit 95abd24

Browse files
committed
test(assistant): Update tests for new functionality
1 parent 1a503be commit 95abd24

File tree

2 files changed

+108
-32
lines changed

2 files changed

+108
-32
lines changed

assistant/src/test/java/com/ibm/watson/developer_cloud/assistant/v1/AssistantTest.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.assistant.v1;
1414

15-
import com.google.gson.JsonObject;
16-
import com.google.gson.JsonParser;
1715
import com.ibm.watson.developer_cloud.WatsonServiceUnitTest;
1816
import com.ibm.watson.developer_cloud.assistant.v1.model.Context;
1917
import com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample;
@@ -54,7 +52,6 @@
5452
import static org.junit.Assert.assertArrayEquals;
5553
import static org.junit.Assert.assertEquals;
5654
import static org.junit.Assert.assertNotNull;
57-
import static org.junit.Assert.assertTrue;
5855

5956
/**
6057
* Unit tests for the {@link Assistant}.
@@ -131,18 +128,18 @@ public void testAssistantWithEmptyWorkspaceId() {
131128
*/
132129
@Test
133130
public void testSendMessage() throws IOException, InterruptedException {
134-
String text = "I'd like to get insurance to for my home";
131+
String text = "I would love to hear some jazz music.";
135132

136133
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
137134
server.enqueue(jsonResponse(mockResponse));
138135

139136
InputData input = new InputData.Builder(text).build();
140137
RuntimeIntent intent = new RuntimeIntent();
141-
intent.setIntent("turn_off");
138+
intent.setIntent("turn_on");
142139
intent.setConfidence(0.0);
143140
RuntimeEntity entity = new RuntimeEntity();
144-
entity.setEntity("car");
145-
entity.setValue("ford");
141+
entity.setEntity("genre");
142+
entity.setValue("jazz");
146143
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID)
147144
.input(input)
148145
.addIntent(intent)
@@ -158,18 +155,16 @@ public void testSendMessage() throws IOException, InterruptedException {
158155

159156
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
160157
assertEquals(path, request.getPath());
161-
assertArrayEquals(new String[] { "Do you want to get a quote?" },
158+
assertArrayEquals(new String[] { "Great choice! Playing some jazz for you" },
162159
serviceResponse.getOutput().getText().toArray(new String[0]));
163160
assertEquals(request.getMethod(), "POST");
164161
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
165-
String expected = "{" + "\"input\":{\"text\":\"I'd like to get insurance to for my home\"},"
166-
+ "\"intents\":[{\"confidence\":0.0,\"intent\":\"turn_off\"}],"
167-
+ "\"entities\":[{\"value\":\"ford\",\"entity\":\"car\"}],"
168-
+ "\"alternate_intents\":true" + "}";
169-
JsonParser parser = new JsonParser();
170-
JsonObject expectedObj = parser.parse(expected).getAsJsonObject();
171-
JsonObject actualObj = parser.parse(request.getBody().readUtf8()).getAsJsonObject();
172-
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());
173168
assertEquals(serviceResponse, mockResponse);
174169
}
175170

@@ -202,13 +197,10 @@ public void testSendMessageWithAlternateIntents() throws IOException, Interrupte
202197

203198
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
204199
assertEquals(path, request.getPath());
205-
assertArrayEquals(new String[] { "Do you want to get a quote?" },
200+
assertArrayEquals(new String[] { "Great choice! Playing some jazz for you" },
206201
serviceResponse.getOutput().getText().toArray(new String[0]));
207202
assertEquals(request.getMethod(), "POST");
208203
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
209-
assertEquals(
210-
"{\"input\":{\"text\":\"My text\"},\"alternate_intents\":false," + "\"context\":{\"name\":\"Myname\"}}",
211-
request.getBody().readUtf8());
212204
assertEquals(serviceResponse, mockResponse);
213205
}
214206

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)