Search in sources :

Example 26 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method shouldEncodeTwoCustomCodecCommands.

@Test
public void shouldEncodeTwoCustomCodecCommands() {
    final Command command = createCPMCommand();
    final String actual = OptimizedJsonCodec.getInstance().encode(Arrays.asList(command, command));
    final String expected = createCPMCommandString();
    assertThat(actual, is("[" + expected + "," + expected + "]"));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) Test(org.testng.annotations.Test)

Example 27 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithBooleans.

@Test
public void shouldDecodeValueChangedCommandWithBooleans() {
    final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":false,\"id\":\"ValueChanged\"}]");
    final ValueChangedCommand command = new ValueChangedCommand();
    command.setNewValue(false);
    command.setAttributeId("3357S");
    assertThat(commands, hasSize(1));
    assertThat(commands.get(0), Matchers.<Command>samePropertyValuesAs(command));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 28 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithStrings.

@Test
public void shouldDecodeValueChangedCommandWithStrings() {
    final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":\"Good Bye\",\"id\":\"ValueChanged\"}]");
    final ValueChangedCommand command = new ValueChangedCommand();
    command.setNewValue("Good Bye");
    command.setAttributeId("3357S");
    assertThat(commands, hasSize(1));
    assertThat(commands.get(0), Matchers.<Command>samePropertyValuesAs(command));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 29 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method shouldEncodeCustomCodecCommandAndStandardCodecCommand.

@Test
public void shouldEncodeCustomCodecCommandAndStandardCodecCommand() {
    final Command customCodecCommand = createCPMCommand();
    final Command standardCodecCommand = createCommand();
    final String actual = OptimizedJsonCodec.getInstance().encode(Arrays.asList(customCodecCommand, standardCodecCommand));
    final String customCodecCommandString = createCPMCommandString();
    final String standardCodecCommandString = createCommandJsonString();
    assertThat(actual, is("[" + customCodecCommandString + "," + standardCodecCommandString + "]"));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) Test(org.testng.annotations.Test)

Example 30 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class OptimizedJsonCodec method encode.

@Override
@SuppressWarnings("unchecked")
public String encode(final List<? extends Command> commands) {
    Assert.requireNonNull(commands, "commands");
    LOG.debug("Encoding command list with {} commands", commands.size());
    final StringBuilder builder = new StringBuilder("[");
    for (final Command command : commands) {
        if (command == null) {
            throw new IllegalArgumentException("Command list contains a null command: " + command);
        } else {
            LOG.trace("Encoding command of type {}", command.getClass());
            final CommandTranscoder encoder = transcoders.get(command.getId());
            if (encoder == null) {
                throw new RuntimeException("No encoder for command type " + command.getClass() + " found");
            }
            final JsonObject jsonObject = encoder.encode(command);
            GSON.toJson(jsonObject, builder);
            builder.append(",");
        }
    }
    if (!commands.isEmpty()) {
        final int length = builder.length();
        builder.delete(length - 1, length);
    }
    builder.append("]");
    if (LOG.isTraceEnabled()) {
        LOG.trace("Encoded message: {}", builder.toString());
    }
    return builder.toString();
}
Also used : Command(com.canoo.dp.impl.remoting.legacy.communication.Command) JsonObject(com.google.gson.JsonObject) AbstractCommandTranscoder(com.canoo.dp.impl.remoting.codec.encoders.AbstractCommandTranscoder) CommandTranscoder(com.canoo.dp.impl.remoting.codec.encoders.CommandTranscoder)

Aggregations

Command (com.canoo.dp.impl.remoting.legacy.communication.Command)43 CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)25 ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)23 Test (org.testng.annotations.Test)22 EmptyCommand (com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand)19 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)18 StartLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand)10 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)8 ChangeAttributeMetadataCommand (com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand)8 ArrayList (java.util.ArrayList)8 PresentationModelDeletedCommand (com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand)7 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)5 LinkedList (java.util.LinkedList)5 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)4 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)3 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)3 DestroyContextCommand (com.canoo.dp.impl.remoting.commands.DestroyContextCommand)3 AttributeMetadataChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand)3 DeletePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand)3 CommandHandler (com.canoo.dp.impl.server.legacy.communication.CommandHandler)3