17
17
*/
18
18
package org .opensearch .ml .memory .action .conversation ;
19
19
20
+ import static org .junit .Assert .assertEquals ;
21
+
20
22
import java .io .IOException ;
23
+ import java .io .UncheckedIOException ;
21
24
25
+ import org .junit .Before ;
26
+ import org .junit .Test ;
22
27
import org .opensearch .common .io .stream .BytesStreamOutput ;
23
28
import org .opensearch .common .xcontent .XContentType ;
29
+ import org .opensearch .core .action .ActionResponse ;
24
30
import org .opensearch .core .common .bytes .BytesReference ;
25
31
import org .opensearch .core .common .io .stream .BytesStreamInput ;
26
32
import org .opensearch .core .common .io .stream .OutputStreamStreamOutput ;
32
38
33
39
public class CreateConversationResponseTests extends OpenSearchTestCase {
34
40
41
+ CreateConversationResponse response ;
42
+
43
+ @ Before
44
+ public void setup () {
45
+ response = new CreateConversationResponse ("test-id" );
46
+ }
47
+
35
48
public void testCreateConversationResponseStreaming () throws IOException {
36
49
CreateConversationResponse response = new CreateConversationResponse ("test-id" );
37
50
assert (response .getId ().equals ("test-id" ));
@@ -51,4 +64,34 @@ public void testToXContent() throws IOException {
51
64
String result = BytesReference .bytes (builder ).utf8ToString ();
52
65
assert (result .equals (expected ));
53
66
}
67
+
68
+ @ Test
69
+ public void fromActionResponseWithCreateConversationResponseSuccess () {
70
+ CreateConversationResponse responseFromActionResponse = CreateConversationResponse .fromActionResponse (response );
71
+ assertEquals (response .getId (), responseFromActionResponse .getId ());
72
+ }
73
+
74
+ @ Test
75
+ public void fromActionResponseSuccess () {
76
+ ActionResponse actionResponse = new ActionResponse () {
77
+ @ Override
78
+ public void writeTo (StreamOutput out ) throws IOException {
79
+ response .writeTo (out );
80
+ }
81
+ };
82
+ CreateConversationResponse responseFromActionResponse = CreateConversationResponse .fromActionResponse (actionResponse );
83
+ assertNotSame (response , responseFromActionResponse );
84
+ assertEquals (response .getId (), responseFromActionResponse .getId ());
85
+ }
86
+
87
+ @ Test (expected = UncheckedIOException .class )
88
+ public void fromActionResponseIOException () {
89
+ ActionResponse actionResponse = new ActionResponse () {
90
+ @ Override
91
+ public void writeTo (StreamOutput out ) throws IOException {
92
+ throw new IOException ();
93
+ }
94
+ };
95
+ CreateConversationResponse .fromActionResponse (actionResponse );
96
+ }
54
97
}
0 commit comments