Package com.google.appengine.datanucleus.test.jdo

Examples of com.google.appengine.datanucleus.test.jdo.HasStringAncestorStringPkJDO


  public void testUpdateStrAncestor_SetNewName() {
    Key parentKey = ds.put(new Entity(String.class.getSimpleName()));
    Key key = ds.put(new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), parentKey));

    beginTxn();
    HasStringAncestorStringPkJDO pojo = pm.getObjectById(HasStringAncestorStringPkJDO.class, KeyFactory.keyToString(key));
    pojo.setAncestorId("other");
    try {
      commitTxn();
      fail("expected exception");
    } catch (JDOFatalUserException e) {
      // good
View Full Code Here


  public void testUpdateStrAncestor_SetNewKey() {
    Key parentKey = ds.put(new Entity(Flight.class.getSimpleName()));
    Key key = ds.put(new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), parentKey));

    beginTxn();
    HasStringAncestorStringPkJDO pojo = pm.getObjectById(HasStringAncestorStringPkJDO.class, KeyFactory.keyToString(key));
    pojo.setAncestorId(KeyFactory.keyToString(KeyFactory.createKey(key.getKind(), 33)));

    try {
      commitTxn();
      fail("expected exception");
    } catch (JDOFatalUserException e) {
View Full Code Here

  public void testUpdateStrAncestor_NullKey() {
    Key parentKey = ds.put(new Entity(Flight.class.getSimpleName()));
    Key key = ds.put(new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), parentKey));

    beginTxn();
    HasStringAncestorStringPkJDO pojo = pm.getObjectById(HasStringAncestorStringPkJDO.class, KeyFactory.keyToString(key));
    pojo.setAncestorId(null);
    try {
      commitTxn();
      fail("expected exception");
    } catch (JDOFatalUserException e) {
      // good
View Full Code Here

    commitTxn();
  }

  public void testOneToOnePersistChildWithAncestorCascadeAll() throws EntityNotFoundException {
    HasOneToOnesWithDifferentCascadesJDO parent = new HasOneToOnesWithDifferentCascadesJDO();
    HasStringAncestorStringPkJDO child = new HasStringAncestorStringPkJDO();
    parent.setCascadeAllChild(child);

    beginTxn();
    pm.makePersistent(parent);
    commitTxn();

    beginTxn();
    parent = pm.getObjectById(HasOneToOnesWithDifferentCascadesJDO.class, parent.getId());
    assertNotNull(parent.getCascadeAllChild());
    child = pm.getObjectById(HasStringAncestorStringPkJDO.class, child.getId());
    assertEquals(parent.getId(), child.getAncestorId());
    commitTxn();

    Entity childEntity = ds.get(KeyFactory.stringToKey(child.getId()));
    assertKeyParentEquals(parent.getId(), childEntity, childEntity.getKey());
  }
View Full Code Here

    HasOneToOnesWithDifferentCascadesJDO anotherParent = new HasOneToOnesWithDifferentCascadesJDO();
    beginTxn();
    pm.makePersistent(anotherParent);
    commitTxn();

    HasStringAncestorStringPkJDO child = new HasStringAncestorStringPkJDO(anotherParent.getId());
    parent.setCascadeAllChild(child);

    beginTxn();
    try {
      pm.makePersistent(parent);
View Full Code Here

  public void testInsert_IdGen() {
    Entity flightEntity = Flight.newFlightEntity("max", "bos", "mia", 3, 4);
    ds.put(flightEntity);
    Key flightKey = flightEntity.getKey();
    HasStringAncestorStringPkJDO ha = new HasStringAncestorStringPkJDO(KeyFactory.keyToString(flightKey));
    makePersistentInTxn(ha, TXN_START_END);
    Key keyWithParent = KeyFactory.stringToKey(ha.getId());
    assertEquals(flightKey, keyWithParent.getParent());
    // now we'll issue an ancestor query directly against the datastore and see
    // if our object comes back.
    Query q = new Query(ha.getClass().getSimpleName());
    q.setAncestor(flightKey);
    Entity result = ds.prepare(q).asSingleEntity();
    assertEquals(flightKey, result.getKey().getParent());
  }
View Full Code Here

  public void testInsert_NamedKey() {
    Entity flightEntity = Flight.newFlightEntity("parent named key", "max", "bos", "mia", 3, 4);
    ds.put(flightEntity);
    Key flightKey = flightEntity.getKey();
    Key key = new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), "named key", flightKey).getKey();
    HasStringAncestorStringPkJDO ha = new HasStringAncestorStringPkJDO(null, KeyFactory.keyToString(key));
    makePersistentInTxn(ha, TXN_START_END);
    Key keyWithParent = KeyFactory.stringToKey(ha.getId());
    assertEquals(flightKey, keyWithParent.getParent());
    // now we'll issue an ancestor query directly against the datastore and see
    // if our object comes back.
    Query q = new Query(ha.getClass().getSimpleName());
    q.setAncestor(flightKey);
    Entity result = ds.prepare(q).asSingleEntity();
    assertEquals(flightKey, result.getKey().getParent());
    assertEquals("named key", result.getKey().getName());
    assertEquals("parent named key", result.getKey().getParent().getName());
View Full Code Here

  public void testInsert_SetAncestorAndPk() {
    Entity flightEntity = Flight.newFlightEntity("parent named key", "max", "bos", "mia", 3, 4);
    ds.put(flightEntity);
    Key flightKey = flightEntity.getKey();
    HasStringAncestorStringPkJDO ha = new HasStringAncestorStringPkJDO(
        KeyFactory.keyToString(flightKey),
        KeyFactory.keyToString(KeyFactory.createKey(HasStringAncestorStringPkJDO.class.getSimpleName(), "named key")));
    beginTxn();
    try {
      pm.makePersistent(ha);
View Full Code Here

    ds.put(flightEntity);
    Entity hasAncestorEntity = new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), flightEntity.getKey());
    ds.put(hasAncestorEntity);

    beginTxn();
    HasStringAncestorStringPkJDO ha = pm.getObjectById(HasStringAncestorStringPkJDO.class, KeyFactory.keyToString(hasAncestorEntity.getKey()));
    assertEquals(KeyFactory.keyToString(flightEntity.getKey()), ha.getAncestorId());
    commitTxn();
  }
View Full Code Here

    Entity hasAncestorEntity =
        new Entity(HasStringAncestorStringPkJDO.class.getSimpleName(), "named key", flightEntity.getKey());
    ds.put(hasAncestorEntity);

    beginTxn();
    HasStringAncestorStringPkJDO ha = pm.getObjectById(HasStringAncestorStringPkJDO.class, KeyFactory.keyToString(hasAncestorEntity.getKey()));
    assertEquals(KeyFactory.keyToString(flightEntity.getKey()), ha.getAncestorId());
    assertEquals("named key", KeyFactory.stringToKey(ha.getId()).getName());
    assertEquals("parent named key", KeyFactory.stringToKey(ha.getId()).getParent().getName());
    commitTxn();
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jdo.HasStringAncestorStringPkJDO

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.