From 4e68a40c77240800dce14094b4cc55907410c208 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 6 Mar 2019 19:03:41 -0800 Subject: Fix OwnTracks decoder --- src/org/traccar/protocol/OwnTracksProtocolDecoder.java | 3 +-- test/org/traccar/ProtocolTest.java | 1 + test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java index 4ce880316..323d97fa3 100644 --- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java +++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java @@ -56,7 +56,7 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder { return null; } - Position position = new Position(); + Position position = new Position(getProtocolName()); String uniqueId; if (root.containsKey("topic")) { @@ -84,7 +84,6 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder { } position.setDeviceId(deviceSession.getDeviceId()); - position.setProtocol(getProtocolName()); position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000)); if (root.containsKey("sent")) { diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index 181af885d..4d48bb763 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -173,6 +173,7 @@ public class ProtocolTest extends BaseTest { } else { + assertNotNull(position.getServerTime()); assertNotNull(position.getFixTime()); assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L))); assertTrue("time < +25 hours", diff --git a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java index 553e7eb16..248920e21 100644 --- a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class OwnTracksProtocolDecoderTest extends ProtocolTest { OwnTracksProtocolDecoder decoder = new OwnTracksProtocolDecoder(null); + verifyPosition(decoder, request(HttpMethod.POST, "/", + buffer("{\"_type\":\"location\",\"acc\":15,\"alt\":440,\"batt\":46,\"conn\":\"w\",\"lat\":46.0681247,\"lon\":11.1512805,\"t\":\"u\",\"tid\":\"5t\",\"tst\":1551874878,\"vac\":2,\"vel\":0}"))); + verifyPosition(decoder, request(HttpMethod.POST, "/", buffer("{\"lon\":2.29513,\"lat\":48.85833,\"tst\":1497349316,\"_type\":\"location\",\"tid\":\"JJ\"}"))); -- cgit v1.2.3