Search in sources :

Example 1 with DtoWithFieldNames

use of org.eclipse.che.dto.definitions.DtoWithFieldNames in project che by eclipse.

the class ServerDtoTest method testSerializerWithFieldNames.

@Test
public void testSerializerWithFieldNames() throws Exception {
    final String fooString = "Something";
    final String _default = "test_default_keyword";
    DtoWithFieldNames dto = dtoFactory.createDto(DtoWithFieldNames.class).withTheName(fooString).withTheDefault(_default);
    final String json = dtoFactory.toJson(dto);
    JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
    assertEquals(jsonObject.get(DtoWithFieldNames.THENAME_FIELD).getAsString(), fooString);
    assertEquals(jsonObject.get(DtoWithFieldNames.THEDEFAULT_FIELD).getAsString(), _default);
}
Also used : DtoWithFieldNames(org.eclipse.che.dto.definitions.DtoWithFieldNames) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Example 2 with DtoWithFieldNames

use of org.eclipse.che.dto.definitions.DtoWithFieldNames in project che by eclipse.

the class ServerDtoTest method testDeerializerWithFieldNames.

@Test
public void testDeerializerWithFieldNames() throws Exception {
    final String fooString = "Something";
    final String _default = "test_default_keyword";
    JsonObject json = new JsonObject();
    json.add(DtoWithFieldNames.THENAME_FIELD, new JsonPrimitive(fooString));
    json.add(DtoWithFieldNames.THEDEFAULT_FIELD, new JsonPrimitive(_default));
    DtoWithFieldNames dto = dtoFactory.createDtoFromJson(json.toString(), DtoWithFieldNames.class);
    assertEquals(dto.getTheName(), fooString);
    assertEquals(dto.getTheDefault(), _default);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) DtoWithFieldNames(org.eclipse.che.dto.definitions.DtoWithFieldNames) Test(org.testng.annotations.Test)

Aggregations

JsonObject (com.google.gson.JsonObject)2 DtoWithFieldNames (org.eclipse.che.dto.definitions.DtoWithFieldNames)2 Test (org.testng.annotations.Test)2 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1