aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar
diff options
context:
space:
mode:
authorValerii Vyshniak <valeravi@vi-soft.com.ua>2017-11-20 02:40:37 +0100
committerValerii Vyshniak <valeravi@vi-soft.com.ua>2017-11-20 02:40:37 +0100
commitfd9f7b72c1994508ef26df05f4001ab0fd8449e3 (patch)
treedb3f8da64d49151de67938a41fd44e26b89d6831 /test/org/traccar
parentb5f33434ff94cbad7a8c37f9211b0c939c6cdc4b (diff)
downloadtraccar-server-fd9f7b72c1994508ef26df05f4001ab0fd8449e3.tar.gz
traccar-server-fd9f7b72c1994508ef26df05f4001ab0fd8449e3.tar.bz2
traccar-server-fd9f7b72c1994508ef26df05f4001ab0fd8449e3.zip
T580W: review comments fixes
Diffstat (limited to 'test/org/traccar')
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java17
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolEncoderTest.java160
2 files changed, 169 insertions, 8 deletions
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index f10912d68..b8fe872ee 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -184,6 +184,23 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest {
verifyNotNull(decoder, text(
"(013632651491,DW50,460,0,0,6,0,040613,040137"));
+ verifyNotNull(decoder, text(
+ "(864555555555555,ZC03,191117,234207,$Notice: Device version: 1.0$"));
+
+ verifyNotNull(decoder, text(
+ "(864555555555555,ZC03,191117,234207,$1 .Sensor sensitivity: 1\r\n" +
+ "2 .Alert status: Off\r\n" +
+ "3 .Check interval is set to 240 minute(s).\r\n" +
+ "4 .Checkgsm interval is set to 60 minute(s).\r\n" +
+ "5 .SOS SMS Alert: On\r\n" +
+ "6 .SOS Call Alert: On\r\n" +
+ "7 . Power: 95%$"));
+
+ verifyNotNull(decoder, text(
+ "(864555555555555,ZC03,191117,234207,$1 .Sensor sensitivity: 1\r\n" +
+ "2 .Alert status: Off\r\n" +
+ "3 .Check interval is set to 240 minute(s"));
+
}
}
diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
index 8439f8d48..2e5b66572 100644
--- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
@@ -2,11 +2,76 @@ package org.traccar.protocol;
import org.junit.Assert;
import org.junit.Test;
+import org.traccar.Context;
import org.traccar.ProtocolTest;
+import org.traccar.database.IdentityManager;
import org.traccar.model.Command;
+import org.traccar.model.Device;
+import org.traccar.model.Position;
public class Tk103ProtocolEncoderTest extends ProtocolTest {
+ private static IdentityManager defaultManager;
+ static {
+ defaultManager = Context.getIdentityManager();
+ }
+
+ private static IdentityManager t580wManager = new IdentityManager() {
+
+ private Device createDevice() {
+ Device device = new Device();
+ device.setId(1);
+ device.setName("test");
+ device.setUniqueId("123456789012345");
+ device.set(Command.KEY_DEVICE_PASSWORD, "654321");
+ return device;
+ }
+
+ @Override
+ public Device getById(long id) {
+ return createDevice();
+ }
+
+ @Override
+ public Device getByUniqueId(String uniqueId) {
+ return createDevice();
+ }
+
+ @Override
+ public Position getLastPosition(long deviceId) {
+ return null;
+ }
+
+ @Override
+ public boolean isLatestPosition(Position position) {
+ return true;
+ }
+
+ @Override
+ public boolean lookupAttributeBoolean(
+ long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) {
+ return deviceId == 1 && attributeName == "tk103.deviceT580W" && lookupConfig ? true : defaultValue;
+ }
+
+ @Override
+ public String lookupAttributeString(
+ long deviceId, String attributeName, String defaultValue, boolean lookupConfig) {
+ return defaultValue;
+ }
+
+ @Override
+ public int lookupAttributeInteger(
+ long deviceId, String attributeName, int defaultValue, boolean lookupConfig) {
+ return defaultValue;
+ }
+
+ @Override
+ public long lookupAttributeLong(
+ long deviceId, String attributeName, long defaultValue, boolean lookupConfig) {
+ return defaultValue;
+ }
+ };
+
@Test
public void testEncodeEngineStop() throws Exception {
@@ -16,6 +81,8 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AV011)", encoder.encodeCommand(command));
}
@@ -29,8 +96,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_SINGLE);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
+
}
@Test
@@ -43,8 +116,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_POSITION_PERIODIC);
command.set(Command.KEY_FREQUENCY, 60);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
+
}
@Test
@@ -56,8 +135,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_STOP);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
+
}
@Test
@@ -69,8 +154,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_GET_VERSION);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
+
}
@Test
@@ -82,8 +173,14 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
+
}
@Test
@@ -95,20 +192,24 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_SET_ODOMETER);
+ Context.init(defaultManager);
+
Assert.assertEquals("(123456789012345AX01)", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WRebootDevice() throws Exception {
+ public void testEncodeT580WIdentification() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
command.setDeviceId(1);
- command.setType("T580W_rebootDevice");
+ command.setType(Command.TYPE_IDENTIFICATION);
- Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
}
@@ -119,7 +220,10 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Command command = new Command();
command.setDeviceId(1);
- command.setType("T580W_alarmSosOn");
+ command.setType(Command.TYPE_ALARM_SOS);
+ command.set(Command.KEY_ENABLE, true);
+
+ Context.init(t580wManager);
Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
@@ -132,22 +236,62 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Command command = new Command();
command.setDeviceId(1);
- command.setType("T580W_alarmSosOff");
+ command.setType(Command.TYPE_ALARM_SOS);
+ command.set(Command.KEY_ENABLE, false);
+
+ Context.init(t580wManager);
Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WRouteTrack() throws Exception {
+ public void testEncodeT580WCustom() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
command.setDeviceId(1);
- command.setType("T580W_positionRealtime");
+ command.setType(Command.TYPE_CUSTOM);
+ command.set(Command.KEY_DATA, "any text is ok");
- Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeT580WSetConnection() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SET_CONNECTION);
+ command.set(Command.KEY_SERVER, "1.2.3.4");
+ command.set(Command.KEY_PORT, "5555");
+
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeT580WSosNumber() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SOS_NUMBER);
+ command.set(Command.KEY_INDEX, "0");
+ command.set(Command.KEY_PHONE, "+55555555555");
+
+ Context.init(t580wManager);
+
+ Assert.assertEquals("[begin]sms2,*master*654321*+55555555555*,[end]", encoder.encodeCommand(command));
}