Examples of HasOneToManyMapJPA


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

* Simple tests for persisting/retrieving maps in JPA.
*/
public class JPAMapTest extends JPATestCase {

  public void testInsert() {
    HasOneToManyMapJPA pojo = new HasOneToManyMapJPA();
    pojo.setVal("First");
    Book book1 = new Book();
    book1.setAuthor("Billy Nomates");
    book1.setTitle("Lonely Time");
    book1.setFirstPublished(1981);
    pojo.getBooksByName().put(book1.getTitle(), book1);

    pojo.getBasicMap().put(1, "First Entry");
    pojo.getBasicMap().put(2, "Second Entry");

    // Persist it
    String bookId = null;
    String pojoId = null;
    beginTxn();
    em.persist(pojo);
    commitTxn();
    pojoId = pojo.getId();
    bookId = book1.getId();
    em.clear();

    // Retrieve it and validate
    beginTxn();
    HasOneToManyMapJPA pojo2 = em.find(HasOneToManyMapJPA.class, pojoId);
    assertNotNull(pojo2);

    Map<String, Book> booksByName = pojo2.getBooksByName();
    assertNotNull(booksByName);
    assertEquals("Number of elements in first map is wrong", 1, booksByName.size());
    assertTrue(booksByName.containsKey("Lonely Time"));
    Book bk = booksByName.get("Lonely Time");
    assertEquals("Book id is incorrect", bookId, bk.getId());
    assertEquals("Book published is wrong", 1981, bk.getFirstPublished());

    Map<Integer, String> basicMap = pojo2.getBasicMap();
    assertNotNull(basicMap);
    assertEquals("Number of elements in second map is wrong", 2, basicMap.size());
    assertTrue(basicMap.containsKey(1));
    assertEquals("First Entry", basicMap.get(1));
    assertTrue(basicMap.containsKey(2));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.