use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class OptimizedJsonCodec method decode.
@Override
public List<Command> decode(final String transmitted) {
Assert.requireNonNull(transmitted, "transmitted");
LOG.trace("Decoding message: {}", transmitted);
try {
final JsonArray array = (JsonArray) new JsonParser().parse(transmitted);
final List<Command> commands = new ArrayList<>(array.size());
for (final JsonElement jsonElement : array) {
final JsonObject command = (JsonObject) jsonElement;
final JsonPrimitive idElement = command.getAsJsonPrimitive("id");
if (idElement == null) {
throw new RuntimeException("Can not encode command without id!");
}
String id = idElement.getAsString();
LOG.trace("Decoding command: {}", id);
final CommandTranscoder<?> encoder = transcoders.get(id);
if (encoder == null) {
throw new RuntimeException("Can not encode command of type " + id + ". No matching encoder found!");
}
final Command convertedCommand = encoder.decode(command);
Assert.requireNonNull(convertedCommand, "convertedCommand");
commands.add(convertedCommand);
}
LOG.debug("Decoded command list with {} commands", commands.size());
return commands;
} catch (Exception ex) {
throw new JsonParseException("Illegal JSON detected", ex);
}
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class ClientConnectorTests method testValueChange_noQualifier.
@Test
public void testValueChange_noQualifier() {
ClientAttribute attribute = new ClientAttribute("attr", "initialValue");
clientModelStore.registerAttribute(attribute);
attributeChangeListener.propertyChange(new PropertyChangeEvent(attribute, Attribute.VALUE_NAME, attribute.getValue(), "newValue"));
syncAndWaitUntilDone();
assertCommandsTransmitted(2);
Assert.assertEquals("initialValue", attribute.getValue());
boolean valueChangedCommandFound = false;
for (Command c : clientConnector.getTransmittedCommands()) {
if (c instanceof ValueChangedCommand) {
}
valueChangedCommandFound = true;
}
Assert.assertTrue(valueChangedCommandFound);
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class ClientConnectorTests method testValueChange_withQualifier.
@Test
public void testValueChange_withQualifier() {
syncDone = new CountDownLatch(1);
ClientAttribute attribute = new ClientAttribute("attr", "initialValue", "qualifier");
clientModelStore.registerAttribute(attribute);
attributeChangeListener.propertyChange(new PropertyChangeEvent(attribute, Attribute.VALUE_NAME, attribute.getValue(), "newValue"));
syncAndWaitUntilDone();
assertCommandsTransmitted(3);
Assert.assertEquals("newValue", attribute.getValue());
boolean valueChangedCommandFound = false;
for (Command c : clientConnector.getTransmittedCommands()) {
if (c instanceof ValueChangedCommand) {
}
valueChangedCommandFound = true;
}
Assert.assertTrue(valueChangedCommandFound);
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldEncodeSingleCreatePresentationModelCommand.
@Test
public void shouldEncodeSingleCreatePresentationModelCommand() {
final Command command = createCPMCommand();
final String actual = OptimizedJsonCodec.getInstance().encode(Collections.singletonList(command));
assertThat(actual, is("[" + createCPMCommandString() + "]"));
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method testQualifierSupport.
@Test
public void testQualifierSupport() {
final String input = "[{\"id\":\"ChangeAttributeMetadata\",\"a_id\":\"79S\",\"n\":\"qualifier\",\"v\":\"237fb6b9-32d5-4feb-9679-57f1dd7cc7a2\"},{\"id\":\"ChangeAttributeMetadata\",\"a_id\":\"81S\",\"n\":\"qualifier\",\"v\":\"0e36799a-e501-4af4-a2f0-04b98897a1de\"}]";
final List<Command> commands = OptimizedJsonCodec.getInstance().decode(input);
Assert.assertNotNull(commands);
for (Command command : commands) {
Assert.assertNotNull(command);
}
}
Aggregations