Package cz.muni.fi.pa165.ddtroops.entities

Examples of cz.muni.fi.pa165.ddtroops.entities.User


        //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

    /**
     * Test of findAllBooks method, of class BookDAOImpl.
     */
    public void testFindAllBooks() {
        Book book = createCustomBook1();
        persist(book);
        assertEquals(1, bookDAOImpl.findAllBooks().size());
      
        createBooks();
        assertEquals(6, bookDAOImpl.findAllBooks().size());
View Full Code Here

            fail("Method should not accept nonpositive ID.");
        } catch (IllegalArgumentException e) {
            //OK
        }
      
        Book book1 = createCustomBook1();
        Book book2 = createCustomBook1();
        book2.setAuthor("pepa");
        em.getTransaction().begin();
        em.persist(book1);
        em.persist(book2);
        em.getTransaction().commit();
      
        Long id1 = new Long(book1.getId());
        Long id2 = new Long(book2.getId());
      
        assertEquals(book1, bookDAOImpl.findBookById(id1));
        assertEquals(book2, bookDAOImpl.findBookById(id2));
      
        book1.setAuthor("pepa");
View Full Code Here

      
        assertEquals(2, kniha2States.size());
      
        assertEquals(kniha1States, kniha3States);
      
        Book book = createCustomBook1();
        persist(book);
        assertTrue("Created book should be in the list of books with it's title.",
                bookDAOImpl.findBookByTitle("Kniha1").contains(book));
    }
View Full Code Here

        } catch (IllegalArgumentException e) {
            //OK
        }
      
        createBooks();
        Book book = createCustomBook2();
        persist(book);
        Long id1 = new Long(book.getId());
        book.setGenre(Genre.DRAMA);
      
        bookDAOImpl.setEntityManager(emf.createEntityManager());
        assertEquals(3, bookDAOImpl.findBookByGenre(Genre.ACTION).size());
        assertEquals(3, bookDAOImpl.findBookByGenre(Genre.ADVENTURE).size());
        assertEquals(0, bookDAOImpl.findBookByGenre(Genre.DRAMA).size());
      
        book = createCustomBook2();
        book.setGenre(Genre.DRAMA);
        persist(book);
        Long id2 = new Long(book.getId());
      
        assertEquals(1, bookDAOImpl.findBookByGenre(Genre.DRAMA).size());
      
        book = new Book();
        book.setId(id1);
        assertTrue("", bookDAOImpl.findBookByGenre(Genre.ADVENTURE).contains(book));
        book.setId(id2);
        assertTrue("", bookDAOImpl.findBookByGenre(Genre.DRAMA).contains(book));
    }
View Full Code Here

      
        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

TOP

Related Classes of cz.muni.fi.pa165.ddtroops.entities.User

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.