diff options
author | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-20 23:06:09 +0100 |
---|---|---|
committer | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-20 23:06:09 +0100 |
commit | 8d8bab8a2df30629fb612b0573b2bd5f46c4b05e (patch) | |
tree | e8fbcb26b185cc15843bedd14b7279eef26f3836 /test/org | |
parent | eca7ba9dcedb01c98b6945890f45f2b19bf049a7 (diff) | |
download | trackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.tar.gz trackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.tar.bz2 trackermap-server-8d8bab8a2df30629fb612b0573b2bd5f46c4b05e.zip |
T580W: review comments fixes 2
Diffstat (limited to 'test/org')
-rw-r--r-- | test/org/traccar/BaseTest.java | 2 | ||||
-rw-r--r-- | test/org/traccar/FilterHandlerTest.java | 2 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 16 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolEncoderTest.java | 183 |
4 files changed, 38 insertions, 165 deletions
diff --git a/test/org/traccar/BaseTest.java b/test/org/traccar/BaseTest.java index 4b9ee5451..87ff3842c 100644 --- a/test/org/traccar/BaseTest.java +++ b/test/org/traccar/BaseTest.java @@ -40,7 +40,7 @@ public class BaseTest { @Override public boolean lookupAttributeBoolean( long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) { - return defaultValue; + return (deviceId == 2 && attributeName == "tk103.alternative" && lookupConfig) ? true : defaultValue; } @Override diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java index 7ebab3af5..e896aa450 100644 --- a/test/org/traccar/FilterHandlerTest.java +++ b/test/org/traccar/FilterHandlerTest.java @@ -48,7 +48,7 @@ public class FilterHandlerTest { @Override public boolean lookupAttributeBoolean( long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) { - return defaultValue; + return (deviceId == 2 && attributeName == "tk103.alternative" && lookupConfig) ? true : defaultValue; } @Override diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index b8fe872ee..74edd10ab 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -189,17 +189,17 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { 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%$")); + "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")); + "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 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)); } |