Package cz.muni.fi.pa165

Examples of cz.muni.fi.pa165.BookDAOImplTest


      
        assertEquals(2, isbn2States.size());
      
        assertEquals(isbn1States, isbn3States);
      
        Book book = createCustomBook1();
        persist(book);
        assertTrue("Created book should be in the list of books with it's isbn.",
                bookDAOImpl.findBookByIsbn("isbn1").contains(book));
    }
View Full Code Here


            fail("Method should fail on null parameter.");
        } catch (IllegalArgumentException e) {
            // OK
        }

        Book book = createCustomBook1();
        persist(book);
        book.setId(book.getId() + 1);
        try {
            bookDAOImpl.updateBook(book);
            fail("Method should fail on updating book with incorrect id"
                    + "as it should not be in the database.");
        } catch (IllegalArgumentException e) {
            // OK
        }
      
        book = createCustomBook1();
        persist(book);
        book.setISBN(null);
        try {
            bookDAOImpl.updateBook(book);
            fail("Method should fail on updating book with incorrect parameters.");
        } catch (IllegalArgumentException e) {
            //OK
        }
      
        book = createCustomBook1();
        Book book2 = createCustomBook2();
        persist(book);
        book2.setId(book.getId());
        em.getTransaction().begin();
        bookDAOImpl.updateBook(book2);
        em.getTransaction().commit();

        //if method findBookById() does not work properly, result of this test is irrelevant
        assertEquals(book2.getTitle(), bookDAOImpl.findBookById(book2.getId()).getTitle());
        assertEquals(1, bookDAOImpl.findBookByAuthor("Autor2").size());
    }
View Full Code Here

      
        try {
            emf = Persistence.createEntityManagerFactory("testPU");
            em = emf.createEntityManager();
            readerDAOImpl = new ReaderDAOImpl();
            bookDAOImpl = new BookDAOImpl();
            reservationDAOImpl = new ReservationDAOImpl();
            reservationDAOImpl.setEntityManager(em);
          
            createReaderData();
            createBookData();
View Full Code Here

        }

        try {
            emf = Persistence.createEntityManagerFactory("testPU");

            bookDAOImpl = new BookDAOImpl();
            em = emf.createEntityManager();
            bookDAOImpl.setEntityManager(em);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception during JPA EntityManager instanciation.");
View Full Code Here

  
    public void testInsertCorrectBorrow() {
        long currentTime = System.currentTimeMillis();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
       
        Borrow borrow = new Borrow(entityManager.find(Reader.class, 1l), prepareBorrowList(),
                new Date(currentTime), new Date(currentTime + 2592000000l));
        entityManager.close();
       
        em.getTransaction().begin();
        borrowDAO.createBorrow(borrow);
View Full Code Here

    public void testInsertBorrowWithNullReaderID() {
        List<Book> borrowList = prepareBorrowList();
        long currentTime = System.currentTimeMillis();
      
        try {
            borrowDAO.createBorrow(new Borrow(null, borrowList,
                    new Date(currentTime), new Date(currentTime + 2592000000l)));
            fail("Cannot insert borrow without reader's id");
        } catch (IllegalArgumentException ex) {
            // OK
        }
View Full Code Here

    public void testInsertBorrowWithNullBorrowList() {
        long currentTime = System.currentTimeMillis();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
      
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), null, new Date(currentTime), new Date(currentTime + 2592000000l)));
            fail("Cannot insert borrow without borrowed books");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
            entityManager.close();
View Full Code Here

    public void testInsertBorrowWithoutBorrowDate() {
        List<Book> borrowList = prepareBorrowList();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
   
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), borrowList, null, new Date(System.currentTimeMillis() + 2592000000l)));
            fail("Cannot insert borrow without borrow date");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
            entityManager.close();
View Full Code Here

    public void testInsertBorrowWithoutReturnDate() {
        List<Book> borrowList = prepareBorrowList();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
      
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), borrowList, new Date(System.currentTimeMillis()), null));
            fail("Cannot insert borrow without borrowed books");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
            entityManager.close();
View Full Code Here

    public void testInsertBorrowWithEmptyBorrowList() {
        long currentTime = System.currentTimeMillis();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
       
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), new ArrayList<Book>(),
                    new Date(currentTime), new Date(currentTime +  2592000000l)));
            fail("Cannot insert empty borrow list");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.BookDAOImplTest

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.