aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
diff options
context:
space:
mode:
authorValerii Vyshniak <valeravi@vi-soft.com.ua>2017-11-20 23:06:09 +0100
committerValerii Vyshniak <valeravi@vi-soft.com.ua>2017-11-20 23:06:09 +0100
commit8d8bab8a2df30629fb612b0573b2bd5f46c4b05e (patch)
treee8fbcb26b185cc15843bedd14b7279eef26f3836 /test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
parenteca7ba9dcedb01c98b6945890f45f2b19bf049a7 (diff)
downloadtrackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.tar.gz
trackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.tar.bz2
trackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.zip
T580W: review comments fixes 2
Diffstat (limited to 'test/org/traccar/protocol/Tk103ProtocolEncoderTest.java')
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolEncoderTest.java183
1 files changed, 28 insertions, 155 deletions
diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
index 4afb7b0e4..f902268ce 100644
--- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
@@ -2,71 +2,11 @@ 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 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 {
@@ -91,14 +31,9 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
+ command.setDeviceId(2);
- try {
- Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
}
@@ -114,14 +49,9 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
+ command.setDeviceId(2);
- try {
- Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
}
@@ -136,14 +66,9 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
+ command.setDeviceId(2);
- try {
- Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
}
@@ -158,14 +83,9 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
+ command.setDeviceId(2);
- try {
- Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
}
@@ -180,14 +100,9 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
+ command.setDeviceId(2);
- try {
- Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
}
@@ -205,129 +120,87 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
}
@Test
- public void testEncodeT580WIdentification() throws Exception {
+ public void testEncodeIdentification() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_IDENTIFICATION);
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WSosOn() throws Exception {
+ public void testEncodeSosOn() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, true);
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WSosOff() throws Exception {
+ public void testEncodeSosOff() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, false);
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WCustom() throws Exception {
+ public void testEncodeCustom() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "any text is ok");
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WSetConnection() throws Exception {
+ public void testEncodeSetConnection() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_SET_CONNECTION);
command.set(Command.KEY_SERVER, "1.2.3.4");
command.set(Command.KEY_PORT, "5555");
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
}
@Test
- public void testEncodeT580WSosNumber() throws Exception {
+ public void testEncodeSosNumber() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
Command command = new Command();
- command.setDeviceId(1);
+ command.setDeviceId(2);
command.setType(Command.TYPE_SOS_NUMBER);
command.set(Command.KEY_INDEX, "0");
command.set(Command.KEY_PHONE, "+55555555555");
- IdentityManager old = Context.getIdentityManager();
- Context.init(t580wManager);
-
- try {
- Assert.assertEquals("[begin]sms2,*master*654321*+55555555555*,[end]", encoder.encodeCommand(command));
- } finally {
- Context.init(old);
- }
+ Assert.assertEquals("[begin]sms2,*master*123456*+55555555555*,[end]", encoder.encodeCommand(command));
}