Ejemplo n.º 1
0
  @Test
  public void testMarshall_Embedded() {
    RootEntity rootObject = new RootEntity(); // one entity
    ChildEntity childObject = new ChildEntity("Test City");
    ChildEntity embeddedObject = new ChildEntity("Old Test City");
    embeddedObject.setId(1L);
    embeddedObject.setType("EmbeddedType");
    rootObject.setId("TestUser");
    rootObject.setCount(25);
    childObject.setParent(rootObject);
    rootObject.setNewChildEntity(childObject); // one entity
    rootObject.setEmbeddedEntity(embeddedObject); // not included, @Embedded

    IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, rootObject);

    Entity rootObjectEntity = stack.get(rootObject);
    Entity childObjectEntity = stack.get(childObject);

    EmbeddedEntity ee = (EmbeddedEntity) rootObjectEntity.getProperty("embeddedEntity");
    Key childKey = (Key) rootObjectEntity.getProperty("newChildEntity");
    Key parentKey = childKey.getParent();

    assertEquals(2, stack.size());
    assertNotNull(parentKey);
    assertEquals(EmbeddedEntity.class, ee.getClass());
    assertTrue(childKey instanceof Key);
    assertEquals(rootObjectEntity.getKey().getId(), parentKey.getId());
    assertEquals(rootObjectEntity.getKey().getName(), parentKey.getName());

    assertEquals(1L, ee.getProperties().get("id"));
    assertEquals("EmbeddedType", ee.getProperties().get("type"));
  }
Ejemplo n.º 2
0
  @Test
  public void test_Marshall_List() {
    Post post = new Post();
    post.setTags(list("tag1", "tag2", "tag3"));

    IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, post);
    Entity e = stack.get(post);
    Object tags = e.getProperty("tags");

    assertNotNull(e);
    assertTrue(tags instanceof List);
    assertEquals("tag1", ((List) tags).get(0));
    assertEquals("tag2", ((List) tags).get(1));
    assertEquals("tag3", ((List) tags).get(2));
  }
Ejemplo n.º 3
0
  @Test
  public void testMarshall_Child() {
    RootEntity rootObject = new RootEntity(); // one entity
    ChildEntity childObject = new ChildEntity("Test City");
    rootObject.setId("TestUser");
    rootObject.setCount(25);
    childObject.setParent(rootObject);
    rootObject.setNewChildEntity(childObject); // one entity

    IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, rootObject);

    Entity rootObjectEntity = stack.get(rootObject);
    Entity childObjectEntity = stack.get(childObject);

    Key childKey = (Key) rootObjectEntity.getProperty("newChildEntity");
    Key parentKey = childKey.getParent();

    assertEquals(2, stack.size());
    assertNotNull(parentKey);
    assertTrue(childKey instanceof Key);
    assertEquals(rootObjectEntity.getKey().getId(), parentKey.getId());
    assertEquals(rootObjectEntity.getKey().getName(), parentKey.getName());
  }
Ejemplo n.º 4
0
  @Test
  public void test() {
    Entity parent = new Entity("Parent");
    // set parent properties...
    List<EmbeddedEntity> children = new ArrayList<EmbeddedEntity>();
    for (int i = 0; i < 5; i++) {
      EmbeddedEntity child = new EmbeddedEntity();
      // set child properties...
      children.add(child);
    }
    parent.setUnindexedProperty("children", children);
    parent.setUnindexedProperty("children2", list("tag1", "tag2", "tag3"));

    DatastoreServiceFactory.getDatastoreService().put(parent);

    try {
      Entity e = DatastoreServiceFactory.getDatastoreService().get(parent.getKey());
      e.getKey();
      Object children2 = e.getProperty("children2");
      assertTrue(children2 instanceof List);
    } catch (EntityNotFoundException e1) {
      e1.printStackTrace();
    }
  }