Package com.getperka.flatpack.domain

Examples of com.getperka.flatpack.domain.Employee


  protected Configuration getConfiguration() {
    return new Configuration().withPrettyPrint(true).withVerbose(true);
  }

  protected Employee makeEmployee() {
    Employee toReturn = employees.get();
    toReturn.setEmployeeNumber(++counter);
    toReturn.setName("Employee Name");
    toReturn.getAddress().setStreet("street");
    return toReturn;
  }
View Full Code Here


*/
public class PackTest extends FlatPackTest {

  @Test
  public void test() throws IOException {
    Employee employee = makeEmployee();
    Employee employee2 = deepPack(Employee.class, employee);

    check(employee, employee2);
  }
View Full Code Here

  }

  @Test
  public void testImpliedProperties() throws IOException {
    Manager manager = makeManager();
    Employee employeeA = makeEmployee();
    Employee employeeB = makeEmployee();

    // A -> manager -> B
    employeeA.setManager(manager);
    manager.getEmployees().add(employeeB);

    Employee employeeA2 = deepPack(Employee.class, employeeA);
    assertEquals(2, employeeA2.getManager().getEmployees().size());
    for (Employee toTest : employeeA2.getManager().getEmployees()) {
      if (employeeA.equals(toTest)) {
        check(employeeA, toTest);
      } else if (employeeB.equals(toTest)) {
        check(employeeB, toTest);
      } else {
View Full Code Here

    }
  }

  @Test
  public void testSingleEntityElement() throws IOException {
    Employee employee = makeEmployee();

    JsonElement elt = flatpack.getPacker().append(employee, null);

    Employee employee2 = flatpack.getUnpacker().read(Employee.class, elt, null);

    check(employee, employee2);
  }
View Full Code Here

    check(employee, employee2);
  }

  @Test
  public void testSingleEntityWriter() throws IOException {
    Employee employee = makeEmployee();

    StringWriter out = new StringWriter();
    flatpack.getPacker().append(employee, null, out);

    StringReader in = new StringReader(out.toString());
    Employee employee2 = flatpack.getUnpacker().read(Employee.class, in, null);

    check(employee, employee2);
  }
View Full Code Here

  @Test
  public void testReadWriteProperties() {
    assertEquals("employee", employeeCodex.describe().getName());

    Employee e1 = makeEmployee();

    StringWriter out = new StringWriter();
    serializationContext(out);
    try {
      visitors.visit(writers.get(), e1);
    } finally {
      closeContext();
    }

    JsonObject obj = new JsonParser().parse(out.toString()).getAsJsonObject();
    // Check embedded properties
    assertFalse(obj.has("address"));
    assertTrue(obj.has("street"));

    Employee e2;
    DeserializationContext d = deserializationContext();
    try {
      e2 = employeeCodex.allocate(obj, d);

      PackReader reader = readers.get();
      reader.setPayload(obj);
      visitors.visit(reader, e2);

      // Check referential integrity
      assertSame(e2, employeeCodex.read(new JsonPrimitive(e2.getUuid().toString()), d));
    } finally {
      d.runPostWork();
      closeContext();
    }
View Full Code Here

    JsonObject obj = new JsonObject();
    obj.addProperty("uuid", uuid.toString());
    obj.addProperty("writeOnlyProperty", "Hello World!");

    Employee e;
    DeserializationContext d = deserializationContext();
    try {
      e = employeeCodex.allocate(obj, d);
      PackReader reader = readers.get();
      reader.setPayload(obj);
View Full Code Here

public class FlatPackEntityMergeTest extends FlatPackTest {

  @Test
  public void test() throws IOException {
    Employee e1 = makeEmployee();
    Employee e2 = makeEmployee();

    JsonElement j1 = flatpack.getPacker().pack(FlatPackEntity.entity(e1));
    JsonElement j2 = flatpack.getPacker().pack(FlatPackEntity.entity(e2));

    JsonObject merged = FlatPackEntityMerge.merge(j2, j1).getAsJsonObject();

    assertEquals(2, merged.entrySet().size());
    assertEquals(e1.getUuid().toString(), merged.get("value").getAsString());
    JsonArray employeeArray = merged.get("data").getAsJsonObject().get("employee").getAsJsonArray();
    assertEquals(2, employeeArray.size());

    FlatPackEntity<Employee> entity =
        flatpack.getUnpacker().<Employee> unpack(Employee.class, merged, null);
    Employee u1 = entity.getValue();
    assertEquals(e1, u1);
    assertEquals(2, entity.getExtraEntities().size());
  }
View Full Code Here

  @Inject
  private TypeLiteral<StringMapCodex<UUID, String>> uuidString;

  @Test
  public void testEntities() {
    Employee e = makeEmployee();
    Map<Employee, String> map = Collections.singletonMap(e, e.getUuid().toString());

    Set<HasUuid> scanned = FlatPackCollections.setForIteration();
    Map<Employee, String> map2 = testCodex(employeeString, map, scanned);

    assertEquals(map, map2);
View Full Code Here

  @Test
  public void test() {
    // Create a cyclic datastructure
    Manager manager = makeManager();
    Employee employee = makeEmployee();

    manager.setEmployees(Collections.singletonList(employee));
    employee.setManager(manager);

    MyVisitor visitor = new MyVisitor();
    visitors.visit(visitor, employee);
    assertTrue(visitor.sawEmployee);
    assertTrue(visitor.sawManager);
View Full Code Here

TOP

Related Classes of com.getperka.flatpack.domain.Employee

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.