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

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


public class JDOMapTest extends JDOTestCase {

  public void testInsert() {
    HasOneToManyMapJDO pojo = new HasOneToManyMapJDO();
    pojo.setVal("First");
    Flight fl = new Flight("LHR", "CHI", "BA201", 1, 15);
    pojo.addFlight(fl.getName(), fl);
    Flight fl2 = new Flight("BCN", "MAD", "IB3311", 2, 26);
    pojo.addFlight(fl2.getName(), fl2);
    pojo.addBasicEntry(1, "First Entry");
    pojo.addBasicEntry(2, "Second Entry");

    Object id = null;
    beginTxn();
    pm.makePersistent(pojo);
    pm.flush();
    id = JDOHelper.getObjectId(pojo);
    commitTxn();
    pm.evictAll(); // Make sure not cached

    beginTxn();
    HasOneToManyMapJDO pojoRead = (HasOneToManyMapJDO)pm.getObjectById(id);

    Map<String, Flight> map1 = pojoRead.getFlightsByName();
    assertNotNull("Map<String,Flight> is null!", map1);
    assertEquals(2, map1.size());
    assertTrue(map1.containsKey("BA201"));
    Flight fl11 = map1.get("BA201");
    assertEquals("LHR", fl11.getOrigin());
    assertEquals("CHI", fl11.getDest());
    assertTrue(map1.containsKey("IB3311"));
    Flight fl12 = map1.get("IB3311");
    assertEquals("BCN", fl12.getOrigin());
    assertEquals("MAD", fl12.getDest());

    Map<Integer, String> map2 = pojoRead.getBasicMap();
    assertNotNull("Map<Integer,String> is null!", map2);
    assertEquals(2, map2.size());
    assertTrue(map2.containsKey(1));
View Full Code Here


  public void testDeletePersistentAll_NoTxn() {
    switchDatasource(PersistenceManagerFactoryName.nontransactional);
    Key k1 = ds.put(newFlightEntity());
    Key k2 = ds.put(newFlightEntity());
    Flight f1 = pm.getObjectById(Flight.class, k1);
    Flight f2 = pm.getObjectById(Flight.class, k2);
    pm.deletePersistentAll(f1, f2);
    assertEquals(0, countForClass(Flight.class));
    assertEquals(1, batchRecorder.batchOps);

    Key k3 = ds.put(newFlightEntity());
    Key k4 = ds.put(newFlightEntity());
    Flight f3 = pm.getObjectById(Flight.class, k3);
    Flight f4 = pm.getObjectById(Flight.class, k4);
    pm.deletePersistentAll(Utils.newArrayList(f3, f4));
    assertEquals(0, countForClass(Flight.class));
    assertEquals(2, batchRecorder.batchOps);
  }
View Full Code Here

  }

  public void testDeletePersistentAll_OneEntity_NoTxn() {
    switchDatasource(PersistenceManagerFactoryName.nontransactional);
    Key k1 = ds.put(newFlightEntity());
    Flight f1 = pm.getObjectById(Flight.class, k1);
    pm.deletePersistentAll(f1);
    assertEquals(0, countForClass(Flight.class));
    assertEquals(0, batchRecorder.batchOps);

    Key k2 = ds.put(newFlightEntity());
    Flight f2 = pm.getObjectById(Flight.class, k2);
    pm.deletePersistentAll(Utils.newArrayList(f2));
    assertEquals(0, countForClass(Flight.class));
    assertEquals(0, batchRecorder.batchOps);
  }
View Full Code Here

  public void testDeletePersistentAll_Txn_MultipleEntityGroups() {
    switchDatasource(PersistenceManagerFactoryName.transactional);
    Key k1 = ds.put(newFlightEntity());
    Key k2 = ds.put(newFlightEntity());
    beginTxn();
    Flight f1 = pm.getObjectById(Flight.class, k1);
    commitTxn();
    beginTxn();
    Flight f2 = pm.getObjectById(Flight.class, k2);
    commitTxn();
    beginTxn();
    try {
      pm.deletePersistentAll(f1, f2);
      fail("expected exception");
    } catch (JDOUserException e) {
      // good
    }
    rollbackTxn();
    assertEquals(2, countForClass(Flight.class));
    // We don't get to the batch delete because we blow up
    // before we get there.
    assertEquals(0, batchRecorder.batchOps);

    Key k3 = ds.put(newFlightEntity());
    Key k4 = ds.put(newFlightEntity());
    beginTxn();
    Flight f3 = pm.getObjectById(Flight.class, k3);
    commitTxn();
    beginTxn();
    Flight f4 = pm.getObjectById(Flight.class, k4);
    commitTxn();
    beginTxn();
    try {
      pm.deletePersistentAll(Utils.newArrayList(f3, f4));
      fail("expected exception");
View Full Code Here

  public void testDeletePersistentAll_OneEntity_Txn() {
    switchDatasource(PersistenceManagerFactoryName.transactional);
    Key k1 = ds.put(newFlightEntity());
    beginTxn();
    Flight f1 = pm.getObjectById(Flight.class, k1);
    pm.deletePersistentAll(f1);
    commitTxn();
    assertEquals(0, countForClass(Flight.class));
    assertEquals(0, batchRecorder.batchOps);

    Key k2 = ds.put(newFlightEntity());
    beginTxn();
    Flight f2 = pm.getObjectById(Flight.class, k2);
    pm.deletePersistentAll(Utils.newArrayList(f2));
    commitTxn();
    assertEquals(0, countForClass(Flight.class));
    assertEquals(0, batchRecorder.batchOps);
  }
View Full Code Here

  }

  public void testInsertWithCustomIdPolicy() throws EntityNotFoundException {
    setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase");

    Flight f1 = new Flight();
    f1.setOrigin("BOS");
    f1.setDest("MIA");
    f1.setMe(2);
    f1.setYou(4);
    f1.setName("Harold");
    f1.setFlightNumber(400);
    pm.makePersistent(f1);
    Entity entity = ds.get(KeyFactory.stringToKey(f1.getId()));
    assertNotNull(entity);
    assertEquals("PREFIX" + Flight.class.getSimpleName().toUpperCase() + "SUFFIX", entity.getKind());
    assertEquals("Harold", entity.getProperty("NAME"));
    // column name isn't generated if explicitly set
    assertEquals(400L, entity.getProperty("flight_number"));
View Full Code Here

    assertEquals(1, countForClass(Flight.class));
  }

  public void testDeleteCascades() {
    HasOneToManyListJDO parent = new HasOneToManyListJDO();
    Flight f = new Flight();
    parent.getFlights().add(f);
    beginTxn();
    pm.makePersistent(parent);
    commitTxn();
    assertEquals(1, countForClass(Flight.class));
View Full Code Here

  }

  public void testQueryWithCustomIdPolicy() {
    setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase");

    Flight f1 = new Flight();
    f1.setOrigin("BOS");
    f1.setDest("MIA");
    f1.setMe(2);
    f1.setYou(4);
    f1.setName("Harold");
    f1.setFlightNumber(400);
    pm.makePersistent(f1);

    Flight f2 = new Flight();
    f2.setOrigin("BOS");
    f2.setDest("MIA");
    f2.setMe(2);
    f2.setYou(4);
    f2.setName("Harold2");
    f2.setFlightNumber(401);
    pm.makePersistent(f2);

    Query q = pm.newQuery("select from " + Flight.class.getName()
        + " where flightNumber > 300 "
        + " order by flightNumber desc");
View Full Code Here

  public void testSimpleUpdate() throws EntityNotFoundException {
    Key key = ds.put(Flight.newFlightEntity("1", "yam", "bam", 1, 2));

    String keyStr = KeyFactory.keyToString(key);
    beginTxn();
    Flight flight = pm.getObjectById(Flight.class, keyStr);

    assertEquals(keyStr, flight.getId());
    assertEquals("yam", flight.getOrigin());
    assertEquals("bam", flight.getDest());
    assertEquals("1", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());

    flight.setName("2");
    commitTxn();

    Entity flightCheck = ds.get(key);
    assertEquals("yam", flightCheck.getProperty("origin"));
    assertEquals("bam", flightCheck.getProperty("dest"));
View Full Code Here

  public void testSimpleUpdateWithNamedKey() throws EntityNotFoundException {
    Key key = ds.put(Flight.newFlightEntity("named key", "1", "yam", "bam", 1, 2));

    String keyStr = KeyFactory.keyToString(key);
    beginTxn();
    Flight flight = pm.getObjectById(Flight.class, keyStr);

    assertEquals(keyStr, flight.getId());
    assertEquals("yam", flight.getOrigin());
    assertEquals("bam", flight.getDest());
    assertEquals("1", flight.getName());
    assertEquals(1, flight.getYou());
    assertEquals(2, flight.getMe());

    flight.setName("2");
    commitTxn();

    Entity flightCheck = ds.get(key);
    assertEquals("yam", flightCheck.getProperty("origin"));
    assertEquals("bam", flightCheck.getProperty("dest"));
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.