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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
39    82    1    23-06-2024
Đã 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.