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

Examples of com.google.appengine.datanucleus.test.jpa.HasEmbeddedJPA


* @author Max Ross <maxr@google.com>
*/
public class JPAEmbeddedTest extends JPATestCase {

  public void testEmbedded() throws EntityNotFoundException {
    HasEmbeddedJPA pojo = new HasEmbeddedJPA();
    EmbeddableJPA embedded = new EmbeddableJPA();
    embedded.setEmbeddedString("yar");
    embedded.setMultiVal(Utils.newArrayList("m1", "m2"));
    pojo.setEmbeddable(embedded);
    embedded = new EmbeddableJPA();
    embedded.setEmbeddedString("yar2");
    embedded.setMultiVal(Utils.newArrayList("m3", "m4"));
    pojo.setEmbeddable2(embedded);
    beginTxn();
    em.persist(pojo);
    commitTxn();
    assertEquals(1, countForClass(HasEmbeddedJPA.class));
    Entity e = ds.get(KeyFactory.createKey(pojo.getClass().getSimpleName(), pojo.getId()));
    assertEquals("yar", e.getProperty("embeddedString"));
    assertEquals(Utils.newArrayList("m1", "m2"), e.getProperty("multiVal"));
    assertEquals("yar2", e.getProperty("EMBEDDEDSTRING"));
    assertEquals(Utils.newArrayList("m3", "m4"), e.getProperty("MULTIVAL"));
    beginTxn();
    pojo = em.find(HasEmbeddedJPA.class, pojo.getId());
    assertNotNull(pojo.getEmbeddable());
    assertEquals("yar", pojo.getEmbeddable().getEmbeddedString());
    assertEquals(Utils.newArrayList("m1", "m2"), pojo.getEmbeddable().getMultiVal());
    assertEquals("yar2", pojo.getEmbeddable2().getEmbeddedString());
    assertEquals(Utils.newArrayList("m3", "m4"), pojo.getEmbeddable2().getMultiVal());
    commitTxn();
  }
View Full Code Here


    assertEquals(Utils.newArrayList("m3", "m4"), pojo.getEmbeddable2().getMultiVal());
    commitTxn();
  }

  public void testEmbeddedWithKeyPk_NullEmbedded() {
    HasEmbeddedJPA pojo = new HasEmbeddedJPA();
    beginTxn();
    em.persist(pojo);
    commitTxn();
    em.clear();

    beginTxn();
    pojo = em.find(HasEmbeddedJPA.class, pojo.getId());
    assertNull(pojo.getEmbeddable());
    assertNull(pojo.getEmbeddable2());
    commitTxn();
  }
View Full Code Here

    assertNull(pojo.getEmbeddable2());
    commitTxn();
  }

  public void testEmbeddedWithKeyPk_AddEmbeddedToExistingParent() {
    HasEmbeddedJPA pojo = new HasEmbeddedJPA();
    beginTxn();
    em.persist(pojo);
    commitTxn();

    EmbeddableJPA embeddable = new EmbeddableJPA();
    embeddable.setEmbeddedString("yar");
    EmbeddableJPA embeddable2 = new EmbeddableJPA();
    embeddable2.setEmbeddedString("yar2");
    beginTxn();
    pojo.setEmbeddable(embeddable);
    pojo.setEmbeddable2(embeddable2);
    pojo = em.find(HasEmbeddedJPA.class, pojo.getId()); // Finds it in L1 cache from first txn (but with fields set now)
    assertNotNull(pojo.getEmbeddable());
    assertNotNull(pojo.getEmbeddable().getEmbeddedString());
    assertNotNull(pojo.getEmbeddable2());
    assertNotNull(pojo.getEmbeddable2().getEmbeddedString());
    commitTxn(); // Flushes the changes to embeddable fields

    beginTxn();
    pojo = em.find(HasEmbeddedJPA.class, pojo.getId());
    assertNotNull(pojo.getEmbeddable());
    assertEquals("yar", pojo.getEmbeddable().getEmbeddedString());
    assertNotNull(pojo.getEmbeddable2());
    assertEquals("yar2", pojo.getEmbeddable2().getEmbeddedString());
    commitTxn();
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.HasEmbeddedJPA

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.