use of com.robo4j.socket.http.dto.ResponseUnitDTO in project robo4j by Robo4J.
the class RoboRequestFactory method processGet.
/**
* Generic robo context overview. It returns all units registered into the context including system id.
* The 1st position is reserved for the system
*
* @param context
* robo context
* @return descripton of desired context
*/
@Override
public Object processGet(RoboContext context) {
if (!context.getUnits().isEmpty()) {
final List<ResponseUnitDTO> unitList = context.getUnits().stream().map(u -> new ResponseUnitDTO(u.getId(), u.getState())).collect(Collectors.toList());
unitList.add(0, new ResponseUnitDTO(context.getId(), context.getState()));
return JsonUtil.toJsonArray(unitList);
} else {
SimpleLoggingUtil.error(getClass(), "internal error: no units available");
}
return null;
}
use of com.robo4j.socket.http.dto.ResponseUnitDTO in project robo4j by Robo4J.
the class JsonUtilTests method jsonToListTest.
@Test
void jsonToListTest() {
String json = "[{\"id\":\"unit1\",\"state\":\"INITIALIZED\"}," + "{\"id\":\"unit2\",\"state\":\"STARTED\"}, " + "{\"id\":\"unit3\",\"state\":\"FAILED\"}]";
List<ResponseUnitDTO> expectedResult = Arrays.asList(new ResponseUnitDTO("unit1", LifecycleState.INITIALIZED), new ResponseUnitDTO("unit2", LifecycleState.STARTED), new ResponseUnitDTO("unit3", LifecycleState.FAILED));
List<ResponseUnitDTO> result = JsonUtil.jsonToList(ResponseUnitDTO.class, json);
assertNotNull(result);
assertArrayEquals(expectedResult.toArray(), result.toArray());
}
Aggregations