19
19
20
20
import static org .junit .Assert .assertEquals ;
21
21
22
+ import com .uber .cadence .EventType ;
22
23
import com .uber .cadence .History ;
23
24
import com .uber .cadence .HistoryEvent ;
24
25
import com .uber .cadence .TaskList ;
29
30
import java .nio .charset .StandardCharsets ;
30
31
import java .util .ArrayList ;
31
32
import java .util .List ;
33
+ import java .util .Objects ;
32
34
import java .util .UUID ;
33
35
import org .junit .Test ;
34
36
35
37
public class JsonDataConverterTest {
36
38
37
39
private final DataConverter converter = JsonDataConverter .getInstance ();
38
40
41
+ static class TestData {
42
+ String val1 ;
43
+ // TBase value;
44
+ HistoryEvent val2 ;
45
+ // TEnum value;
46
+ EventType val3 ;
47
+
48
+ public TestData (String val1 , HistoryEvent val2 , EventType val3 ) {
49
+ this .val1 = val1 ;
50
+ this .val2 = val2 ;
51
+ this .val3 = val3 ;
52
+ }
53
+
54
+ @ Override
55
+ public boolean equals (Object o ) {
56
+ if (this == o ) return true ;
57
+ if (!(o instanceof TestData )) return false ;
58
+ TestData testData = (TestData ) o ;
59
+ return Objects .equals (val1 , testData .val1 )
60
+ && Objects .equals (val2 , testData .val2 )
61
+ && val3 == testData .val3 ;
62
+ }
63
+
64
+ @ Override
65
+ public int hashCode () {
66
+
67
+ return Objects .hash (val1 , val2 , val3 );
68
+ }
69
+ }
70
+
39
71
@ Test
40
72
public void testThrift () {
41
73
List <HistoryEvent > events = new ArrayList <>();
@@ -57,6 +89,76 @@ public void testThrift() {
57
89
assertEquals (new String (converted , StandardCharsets .UTF_8 ), history , fromConverted );
58
90
}
59
91
92
+ @ Test
93
+ public void testThriftArray () {
94
+ List <HistoryEvent > events = new ArrayList <>();
95
+ WorkflowExecutionStartedEventAttributes started =
96
+ new WorkflowExecutionStartedEventAttributes ()
97
+ .setExecutionStartToCloseTimeoutSeconds (11 )
98
+ .setIdentity ("testIdentity" )
99
+ .setInput ("input" .getBytes (StandardCharsets .UTF_8 ))
100
+ .setWorkflowType (new WorkflowType ().setName ("workflowType1" ))
101
+ .setTaskList (new TaskList ().setName ("taskList1" ));
102
+ events .add (
103
+ new HistoryEvent ()
104
+ .setTimestamp (1234567 )
105
+ .setEventId (321 )
106
+ .setWorkflowExecutionStartedEventAttributes (started ));
107
+ History history = new History ().setEvents (events );
108
+ byte [] converted = converter .toData ("abc" , history );
109
+ Object [] fromConverted = converter .fromDataArray (converted , String .class , History .class );
110
+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), "abc" , fromConverted [0 ]);
111
+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), history , fromConverted [1 ]);
112
+ }
113
+
114
+ @ Test
115
+ public void testThriftFieldsInPOJO () {
116
+ WorkflowExecutionStartedEventAttributes started =
117
+ new WorkflowExecutionStartedEventAttributes ()
118
+ .setExecutionStartToCloseTimeoutSeconds (11 )
119
+ .setIdentity ("testIdentity" )
120
+ .setInput ("input" .getBytes (StandardCharsets .UTF_8 ))
121
+ .setWorkflowType (new WorkflowType ().setName ("workflowType1" ))
122
+ .setTaskList (new TaskList ().setName ("taskList1" ));
123
+
124
+ HistoryEvent historyEvent =
125
+ new HistoryEvent ()
126
+ .setTimestamp (1234567 )
127
+ .setEventId (321 )
128
+ .setWorkflowExecutionStartedEventAttributes (started );
129
+
130
+ TestData testData = new TestData ("test-thrift" , historyEvent , EventType .ActivityTaskCompleted );
131
+
132
+ byte [] converted = converter .toData (testData );
133
+ TestData fromConverted = converter .fromData (converted , TestData .class , TestData .class );
134
+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), testData , fromConverted );
135
+ }
136
+
137
+ @ Test
138
+ public void testThriftFieldsInPOJOArray () {
139
+ WorkflowExecutionStartedEventAttributes started =
140
+ new WorkflowExecutionStartedEventAttributes ()
141
+ .setExecutionStartToCloseTimeoutSeconds (11 )
142
+ .setIdentity ("testIdentity" )
143
+ .setInput ("input" .getBytes (StandardCharsets .UTF_8 ))
144
+ .setWorkflowType (new WorkflowType ().setName ("workflowType1" ))
145
+ .setTaskList (new TaskList ().setName ("taskList1" ));
146
+
147
+ HistoryEvent historyEvent =
148
+ new HistoryEvent ()
149
+ .setTimestamp (1234567 )
150
+ .setEventId (321 )
151
+ .setWorkflowExecutionStartedEventAttributes (started );
152
+
153
+ TestData testData = new TestData ("test-thrift" , historyEvent , EventType .ActivityTaskCompleted );
154
+
155
+ byte [] converted = converter .toData ("abc" , testData );
156
+ Object [] fromConverted = converter .fromDataArray (converted , String .class , TestData .class );
157
+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), "abc" , fromConverted [0 ]);
158
+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), testData , fromConverted [1 ]);
159
+ }
160
+
161
+
60
162
public static void foo (List <UUID > arg ) {}
61
163
62
164
@ Test
0 commit comments