### Question:
LoginServlet extends RegistryBasedServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } LoginServlet(GridRegistry registry);  LoginServlet();  static final String LOGOUT; static final String FORM_ID; static final String USER_ID; static final String PASSWORD; }### Answer:
@Test public void testPostForNewLoginPage() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateForNewLoginPage(response); }
@Test public void testPostForNewLoginPageWithSessionPresent() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.getSession(true); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateForNewLoginPage(response); }
@Test public void testPostForLogin() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(LoginServlet.FORM_ID, "login"); request.addParameter(LoginServlet.USER_ID, "admin"); request.addParameter(LoginServlet.PASSWORD, "admin"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateLoginSuccess(request, response, SeLionGridConstants.GRID_HOME_PAGE_URL); }
@Test public void testPostForLoginFailure() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.getSession(true); request.addParameter(LoginServlet.FORM_ID, "login"); request.addParameter(LoginServlet.USER_ID, "admin"); request.addParameter(LoginServlet.PASSWORD, "password"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateLoginFailure(request, response); }
@Test public void testPostForLoginWithSessionCredentialsPresent() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); HttpSession session = request.getSession(true); session.setAttribute(LoginServlet.USER_ID, "admin"); session.setAttribute(LoginServlet.PASSWORD, "admin"); request.addParameter(LoginServlet.FORM_ID, "login"); request.addParameter(LoginServlet.USER_ID, "admin"); request.addParameter(LoginServlet.PASSWORD, "password"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateLoginSuccess(request, response, SeLionGridConstants.GRID_HOME_PAGE_URL); }
@Test public void testProcessForSauceGridLogin() throws Exception { GridHubConfiguration hubConfig = new GridHubConfiguration(); hubConfig.capabilityMatcher = new SeLionSauceCapabilityMatcher(); GridRegistry registry = DefaultGridRegistry.newInstance(new Hub(hubConfig)); GridNodeConfiguration nodeConfig = new GridNodeConfiguration(); nodeConfig.host = ipAddress; nodeConfig.port = nodePort; RegistrationRequest registrationRequest = new RegistrationRequest(nodeConfig); RemoteProxy remoteProxy = new DefaultRemoteProxy(registrationRequest, registry); registry.add(remoteProxy); LoginServlet servlet = new LoginServlet(registry); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(LoginServlet.FORM_ID, "login"); request.addParameter(LoginServlet.USER_ID, "admin"); request.addParameter(LoginServlet.PASSWORD, "admin"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.doPost(request, response); validateLoginSuccess(request, response, SeLionGridConstants.SAUCE_GRID_HOMEPAGE_URL); }