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

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


    }
  }

  void testNonTxnAddOfChildToParentFailsPartwayThrough(HasOneToManyJDO pojo)
      throws Throwable {
    Flight flight1 = new Flight();
    pojo.addFlight(flight1);
    beginTxn();
    pm.makePersistent(pojo);
    commitTxn();
    final String kind = kindForObject(pojo);
    DatastoreServiceInterceptor.Policy policy = new DatastoreServiceInterceptor.Policy() {
      public void intercept(Object o, Method method, Object[] params) {
        if (method.getName().equals("put") && ((Entity) params[0]).getKind().equals(kind)) {
          throw new ConcurrentModificationException("kaboom");
        }
      }
    };
    DatastoreServiceInterceptor.install(getStoreManager(), policy);
    Flight flight2 = new Flight();
    try {
      pmf.close();
      switchDatasource(PersistenceManagerFactoryName.nontransactional);
      pojo = pm.getObjectById(pojo.getClass(), pojo.getId());
      pojo.addFlight(flight2);
      pm.close();
      fail("expected exception");
    } catch (ConcurrentModificationException cme) {
      // good
    } finally {
      DatastoreServiceInterceptor.uninstall();
    }
    // prove that the book entity exists
    ds.get(KeyFactory.stringToKey(flight2.getId()));
    Entity pojoEntity = ds.get(KeyFactory.stringToKey(pojo.getId()));
    // the parent has a reference to the first book that was already there
    // but no reference to the second book
    assertEquals(
        Collections.singletonList(KeyFactory.stringToKey(flight1.getId())),
View Full Code Here


    assertEquals(
        HasKeyPkJDO.class.getName(), expectedChildren, countForClass(HasKeyPkJDO.class));
  }

  Flight newFlight() {
    Flight f = new Flight();
    f.setOrigin("bos");
    f.setDest("mia");
    f.setName("jimmy");
    f.setMe(22);
    f.setYou(26);
    f.setFlightNumber(99);
    return f;
  }
View Full Code Here

  public void testSimpleFetch_Id() {
    Key key = ds.put(Flight.newFlightEntity("1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();
    String keyStr = KeyFactory.keyToString(key);
    Flight flight = pm.getObjectById(Flight.class, keyStr);
    assertNotNull(flight);
    assertEquals(keyStr, flight.getId());
    assertEquals("yam", flight.getOrigin());
    assertEquals("bam", flight.getDest());
    assertEquals("1", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());
  }
View Full Code Here

  public void testSimpleFetch_Id_LongIdOnly() {
    Key key = ds.put(Flight.newFlightEntity("1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();

    Flight flight = pm.getObjectById(Flight.class, key.getId());
    assertNotNull(flight);
    String keyStr = KeyFactory.keyToString(key);
    assertEquals(keyStr, flight.getId());
    assertEquals("yam", flight.getOrigin());
    assertEquals("bam", flight.getDest());
    assertEquals("1", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());
  }
View Full Code Here

  public void testSimpleFetch_Id_IntIdOnly() {
    Key key = ds.put(Flight.newFlightEntity("1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();

    Flight flight = pm.getObjectById(Flight.class, Long.valueOf(key.getId()).intValue());
    assertNotNull(flight);
    String keyStr = KeyFactory.keyToString(key);
    assertEquals(keyStr, flight.getId());
    assertEquals("yam", flight.getOrigin());
    assertEquals("bam", flight.getDest());
    assertEquals("1", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());
  }
View Full Code Here

    Key key = ds.put(Flight.newFlightEntity("named key", "1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();

    String keyStr = KeyFactory.keyToString(key);
    Flight flight = pm.getObjectById(Flight.class, keyStr);
    assertNotNull(flight);
    assertEquals(keyStr, flight.getId());
    assertEquals("named key", KeyFactory.stringToKey(flight.getId()).getName());
  }
View Full Code Here

  public void testSimpleFetch_NamedKey_NameOnly() {
    Key key = ds.put(Flight.newFlightEntity("named key", "1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();

    Flight flight = pm.getObjectById(Flight.class, "named key");
    assertNotNull(flight);
    assertEquals(KeyFactory.keyToString(key), flight.getId());
    assertEquals("named key", KeyFactory.stringToKey(flight.getId()).getName());
  }
View Full Code Here

    e.setProperty("you", Integer.MAX_VALUE + 1L);
    ds.put(e);
    commitTxn();
    beginTxn();

    Flight f = pm.getObjectById(Flight.class, "yar");
    // no exception, just overflow
    assertEquals(-2147483648, f.getYou());
  }
View Full Code Here

  public void testSimpleFetch_NamedKey_NameOnly_NewObjectIdInstance() {
    Key key = ds.put(Flight.newFlightEntity("named key", "1", "yam", "bam", 1, 2));
    commitTxn();
    beginTxn();

    Flight flight = (Flight) pm.getObjectById(pm.newObjectIdInstance(Flight.class, "named key"));
    assertNotNull(flight);
    assertEquals(KeyFactory.keyToString(key), flight.getId());
    assertEquals("named key", KeyFactory.stringToKey(flight.getId()).getName());
  }
View Full Code Here

  public void testSimplePersistGetObjectById() {
    commitTxn();
    DatastoreServiceInterceptor.uninstall();

    beginTxn();
    Flight fl = new Flight("LHR", "CHI", "BA201", 1, 2);
    pm.makePersistent(fl);
    commitTxn();
    Object id = pm.getObjectId(fl);
    String idKey = ((StringIdentity)id).getKey();
    pm.evictAll();
    pmf.getDataStoreCache().evictAll();

    beginTxn();
    Flight flight = (Flight)pm.getObjectById(id);
    assertNotNull(flight);
    assertEquals(idKey, flight.getId());
    assertEquals("LHR", flight.getOrigin());
    assertEquals("CHI", flight.getDest());
    assertEquals("BA201", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());
  }
View Full Code Here

TOP

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

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.