Search in sources :

Example 1 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 2 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpServerConfigTests method serverConfigurationWithoutPropertiesDTOTest.

@Test
void serverConfigurationWithoutPropertiesDTOTest() {
    String configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"}";
    HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
    System.out.println("serverUnitPathDTO: " + serverUnitPathDTO);
    assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
    assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
    assertTrue(serverUnitPathDTO.getCallbacks().isEmpty());
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 3 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpServerConfigTests method serverConfigurationNullTest.

@Test
void serverConfigurationNullTest() {
    Throwable exception = assertThrows(NullPointerException.class, () -> {
        HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(null);
        assertNull(serverUnitPathDTO);
    });
    assertNull(exception.getMessage());
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 4 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpServerConfigTests method serverConfigurationWithMultiplePathsWithPropertiesTest.

@Test
void serverConfigurationWithMultiplePathsWithPropertiesTest() {
    String configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\" , \"callbacks\":[\"filter1\",\"filter2\"]}," + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}, {\"roboUnit\":\"roboUnit3\",\"method\":\"GET\",\"callbacks\":[]}]";
    List<HttpPathMethodDTO> expectedPathList = Arrays.asList(new HttpPathMethodDTO("roboUnit1", HttpMethod.GET, Arrays.asList("filter1", "filter2")), new HttpPathMethodDTO("roboUnit2", HttpMethod.POST), new HttpPathMethodDTO("roboUnit3", HttpMethod.GET, Collections.emptyList()));
    List<HttpPathMethodDTO> paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
    System.out.println("paths: " + paths);
    assertNotNull(paths);
    assertEquals(expectedPathList.size(), paths.size());
    assertArrayEquals(expectedPathList.toArray(), paths.toArray());
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 5 with HttpPathMethodDTO

use of com.robo4j.socket.http.dto.HttpPathMethodDTO in project robo4j by Robo4J.

the class HttpServerConfigTests method serverConfigurationWithMultiplePathsWithoutPropertiesTest.

@Test
void serverConfigurationWithMultiplePathsWithoutPropertiesTest() {
    String configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"}," + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}]";
    List<HttpPathMethodDTO> expectedPathList = Arrays.asList(new HttpPathMethodDTO("roboUnit1", HttpMethod.GET), new HttpPathMethodDTO("roboUnit2", HttpMethod.POST));
    List<HttpPathMethodDTO> paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
    assertEquals(expectedPathList.size(), paths.size());
    assertArrayEquals(expectedPathList.toArray(), paths.toArray());
}
Also used : HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

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