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

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


    // make sure these books are connected
    beginTxn();
    books.get(0).setTitle("different title");
    commitTxn();
    beginTxn();
    Book f = em.find(Book.class, id);
    assertEquals("different title", f.getTitle());
    commitTxn();
    deleteAll();
  }
View Full Code Here


    // make sure these books are connected
    beginTxn();
    books.get(0).setTitle("different title");
    commitTxn();
    beginTxn();
    Book f = em.find(Book.class, id);
    assertEquals("different title", f.getTitle());
    commitTxn();
    deleteAll();
  }
View Full Code Here

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));
View Full Code Here

  public void testUpdateAfterFetch() throws EntityNotFoundException {
    Key key = ds.put(Book.newBookEntity("jimmy", "12345", "the title"));

    String keyStr = KeyFactory.keyToString(key);
    beginTxn();
    Book book = em.find(Book.class, keyStr);

    assertEquals(keyStr, book.getId());
    assertEquals("jimmy", book.getAuthor());
    assertEquals("12345", book.getIsbn());
    assertEquals("the title", book.getTitle());

    book.setIsbn("56789");
    commitTxn();

    Entity bookCheck = ds.get(key);
    assertEquals("jimmy", bookCheck.getProperty("author"));
    assertEquals("56789", bookCheck.getProperty("isbn"));
View Full Code Here

    assertEquals("56789", bookCheck.getProperty("isbn"));
    assertEquals("the title", bookCheck.getProperty("title"));
  }

  public void testUpdateAfterSave() throws EntityNotFoundException {
    Book b = new Book();
    b.setAuthor("max");
    b.setIsbn("22333");
    b.setTitle("yam");

    beginTxn();
    em.persist(b);
    commitTxn();

    assertNotNull(b.getId());

    beginTxn();
    b.setTitle("not yam");
    em.merge(b);
    commitTxn();

    Entity bookCheck = ds.get(KeyFactory.stringToKey(b.getId()));
    assertEquals("max", bookCheck.getProperty("author"));
    assertEquals("22333", bookCheck.getProperty("isbn"));
    assertEquals("not yam", bookCheck.getProperty("title"));
  }
View Full Code Here

    ds.put(Book.newBookEntity("Joe Blow", "67890", "Bar Book"));
    ds.put(Book.newBookEntity("Joe Blow", "11111", "Bar Book"));
    ds.put(Book.newBookEntity("Joe Blow", "12345", "Foo Book"));
    ds.put(Book.newBookEntity("Joe Blow", "54321", "A Book"));
    ds.put(Book.newBookEntity("Jane Blow", "13579", "Baz Book"));
    Book book = new Book();
    book.setAuthor("joe bob");
    book.setFirstPublished(1922);
    book.setIsbn("24242");
    book.setTitle("my title");
//    beginTxn();
//    em.persist(book);
//    commitTxn();
//
//    CriteriaBuilder builder = emf.getCriteriaBuilder();
View Full Code Here

  private void testWritePermutationWithoutExpectedDatastoreTxn(
      EntityManagerFactory emf, boolean explicitDemarcation) {
    EasyMock.expect(mockDatastoreService.put(EasyMock.isA(Entity.class))).andReturn(null);
    EasyMock.replay(mockDatastoreService, mockTxn);

    Book b1 = new Book();
    b1.setTitle("Foo Bar");
    b1.setAuthor("Joe Blow");
    b1.setIsbn("12345");

    EntityManager em = emf.createEntityManager();
    EntityTransaction txn = em.getTransaction();
    if (explicitDemarcation) {
      txn.begin();
View Full Code Here

  public void testSimpleFetch_Id() {
    Key key = ds.put(Book.newBookEntity("max", "47", "yam"));

    String keyStr = KeyFactory.keyToString(key);
    Book book = em.find(Book.class, keyStr);
    assertNotNull(book);
    assertEquals(keyStr, book.getId());
    assertEquals("max", book.getAuthor());
    assertEquals("47", book.getIsbn());
    assertEquals("yam", book.getTitle());
  }
View Full Code Here

  public void testSimpleFetchWithNonTransactionalDatasource() {
    switchDatasource(EntityManagerFactoryName.nontransactional_ds_non_transactional_ops_not_allowed);
    Key key = ds.put(Book.newBookEntity("max", "47", "yam"));

    String keyStr = KeyFactory.keyToString(key);
    Book book = em.find(Book.class, keyStr);
    assertNotNull(book);
    assertEquals(keyStr, book.getId());
    assertEquals("max", book.getAuthor());
    assertEquals("47", book.getIsbn());
    assertEquals("yam", book.getTitle());
  }
View Full Code Here

  }

  public void testSimpleFetch_Id_LongIdOnly() {
    Key key = ds.put(Book.newBookEntity("max", "47", "yam"));

    Book book = em.find(Book.class, key.getId());
    assertNotNull(book);
    String keyStr = KeyFactory.keyToString(key);
    assertEquals(keyStr, book.getId());
    assertEquals("max", book.getAuthor());
    assertEquals("47", book.getIsbn());
    assertEquals("yam", book.getTitle());
  }
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.