use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.
the class ClientConnectorTests method testHandleSimpleCreatePresentationModelCommand.
@Test
public void testHandleSimpleCreatePresentationModelCommand() {
final String myPmId = "myPmId";
Assert.assertEquals(null, clientModelStore.findPresentationModelById(myPmId));
CreatePresentationModelCommand command = new CreatePresentationModelCommand();
command.setPmId(myPmId);
clientConnector.dispatchHandle(command);
Assert.assertNotNull(clientModelStore.findPresentationModelById(myPmId));
syncAndWaitUntilDone();
assertCommandsTransmitted(2);
}
use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.
the class ClientConnectorTests method testHandle_CreatePresentationModelTwiceFails.
@Test(expectedExceptions = Exception.class)
public void testHandle_CreatePresentationModelTwiceFails() {
List<Map<String, Object>> attributes = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("propertyName", "attr");
map.put("value", "initialValue");
map.put("qualifier", "qualifier");
((ArrayList<Map<String, Object>>) attributes).add(map);
clientConnector.dispatchHandle(new CreatePresentationModelCommand("p1", "type", attributes));
clientConnector.dispatchHandle(new CreatePresentationModelCommand("p1", "type", attributes));
}
use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method createCPMCommand.
private static CreatePresentationModelCommand createCPMCommand() {
final CreatePresentationModelCommand command = new CreatePresentationModelCommand();
command.setPmId("05ee43b7-a884-4d42-9fc5-00b083664eed");
command.setClientSideOnly(false);
command.setPmType("com.canoo.icos.casemanager.model.casedetails.CaseInfoBean");
final Map<String, Object> sourceSystem = new HashMap<>();
sourceSystem.put(Attribute.PROPERTY_NAME, "@@@ SOURCE_SYSTEM @@@");
sourceSystem.put(Attribute.ID, "3204S");
sourceSystem.put(Attribute.QUALIFIER_NAME, null);
sourceSystem.put(Attribute.VALUE_NAME, "server");
final Map<String, Object> caseDetailsLabel = new HashMap<>();
caseDetailsLabel.put(Attribute.PROPERTY_NAME, "caseDetailsLabel");
caseDetailsLabel.put(Attribute.ID, "3205S");
caseDetailsLabel.put(Attribute.QUALIFIER_NAME, null);
caseDetailsLabel.put(Attribute.VALUE_NAME, null);
final Map<String, Object> caseIdLabel = new HashMap<>();
caseIdLabel.put(Attribute.PROPERTY_NAME, "caseIdLabel");
caseIdLabel.put(Attribute.ID, "3206S");
caseIdLabel.put(Attribute.QUALIFIER_NAME, null);
caseIdLabel.put(Attribute.VALUE_NAME, null);
final Map<String, Object> statusLabel = new HashMap<>();
statusLabel.put(Attribute.PROPERTY_NAME, "statusLabel");
statusLabel.put(Attribute.ID, "3207S");
statusLabel.put(Attribute.QUALIFIER_NAME, null);
statusLabel.put(Attribute.VALUE_NAME, null);
final Map<String, Object> status = new HashMap<>();
status.put(Attribute.PROPERTY_NAME, "status");
status.put(Attribute.ID, "3208S");
status.put(Attribute.QUALIFIER_NAME, null);
status.put(Attribute.VALUE_NAME, null);
command.setAttributes(Arrays.asList(sourceSystem, caseDetailsLabel, caseIdLabel, statusLabel, status));
return command;
}
use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.
the class CreatePresentationModelCommandEncoder method decode.
@Override
public CreatePresentationModelCommand decode(final JsonObject jsonObject) {
Assert.requireNonNull(jsonObject, "jsonObject");
try {
final CreatePresentationModelCommand command = new CreatePresentationModelCommand();
command.setPmId(getStringElement(jsonObject, PM_ID));
command.setPmType(getStringElement(jsonObject, PM_TYPE));
command.setClientSideOnly(false);
final JsonArray jsonArray = jsonObject.getAsJsonArray(PM_ATTRIBUTES);
final List<Map<String, Object>> attributes = new ArrayList<>();
for (final JsonElement jsonElement : jsonArray) {
final JsonObject attribute = jsonElement.getAsJsonObject();
final HashMap<String, Object> map = new HashMap<>();
map.put(Attribute.PROPERTY_NAME, getStringElement(attribute, NAME));
map.put(Attribute.ID, getStringElement(attribute, ATTRIBUTE_ID));
final Object value = attribute.has(VALUE) ? ValueEncoder.decodeValue(attribute.get(VALUE)) : null;
map.put(Attribute.VALUE_NAME, value);
attributes.add(map);
}
command.setAttributes(attributes);
return command;
} catch (final IllegalStateException | ClassCastException | NullPointerException ex) {
throw new JsonParseException("Illegal JSON detected", ex);
}
}
use of com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand in project dolphin-platform by canoo.
the class TestDolphinPlatformHttpClientConnector method testSimpleCall.
@Test
public void testSimpleCall() throws DolphinRemotingException, URISyntaxException {
PlatformClient.init(new HeadlessToolkit());
PlatformClient.getClientConfiguration().setHttpURLConnectionFactory(new HttpURLConnectionFactory() {
@Override
public HttpURLConnection create(URI url) throws IOException {
return new HttpURLConnection(url.toURL()) {
@Override
public void disconnect() {
}
@Override
public boolean usingProxy() {
return false;
}
@Override
public void connect() throws IOException {
}
@Override
public int getResponseCode() throws IOException {
return HttpStatus.HTTP_OK;
}
@Override
public OutputStream getOutputStream() throws IOException {
return new ByteArrayOutputStream();
}
@Override
public InputStream getInputStream() throws IOException {
String response = "[{\"pmId\":\"p1\",\"clientSideOnly\":false,\"id\":\"CreatePresentationModel\",\"attributes\":[],\"pmType\":null,\"className\":\"com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand\"}]";
return new ByteArrayInputStream(response.getBytes("UTF-8"));
}
@Override
public String getHeaderField(String name) {
if (PlatformConstants.CLIENT_ID_HTTP_HEADER_NAME.equals(name)) {
return "TEST-ID";
}
return super.getHeaderField(name);
}
};
}
});
final ClientModelStore clientModelStore = new ClientModelStore(new DefaultModelSynchronizer(() -> null));
final DolphinPlatformHttpClientConnector connector = new DolphinPlatformHttpClientConnector(getDummyURL(), PlatformClient.getClientConfiguration(), clientModelStore, new JsonCodec(), new SimpleExceptionHandler(), PlatformClient.getService(HttpClient.class));
final CreatePresentationModelCommand command = new CreatePresentationModelCommand();
command.setPmId("p1");
Command rawCommand = command;
final List<Command> result = connector.transmit(Collections.singletonList(rawCommand));
Assert.assertEquals(result.size(), 1);
Assert.assertTrue(result.get(0) instanceof CreatePresentationModelCommand);
Assert.assertEquals(((CreatePresentationModelCommand) result.get(0)).getPmId(), "p1");
}
Aggregations