TAILIEUCHUNG - Java Extreme Programming Cookbook phần 7

LoginServlet lấy, kiểm tra, và xử lý dữ liệu, trong trường hợp này là nhằm mục đíchxác thực người dùng. Ví dụ 7-1 cho thấy phiên đầu tiên của servlet. Ví dụ 7-1. Lặp đi lặp lại của các LoginServlet Một thử nghiệm nonwaiting, hoặc thử nghiệm một thất bại ngay lập tức, không thể in thời gian thực tế nó đã hoàn thành các kiểm tra. | LoginServlet retrieves verifies and processes the data which in this case is intended to authenticate a user. Example 7-1 shows the first iteration of the servlet. Example 7-1. First iteration of the LoginServlet package import import import import import public class LoginServlet extends HttpServlet Cactus does not automatically invoke this method. If you want to test this method then your test method must explicitly invoke it. protected void doPost HttpServletRequest req HttpServletResponse res throws IOException ServletException if validateParameters req errorMessage Please enter your username and password .forward req res return authenticate user protected boolean validateParameters HttpServletRequest req @todo - implement this return false Our servlet overrides the doPost method and immediately calls the validateParameters method which is the method we are going to test. First we make the test fail and then write the code to make it pass. Example 7-2 shows the next iteration of the Cactus test. Example 7-2. Second iteration of the LoginServlet test package import import public class TestLoginServlet extends ServletTestCase private LoginServlet servlet public TestLoginServlet String name super name public void setUp new LoginServlet public void beginValidFormParameters WebRequest webRequest username coyner_b password secret public void testValidFormParameters assertTrue Valid Parameters. The test method testValidFormParameters fails because our servlet is hardcoded to return .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.