Example #1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    logger.debug("Get received");

    String bookid = request.getParameter("bookid");
    logger.debug("param bookid : " + bookid);
    Book book = new Book(bookid);
    Session session = HibernateUtil.getSessionFactory().openSession();
    BookDao bookDao = new BookDao(session);
    LoanDao loanDao = new LoanDao(session);
    BookService bookService = new BookService(bookDao, loanDao);
    if (!bookService.deleteBook(book.getBookid())) {
      logger.debug("Book not deleted");
      request.setAttribute("isBookDeleted", false);
    } else {
      request.setAttribute("isBookDeleted", true);
      logger.debug("Book  deleted");
    }
    List<Book> bookList = bookService.getAll();
    logger.debug("bookList : " + bookList);
    request.setAttribute("bookList", bookList);
    session.close();

    logger.debug(LogConstant.REDIRECT + PageConstant.BOOK_LIST_URL);
    RequestDispatcher rd = request.getRequestDispatcher(PageConstant.BOOK_LIST_URL);
    rd.forward(request, response);
  }
Example #2
0
  public void testDeleteUserWithLoan() throws Exception {
    logger.info("Entered TC18 testDeleteUserWithLoan");
    User user;
    String parameterUserName = "******" + System.currentTimeMillis();
    String IsbnName = "testISBN" + System.currentTimeMillis();
    user = new User("TestFirstName", "TestLastName", parameterUserName, "password", Role.STUDENT);
    String parameterBookName = "MyBook" + System.currentTimeMillis();
    userService.saveOrUpdate(user);
    Book book = new Book(parameterBookName, IsbnName, 2);
    bookService.saveOrUpdate(book);
    session.refresh(book);
    logger.info("User added" + user.getUsername());
    // now create loan for this user
    Calendar now = Calendar.getInstance();
    now.add(Calendar.MINUTE, 5);
    logger.info("Book " + book.getBookid() + " user " + user.getUserId());

    Loan loan = new Loan(user.getUserId(), book.getBookid(), now.getTime(), 0, 10, false);
    loandao.saveOrUpdate(loan);
    loanId = loan.getLoanId();
    bookId = book.getBookid();
    userId = user.getUserId();
    logger.debug("Loan " + loan.getLoanId() + " created for user " + user.getUserId());
    logger.info("Loan created: " + loan.getLoanId());
    logger.info("trying to delete userID: " + user.getUserId());
    WebConversation conversation = new WebConversation();
    WebRequest requestDeleteUser =
        new GetMethodWebRequest(Constant.DELETE_USER_URL + user.getUserId());
    WebResponse responseGetUser = conversation.getResponse(requestDeleteUser);
    WebTable bookListUpdatedTable = responseGetUser.getTableWithID("userListTable");
    TableCell tableUpdatedCell = bookListUpdatedTable.getTableCellWithID(user.getUserId());
    assertEquals(tableUpdatedCell.getText(), user.getUserId());
    logger.info("Exited TC18 testDeleteUserWithLoan");
  }
Example #3
0
 public void tearDown() throws Exception {
   // Delete the loan
   logger.info("Entered tear down for TC18");
   logger.debug("trying to delete the loanID: " + loanId);
   loanService.deleteLoanByLoanID(loanId);
   // delete the book
   logger.debug("trying to delete the BookID: " + bookId);
   bookService.deleteBook(bookId);
   // delete the user
   logger.debug("trying to delete the UserID: " + userId);
   userService.delete(userService.getUserbyUserID(userId));
   // close the session
   session.close();
   logger.info("Exit tear down for TC17");
 }