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

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


    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

        for (long id = 1l; id < 8; id++) {
            borrowList.add(entityManager.find(Book.class, id));
        }
       
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), borrowList,
                    new Date(currentTime), new Date(currentTime +  2592000000l)));
            fail("Cannot insert empty borrow list");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
View Full Code Here

        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Reader reader = entityManager.find(Reader.class, 1l);
        entityManager.close();
       
        em.getTransaction().begin();
        borrowDAO.createBorrow(new Borrow(reader, prepareBorrowList(),
                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());
View Full Code Here

        List<Book> borrowedBook = new ArrayList<Book>();
        borrowedBook.add(entityManager.find(Book.class, 10l));
        long currentTime = System.currentTimeMillis();
        
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 1l), borrowedBook,
                    new Date(currentTime), new Date(currentTime +  2592000000l)));
            fail("Cannot insert borrow list with borrowed book");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
View Full Code Here

        List<Book> borrowedBook = new ArrayList<Book>();
        borrowedBook.add(entityManager.find(Book.class, 8l));
        long currentTime = System.currentTimeMillis();
              
        try {
            borrowDAO.createBorrow(new Borrow(entityManager.find(Reader.class, 2l), borrowedBook,
                    new Date(currentTime), new Date(currentTime +  2592000000l)));
            fail("Cannot insert borrow list with book reserved by another reader");
        } catch (IllegalArgumentException ex) {
            // OK
        } finally {
View Full Code Here

        List<Book> borrowList2 = new ArrayList<Book>();
        borrowList2.add(entityManager.find(Book.class, 3l));
        borrowList2.add(entityManager.find(Book.class, 4l));
  
        // ID 1
        Borrow borrow1 = new Borrow(entityManager.find(Reader.class, 1l), borrowList1, new Date(System.currentTimeMillis()),
                new Date(System.currentTimeMillis()));
        // ID 2
        Borrow borrow2 = new Borrow(entityManager.find(Reader.class, 2l), borrowList2, new Date(System.currentTimeMillis()),
                new Date(System.currentTimeMillis()));
              
        entityManager.getTransaction().begin();
        entityManager.persist(borrow1);
        entityManager.persist(borrow2);
View Full Code Here

        List<Book> borrowList2 = new ArrayList<Book>();
        borrowList2.add(entityManager.find(Book.class, 3l));
        borrowList2.add(entityManager.find(Book.class, 4l));
      
        // ID 1
        Borrow borrow1 = new Borrow(entityManager.find(Reader.class, 1l), borrowList1, new Date(System.currentTimeMillis()),
                new Date(System.currentTimeMillis()));
        // ID 2
        Borrow borrow2 = new Borrow(entityManager.find(Reader.class, 2l), borrowList2, new Date(System.currentTimeMillis()),
                new Date(System.currentTimeMillis()));
        entityManager.close();
       
        entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
        entityManager.persist(borrow1);
        entityManager.getTransaction().commit();
        entityManager.getTransaction().begin();
        entityManager.persist(borrow2);
        entityManager.getTransaction().commit();
        entityManager.close();
      
        borrow1.setBorrowID(1l);
        borrow2.setBorrowID(2l);
      
        assertEquals(borrow1, borrowDAO.findBorrowById(1l));
        assertEquals(borrow2, borrowDAO.findBorrowById(2l))
    }
View Full Code Here

        Reader reader1 = entityManager.find(Reader.class, 1l);
        Reader reader2 = entityManager.find(Reader.class, 2l);
        entityManager.close();
       
        // ID 1
        Borrow borrow1 = new Borrow(reader1, borrowList1,
                new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()));
        // ID 2
        Borrow borrow2 = new Borrow(reader2, borrowList2,
                new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()));
       
        entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
        entityManager.persist(borrow1);
        entityManager.persist(borrow2);
        entityManager.getTransaction().commit();
        entityManager.close();
      
        borrow1.setBorrowID(1l);
        borrow2.setBorrowID(2l);
      
        em.getTransaction().begin();
        assertEquals(borrow1, borrowDAO.findBorrowsByReader(reader1).get(0));
        assertEquals(borrow2, borrowDAO.findBorrowsByReader(reader2).get(0));
        em.getTransaction().commit();
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.library.backend.Borrow

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.