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

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


            reservationDAOImpl = new ReservationDAOImpl();
            reservationDAOImpl.setEntityManager(em);
          
            createReaderData();
            createBookData();
            book = new Book("Da Vinciho kod", "Dan Brown", Genre.DRAMA, "2005", "USA",
                "Foursick", "95860948503", State.NEW, Available.AVAILABLE);
          
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Exception during JPA EntityManager instantiation.");
View Full Code Here


    public void createBookData() {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
      
        // ID 1
        em.persist(new Book("Da Vinciho kod", "Dan Brown", Genre.DRAMA, "2005", "USA",
                "Foursick", "95860948503", State.NEW, Available.AVAILABLE));
        // ID 2
        em.persist(new Book("Cesta", "Brandon Boys", Genre.DRAMA, "2007", "Great Britain",
                "Eminent", "8072813001", State.NEW, Available.AVAILABLE));
        // ID 3
        em.persist(new Book("Peniaze", "Arnold Doughty", Genre.NOVEL, "2000", "USA",
                "Mackpublishing", "43543459834", State.USED, Available.BORROWED));
        // ID 4
        em.persist(new Book("Smely zajko v Afrike", "Ludmila Podjavorinska", Genre.ADVENTURE, "1993", "Slovakia",
                "Ikar", "49684586044", State.USED, Available.AVAILABLE));
        // ID 5
        em.persist(new Book("Kazisvet Jurko", "Lubomir Feldek", Genre.ADVENTURE, "1992", "Slovakia",
                "Mlade leta", "548684030023", State.USED, Available.RESERVED));
        // ID 6
        em.persist(new Book("Mierny vanok", "Juraj Lauko", Genre.CHILDREN, "2001", "Slovakia",
                "Ikar", "9788055151191", State.USED, Available.BORROWED));
        // ID 7
        em.persist(new Book("Neposlusny Janko", "Peter Konecny", Genre.CHILDREN, "2012", "Slovakia",
                "Mlade leta", "9788055161191", State.DAMAGED, Available.BORROWED));
        // ID 8
        em.persist(new Book("Cap zahradnik", "Anton Maly", Genre.ADVENTURE, "2011", "Slovakia",
                "Ikar", "9788055171191", State.USED, Available.RESERVED));
        // ID 9
        em.persist(new Book("Snehuliak", "Jo Nesbo", Genre.ADVENTURE, "2010", "Slovakia",
                "Mlade leta", "9788055181191", State.USED, Available.RESERVED));
      
        em.getTransaction().commit();
        em.close();
    }
View Full Code Here

            }
        }
    }

    protected Book createCustomBook1() {
        return new Book("Kniha1", "Autor1", Genre.ACTION, "1999", "place1",
                "pub1", "isbn1", State.NEW, Available.AVAILABLE);
    }
View Full Code Here

        return new Book("Kniha1", "Autor1", Genre.ACTION, "1999", "place1",
                "pub1", "isbn1", State.NEW, Available.AVAILABLE);
    }
  
    protected Book createCustomBook2() {
        return new Book("Kniha2", "Autor2", Genre.ADVENTURE, "2000", "place2",
                "pub2", "isbn2", State.DAMAGED, Available.AVAILABLE);
    }
View Full Code Here

        //2
        em.persist(createCustomBook1());
        //3
        em.persist(createCustomBook2());
        //4
        Book book = createCustomBook2();
        book.setState(State.USED);
        book.setAvailability(Available.BORROWED);
        em.persist(book);
        //5
        em.persist(new Book("Kniha3", "Autor1", Genre.ACTION, "2000", "place3",
                "pub3", "isbn3", State.NEW, Available.RESERVED));
        em.getTransaction().commit();
        if (em != null) {
            em.close();
        }
View Full Code Here

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

        Book book = createCustomBook1();
        book.setISBN(null);
        try {
            bookDAOImpl.createBook(book);
            fail("Method should fail on null ISBN.");
        } catch (IllegalArgumentException e) {
            //OK
        }

        book = createCustomBook1();
        book.setTitle("");
        try {
            bookDAOImpl.createBook(book);
            fail("Method should fail on empty title.");
        } catch (IllegalArgumentException e) {
            //OK
        }

        book = createCustomBook1();
        book.setId(new Long(1));
        try {
            bookDAOImpl.createBook(book);
            fail("Method should fail on creating book with already set ID.");
        } catch (IllegalArgumentException e) {
            //OK
        }

        book = createCustomBook1();
        em.getTransaction().begin();
        Book book2 = bookDAOImpl.createBook(book);
        em.getTransaction().commit();
        assertNotNull(book2.getId());
    }
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

  
    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

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.