Search in sources :

Example 11 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldEncodeValueChangedCommandWithIntegers.

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

Example 12 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithNulls.

@Test
public void shouldDecodeValueChangedCommandWithNulls() {
    final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"id\":\"ValueChanged\"}]");
    final ValueChangedCommand command = new ValueChangedCommand();
    command.setNewValue(null);
    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 13 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithDoubles.

@Test
public void shouldDecodeValueChangedCommandWithDoubles() {
    final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":2.7182,\"id\":\"ValueChanged\"}]");
    final ValueChangedCommand command = (ValueChangedCommand) commands.get(0);
    assertThat(command.getAttributeId(), is("3357S"));
    assertThat(((Number) command.getNewValue()).doubleValue(), closeTo(2.7182, 1e-6));
}
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 14 with ValueChangedCommand

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

the class TestOptimizedJsonCodec method shouldEncodeValueChangedCommandWithStrings.

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

Example 15 with ValueChangedCommand

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

the class BlindCommandBatcherTest method testMergeCreatePmAfterValueChange.

@Test
public void testMergeCreatePmAfterValueChange() {
    // given:
    batcher.setMergeValueChanges(true);
    List<CommandAndHandler> list = new ArrayList<CommandAndHandler>();
    ValueChangedCommand command = new ValueChangedCommand();
    command.setAttributeId("0");
    command.setNewValue(1);
    list.add(new CommandAndHandler(command));
    list.add(new CommandAndHandler(new CreatePresentationModelCommand()));
    // when:
    for (CommandAndHandler commandAndHandler : list) {
        batcher.batch(commandAndHandler);
    }
    // then:
    try {
        List<CommandAndHandler> nextBatch = batcher.getWaitingBatches().getVal();
        Assert.assertEquals(2, nextBatch.size());
        Assert.assertEquals(ValueChangedCommand.class, nextBatch.get(0).getCommand().getClass());
        Assert.assertEquals(CreatePresentationModelCommand.class, nextBatch.get(1).getCommand().getClass());
        Assert.assertTrue(batcher.isEmpty());
    } catch (InterruptedException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : CommandAndHandler(com.canoo.dp.impl.client.legacy.communication.CommandAndHandler) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

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