aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-18 13:43:41 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-18 13:43:41 -0800
commite6b1c27e6aba0e338a278a09d5e085a7d53d4f52 (patch)
treec888d13c0a0f1b528eac803c0000851d49db51ec
parent0e209e80f03e72095e5b449679925066b01403d2 (diff)
downloadtrackermap-server-e6b1c27e6aba0e338a278a09d5e085a7d53d4f52.tar.gz
trackermap-server-e6b1c27e6aba0e338a278a09d5e085a7d53d4f52.tar.bz2
trackermap-server-e6b1c27e6aba0e338a278a09d5e085a7d53d4f52.zip
Minor watch tests cleanup
-rw-r--r--test/org/traccar/ProtocolTest.java4
-rw-r--r--test/org/traccar/protocol/WatchProtocolDecoderTest.java21
-rw-r--r--test/org/traccar/protocol/WatchProtocolEncoderTest.java31
3 files changed, 28 insertions, 28 deletions
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 377474556..181af885d 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -68,10 +68,6 @@ public class ProtocolTest extends BaseTest {
return concatenateStrings(data);
}
- protected String text(ByteBuf data) {
- return data.toString(StandardCharsets.ISO_8859_1);
- }
-
protected ByteBuf buffer(String... data) {
return Unpooled.copiedBuffer(concatenateStrings(data), StandardCharsets.ISO_8859_1);
}
diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
index 51846f51a..539e63253 100644
--- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -4,14 +4,9 @@ import io.netty.buffer.ByteBuf;
import org.junit.Test;
import org.traccar.Context;
import org.traccar.ProtocolTest;
-import org.traccar.database.MediaManager;
import org.traccar.model.Position;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public class WatchProtocolDecoderTest extends ProtocolTest {
@@ -111,19 +106,23 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, buffer(
"[ZJ*014111001350304*0038*008a*UD,070318,021027,V,00.000000,N,000.000000,E,0,0,0,0,100,18,1000,50,00000000,4,255,460,0,9346,5223,42,9346,5214,20,9784,4083,11,9346,5221,5]"));
+
}
@Test
public void testDecodeVoiceMessage() throws Exception {
+
WatchProtocolDecoder decoder = new WatchProtocolDecoder(null);
verifyNull(decoder.decode(null, null, buffer("[CS*1234567890*0004*TK,1]")));
- String hex = "7d5b5d2c2aff";
- Object decodedObject = decoder.decode(null, null, concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), binary(hex), buffer("]")));
- assertTrue("not a position", decodedObject instanceof Position);
- Position position = (Position) decodedObject;
- assertEquals("1234567890/mock.amr", position.getAttributes().get("audio"));
- verifyFrame(concatenateBuffers(buffer("#!AMR"), binary(hex)), ((MockMediaManager) Context.getMediaManager()).readFile("1234567890/mock.amr"));
+ ByteBuf data = binary("7d5b5d2c2aff");
+
+ Object decodedObject = decoder.decode(null, null, concatenateBuffers(buffer("[CS*1234567890*000e*TK,#!AMR"), data.resetReaderIndex(), buffer("]")));
+ assertEquals("1234567890/mock.amr", ((Position) decodedObject).getAttributes().get("audio"));
+
+ verifyFrame(concatenateBuffers(buffer("#!AMR"), data.resetReaderIndex()), ((MockMediaManager) Context.getMediaManager()).readFile("1234567890/mock.amr"));
+
}
+
}
diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
index 649f5a10d..a0631be3b 100644
--- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
@@ -1,12 +1,9 @@
package org.traccar.protocol;
-import io.netty.buffer.ByteBuf;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
-import static org.junit.Assert.assertEquals;
-
public class WatchProtocolEncoderTest extends ProtocolTest {
@Test
@@ -19,20 +16,20 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- assertEquals("[CS*123456789012345*0005*RESET]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0005*RESET]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SOS_NUMBER);
command.set(Command.KEY_INDEX, 1);
command.set(Command.KEY_PHONE, "123456789");
- assertEquals("[CS*123456789012345*000e*SOS1,123456789]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*000e*SOS1,123456789]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "2321414d520a2573");
- assertEquals(buffer("[CS*123456789012345*000b*TK,#!AMR\n%s]"), encoder.encodeCommand(null, command));
+ verifyFrame(buffer("[CS*123456789012345*000b*TK,#!AMR\n%s]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
@@ -50,28 +47,36 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_MESSAGE);
command.set(Command.KEY_MESSAGE, "text");
- assertEquals("[CS*123456789012345*0018*MESSAGE,0074006500780074]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0018*MESSAGE,0074006500780074]"), encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "WORK,6-9,11-13,13-15,17-19");
- assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]"), encoder.encodeCommand(null, command));
- command = new Command();
+ }
+
+ @Test
+ public void testEncodeTimezone() {
+
+ WatchProtocolEncoder encoder = new WatchProtocolEncoder();
+
+ Command command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SET_TIMEZONE);
+
command.set(Command.KEY_TIMEZONE, "Europe/Amsterdam");
- assertEquals("[CS*123456789012345*0006*LZ,,+1]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0006*LZ,,+1]"), encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "GMT+01:30");
- assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0008*LZ,,+1.5]"), encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "Atlantic/Azores");
- assertEquals("[CS*123456789012345*0006*LZ,,-1]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0006*LZ,,-1]"), encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "GMT-11:30");
- assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", text((ByteBuf)encoder.encodeCommand(null, command)));
+ verifyFrame(buffer("[CS*123456789012345*0009*LZ,,-11.5]"), encoder.encodeCommand(null, command));
}