@Test public void testCloseSessionByNormalUser() throws Exception { String sessionIdString = "555"; String actionString = Action.CloseSession.toString(); long sessionIdLong = Long.parseLong(sessionIdString); when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString); when(mockHttpServletRequest.getParameter(ServletUtil.SESSION_ID)).thenReturn(sessionIdString); // set AuthenticateOneTimeUser false prepareEnterAuthenticateOneTimeUser(false); User user = stubbingCheckUser(); UsersCache userCacheHelper = mock(UsersCache.class); mockStatic(UsersCacheFactory.class); when(UsersCacheFactory.getInstance()).thenReturn(userCacheHelper); doNothing().when(userCacheHelper); userCacheHelper.remove(sessionIdLong); // RUN... defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse); verifyNecessaryChecks(actionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.checkUser(loginString, password, false); PrintWriter writer = mockHttpServletResponse.getWriter(); writer.flush(); System.out.println(outStringWriter.toString()); // ASSERT... assertThat(outStringWriter.toString(), is("RESPONSE:" + String.valueOf(sessionIdLong))); }
@Test public void testOpenSessionByNormalUser() throws Exception { long sessionLong = 555; String actionString = Action.OpenSession.toString(); when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString); when(mockHttpServletRequest.getParameter(ServletUtil.PROJECT)).thenReturn(projectString); // set AuthenticateOneTimeUser false prepareEnterAuthenticateOneTimeUser(false); User user = stubbingCheckUser(); UsersCache userCacheHelper = mock(UsersCache.class); mockStatic(UsersCacheFactory.class); when(UsersCacheFactory.getInstance()).thenReturn(userCacheHelper); when(userCacheHelper.logWithProjectLabel(loginString, CLIENT_TYPE, projectString)) .thenReturn(sessionLong); // RUN... defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse); verifyNecessaryChecks(actionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.checkUser(loginString, password, false); PrintWriter writer = mockHttpServletResponse.getWriter(); writer.flush(); System.out.println(outStringWriter.toString()); // ASSERT... assertThat(outStringWriter.toString(), is("RESPONSE:" + String.valueOf(sessionLong))); }