/* * Copyright 2017 Christoph Krey (c@ckrey.de) * Copyright 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.traccar.protocol; import org.junit.Assert; import org.junit.Test; import org.traccar.ProtocolTest; import org.traccar.model.Command; public class Tk103ProtocolEncoderTest extends ProtocolTest { @Test public void testEncodeEngineStop() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_ENGINE_STOP); Assert.assertEquals("(123456789012345AV011)", encoder.encodeCommand(command)); } @Test public void testEncodePositionSingle() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_POSITION_SINGLE); Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command)); } @Test public void testEncodePositionPeriodic() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_POSITION_PERIODIC); command.set(Command.KEY_FREQUENCY, 60); Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command)); } @Test public void testEncodePositionStop() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_POSITION_STOP); Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command)); } @Test public void testEncodeGetVersion() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_GET_VERSION); Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command)); } @Test public void testEncodeRebootDevice() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_REBOOT_DEVICE); Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command)); } @Test public void testEncodeSetOdometer() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); Command command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_SET_ODOMETER); Assert.assertEquals("(123456789012345AX01)", encoder.encodeCommand(command)); } }