use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.
the class HttpContextTests method clientSimpleContextTest.
@Test
void clientSimpleContextTest() throws Exception {
RoboBuilder builderProducer = new RoboBuilder();
InputStream contextIS = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_client_context.xml");
builderProducer.add(contextIS);
List<HttpPathMethodDTO> paths = Collections.singletonList(new HttpPathMethodDTO(StringConstants.EMPTY, HttpMethod.GET, Collections.singletonList(StringConsumer.NAME)));
ClientContext context = new ClientContext();
HttpPathUtils.updateHttpClientContextPaths(context, paths);
PathHttpMethod basicGet = new PathHttpMethod(Utf8Constant.UTF8_SOLIDUS, HttpMethod.GET);
System.out.println("context: " + context);
assertNotNull(context);
assertNotNull(context.getPathConfig(basicGet));
assertTrue(!context.getPathConfig(basicGet).getCallbacks().isEmpty());
assertEquals(HttpMethod.GET, context.getPathConfig(basicGet).getMethod());
assertEquals(1, context.getPathConfig(basicGet).getCallbacks().size());
assertEquals(StringConsumer.NAME, context.getPathConfig(basicGet).getCallbacks().get(0));
}
use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.
the class JsonCodecsTests method encodeServerPathDTOMessageNoFilterTest.
@SuppressWarnings("unchecked")
@Test
void encodeServerPathDTOMessageNoFilterTest() {
// String expectedJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"}";
HttpPathMethodDTO message = new HttpPathMethodDTO();
message.setRoboUnit("roboUnit1");
message.setMethod(HttpMethod.GET);
message.setCallbacks(Collections.EMPTY_LIST);
String resultJson = httpPathDTOCodec.encode(message);
HttpPathMethodDTO decodedMessage = httpPathDTOCodec.decode(resultJson);
System.out.println("resultJson: " + resultJson);
System.out.println("decodedMessage: " + decodedMessage);
// Assert.assertTrue(expectedJson.equals(resultJson));
assertEquals(message, decodedMessage);
}
use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.
the class HttpPathUtilTests method parseFullPathMethod.
@Test
void parseFullPathMethod() {
List<String> jsonList = Arrays.asList("{\"roboUnit\":\"\", \"method\":\"POST\", \"callbacks\":[\"callbackPOSTController\"]}", "{\"roboUnit\":\"imageController\", \"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}", "{\"roboUnit\":\"imageController\", \"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}", "{\"roboUnit\":\"imageController\", \"method\":\"POST\",\"callbacks\":[\"callbackPOSTController\"]}");
jsonList.forEach(json -> {
HttpPathMethodDTO pathMethod = JsonUtil.getPathMethodByJson(json);
System.out.println("pathMethod: " + pathMethod);
assertNotNull(pathMethod, json);
assertNotNull(pathMethod.getRoboUnit(), json);
assertTrue(pathMethod.getRoboUnit().isEmpty() ? pathMethod.getRoboUnit().equals(StringConstants.EMPTY) : pathMethod.getRoboUnit().equals("imageController"));
});
}
use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.
the class HttpServerConfigTests method serverConfigurationWithPropertiesParsingDTOTest.
@Test
void serverConfigurationWithPropertiesParsingDTOTest() {
String configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\",\"callbacks\":[\"filter1\",\"filter2\"]}";
HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
assertArrayEquals(Arrays.asList("filter1", "filter2").toArray(), serverUnitPathDTO.getCallbacks().toArray());
System.out.println("serverUnitPathDTO: " + serverUnitPathDTO);
}
use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.
the class SocketMessageDecoratedProducerUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
target = configuration.getString(PROPERTY_TARGET, null);
message = configuration.getString("message", null);
List<HttpPathMethodDTO> paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configuration.getString(PROPERTY_UNIT_PATHS_CONFIG, null));
HttpPathUtils.updateHttpClientContextPaths(clientContext, paths);
counter = new AtomicInteger(DEFAULT);
type = CommunicationType.valueOf(configuration.getString(PROP_COMMUNICATION_TYPE, CommunicationType.HTTP.toString()).toUpperCase());
}
Aggregations