Search in sources :

Example 1 with DtoWithAny

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));
    }
}
Also used : JsonArray(com.google.gson.JsonArray) DtoWithAny(org.eclipse.che.dto.definitions.DtoWithAny) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 2 with DtoWithAny

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);
}
Also used : JsonArray(com.google.gson.JsonArray) DtoWithAny(org.eclipse.che.dto.definitions.DtoWithAny) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 3 with DtoWithAny

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);
}
Also used : JsonArray(com.google.gson.JsonArray) DtoWithAny(org.eclipse.che.dto.definitions.DtoWithAny) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Aggregations

JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 DtoWithAny (org.eclipse.che.dto.definitions.DtoWithAny)3 Test (org.testng.annotations.Test)3 JsonParser (com.google.gson.JsonParser)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1