use of org.eclipse.che.dto.definitions.SimpleDto in project che by eclipse.
the class ServerDtoTest method testComplicatedDtoSerializer.
@Test
public void testComplicatedDtoSerializer() throws Exception {
final String fooString = "Something";
final int fooId = 1;
final String _default = "test_default_keyword";
List<String> listStrings = new ArrayList<>(2);
listStrings.add("Something 1");
listStrings.add("Something 2");
ComplicatedDto.SimpleEnum simpleEnum = ComplicatedDto.SimpleEnum.ONE;
// Assume that SimpleDto works. Use it to test nested objects
SimpleDto simpleDto = dtoFactory.createDto(SimpleDto.class).withName(fooString).withId(fooId).withDefault(_default);
Map<String, SimpleDto> mapDtos = new HashMap<>(1);
mapDtos.put(fooString, simpleDto);
List<SimpleDto> listDtos = new ArrayList<>(1);
listDtos.add(simpleDto);
List<List<ComplicatedDto.SimpleEnum>> listOfListOfEnum = new ArrayList<>(1);
List<ComplicatedDto.SimpleEnum> listOfEnum = new ArrayList<>(3);
listOfEnum.add(ComplicatedDto.SimpleEnum.ONE);
listOfEnum.add(ComplicatedDto.SimpleEnum.TWO);
listOfEnum.add(ComplicatedDto.SimpleEnum.THREE);
listOfListOfEnum.add(listOfEnum);
ComplicatedDto dto = dtoFactory.createDto(ComplicatedDto.class).withStrings(listStrings).withSimpleEnum(simpleEnum).withMap(mapDtos).withSimpleDtos(listDtos).withArrayOfArrayOfEnum(listOfListOfEnum);
final String json = dtoFactory.toJson(dto);
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
Assert.assertTrue(jsonObject.has("strings"));
JsonArray jsonArray = jsonObject.get("strings").getAsJsonArray();
assertEquals(jsonArray.get(0).getAsString(), listStrings.get(0));
assertEquals(jsonArray.get(1).getAsString(), listStrings.get(1));
Assert.assertTrue(jsonObject.has("simpleEnum"));
assertEquals(jsonObject.get("simpleEnum").getAsString(), simpleEnum.name());
Assert.assertTrue(jsonObject.has("map"));
JsonObject jsonMap = jsonObject.get("map").getAsJsonObject();
JsonObject value = jsonMap.get(fooString).getAsJsonObject();
assertEquals(value.get("name").getAsString(), fooString);
assertEquals(value.get("id").getAsInt(), fooId);
assertEquals(value.get("default").getAsString(), _default);
Assert.assertTrue(jsonObject.has("simpleDtos"));
JsonArray simpleDtos = jsonObject.get("simpleDtos").getAsJsonArray();
JsonObject simpleDtoJsonObject = simpleDtos.get(0).getAsJsonObject();
assertEquals(simpleDtoJsonObject.get("name").getAsString(), fooString);
assertEquals(simpleDtoJsonObject.get("id").getAsInt(), fooId);
assertEquals(simpleDtoJsonObject.get("default").getAsString(), _default);
Assert.assertTrue(jsonObject.has("arrayOfArrayOfEnum"));
JsonArray arrayOfArrayOfEnum = jsonObject.get("arrayOfArrayOfEnum").getAsJsonArray().get(0).getAsJsonArray();
assertEquals(arrayOfArrayOfEnum.get(0).getAsString(), ComplicatedDto.SimpleEnum.ONE.name());
assertEquals(arrayOfArrayOfEnum.get(1).getAsString(), ComplicatedDto.SimpleEnum.TWO.name());
assertEquals(arrayOfArrayOfEnum.get(2).getAsString(), ComplicatedDto.SimpleEnum.THREE.name());
}
use of org.eclipse.che.dto.definitions.SimpleDto in project che by eclipse.
the class ServerDtoTest method testSimpleDtoDeserializer.
@Test
public void testSimpleDtoDeserializer() throws Exception {
final String fooString = "Something";
final int fooId = 1;
final String _default = "test_default_keyword";
JsonObject json = new JsonObject();
json.add("name", new JsonPrimitive(fooString));
json.add("id", new JsonPrimitive(fooId));
json.add("default", new JsonPrimitive(_default));
SimpleDto dto = dtoFactory.createDtoFromJson(json.toString(), SimpleDto.class);
// Check to make sure things are in a sane state.
checkSimpleDto(dto, fooString, fooId, _default);
}
use of org.eclipse.che.dto.definitions.SimpleDto in project che by eclipse.
the class ServerDtoTest method testListSimpleDtoDeserializer.
@Test
public void testListSimpleDtoDeserializer() throws Exception {
final String fooString_1 = "Something 1";
final int fooId_1 = 1;
final String _default_1 = "test_default_keyword_1";
final String fooString_2 = "Something 2";
final int fooId_2 = 2;
final String _default_2 = "test_default_keyword_2";
JsonObject json1 = new JsonObject();
json1.add("name", new JsonPrimitive(fooString_1));
json1.add("id", new JsonPrimitive(fooId_1));
json1.add("default", new JsonPrimitive(_default_1));
JsonObject json2 = new JsonObject();
json2.add("name", new JsonPrimitive(fooString_2));
json2.add("id", new JsonPrimitive(fooId_2));
json2.add("default", new JsonPrimitive(_default_2));
JsonArray jsonArray = new JsonArray();
jsonArray.add(json1);
jsonArray.add(json2);
org.eclipse.che.dto.shared.JsonArray<SimpleDto> listDtoFromJson = dtoFactory.createListDtoFromJson(jsonArray.toString(), SimpleDto.class);
assertEquals(listDtoFromJson.get(0).getName(), fooString_1);
assertEquals(listDtoFromJson.get(0).getId(), fooId_1);
assertEquals(listDtoFromJson.get(0).getDefault(), _default_1);
assertEquals(listDtoFromJson.get(1).getName(), fooString_2);
assertEquals(listDtoFromJson.get(1).getId(), fooId_2);
assertEquals(listDtoFromJson.get(1).getDefault(), _default_2);
}
use of org.eclipse.che.dto.definitions.SimpleDto in project che by eclipse.
the class ServerDtoTest method testSimpleDtoSerializer.
@Test
public void testSimpleDtoSerializer() throws Exception {
final String fooString = "Something";
final int fooId = 1;
final String _default = "test_default_keyword";
SimpleDto dto = dtoFactory.createDto(SimpleDto.class).withName(fooString).withId(fooId).withDefault(_default);
final String json = dtoFactory.toJson(dto);
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
assertEquals(jsonObject.get("name").getAsString(), fooString);
assertEquals(jsonObject.get("id").getAsInt(), fooId);
assertEquals(jsonObject.get("default").getAsString(), _default);
}
use of org.eclipse.che.dto.definitions.SimpleDto in project che by eclipse.
the class ServerDtoTest method testCreateSimpleDto.
@Test
public void testCreateSimpleDto() throws Exception {
final String fooString = "Something";
final int fooId = 1;
final String _default = "test_default_keyword";
SimpleDto dto = dtoFactory.createDto(SimpleDto.class).withName(fooString).withId(fooId).withDefault(_default);
// Check to make sure things are in a sane state.
checkSimpleDto(dto, fooString, fooId, _default);
}
Aggregations