@Test public void testDeleteBookCopyReservation() { try { simulateBeginTransaction(); bDao.deleteBookCopyReservation(null); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, " + "book copy is null"); assertFalse(true); } catch (NullPointerException ex) { } BookCopyReservation myBCReservation = new BookCopyReservation(); myBCReservation.setId(null); try { simulateBeginTransaction(); bDao.deleteBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println( "Should have thrown IllegalArgumentException, " + "book copy's id is null"); assertFalse(true); } catch (IllegalArgumentException ex) { } simulateBeginTransaction(); bDao.createBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); simulateBeginTransaction(); bDao.deleteBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); simulateBeginTransaction(); List<BookCopyReservation> reservations = bDao.findAllBookCopyReservations(); simulateEndTransaction(); assertFalse(reservations.contains(testBookCopyReservation1)); }
private BookCopyReservation createTestBookCopyReservation() { BookCopyReservation newReservation = new BookCopyReservation(); newReservation.setBookCopy(createTestBookCopy()); newReservation.setReservationState(ReservationState.NEW); newReservation.setUser(user); newReservation.setCreated(new Date(2012, 1, 1)); return newReservation; }
@Test public void testFindBookCopyReservations() { simulateBeginTransaction(); bDao.createBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); simulateBeginTransaction(); List<BookCopyReservation> reservations = bDao.findBookCopyReservationsByReservationState( testBookCopyReservation1.getReservationState()); simulateEndTransaction(); assertTrue(reservations.contains(testBookCopyReservation1)); simulateBeginTransaction(); reservations = bDao.findBookCopyReservationsByBookCopy(testBookCopyReservation1.getBookCopy()); simulateEndTransaction(); assertTrue(reservations.contains(testBookCopyReservation1)); }
@Test public void testUpdateBookCopyReservation() { try { simulateBeginTransaction(); bDao.updateBookCopyReservation(null); simulateEndTransaction(); System.out.println("Should have thrown NPException"); assertTrue(false); } catch (NullPointerException ex) { } BookCopyReservation myBCReservation = new BookCopyReservation(); myBCReservation.setReservationState(null); myBCReservation.setId(Long.MAX_VALUE); myBCReservation.setBookCopy(createTestBookCopy()); try { // reservation state is null simulateBeginTransaction(); bDao.updateBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, state is null"); assertTrue(false); } catch (IllegalArgumentException ex) { } myBCReservation.setReservationState(ReservationState.LENT); myBCReservation.setBookCopy(null); try { // book copy is null simulateBeginTransaction(); bDao.updateBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, book copy is null"); assertTrue(false); } catch (IllegalArgumentException ex) { } myBCReservation.setReservationState(ReservationState.READY); myBCReservation.setId(null); myBCReservation.setBookCopy(createTestBookCopy()); try { // id is null simulateBeginTransaction(); bDao.updateBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, book copy is null"); assertTrue(false); } catch (IllegalArgumentException ex) { } simulateBeginTransaction(); bDao.createBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); testBookCopyReservation1.setBookCopy(createTestBookCopy()); testBookCopyReservation1.setReservationState(ReservationState.RETURNED); BookCopyReservation resultOfUpdate = null; try { simulateBeginTransaction(); resultOfUpdate = bDao.updateBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); } catch (Exception ex) { ex.printStackTrace(); } assertEquals(testBookCopyReservation1.getBookCopy(), resultOfUpdate.getBookCopy()); assertEquals( testBookCopyReservation1.getReservationState(), resultOfUpdate.getReservationState()); }
@Test public void testCreateBookCopyReservation() { try { simulateBeginTransaction(); bDao.createBookCopyReservation(null); simulateEndTransaction(); System.out.println("Should have thrown NPException"); assertTrue(false); } catch (NullPointerException ex) { } BookCopyReservation myBCReservation = new BookCopyReservation(); myBCReservation.setReservationState(null); myBCReservation.setBookCopy(createTestBookCopy()); try { simulateBeginTransaction(); bDao.createBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, state is null"); assertTrue(false); } catch (IllegalArgumentException ex) { } myBCReservation.setReservationState(ReservationState.LENT); myBCReservation.setBookCopy(null); try { simulateBeginTransaction(); bDao.createBookCopyReservation(myBCReservation); simulateEndTransaction(); System.out.println("Should have thrown IllegalArgumentException, book copy is null"); assertTrue(false); } catch (IllegalArgumentException ex) { } BookCopyReservation result = null; try { simulateBeginTransaction(); result = bDao.createBookCopyReservation(testBookCopyReservation1); simulateEndTransaction(); } catch (Exception ex) { ex.printStackTrace(); } assertNotNull(result.getId()); assertEquals(testBookCopyReservation1.getBookCopy(), result.getBookCopy()); assertEquals(testBookCopyReservation1.getReservationState(), result.getReservationState()); }