mirror of
https://github.com/traccar/traccar.git
synced 2026-06-12 19:04:56 -04:00
Add Suntech encoder test
This commit is contained in:
@@ -353,14 +353,14 @@ public class ProtocolTest extends BaseTest {
|
||||
verifyFrame(expected, encoder.encodeCommand(command));
|
||||
}
|
||||
|
||||
protected void verifyCommand(
|
||||
BaseProtocolEncoder encoder, BaseProtocolDecoder decoder, Command command, ByteBuf expected) {
|
||||
protected Object encodeCommand(
|
||||
BaseProtocolEncoder encoder, BaseProtocolDecoder decoder, Command command) {
|
||||
var pipeline = mock(ChannelPipeline.class);
|
||||
when(pipeline.iterator()).thenReturn(
|
||||
List.<Map.Entry<String, ChannelHandler>>of(Map.entry("decoder", decoder)).iterator());
|
||||
var channel = mock(Channel.class);
|
||||
when(channel.pipeline()).thenReturn(pipeline);
|
||||
verifyFrame(expected, encoder.encodeCommand(channel, command));
|
||||
return encoder.encodeCommand(channel, command);
|
||||
}
|
||||
|
||||
protected void verifyFrame(ByteBuf expected, Object object) {
|
||||
|
||||
@@ -16,7 +16,9 @@ public class Jt808ProtocolEncoderTest extends ProtocolTest {
|
||||
command.setDeviceId(1);
|
||||
command.setType(Command.TYPE_ENGINE_STOP);
|
||||
|
||||
verifyCommand(encoder, decoder, command, binary("7e810500010b3a73ce2ff20000f0247e"));
|
||||
verifyFrame(
|
||||
binary("7e810500010b3a73ce2ff20000f0247e"),
|
||||
encodeCommand(encoder, decoder, command));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.traccar.protocol;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.traccar.ProtocolTest;
|
||||
import org.traccar.model.Command;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SuntechProtocolEncoderTest extends ProtocolTest {
|
||||
|
||||
@Test
|
||||
public void testEncode() throws Exception {
|
||||
|
||||
var decoder = inject(new SuntechProtocolDecoder(null));
|
||||
var encoder = inject(new SuntechProtocolEncoder(null));
|
||||
|
||||
Command command = new Command();
|
||||
command.setDeviceId(1);
|
||||
command.setType(Command.TYPE_REBOOT_DEVICE);
|
||||
|
||||
assertEquals(
|
||||
"SA200CMD;123456789012345;02;Reboot\r",
|
||||
encodeCommand(encoder, decoder, command));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user