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

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


* Some simple tests where we have a Map field in the persistable object.
*/
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));
    assertEquals("First Entry", map2.get(1));
    assertTrue(map2.containsKey(2));
View Full Code Here

TOP

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

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.