use of org.eclipse.che.dto.definitions.DtoWithAny in project che by eclipse.
the class ServerDtoTest method testSerializerWithAny.
@Test
public void testSerializerWithAny() throws Exception {
final List<Object> objects = createListTestValueForAny();
DtoWithAny dto = dtoFactory.createDto(DtoWithAny.class).withStuff(createTestValueForAny()).withObjects(objects);
final String json = dtoFactory.toJson(dto);
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
Assert.assertEquals(jsonObject.get("stuff"), createTestValueForAny());
Assert.assertTrue(jsonObject.has("objects"));
JsonArray jsonArray = jsonObject.get("objects").getAsJsonArray();
assertEquals(jsonArray.size(), objects.size());
for (int i = 0; i < jsonArray.size(); i++) {
assertEquals(jsonArray.get(i), objects.get(i));
}
}
use of org.eclipse.che.dto.definitions.DtoWithAny in project che by eclipse.
the class ServerDtoTest method testCloneWithNullAny.
@Test
public void testCloneWithNullAny() throws Exception {
DtoWithAny dto1 = dtoFactory.createDto(DtoWithAny.class);
DtoWithAny dto2 = dtoFactory.clone(dto1);
Assert.assertEquals(dto1, dto2);
JsonElement json = new JsonParser().parse(dtoFactory.toJson(dto1));
JsonObject expJson = new JsonObject();
expJson.addProperty("id", 0);
expJson.add("objects", new JsonArray());
assertEquals(expJson, json);
}
use of org.eclipse.che.dto.definitions.DtoWithAny in project che by eclipse.
the class ServerDtoTest method testDeserializerWithAny.
@Test
public void testDeserializerWithAny() throws Exception {
JsonObject json = new JsonObject();
json.add("stuff", createTestValueForAny());
JsonArray jsonArray = createElementListTestValueForAny();
json.add("objects", jsonArray);
DtoWithAny dto = dtoFactory.createDtoFromJson(json.toString(), DtoWithAny.class);
Gson gson = new Gson();
Object stuffValue = gson.fromJson(createTestValueForAny(), Object.class);
Assert.assertEquals(dto.getStuff(), stuffValue);
Object objectsValue = gson.fromJson(createElementListTestValueForAny(), Object.class);
Assert.assertEquals(dto.getObjects(), objectsValue);
}
Aggregations