@@ -13,7 +13,6 @@ import streams.events.NodePayload
1313import streams.events.OperationType
1414import streams.events.Schema
1515import streams.events.StreamsTransactionEvent
16- import java.time.LocalTime
1716import java.time.OffsetTime
1817import java.time.ZoneOffset.UTC
1918import java.time.ZonedDateTime
@@ -25,9 +24,9 @@ class JSONUtilsTest {
2524 @Test
2625 fun `should serialize driver Point Data Types` () {
2726 // Given
28- val expected = " {\" point2dCartesian\" :{\" crs\" :\" cartesian\" ,\" x\" :1.0,\" y\" :2.0, \" z \" :null }," +
27+ val expected = " {\" point2dCartesian\" :{\" crs\" :\" cartesian\" ,\" x\" :1.0,\" y\" :2.0}," +
2928 " \" point3dCartesian\" :{\" crs\" :\" cartesian-3d\" ,\" x\" :1.0,\" y\" :2.0,\" z\" :3.0}," +
30- " \" point2dWgs84\" :{\" crs\" :\" wgs-84\" ,\" latitude\" :1.0,\" longitude\" :2.0, \" height \" :null }," +
29+ " \" point2dWgs84\" :{\" crs\" :\" wgs-84\" ,\" latitude\" :1.0,\" longitude\" :2.0}," +
3130 " \" point3dWgs84\" :{\" crs\" :\" wgs-84-3d\" ,\" latitude\" :1.0,\" longitude\" :2.0,\" height\" :3.0}," +
3231 " \" time\" :\" 14:01:01.000000001Z\" ,\" dateTime\" :\" 2017-12-17T17:14:35.123456789Z\" }"
3332
@@ -89,6 +88,102 @@ class JSONUtilsTest {
8988 assertEquals(cdcData, fromString)
9089 }
9190
91+ @Test
92+ fun `should convert cdcMap wgs2D with height null to PointValue` () {
93+ // given
94+ val timestamp = System .currentTimeMillis()
95+ val expectedPointValue = Values .point(4326 , 12.78 , 56.7 )
96+
97+ // when
98+ val cdcMap = mapOf<String , Any >(
99+ " meta" to mapOf (" timestamp" to timestamp,
100+ " username" to " user" ,
101+ " txId" to 1 ,
102+ " txEventId" to 0 ,
103+ " txEventsCount" to 1 ,
104+ " operation" to OperationType .created),
105+ " payload" to mapOf (" id" to " 0" ,
106+ " before" to null ,
107+ " after" to NodeChange (properties = mapOf (" location" to mapOf (" crs" to " wgs-84" , " longitude" to 12.78 , " latitude" to 56.7 , " height" to null )),
108+ labels = listOf (" LabelCDC" )),
109+ " type" to EntityType .node),
110+ " schema" to mapOf (" properties" to mapOf (" location" to " PointValue" ))
111+ )
112+
113+ // then
114+ val actualEvent = JSONUtils .asStreamsTransactionEvent(cdcMap)
115+ val actualPointValue = actualEvent.payload.after?.properties?.get(" location" )
116+ assertEquals(expectedPointValue, actualPointValue)
117+ }
118+
119+ @Test
120+ fun `should convert cdcString wgs2D with height null to PointValue` () {
121+ // given
122+ val timestamp = System .currentTimeMillis()
123+ val expectedPointValue = Values .point(4326 , 12.78 , 56.7 )
124+
125+ // when
126+ val cdcString = """ {
127+ |"meta":{"timestamp":$timestamp ,"username":"user","txId":1,"txEventId":0,"txEventsCount":1,"operation":"created"},
128+ |"payload":{"id":"0","before":null,"after":{"properties":{"location":{"crs":"wgs-84","longitude":12.78,"latitude":56.7,"height":null}},
129+ |"labels":["LabelCDC"]},"type":"node"},
130+ |"schema":{"properties":{"location":"PointValue"}}
131+ |}""" .trimMargin()
132+
133+ // then
134+ val actualEvent = JSONUtils .asStreamsTransactionEvent(cdcString)
135+ val actualPointValue = actualEvent.payload.after?.properties?.get(" location" )
136+ assertEquals(expectedPointValue, actualPointValue)
137+ }
138+
139+ @Test
140+ fun `should convert cdcString cartesian2D with z null to PointValue` () {
141+ // given
142+ val timestamp = System .currentTimeMillis()
143+ val expectedPointValue = Values .point(7203 , 12.78 , 56.7 )
144+
145+ // when
146+ val cdcString = """ {
147+ |"meta":{"timestamp":$timestamp ,"username":"user","txId":1,"txEventId":0,"txEventsCount":1,"operation":"created"},
148+ |"payload":{"id":"0","before":null,"after":{"properties":{"location":{"crs":"cartesian","x":12.78,"y":56.7,"z":null}},
149+ |"labels":["LabelCDC"]},"type":"node"},
150+ |"schema":{"properties":{"location":"PointValue"}}
151+ |}""" .trimMargin()
152+
153+ // then
154+ val actualEvent = JSONUtils .asStreamsTransactionEvent(cdcString)
155+ val actualPointValue = actualEvent.payload.after?.properties?.get(" location" )
156+ assertEquals(expectedPointValue, actualPointValue)
157+ }
158+
159+ @Test
160+ fun `should convert cdcMap cartesian2D with z null to PointValue` () {
161+ // given
162+ val timestamp = System .currentTimeMillis()
163+ val expectedPointValue = Values .point(7203 , 12.78 , 56.7 )
164+
165+ // when
166+ val cdcMap = mapOf<String , Any >(
167+ " meta" to mapOf (" timestamp" to timestamp,
168+ " username" to " user" ,
169+ " txId" to 1 ,
170+ " txEventId" to 0 ,
171+ " txEventsCount" to 1 ,
172+ " operation" to OperationType .created),
173+ " payload" to mapOf (" id" to " 0" ,
174+ " before" to null ,
175+ " after" to NodeChange (properties = mapOf (" location" to mapOf (" crs" to " cartesian" , " x" to 12.78 , " y" to 56.7 , " z" to null )),
176+ labels = listOf (" LabelCDC" )),
177+ " type" to EntityType .node),
178+ " schema" to mapOf (" properties" to mapOf (" location" to " PointValue" ))
179+ )
180+
181+ // then
182+ val actualEvent = JSONUtils .asStreamsTransactionEvent(cdcMap)
183+ val actualPointValue = actualEvent.payload.after?.properties?.get(" location" )
184+ assertEquals(expectedPointValue, actualPointValue)
185+ }
186+
92187 @Test
93188 fun `should deserialize plain values` () {
94189 assertEquals(" a" , JSONUtils .readValue(" a" , stringWhenFailure = true ))
0 commit comments