Skip to content

Commit d37e025

Browse files
committed
add the test
1 parent 5f4e85e commit d37e025

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.junit.Assert.assertEquals;
2121

22+
import com.uber.cadence.EventType;
2223
import com.uber.cadence.History;
2324
import com.uber.cadence.HistoryEvent;
2425
import com.uber.cadence.TaskList;
@@ -29,13 +30,44 @@
2930
import java.nio.charset.StandardCharsets;
3031
import java.util.ArrayList;
3132
import java.util.List;
33+
import java.util.Objects;
3234
import java.util.UUID;
3335
import org.junit.Test;
3436

3537
public 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

Comments
 (0)