use of com.canoo.dp.impl.client.legacy.ClientModelStore in project dolphin-platform by canoo.
the class TestDolphinCommandHandler method testInvocation.
@Test
public void testInvocation() throws Exception {
// Given:
final DolphinTestConfiguration configuration = createDolphinTestConfiguration();
final ServerModelStore serverModelStore = configuration.getServerModelStore();
final ClientModelStore clientModelStore = configuration.getClientModelStore();
final DolphinCommandHandler dolphinCommandHandler = new DolphinCommandHandler(configuration.getClientConnector());
final String modelId = UUID.randomUUID().toString();
clientModelStore.createModel(modelId, null, new ClientAttribute("myAttribute", "UNKNOWN"));
configuration.getServerConnector().register(new DolphinServerAction() {
@Override
public void registerIn(ActionRegistry registry) {
registry.register(TestChangeCommand.class, new CommandHandler() {
@Override
public void handleCommand(Command command, List response) {
serverModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").setValue("Hello World");
}
});
}
});
// When:
dolphinCommandHandler.invokeDolphinCommand(new TestChangeCommand()).get();
// Then:
assertEquals(clientModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").getValue(), "Hello World");
}
use of com.canoo.dp.impl.client.legacy.ClientModelStore 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