Package com.google.collide.dtogen.server.TestDtoServerImpls

Examples of com.google.collide.dtogen.server.TestDtoServerImpls.ComplicatedDtoImpl


public class ServerImplTest extends TestCase {
  public void testComplicatedDtoImpl() {
    final String fooString = "Something";
    final int intId = 1;

    ComplicatedDtoImpl dtoImpl = ComplicatedDtoImpl.make();
    dtoImpl.setIntId(intId);
    dtoImpl.setSimpleEnum(SimpleEnum.TWO);
    dtoImpl.getFooStrings().add(fooString);
    dtoImpl.getNightmare();
    dtoImpl.getArrayOfArrayOfEnum();

    // Assume that SimpleDto works. Use it to test nested objects
    SimpleDtoImpl simpleDto = SimpleDtoImpl.make();
    simpleDto.setName(fooString);
    simpleDto.setIDontStartWithGet(intId);

    dtoImpl.getSimpleDtos().add(simpleDto);
    dtoImpl.getMap().put(fooString, simpleDto);

    // Check to make sure things are in a sane state.
    ComplicatedDto dto = dtoImpl;
    assertEquals(intId, dto.getIntId());
    assertEquals(fooString, dto.getFooStrings().get(0));
    // Should be reference equal initially.
    assertEquals(dto.getSimpleDtos().get(0), simpleDto);
    assertEquals(dto.getMap().get(fooString), simpleDto);
    assertEquals(ComplicatedDto.TYPE, dto.getType());

    // Make it json and pull it back out.
    Gson gson = new Gson();
    String serialized = dtoToJson(gson, dtoImpl);
    ComplicatedDtoImpl deserialized = ComplicatedDtoImpl.fromJsonString(serialized);

    // Test correctness of JSON serialization.
    assertEquals(serialized, dtoImpl.toJson());

    assertEquals(intId, deserialized.getIntId());
    assertEquals(fooString, deserialized.getFooStrings().get(0));
    assertEquals(ComplicatedDto.TYPE, deserialized.getType());

    // Pull it out using the DTO's deserializer.
    JsonElement jsonElement = new JsonParser().parse(serialized);
    ComplicatedDtoImpl deserialized2 = ComplicatedDtoImpl.fromJsonElement(jsonElement);
    assertEquals(intId, deserialized2.getIntId());
    assertEquals(fooString, deserialized2.getFooStrings().get(0));
    assertEquals(ComplicatedDto.TYPE, deserialized2.getType());

    // Verify that the hasFields() are correct when using the DTO's deserializer.
    assertTrue(deserialized2.hasIntId());

    // Check that the SimpleDto object looks correct.
    checkSimpleDto(dto.getSimpleDtos().get(0), simpleDto.getName(), simpleDto.iDontStartWithGet());
    checkSimpleDto(dto.getMap().get(fooString), simpleDto.getName(), simpleDto.iDontStartWithGet());
  }
View Full Code Here


    assertEquals(fooString, dto.getSomeField());
  }

  public void testNullEnum() {
    ComplicatedDtoImpl dtoImpl = ComplicatedDtoImpl.make();
    dtoImpl.setIntId(1);
    dtoImpl.setSimpleEnum(null);

    // Make it json and pull it back out.
    Gson gson = new GsonBuilder().serializeNulls().create();
    String serialized = dtoImpl.toJson();
    assertEquals(dtoToJson(gson, dtoImpl), serialized);

    ComplicatedDto dto = ComplicatedDtoImpl.fromJsonString(serialized);
    assertEquals(1, dto.getIntId());
    assertNull(dto.getSimpleEnum());
View Full Code Here

TOP

Related Classes of com.google.collide.dtogen.server.TestDtoServerImpls.ComplicatedDtoImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.