Search in sources :

Example 6 with HttpPathMethodDTO

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));
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 7 with HttpPathMethodDTO

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);
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 8 with HttpPathMethodDTO

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"));
    });
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 9 with HttpPathMethodDTO

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);
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 10 with HttpPathMethodDTO

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO)

Aggregations

HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)19 Test (org.junit.jupiter.api.Test)11 RoboContext (com.robo4j.RoboContext)2 RoboReference (com.robo4j.RoboReference)2 ResponseAttributeListDTO (com.robo4j.socket.http.dto.ResponseAttributeListDTO)2 SystemPath (com.robo4j.socket.http.enums.SystemPath)2 JsonDocument (com.robo4j.socket.http.json.JsonDocument)2 JsonReader (com.robo4j.socket.http.json.JsonReader)2 ClientContext (com.robo4j.socket.http.units.ClientContext)2 ClientPathConfig (com.robo4j.socket.http.units.ClientPathConfig)2 PathHttpMethod (com.robo4j.socket.http.units.PathHttpMethod)2 ServerContext (com.robo4j.socket.http.units.ServerContext)2 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 RoboBuilder (com.robo4j.RoboBuilder)1 HttpMethod (com.robo4j.socket.http.HttpMethod)1 ResponseAttributeDTO (com.robo4j.socket.http.dto.ResponseAttributeDTO)1 HttpPathUtils.toPath (com.robo4j.socket.http.util.HttpPathUtils.toPath)1