Package com.google.appengine.datanucleus.test.jpa

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


    DatastoreServiceInterceptor.uninstall();

    Query q = em.createQuery("select b from bookalias b where title = 'yam'");
    assertTrue(q.getResultList().isEmpty());

    Book b = new Book();
    b.setTitle("yam");
    beginTxn();
    em.persist(b);
    commitTxn();

    assertEquals(b, q.getResultList().get(0));
View Full Code Here


    Query q = em.createQuery("select from " + Book.class.getName() + " c" + " where title = 'y'");
    assertTrue(q.getResultList().isEmpty());

    Entity e = Book.newBookEntity("author", "12345", "y");
    ds.put(e);
    Book b = (Book) q.getSingleResult();
    assertEquals(e.getKey(), KeyFactory.stringToKey(b.getId()));
  }
View Full Code Here

    ds.put(e);

    Query query = em.createQuery("SELECT b FROM " + Book.class.getName() + " b WHERE b.title = :title");
    query.setParameter("title", "y");
    query.setFirstResult(1);
    Book b = (Book) query.getSingleResult();
    assertEquals(e.getKey(), KeyFactory.stringToKey(b.getId()));
  }
View Full Code Here

    ds.put(e2);

    Query query = em.createQuery("SELECT b FROM " + Book.class.getName() + " b WHERE b.title = :title");
    query.setParameter("title", "y");
    query.setMaxResults(1);
    Book b = (Book) query.getSingleResult();
    assertEquals(e.getKey(), KeyFactory.stringToKey(b.getId()));
  }
View Full Code Here

    List<Book> results = q.getResultList();
    Iterator<Book> iter = results.iterator();
    iter.next();
    commitTxn();
    em.close();
    Book b = iter.next();
    b.getIsbn();
    b.getAuthor();
    iter.next();
  }
View Full Code Here

    DatastoreServiceInterceptor.uninstall();

    Query q = em.createQuery("select b from bookalias b where title = 'yam'");
    assertTrue(q.getResultList().isEmpty());

    Book b = new Book();
    b.setTitle("yam");
    beginTxn();
    em.persist(b);
    commitTxn();

    assertEquals(b, q.getResultList().get(0));
View Full Code Here

* @author Max Ross <maxr@google.com>
*/
public class JPAInsertionTest extends JPATestCase {

  public void testSimpleInsert() throws EntityNotFoundException {
    Book b1 = new Book();
    b1.setAuthor("jimmy");
    b1.setIsbn("isbn");
    b1.setTitle("the title");
    assertNull(b1.getId());
    beginTxn();
    em.persist(b1);
    assertNull(b1.getId());
    commitTxn();
    assertNotNull(b1.getId());
    Entity entity = ds.get(KeyFactory.stringToKey(b1.getId()));
    assertNotNull(entity);
    assertEquals("jimmy", entity.getProperty("author"));
    assertEquals("isbn", entity.getProperty("isbn"));
    assertEquals("the title", entity.getProperty("title"));
    assertEquals(Book.class.getSimpleName(), entity.getKind());
View Full Code Here

    assertEquals("the title", entity.getProperty("title"));
    assertEquals(Book.class.getSimpleName(), entity.getKind());
  }

  public void testSimpleInsert_Merge() throws EntityNotFoundException {
    Book b1 = new Book();
    b1.setAuthor("jimmy");
    b1.setIsbn("isbn");
    b1.setTitle("the title");
    assertNull(b1.getId());
    beginTxn();
    em.merge(b1);
    commitTxn();
    assertNotNull(b1.getId());
    Entity entity = ds.get(KeyFactory.stringToKey(b1.getId()));
    assertNotNull(entity);
    assertEquals("jimmy", entity.getProperty("author"));
    assertEquals("isbn", entity.getProperty("isbn"));
    assertEquals("the title", entity.getProperty("title"));
    assertEquals(Book.class.getSimpleName(), entity.getKind());
View Full Code Here

    assertEquals("the title", entity.getProperty("title"));
    assertEquals(Book.class.getSimpleName(), entity.getKind());
  }

  public void testSimpleInsertWithNamedKey() throws EntityNotFoundException {
    Book b1 = new Book("named key");
    b1.setAuthor("jimmy");
    b1.setIsbn("isbn");
    b1.setTitle("the title");
    beginTxn();
    em.persist(b1);
    commitTxn();
    assertEquals("named key", KeyFactory.stringToKey(b1.getId()).getName());
    Entity entity = ds.get(KeyFactory.stringToKey(b1.getId()));
    assertNotNull(entity);
    assertEquals("jimmy", entity.getProperty("author"));
    assertEquals("isbn", entity.getProperty("isbn"));
    assertEquals("the title", entity.getProperty("title"));
    assertEquals(Book.class.getSimpleName(), entity.getKind());
View Full Code Here

    assertNotNull(hk.getId());
    assertEquals("name", hk.getId().getName());
  }

  public void testInsertWithFlushBeforeCommit() {
    Book b1 = new Book();
    beginTxn();
    em.persist(b1);
    assertNull(b1.getId());
    em.flush();
    assertNotNull(b1.getId());
    commitTxn();
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.Book

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.