Skip to content

Commit fd3b8f5

Browse files
committed
test(assistant-v2): update unit tests and apply format
1 parent c336bc0 commit fd3b8f5

18 files changed

+550
-263
lines changed

assistant/src/test/java/com/ibm/watson/assistant/v2/AssistantServiceTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public void setUp() throws Exception {
6666
serviceUrl = getProperty("assistant.url");
6767
}
6868

69-
Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
69+
Assume.assumeFalse(
70+
"ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.",
71+
apiKey == null);
7072

7173
Authenticator authenticator = new IamAuthenticator(apiKey);
7274
service = new Assistant("2019-02-28", authenticator);

assistant/src/test/java/com/ibm/watson/assistant/v2/AssistantTest.java

+190-165
Large diffs are not rendered by default.

assistant/src/test/java/com/ibm/watson/assistant/v2/model/DialogNodesVisitedTest.java renamed to assistant/src/test/java/com/ibm/watson/assistant/v2/model/DialogNodeVisitedTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -22,17 +22,17 @@
2222
import java.util.List;
2323
import org.testng.annotations.Test;
2424

25-
/** Unit test class for the DialogNodesVisited model. */
26-
public class DialogNodesVisitedTest {
25+
/** Unit test class for the DialogNodeVisited model. */
26+
public class DialogNodeVisitedTest {
2727
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
2828
final List<FileWithMetadata> mockListFileWithMetadata =
2929
TestUtilities.creatMockListFileWithMetadata();
3030

3131
@Test
32-
public void testDialogNodesVisited() throws Throwable {
33-
DialogNodesVisited dialogNodesVisitedModel = new DialogNodesVisited();
34-
assertNull(dialogNodesVisitedModel.getDialogNode());
35-
assertNull(dialogNodesVisitedModel.getTitle());
36-
assertNull(dialogNodesVisitedModel.getConditions());
32+
public void testDialogNodeVisited() throws Throwable {
33+
DialogNodeVisited dialogNodeVisitedModel = new DialogNodeVisited();
34+
assertNull(dialogNodeVisitedModel.getDialogNode());
35+
assertNull(dialogNodeVisitedModel.getTitle());
36+
assertNull(dialogNodeVisitedModel.getConditions());
3737
}
3838
}

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageContextGlobalStatelessTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -39,6 +39,7 @@ public void testMessageContextGlobalStateless() throws Throwable {
3939
.referenceTime("testString")
4040
.sessionStartTime("testString")
4141
.state("testString")
42+
.skipUserInput(true)
4243
.build();
4344
assertEquals(messageContextGlobalSystemModel.timezone(), "testString");
4445
assertEquals(messageContextGlobalSystemModel.userId(), "testString");
@@ -47,6 +48,7 @@ public void testMessageContextGlobalStateless() throws Throwable {
4748
assertEquals(messageContextGlobalSystemModel.referenceTime(), "testString");
4849
assertEquals(messageContextGlobalSystemModel.sessionStartTime(), "testString");
4950
assertEquals(messageContextGlobalSystemModel.state(), "testString");
51+
assertEquals(messageContextGlobalSystemModel.skipUserInput(), Boolean.valueOf(true));
5052

5153
MessageContextGlobalStateless messageContextGlobalStatelessModel =
5254
new MessageContextGlobalStateless.Builder()

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageContextGlobalSystemTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -39,6 +39,7 @@ public void testMessageContextGlobalSystem() throws Throwable {
3939
.referenceTime("testString")
4040
.sessionStartTime("testString")
4141
.state("testString")
42+
.skipUserInput(true)
4243
.build();
4344
assertEquals(messageContextGlobalSystemModel.timezone(), "testString");
4445
assertEquals(messageContextGlobalSystemModel.userId(), "testString");
@@ -47,6 +48,7 @@ public void testMessageContextGlobalSystem() throws Throwable {
4748
assertEquals(messageContextGlobalSystemModel.referenceTime(), "testString");
4849
assertEquals(messageContextGlobalSystemModel.sessionStartTime(), "testString");
4950
assertEquals(messageContextGlobalSystemModel.state(), "testString");
51+
assertEquals(messageContextGlobalSystemModel.skipUserInput(), Boolean.valueOf(true));
5052

5153
String json = TestUtilities.serialize(messageContextGlobalSystemModel);
5254

@@ -60,5 +62,6 @@ public void testMessageContextGlobalSystem() throws Throwable {
6062
assertEquals(messageContextGlobalSystemModelNew.referenceTime(), "testString");
6163
assertEquals(messageContextGlobalSystemModelNew.sessionStartTime(), "testString");
6264
assertEquals(messageContextGlobalSystemModelNew.state(), "testString");
65+
assertEquals(messageContextGlobalSystemModelNew.skipUserInput(), Boolean.valueOf(true));
6366
}
6467
}

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageContextGlobalTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -39,6 +39,7 @@ public void testMessageContextGlobal() throws Throwable {
3939
.referenceTime("testString")
4040
.sessionStartTime("testString")
4141
.state("testString")
42+
.skipUserInput(true)
4243
.build();
4344
assertEquals(messageContextGlobalSystemModel.timezone(), "testString");
4445
assertEquals(messageContextGlobalSystemModel.userId(), "testString");
@@ -47,6 +48,7 @@ public void testMessageContextGlobal() throws Throwable {
4748
assertEquals(messageContextGlobalSystemModel.referenceTime(), "testString");
4849
assertEquals(messageContextGlobalSystemModel.sessionStartTime(), "testString");
4950
assertEquals(messageContextGlobalSystemModel.state(), "testString");
51+
assertEquals(messageContextGlobalSystemModel.skipUserInput(), Boolean.valueOf(true));
5052

5153
MessageContextGlobal messageContextGlobalModel =
5254
new MessageContextGlobal.Builder().system(messageContextGlobalSystemModel).build();

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageContextStatelessTest.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -39,6 +39,7 @@ public void testMessageContextStateless() throws Throwable {
3939
.referenceTime("testString")
4040
.sessionStartTime("testString")
4141
.state("testString")
42+
.skipUserInput(true)
4243
.build();
4344
assertEquals(messageContextGlobalSystemModel.timezone(), "testString");
4445
assertEquals(messageContextGlobalSystemModel.userId(), "testString");
@@ -47,6 +48,7 @@ public void testMessageContextStateless() throws Throwable {
4748
assertEquals(messageContextGlobalSystemModel.referenceTime(), "testString");
4849
assertEquals(messageContextGlobalSystemModel.sessionStartTime(), "testString");
4950
assertEquals(messageContextGlobalSystemModel.state(), "testString");
51+
assertEquals(messageContextGlobalSystemModel.skipUserInput(), Boolean.valueOf(true));
5052

5153
MessageContextGlobalStateless messageContextGlobalStatelessModel =
5254
new MessageContextGlobalStateless.Builder()
@@ -92,6 +94,12 @@ public void testMessageContextStateless() throws Throwable {
9294
put("foo", messageContextSkillModel);
9395
}
9496
})
97+
.integrations(
98+
new java.util.HashMap<String, Object>() {
99+
{
100+
put("foo", "testString");
101+
}
102+
})
95103
.build();
96104
assertEquals(messageContextStatelessModel.global(), messageContextGlobalStatelessModel);
97105
assertEquals(
@@ -101,6 +109,13 @@ public void testMessageContextStateless() throws Throwable {
101109
put("foo", messageContextSkillModel);
102110
}
103111
});
112+
assertEquals(
113+
messageContextStatelessModel.integrations(),
114+
new java.util.HashMap<String, Object>() {
115+
{
116+
put("foo", "testString");
117+
}
118+
});
104119

105120
String json = TestUtilities.serialize(messageContextStatelessModel);
106121

@@ -110,5 +125,12 @@ public void testMessageContextStateless() throws Throwable {
110125
assertEquals(
111126
messageContextStatelessModelNew.global().toString(),
112127
messageContextGlobalStatelessModel.toString());
128+
assertEquals(
129+
messageContextStatelessModelNew.integrations().toString(),
130+
new java.util.HashMap<String, Object>() {
131+
{
132+
put("foo", "testString");
133+
}
134+
}.toString());
113135
}
114136
}

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageContextTest.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -39,6 +39,7 @@ public void testMessageContext() throws Throwable {
3939
.referenceTime("testString")
4040
.sessionStartTime("testString")
4141
.state("testString")
42+
.skipUserInput(true)
4243
.build();
4344
assertEquals(messageContextGlobalSystemModel.timezone(), "testString");
4445
assertEquals(messageContextGlobalSystemModel.userId(), "testString");
@@ -47,6 +48,7 @@ public void testMessageContext() throws Throwable {
4748
assertEquals(messageContextGlobalSystemModel.referenceTime(), "testString");
4849
assertEquals(messageContextGlobalSystemModel.sessionStartTime(), "testString");
4950
assertEquals(messageContextGlobalSystemModel.state(), "testString");
51+
assertEquals(messageContextGlobalSystemModel.skipUserInput(), Boolean.valueOf(true));
5052

5153
MessageContextGlobal messageContextGlobalModel =
5254
new MessageContextGlobal.Builder().system(messageContextGlobalSystemModel).build();
@@ -88,6 +90,12 @@ public void testMessageContext() throws Throwable {
8890
put("foo", messageContextSkillModel);
8991
}
9092
})
93+
.integrations(
94+
new java.util.HashMap<String, Object>() {
95+
{
96+
put("foo", "testString");
97+
}
98+
})
9199
.build();
92100
assertEquals(messageContextModel.global(), messageContextGlobalModel);
93101
assertEquals(
@@ -97,11 +105,25 @@ public void testMessageContext() throws Throwable {
97105
put("foo", messageContextSkillModel);
98106
}
99107
});
108+
assertEquals(
109+
messageContextModel.integrations(),
110+
new java.util.HashMap<String, Object>() {
111+
{
112+
put("foo", "testString");
113+
}
114+
});
100115

101116
String json = TestUtilities.serialize(messageContextModel);
102117

103118
MessageContext messageContextModelNew = TestUtilities.deserialize(json, MessageContext.class);
104119
assertTrue(messageContextModelNew instanceof MessageContext);
105120
assertEquals(messageContextModelNew.global().toString(), messageContextGlobalModel.toString());
121+
assertEquals(
122+
messageContextModelNew.integrations().toString(),
123+
new java.util.HashMap<String, Object>() {
124+
{
125+
put("foo", "testString");
126+
}
127+
}.toString());
106128
}
107129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2022.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.watson.assistant.v2.model;
15+
16+
import static org.testng.Assert.*;
17+
18+
import com.ibm.cloud.sdk.core.service.model.FileWithMetadata;
19+
import com.ibm.watson.assistant.v2.utils.TestUtilities;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import org.testng.annotations.Test;
24+
25+
/** Unit test class for the MessageInputAttachment model. */
26+
public class MessageInputAttachmentTest {
27+
final HashMap<String, InputStream> mockStreamMap = TestUtilities.createMockStreamMap();
28+
final List<FileWithMetadata> mockListFileWithMetadata =
29+
TestUtilities.creatMockListFileWithMetadata();
30+
31+
@Test
32+
public void testMessageInputAttachment() throws Throwable {
33+
MessageInputAttachment messageInputAttachmentModel =
34+
new MessageInputAttachment.Builder().url("testString").mediaType("testString").build();
35+
assertEquals(messageInputAttachmentModel.url(), "testString");
36+
assertEquals(messageInputAttachmentModel.mediaType(), "testString");
37+
38+
String json = TestUtilities.serialize(messageInputAttachmentModel);
39+
40+
MessageInputAttachment messageInputAttachmentModelNew =
41+
TestUtilities.deserialize(json, MessageInputAttachment.class);
42+
assertTrue(messageInputAttachmentModelNew instanceof MessageInputAttachment);
43+
assertEquals(messageInputAttachmentModelNew.url(), "testString");
44+
assertEquals(messageInputAttachmentModelNew.mediaType(), "testString");
45+
}
46+
47+
@Test(expectedExceptions = IllegalArgumentException.class)
48+
public void testMessageInputAttachmentError() throws Throwable {
49+
new MessageInputAttachment.Builder().build();
50+
}
51+
}

assistant/src/test/java/com/ibm/watson/assistant/v2/model/MessageInputStatelessTest.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2022.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -119,12 +119,6 @@ public void testMessageInputStateless() throws Throwable {
119119
.location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26"))))
120120
.value("testString")
121121
.confidence(Double.valueOf("72.5"))
122-
.metadata(
123-
new java.util.HashMap<String, Object>() {
124-
{
125-
put("foo", "testString");
126-
}
127-
})
128122
.groups(
129123
new java.util.ArrayList<CaptureGroup>(java.util.Arrays.asList(captureGroupModel)))
130124
.interpretation(runtimeEntityInterpretationModel)
@@ -139,13 +133,6 @@ public void testMessageInputStateless() throws Throwable {
139133
new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26"))));
140134
assertEquals(runtimeEntityModel.value(), "testString");
141135
assertEquals(runtimeEntityModel.confidence(), Double.valueOf("72.5"));
142-
assertEquals(
143-
runtimeEntityModel.metadata(),
144-
new java.util.HashMap<String, Object>() {
145-
{
146-
put("foo", "testString");
147-
}
148-
});
149136
assertEquals(
150137
runtimeEntityModel.groups(),
151138
new java.util.ArrayList<CaptureGroup>(java.util.Arrays.asList(captureGroupModel)));
@@ -156,6 +143,11 @@ public void testMessageInputStateless() throws Throwable {
156143
java.util.Arrays.asList(runtimeEntityAlternativeModel)));
157144
assertEquals(runtimeEntityModel.role(), runtimeEntityRoleModel);
158145

146+
MessageInputAttachment messageInputAttachmentModel =
147+
new MessageInputAttachment.Builder().url("testString").mediaType("testString").build();
148+
assertEquals(messageInputAttachmentModel.url(), "testString");
149+
assertEquals(messageInputAttachmentModel.mediaType(), "testString");
150+
159151
MessageInputOptionsSpelling messageInputOptionsSpellingModel =
160152
new MessageInputOptionsSpelling.Builder().suggestions(true).autoCorrect(true).build();
161153
assertEquals(messageInputOptionsSpellingModel.suggestions(), Boolean.valueOf(true));
@@ -182,6 +174,9 @@ public void testMessageInputStateless() throws Throwable {
182174
.entities(
183175
new java.util.ArrayList<RuntimeEntity>(java.util.Arrays.asList(runtimeEntityModel)))
184176
.suggestionId("testString")
177+
.attachments(
178+
new java.util.ArrayList<MessageInputAttachment>(
179+
java.util.Arrays.asList(messageInputAttachmentModel)))
185180
.options(messageInputOptionsStatelessModel)
186181
.build();
187182
assertEquals(messageInputStatelessModel.messageType(), "text");
@@ -193,6 +188,10 @@ public void testMessageInputStateless() throws Throwable {
193188
messageInputStatelessModel.entities(),
194189
new java.util.ArrayList<RuntimeEntity>(java.util.Arrays.asList(runtimeEntityModel)));
195190
assertEquals(messageInputStatelessModel.suggestionId(), "testString");
191+
assertEquals(
192+
messageInputStatelessModel.attachments(),
193+
new java.util.ArrayList<MessageInputAttachment>(
194+
java.util.Arrays.asList(messageInputAttachmentModel)));
196195
assertEquals(messageInputStatelessModel.options(), messageInputOptionsStatelessModel);
197196

198197
String json = TestUtilities.serialize(messageInputStatelessModel);

0 commit comments

Comments
 (0)