1919
2020import static org .junit .Assert .assertEquals ;
2121
22+ import com .uber .cadence .EventType ;
2223import com .uber .cadence .History ;
2324import com .uber .cadence .HistoryEvent ;
2425import com .uber .cadence .TaskList ;
2930import java .nio .charset .StandardCharsets ;
3031import java .util .ArrayList ;
3132import java .util .List ;
33+ import java .util .Objects ;
3234import java .util .UUID ;
3335import org .junit .Test ;
3436
3537public class JsonDataConverterTest {
3638
3739 private final DataConverter converter = JsonDataConverter .getInstance ();
3840
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+
3971 @ Test
4072 public void testThrift () {
4173 List <HistoryEvent > events = new ArrayList <>();
@@ -57,6 +89,29 @@ public void testThrift() {
5789 assertEquals (new String (converted , StandardCharsets .UTF_8 ), history , fromConverted );
5890 }
5991
92+ @ Test
93+ public void testThriftFieldsInPOJO () {
94+ WorkflowExecutionStartedEventAttributes started =
95+ new WorkflowExecutionStartedEventAttributes ()
96+ .setExecutionStartToCloseTimeoutSeconds (11 )
97+ .setIdentity ("testIdentity" )
98+ .setInput ("input" .getBytes (StandardCharsets .UTF_8 ))
99+ .setWorkflowType (new WorkflowType ().setName ("workflowType1" ))
100+ .setTaskList (new TaskList ().setName ("taskList1" ));
101+
102+ HistoryEvent historyEvent =
103+ new HistoryEvent ()
104+ .setTimestamp (1234567 )
105+ .setEventId (321 )
106+ .setWorkflowExecutionStartedEventAttributes (started );
107+
108+ TestData testData = new TestData ("test-thrift" , historyEvent , EventType .ActivityTaskCompleted );
109+
110+ byte [] converted = converter .toData (testData );
111+ TestData fromConverted = converter .fromData (converted , TestData .class , TestData .class );
112+ assertEquals (new String (converted , StandardCharsets .UTF_8 ), testData , fromConverted );
113+ }
114+
60115 public static void foo (List <UUID > arg ) {}
61116
62117 @ Test
0 commit comments