Login { @GET public LoginResult loginStatus() { Subject subject = SecurityUtils.getSubject(); return createLoginResultFromSubject(subject); }  @GET LoginResult loginStatus(); @POST @Consumes(MediaType.APPLICATION_JSON) LoginResult doLogin(LoginCredentials credentials);  }
@Test public void testGetLoginStateWhenLoggedIn() throws Exception { HttpSession session = mock(HttpSession.class); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getSession()).thenReturn(session); HttpServletResponse response = mock(HttpServletResponse.class); MockLogService logservice = new MockLogService(); WebSubject subject = createSubjectAndBindItToThread(request, response); UsernamePasswordToken token = new UsernamePasswordToken("jad", "1ad".toCharArray(), true); subject.login(token); Login resource = new Login(); resource.logservice = logservice; LoginResult result = resource.loginStatus(); assertThat(result.getRoles()).isNotEmpty(); assertEquals("", result.getErrorMessage()); }
@Test public void testGetLoginStateWhenNotLoggedIn() throws Exception { HttpSession session = mock(HttpSession.class); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getSession()).thenReturn(session); HttpServletResponse response = mock(HttpServletResponse.class); MockLogService logservice = new MockLogService(); WebSubject subject = createSubjectAndBindItToThread(request, response); subject.logout(); Login resource = new Login(); resource.logservice = logservice; LoginResult result = resource.loginStatus(); assertEquals(0, result.getRoles().length); assertEquals("", result.getErrorMessage()); }