示例#1
0
  @Test
  public void testContaiment() throws Exception {
    Data initData = createData();
    Emf2Json emf2Json = new Emf2Json(JsontestPackage.eINSTANCE);
    JsonObject jsonObject = emf2Json.serialize(initData);

    Data data = (Data) emf2Json.deserialize(jsonObject);

    assertTrue(EcoreUtil.equals(initData, data));

    assertEquals(jsonObject.toString(), emf2Json.serialize(data).toString());
    assertEquals("@//towns.1/users.0", ((JsonPrimitive) jsonObject.get("admin")).getAsString());
    assertEquals(data.getTowns().get(1).getUsers().get(0), data.getAdmin());
  }
示例#2
0
  private Data createData() {

    JsontestFactory f = JsontestFactory.eINSTANCE;

    Data data = f.createData();

    Town novos = newTown("Novosibirsk", TownKind.BIG, 320);
    Town kem = newTown("Kemerovo", TownKind.SMALL, 480);
    Town omsk = newTown("Omsk", null, 590);

    EList<Town> towns = data.getTowns();
    towns.add(novos);
    towns.add(kem);
    towns.add(omsk);

    User ivan = newUser("Ivan");
    User egor = newUser("Egor");
    User vitya = newUser("Vitya");
    User dasha = newUser("Dasha");
    User anton = newUser("Anton");
    User vova = newUser("Vova");

    addRoles(ivan, "admin", "user");
    addRoles(egor, "admin", "manager");
    addRoles(vitya, "psycho", "manager", "sales");
    addRoles(dasha, "manager", "dummy");
    addRoles(anton, "admin", "sales");
    addRoles(vova, "sales");

    addUser(novos, ivan, vitya);
    addUser(kem, egor, dasha);
    addUser(omsk, anton, vova);

    data.setAdmin(egor);

    return data;
  }