diff options
author | Jesse Hills <jesserockz@gmail.com> | 2019-08-01 09:19:22 +1200 |
---|---|---|
committer | Jesse Hills <jesserockz@gmail.com> | 2019-08-01 09:19:22 +1200 |
commit | c5bfaf57bb0423c8e5af757c15abd3b3e729dce6 (patch) | |
tree | 4b83a6ea131a91c352242e7f60122d6814e6192f /src | |
parent | c4f588bfb161a1e7fe9d927ad28572553ec5c692 (diff) | |
download | traccar-server-c5bfaf57bb0423c8e5af757c15abd3b3e729dce6.tar.gz traccar-server-c5bfaf57bb0423c8e5af757c15abd3b3e729dce6.tar.bz2 traccar-server-c5bfaf57bb0423c8e5af757c15abd3b3e729dce6.zip |
Add simple unit test
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java | 20 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/LeafSpyProtocolDecoderTest.java | 21 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java b/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java index 17824177c..47c37a68b 100644 --- a/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java @@ -80,17 +80,17 @@ public class LeafSpyProtocolDecoder extends BaseHttpProtocolDecoder { case "Elv": position.setAltitude(Double.parseDouble(value)); break; - case "DevBat": + case "SOC": position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value)); break; case "user": position.set(Position.KEY_DRIVER_UNIQUE_ID, value); break; - case "SOC": - position.set(Position.KEY_CHARGE, Double.parseDouble(value)); + case "ChrgMode": + position.set(Position.KEY_CHARGE, Integer.parseInt(value) != 0); break; case "Odo": - position.set(Position.KEY_OBD_ODOMETER, Integer.parseInt(value)); + position.set(Position.KEY_OBD_ODOMETER, Integer.parseInt(value) * 1000); break; default: try { @@ -122,11 +122,13 @@ public class LeafSpyProtocolDecoder extends BaseHttpProtocolDecoder { } if (position.getDeviceId() != 0) { - HttpResponse response = new DefaultFullHttpResponse( - HttpVersion.HTTP_1_1, - HttpResponseStatus.OK, - Unpooled.copiedBuffer("\"status\":\"0\"", StandardCharsets.US_ASCII)); - channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); + if(channel != null) { + HttpResponse response = new DefaultFullHttpResponse( + HttpVersion.HTTP_1_1, + HttpResponseStatus.OK, + Unpooled.copiedBuffer("\"status\":\"0\"", StandardCharsets.US_ASCII)); + channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); + } return position; } else { sendResponse(channel, HttpResponseStatus.BAD_REQUEST); diff --git a/src/test/java/org/traccar/protocol/LeafSpyProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/LeafSpyProtocolDecoderTest.java new file mode 100644 index 000000000..7fe405ea8 --- /dev/null +++ b/src/test/java/org/traccar/protocol/LeafSpyProtocolDecoderTest.java @@ -0,0 +1,21 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class LeafSpyProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + LeafSpyProtocolDecoder decoder = new LeafSpyProtocolDecoder(null); + + verifyNull(decoder, request( + "/?Lat=60.0&Long=30.0")); + + verifyPosition(decoder, request( + "/?user=driver&pass=123456&DevBat=80&Gids=200&Lat=60.0&Long=30.0&Elv=5&Seq=50&Trip=1&Odo=10000&SOC=99.99&AHr=55.00&BatTemp=15.2&Amb=12.0&Wpr=12&PlugState=0&ChrgMode=0&ChrgPwr=0&VIN=ZE0-000000&PwrSw=1&Tunits=C&RPM=1000")); + + } + +} |