Search in sources :

Example 6 with CreatePresentationModelCommand

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);
}
Also used : CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) Test(org.testng.annotations.Test)

Example 7 with CreatePresentationModelCommand

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 8 with CreatePresentationModelCommand

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;
}
Also used : HashMap(java.util.HashMap) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)

Example 9 with CreatePresentationModelCommand

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) JsonObject(com.google.gson.JsonObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with CreatePresentationModelCommand

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");
}
Also used : DolphinPlatformHttpClientConnector(com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) DefaultModelSynchronizer(com.canoo.dp.impl.client.legacy.DefaultModelSynchronizer) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleExceptionHandler(com.canoo.dp.impl.client.legacy.communication.SimpleExceptionHandler) HttpURLConnectionFactory(com.canoo.platform.core.http.HttpURLConnectionFactory) JsonCodec(com.canoo.dp.impl.remoting.legacy.communication.JsonCodec) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateContextCommand(com.canoo.dp.impl.remoting.commands.CreateContextCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HttpClient(com.canoo.platform.core.http.HttpClient) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) HeadlessToolkit(com.canoo.platform.client.HeadlessToolkit) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) Test(org.testng.annotations.Test)

Aggregations

CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)10 HashMap (java.util.HashMap)7 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 DolphinPlatformHttpClientConnector (com.canoo.dp.impl.client.DolphinPlatformHttpClientConnector)1 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)1 DefaultModelSynchronizer (com.canoo.dp.impl.client.legacy.DefaultModelSynchronizer)1 CommandAndHandler (com.canoo.dp.impl.client.legacy.communication.CommandAndHandler)1 SimpleExceptionHandler (com.canoo.dp.impl.client.legacy.communication.SimpleExceptionHandler)1 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)1 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 JsonCodec (com.canoo.dp.impl.remoting.legacy.communication.JsonCodec)1 ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)1 HeadlessToolkit (com.canoo.platform.client.HeadlessToolkit)1 HttpClient (com.canoo.platform.core.http.HttpClient)1 HttpURLConnectionFactory (com.canoo.platform.core.http.HttpURLConnectionFactory)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1