Skip to content

Commit

Permalink
fixes issue where invalid message was not returned
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen committed Sep 7, 2020
1 parent a7b2e9c commit d695c8f
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private RouteSegment CreateRouteSegment(dynamic routeSegment)
var mappedRouteSegment = new RouteSegment
{
Mrid = new Guid(routeSegment.mrid.ToString()),
Coord = routeSegment.coord is null ? null : Convert.FromBase64String(routeSegment.coord.wkb.ToString()),
Coord = (JObject)routeSegment.coord is null ? null : Convert.FromBase64String(routeSegment.coord.wkb.ToString()),
Username = routeSegment.user_name.ToString(),
WorkTaskMrid = routeSegment.work_task_mrid.ToString() == string.Empty ? System.Guid.Empty : new Guid(routeSegment.work_task_mrid.ToString()),
ApplicationName = routeSegment.application_name.ToString(),
Expand Down Expand Up @@ -151,7 +151,7 @@ private RouteNode CreateRouteNode(dynamic routeNode)
{
ApplicationInfo = routeNode.application_info.ToString(),
ApplicationName = routeNode.application_name.ToString(),
Coord = routeNode.coord is null ? null : Convert.FromBase64String(routeNode.coord.wkb.ToString()),
Coord = (JObject)routeNode.coord is null ? null : Convert.FromBase64String(routeNode.coord.wkb.ToString()),
MarkAsDeleted = (bool)routeNode.marked_to_be_deleted,
DeleteMe = (bool)routeNode.delete_me,
Mrid = new Guid(routeNode.mrid.ToString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,61 @@ public void Deserialize_ShouldReturnDeserializedSegmentMessageWithBeforeBeingNul

result.Should().BeEquivalentTo(expected);
}

[Theory]
[JsonFileData("TestData/RouteSegmentSerializerMessageCoordIsNull.json")]
public void Deserialize_ShouldReturnDeserializedSegmentMessage_(string fileData)
{
var serializationMapper = A.Fake<IInfoMapper>();
var routeSegmentSerializer = new RouteNetworkSerializer(serializationMapper);

var position = new Position();
var headers = new Dictionary<string, string>();
var body = Encoding.UTF8.GetBytes(fileData);

var receivedTransportMessage = new ReceivedTransportMessage(position, headers, body);

var expectedRouteSegmentBefore = new RouteSegment
{
Mrid = new Guid("57fb87f5-093c-405d-b619-755e3f39073f"),
Coord = Convert.FromBase64String("AQIAACDoZAAAAgAAAO79HyV51h/B6DWfEXKJVEGgwmxDUMkfwXuWw252iVRB"),
WorkTaskMrid = Guid.Empty,
ApplicationName = string.Empty,
Username = string.Empty,
MarkAsDeleted = false,
ApplicationInfo = string.Empty,
DeleteMe = false,
LifeCycleInfo = null,
MappingInfo = null,
NamingInfo = null,
RouteSegmentInfo = null,
SafetyInfo = null
};

var expectedRouteSegmentAfter = new RouteSegment
{
Mrid = new Guid("57fb87f5-093c-405d-b619-755e3f39073f"),
Coord = null,
WorkTaskMrid = Guid.Empty,
ApplicationName = string.Empty,
Username = string.Empty,
MarkAsDeleted = true,
ApplicationInfo = string.Empty,
DeleteMe = false,
LifeCycleInfo = null,
MappingInfo = null,
NamingInfo = null,
RouteSegmentInfo = null,
SafetyInfo = null
};

var expectedBody = new RouteSegmentMessage(expectedRouteSegmentBefore, expectedRouteSegmentAfter);
var expectedInvalidMessage = new InvalidMessage(expectedBody);

var expected = new ReceivedLogicalMessage(headers, expectedInvalidMessage, position);
var result = routeSegmentSerializer.Deserialize(receivedTransportMessage);

result.Should().BeEquivalentTo(expected);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ItemGroup>
<None Update="TestData/RouteSegmentSerializerMessage.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestData/RouteSegmentSerializerMessageBeforeIsNull.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestData/RouteSegmentSerializerMessageCoordIsNull.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestData/RouteNodeSerializerMessage.json" CopyToOutputDirectory="PreserveNewest" />
<None Update="TestData/RouteNodeSerializerMessageBeforeIsNull.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
{
"schema": {
"type": "struct",
"fields": [
{
"type": "struct",
"fields": [
{
"type": "string",
"optional": false,
"name": "io.debezium.data.Uuid",
"version": 1,
"field": "mrid"
},
{
"type": "struct",
"fields": [
{
"type": "bytes",
"optional": false,
"field": "wkb"
},
{
"type": "int32",
"optional": true,
"field": "srid"
}
],
"optional": true,
"name": "io.debezium.data.geometry.Geometry",
"version": 1,
"doc": "Geometry",
"field": "coord"
},
{
"type": "boolean",
"optional": false,
"field": "marked_to_be_deleted"
},
{
"type": "boolean",
"optional": false,
"field": "delete_me"
},
{
"type": "string",
"optional": true,
"field": "segment_kind"
},
{
"type": "string",
"optional": true,
"name": "io.debezium.data.Uuid",
"version": 1,
"field": "work_task_mrid"
},
{
"type": "string",
"optional": true,
"field": "user_name"
},
{
"type": "string",
"optional": true,
"field": "application_name"
},
{
"type": "string",
"optional": true,
"field": "application_info"
}
],
"optional": true,
"name": "postgres.route_network.route_segment.Value",
"field": "before"
},
{
"type": "struct",
"fields": [
{
"type": "string",
"optional": false,
"name": "io.debezium.data.Uuid",
"version": 1,
"field": "mrid"
},
{
"type": "struct",
"fields": [
{
"type": "bytes",
"optional": false,
"field": "wkb"
},
{
"type": "int32",
"optional": true,
"field": "srid"
}
],
"optional": true,
"name": "io.debezium.data.geometry.Geometry",
"version": 1,
"doc": "Geometry",
"field": "coord"
},
{
"type": "boolean",
"optional": false,
"field": "marked_to_be_deleted"
},
{
"type": "boolean",
"optional": false,
"field": "delete_me"
},
{
"type": "string",
"optional": true,
"field": "segment_kind"
},
{
"type": "string",
"optional": true,
"name": "io.debezium.data.Uuid",
"version": 1,
"field": "work_task_mrid"
},
{
"type": "string",
"optional": true,
"field": "user_name"
},
{
"type": "string",
"optional": true,
"field": "application_name"
},
{
"type": "string",
"optional": true,
"field": "application_info"
}
],
"optional": true,
"name": "postgres.route_network.route_segment.Value",
"field": "after"
},
{
"type": "struct",
"fields": [
{
"type": "string",
"optional": false,
"field": "version"
},
{
"type": "string",
"optional": false,
"field": "connector"
},
{
"type": "string",
"optional": false,
"field": "name"
},
{
"type": "int64",
"optional": false,
"field": "ts_ms"
},
{
"type": "string",
"optional": true,
"name": "io.debezium.data.Enum",
"version": 1,
"parameters": {
"allowed": "true,last,false"
},
"default": "false",
"field": "snapshot"
},
{
"type": "string",
"optional": false,
"field": "db"
},
{
"type": "string",
"optional": false,
"field": "schema"
},
{
"type": "string",
"optional": false,
"field": "table"
},
{
"type": "int64",
"optional": true,
"field": "txId"
},
{
"type": "int64",
"optional": true,
"field": "lsn"
},
{
"type": "int64",
"optional": true,
"field": "xmin"
}
],
"optional": false,
"name": "io.debezium.connector.postgresql.Source",
"field": "source"
},
{
"type": "string",
"optional": false,
"field": "op"
},
{
"type": "int64",
"optional": true,
"field": "ts_ms"
},
{
"type": "struct",
"fields": [
{
"type": "string",
"optional": false,
"field": "id"
},
{
"type": "int64",
"optional": false,
"field": "total_order"
},
{
"type": "int64",
"optional": false,
"field": "data_collection_order"
}
],
"optional": true,
"field": "transaction"
}
],
"optional": false,
"name": "postgres.route_network.route_segment.Envelope"
},
"payload": {
"before": {
"mrid": "57fb87f5-093c-405d-b619-755e3f39073f",
"coord": {
"wkb": "AQIAACDoZAAAAgAAAO79HyV51h/B6DWfEXKJVEGgwmxDUMkfwXuWw252iVRB",
"srid": 25832
},
"marked_to_be_deleted": false,
"delete_me": false,
"segment_kind": null,
"work_task_mrid": null,
"user_name": null,
"application_name": null,
"application_info": null
},
"after": {
"mrid": "57fb87f5-093c-405d-b619-755e3f39073f",
"coord": null,
"marked_to_be_deleted": true,
"delete_me": false,
"segment_kind": null,
"work_task_mrid": null,
"user_name": null,
"application_name": null,
"application_info": null
},
"source": {
"version": "1.1.2.Final",
"connector": "postgresql",
"name": "postgres",
"ts_ms": 1596714486069,
"snapshot": "false",
"db": "OPEN_FTTH",
"schema": "route_network",
"table": "route_segment",
"txId": 637,
"lsn": 1094031440,
"xmin": null
},
"op": "u",
"ts_ms": 1596714486493,
"transaction": null
}
}

0 comments on commit d695c8f

Please sign in to comment.