Package com.google.appengine.datanucleus.test.jpa.UnidirectionalOneToManySubclassesJPA

Examples of com.google.appengine.datanucleus.test.jpa.UnidirectionalOneToManySubclassesJPA.SuperParentWithSubChild


    assertEquals(0, countForClass(superChild.getClass()));
  }

  public void testSuperParentWithSubChild() throws EntityNotFoundException {
    // insertion
    SuperParentWithSubChild parent = new SuperParentWithSubChild();
    parent.setSuperParentString("super parent string");

    SubChild subChild = new SubChild();
    subChild.setAString("a string");
    subChild.setBString("b string");
    parent.getSuperParentSubChildren().add(subChild);

    beginTxn();
    em.persist(parent);
    commitTxn();
    Entity parentEntity =
        ds.get(KeyFactory.createKey(kindForClass(parent.getClass()), parent.getId()));
    Entity superParentSubChildEntity = ds.get(subChild.getId());
    assertEquals(2, parentEntity.getProperties().size());
    assertEquals("super parent string", parentEntity.getProperty("superParentString"));
    assertEquals(Collections.singletonList(superParentSubChildEntity.getKey()), parentEntity.getProperty("subChildren"));

    assertEquals(2, superParentSubChildEntity.getProperties().size());
    assertEquals("a string", superParentSubChildEntity.getProperty("aString"));
    assertEquals("b string", superParentSubChildEntity.getProperty("bString"));

    // lookup
    beginTxn();
    parent = em.find(parent.getClass(), parent.getId());
    assertEquals("super parent string", parent.getSuperParentString());
    assertEquals(1, parent.getSuperParentSubChildren().size());
    assertEquals(subChild.getId(), parent.getSuperParentSubChildren().get(0).getId());
    commitTxn();

    beginTxn();
    subChild = em.find(subChild.getClass(), subChild.getId());
    assertEquals("a string", subChild.getAString());
    assertEquals("b string", subChild.getBString());
    commitTxn();

    // cascade delete
    beginTxn();
    em.remove(em.merge(parent));
    commitTxn();

    assertEquals(0, countForClass(parent.getClass()));
    assertEquals(0, countForClass(subChild.getClass()));
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.UnidirectionalOneToManySubclassesJPA.SuperParentWithSubChild

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.