Package cz.muni.fi.pa165.library.backend

Examples of cz.muni.fi.pa165.library.backend.Book


      
        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

    public void createBookData() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
      
        // ID 1
        entityManager.persist(new Book("Cesta", "Brandon Boys", Genre.DRAMA, "2007", "Great Britan",
                "Eminent", "8072813001", State.NEW, Available.AVAILABLE));
        // ID 2
        entityManager.persist(new Book("Cesta", "Brandon Boys", Genre.DRAMA, "2007", "Great Britan",
                "Eminent", "8072813001", State.NEW, Available.AVAILABLE));
        // ID 3
        entityManager.persist(new Book("Cesta", "Brandon Boys", Genre.DRAMA, "2007", "Great Britan",
                "Eminent", "8072813001", State.USED, Available.AVAILABLE));
        // ID 4
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.NEW, Available.AVAILABLE));
        // ID 5
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.NEW, Available.AVAILABLE));
        // ID 6
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.USED, Available.AVAILABLE));
        // ID 7
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.USED, Available.AVAILABLE));
        // ID 8
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.USED, Available.RESERVED));
        // ID 9
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.USED, Available.RESERVED));
        // ID 10
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.USED, Available.BORROWED));
        // ID 11
        entityManager.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2012", "Slovakia",
                "Ikar", "9788055131191", State.DAMAGED, Available.BORROWED));
      
        entityManager.getTransaction().commit();
        entityManager.close();
    }
View Full Code Here

                new Date(currentTime), new Date(currentTime + 2592000000l)));
        em.getTransaction().commit();
       
        entityManager = entityManagerFactory.createEntityManager();       
        Borrow borrow = entityManager.find(Borrow.class, 1l);
        Book firstBook = entityManager.find(Book.class, 1l);
        Book secondBook = entityManager.find(Book.class, 2l);
        entityManager.close();
  
        assertEquals(Available.BORROWED, firstBook.getAvailability());
        assertEquals(Available.BORROWED, secondBook.getAvailability());
    }
View Full Code Here

        }
    }
  
    public void testReturnBooks() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book1 = entityManager.find(Book.class, 1l);
        Book book2 = entityManager.find(Book.class, 2l);
      
        List<Book> borrowList = new ArrayList<Book>();
        borrowList.add(book1);
        borrowList.add(book2);
        book1.setAvailability(Available.BORROWED);
        book2.setAvailability(Available.BORROWED);
      
        // Borrow with ID 1
        Borrow borrow = new Borrow(entityManager.find(Reader.class, 1l), borrowList,
                new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()));
        entityManager.close();
View Full Code Here

        entityManager.close();
    }
  
    public void testReturnBooksWithUnborrowedBookList() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book1 = entityManager.find(Book.class, 1l);
        Book book2 = entityManager.find(Book.class, 2l);
        Book book3 = entityManager.find(Book.class, 3l);
      
        List<Book> borrowList = new ArrayList<Book>();
        borrowList.add(book1);
        borrowList.add(book2);
      
View Full Code Here

        }
    }
  
    public void testReturnBooksWithNullIDArgument() {   
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book1 = entityManager.find(Book.class, 1l);
      
        List<Book> returnList = new ArrayList<Book>();
        returnList.add(book1);
      
        entityManager.close();
View Full Code Here

        }
    }
  
    public void testBorrowBooks() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book1 = entityManager.find(Book.class, 1l);
        Book book2 = entityManager.find(Book.class, 2l);
        Book book3 = entityManager.find(Book.class, 3l);
      
        List<Book> borrowList1 = new ArrayList<Book>();
        borrowList1.add(book1);
        borrowList1.add(book2);
      
View Full Code Here

        entityManager.close();
    }
  
    public void testBorrowBookWithNullBorrowID() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book = entityManager.find(Book.class, 1l);
        List<Book> borrowBook = new ArrayList<Book>();
        borrowBook.add(book);
        entityManager.close();
      
        try {
View Full Code Here

        }
    }
      
    public void testBorrowMoreBooksThanAllowedCount() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Book book1 = entityManager.find(Book.class, 1l);
        Book book2 = entityManager.find(Book.class, 2l);
        Book book3 = entityManager.find(Book.class, 3l);
        Book book4 = entityManager.find(Book.class, 4l);
        Book book5 = entityManager.find(Book.class, 5l);
        Book book6 = entityManager.find(Book.class, 6l);
        Book book7 = entityManager.find(Book.class, 7l);
      
        List<Book> borrowList1 = new ArrayList<Book>();
        borrowList1.add(book1);
        borrowList1.add(book2);
      
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.library.backend.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.