KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > examples > password > TestForgotPasswordServlet


1 package com.mockobjects.examples.password;
2
3 import java.io.IOException JavaDoc;
4 import javax.servlet.ServletConfig JavaDoc;
5 import javax.servlet.ServletException JavaDoc;
6 import com.mockobjects.servlet.MockHttpServletRequest;
7 import com.mockobjects.servlet.MockHttpServletResponse;
8 import com.mockobjects.util.TestCaseMo;
9
10 public class TestForgotPasswordServlet extends TestCaseMo {
11     public static final String JavaDoc SENT_URI = "sent_uri";
12     public static final String JavaDoc EMAIL_FAILED_URI = "bad_email_uri";
13     public static final String JavaDoc EMAIL_NOT_FOUND_URI = "no_email_uri";
14     public static final String JavaDoc EMAIL = "email@an.address";
15
16     public TestForgotPasswordServlet(String JavaDoc name) {
17         super(name);
18     }
19
20     private MockHttpServletRequest mockRequest = new MockHttpServletRequest();
21     private MockHttpServletResponse mockResponse = new MockHttpServletResponse();
22     private MockPasswordReminder mockReminder = new MockPasswordReminder();
23     private ForgotPasswordServlet passwordServlet;
24
25     public void setUp() throws ServletException JavaDoc, IOException JavaDoc {
26         passwordServlet = new ForgotPasswordServlet(mockReminder);
27
28         mockRequest.setupAddParameter(ForgotPasswordServlet.EMAIL_PARAM, EMAIL);
29     }
30
31     public void testReminderEmailSent() throws ServletException JavaDoc, IOException JavaDoc {
32         mockReminder.setExpectedEmailAddress(EMAIL);
33         mockResponse.setExpectedRedirect(
34                 SENT_URI + "?" + ForgotPasswordServlet.EMAIL_PARAM + "=" + EMAIL);
35
36         passwordServlet.doGet(mockRequest, mockResponse);
37
38         mockResponse.verify();
39         mockReminder.verify();
40     }
41
42 /*
43     public void testEmailNotFound() throws ServletException, IOException {
44         mockReminder.setupEmailNotFound();
45
46         mockReminder.setExpectedEmailAddress(EMAIL);
47         mockResponse.setExpectedRedirect(EMAIL_NOT_FOUND_URI + "?email=" + EMAIL);
48
49         passwordServlet.doGet(mockRequest, mockResponse);
50
51         mockResponse.verify();
52         mockReminder.verify();
53     }
54
55     private ServletConfig createStubServletConfig() {
56         return new StubServletConfig() {
57             public String getInitParameter(String s) {
58                 if (ForgotPasswordServlet.SENT_PARAM_NAME.equals(s)) {
59                     return SENT_URI;
60                 } else if (ForgotPasswordServlet.EMAIL_FAILED_PARAM_NAME.equals(s)) {
61                     return EMAIL_FAILED_URI;
62                 } else if (ForgotPasswordServlet.EMAIL_NOT_FOUND_PARAM_NAME.equals(s)) {
63                     return EMAIL_NOT_FOUND_URI;
64                 }
65                 return super.getInitParameter(s);
66             }
67         };
68     }*/

69 }
70
71
Popular Tags