@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)));
  }
  @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 testListProjectsActionByNormalUser() throws Exception {
    String actionString = Action.ListProjects.toString();

    when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString);

    // set AuthenticateOneTimeUser false
    prepareEnterAuthenticateOneTimeUser(false);
    User user = stubbingCheckUser();

    String xmi = constructProjectsObjectsXmi();
    doThrow(
            new org.talend.gwtadministrator.server.remoteconnection.ConnectionUtil
                .ResponseException(xmi))
        .when(ConnectionUtil.class);
    ConnectionUtil.listAuthorizedProjects(user);

    // RUN...
    defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse);

    verifyNecessaryChecks(actionString);

    verifyStatic(org.mockito.Mockito.times(1));
    ConnectionUtil.checkUser(loginString, password, false);

    verifyStatic(org.mockito.Mockito.times(1));
    ConnectionUtil.listAuthorizedProjects(user);

    PrintWriter writer = mockHttpServletResponse.getWriter();
    writer.flush();
    System.out.println(outStringWriter.toString());
    // ASSERT...
    assertThat(outStringWriter.toString(), is("RESPONSE:" + xmi));
  }
  private User stubbingCheckUser() throws Exception {

    User user = AdminFactory.eINSTANCE.createUser();
    user.setLogin("*****@*****.**");

    doReturn(user).when(ConnectionUtil.class);
    ConnectionUtil.checkUser(loginString, password, false);

    return user;
  }