Search in sources :

Example 21 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldEncodeValueChangedCommandWithBooleans.

@Test
public void shouldEncodeValueChangedCommandWithBooleans() {
    final ValueChangedCommand command = new ValueChangedCommand();
    command.setNewValue(false);
    command.setAttributeId("3357S");
    final String actual = OptimizedJsonCodec.getInstance().encode(Collections.<Command>singletonList(command));
    assertThat(actual, is("[{\"a_id\":\"3357S\",\"v\":false,\"id\":\"ValueChanged\"}]"));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 22 with ValueChangedCommand

use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand 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 23 with ValueChangedCommand

use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand 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 24 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldEncodeValueChangedCommandWithFloats.

@Test
public void shouldEncodeValueChangedCommandWithFloats() {
    final ValueChangedCommand command = new ValueChangedCommand();
    command.setNewValue(2.7182f);
    command.setAttributeId("3357S");
    final String actual = OptimizedJsonCodec.getInstance().encode(Collections.<Command>singletonList(command));
    assertThat(actual, is("[{\"a_id\":\"3357S\",\"v\":2.7182,\"id\":\"ValueChanged\"}]"));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 25 with ValueChangedCommand

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

the class ValueChangedCommandEncoder method decode.

@Override
public ValueChangedCommand decode(final JsonObject jsonObject) {
    Assert.requireNonNull(jsonObject, "jsonObject");
    try {
        final ValueChangedCommand command = new ValueChangedCommand();
        command.setNewValue(ValueEncoder.decodeValue(jsonObject.get(VALUE)));
        command.setAttributeId(getStringElement(jsonObject, ATTRIBUTE_ID));
        return command;
    } catch (IllegalStateException | ClassCastException | NullPointerException ex) {
        throw new JsonParseException("Illegal JSON detected", ex);
    }
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) JsonParseException(com.google.gson.JsonParseException)

Aggregations

ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)25 Test (org.testng.annotations.Test)22 CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)13 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)12 EmptyCommand (com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand)11 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)9 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)4 ChangeAttributeMetadataCommand (com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand)3 PresentationModelDeletedCommand (com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand)3 CommandAndHandler (com.canoo.dp.impl.client.legacy.communication.CommandAndHandler)2 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)2 StartLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand)2 AttributeMetadataChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand)2 DeletePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 ArrayList (java.util.ArrayList)2 JsonParseException (com.google.gson.JsonParseException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1