From 7f62f1671b38b9ffbeff66aa4ee79e0f875b1c66 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 13 Jun 2017 12:30:49 +0200 Subject: New protocol decoder for OwnTracks - removed comments and try/catch as per request - add existence checks --- .../protocol/OwnTracksProtocolDecoderTest.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java (limited to 'test/org/traccar/protocol') diff --git a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java new file mode 100644 index 000000000..c11670cae --- /dev/null +++ b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java @@ -0,0 +1,26 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class OwnTracksProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + OwnTracksProtocolDecoder decoder = new OwnTracksProtocolDecoder(new OwnTracksProtocol()); + +/* + * I don'w know how to get JSON into that ... + * + verifyNull(decoder, request( + "{ \"id\" : \"hello\" }")); + + verifyPosition(decoder, request( + "{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\"}")); + +*/ + + } + +} -- cgit v1.2.3 From 96f37bd4206ad2f2034c026881230ca40436253d Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Tue, 13 Jun 2017 22:13:03 +0200 Subject: add unit tests --- .../org/traccar/protocol/OwnTracksProtocolDecoderTest.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java index c11670cae..30ae95d03 100644 --- a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java @@ -1,5 +1,6 @@ package org.traccar.protocol; +import org.jboss.netty.handler.codec.http.HttpMethod; import org.junit.Test; import org.traccar.ProtocolTest; @@ -10,16 +11,11 @@ public class OwnTracksProtocolDecoderTest extends ProtocolTest { OwnTracksProtocolDecoder decoder = new OwnTracksProtocolDecoder(new OwnTracksProtocol()); -/* - * I don'w know how to get JSON into that ... - * - verifyNull(decoder, request( - "{ \"id\" : \"hello\" }")); + verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer(text("{\"lon\":2.29513,\"lat\":48.85833,\"tst\":1497349316,\"_type\":\"location\",\"tid\":\"JJ\"}")))); - verifyPosition(decoder, request( - "{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\"}")); - -*/ + verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer(text("{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\",\"t\":\"u\",\"batt\":67}")))); } -- cgit v1.2.3 From d4e075a0b285f70d3c9854120f57ce06888f51e4 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Wed, 14 Jun 2017 07:51:33 +0200 Subject: indentation wrapped lines=8 --- src/org/traccar/protocol/OwnTracksProtocolDecoder.java | 2 +- test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test/org/traccar/protocol') diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java index 4baafc118..61950aef8 100644 --- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java +++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java @@ -56,7 +56,7 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder { HttpRequest request = (HttpRequest) msg; JsonObject root = Json.createReader( - new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject(); + new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject(); Position position = new Position(); position.setProtocol(getProtocolName()); diff --git a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java index 30ae95d03..1eb188421 100644 --- a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java @@ -11,11 +11,11 @@ public class OwnTracksProtocolDecoderTest extends ProtocolTest { OwnTracksProtocolDecoder decoder = new OwnTracksProtocolDecoder(new OwnTracksProtocol()); - verifyPosition(decoder, request(HttpMethod.POST, "/", - buffer(text("{\"lon\":2.29513,\"lat\":48.85833,\"tst\":1497349316,\"_type\":\"location\",\"tid\":\"JJ\"}")))); + verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer(text("{\"lon\":2.29513,\"lat\":48.85833,\"tst\":1497349316,\"_type\":\"location\",\"tid\":\"JJ\"}")))); - verifyPosition(decoder, request(HttpMethod.POST, "/", - buffer(text("{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\",\"t\":\"u\",\"batt\":67}")))); + verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer(text("{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\",\"t\":\"u\",\"batt\":67}")))); } -- cgit v1.2.3