List of usage examples for org.springframework.mock.web MockHttpSession putValue
@Override public void putValue(String name, Object value)
From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java
@Test public void testOK() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl")); }
From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java
@Test public void testOKWithState() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET + "&" + OAuthConstants.STATE + "=" + STATE, map.get("callbackUrl")); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyNoClientIdError() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.ERROR_VIEW, modelAndView.getViewName()); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyNoRedirectError() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.ERROR_VIEW, modelAndView.getViewName()); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyActionDenied() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, "deny"); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl()//from w w w.j a v a 2 s .c o m .endsWith(REDIRECT_URI + "?" + OAuthConstants.ERROR + "=" + OAuthConstants.ACCESS_DENIED)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsCodeWithoutState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); when(authorizationCode.getId()).thenReturn(AC_ID); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);/*from w w w . j av a 2s .c om*/ scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.OFFLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + AC_ID); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsCodeWithState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); when(authorizationCode.getId()).thenReturn(AC_ID); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);/* w w w . jav a 2s. c o m*/ scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.OFFLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + AC_ID + "&" + OAuthConstants.STATE + '=' + STATE); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsTokenWithoutState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.getCreationTime()).thenReturn(new Date().getTime()); final AccessToken accessToken = mock(AccessToken.class); when(accessToken.getId()).thenReturn(AT_ID); when(accessToken.getTicket()).thenReturn(ticketGrantingTicket); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);/*from w w w . j a v a2 s . c o m*/ scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.ONLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); when(centralOAuthService.grantOnlineAccessToken(authorizationCode)).thenReturn(accessToken); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.setTimeout(TIMEOUT); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "#" + OAuthConstants.ACCESS_TOKEN + "=" + accessToken.getId() + "&" + OAuthConstants.EXPIRES_IN + '=' + TIMEOUT + "&" + OAuthConstants.TOKEN_TYPE + '=' + OAuthConstants.BEARER_TOKEN); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackActionControllerTests.java
@Test public void verifyResponseIsTokenWithState() throws Exception { final AuthorizationCode authorizationCode = mock(AuthorizationCode.class); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.getCreationTime()).thenReturn(new Date().getTime()); final AccessToken accessToken = mock(AccessToken.class); when(accessToken.getId()).thenReturn(AT_ID); when(accessToken.getTicket()).thenReturn(ticketGrantingTicket); final Set<String> scopes = new HashSet<>(); scopes.add(NAME1);//from w ww . j a v a2 s . c o m scopes.add(NAME2); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.grantAuthorizationCode(TokenType.ONLINE, CLIENT_ID, TICKET_GRANTING_TICKET_ID, REDIRECT_URI, scopes)).thenReturn(authorizationCode); when(centralOAuthService.grantOnlineAccessToken(authorizationCode)).thenReturn(accessToken); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_RESPONSE_TYPE, RESPONSE_TYPE); mockSession.putValue(OAuthConstants.OAUTH20_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE); mockSession.putValue(OAuthConstants.OAUTH20_REDIRECT_URI, REDIRECT_URI); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE_SET, scopes); mockRequest.setSession(mockSession); mockRequest.setParameter(OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION, OAuthConstants.OAUTH20_APPROVAL_PROMPT_ACTION_ALLOW); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.setTimeout(TIMEOUT); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertEquals(redirectView.getUrl(), REDIRECT_URI + "#" + OAuthConstants.ACCESS_TOKEN + "=" + accessToken.getId() + "&" + OAuthConstants.EXPIRES_IN + '=' + TIMEOUT + "&" + OAuthConstants.TOKEN_TYPE + '=' + OAuthConstants.BEARER_TOKEN + "&" + OAuthConstants.STATE + '=' + STATE); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_RESPONSE_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_CLIENT_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_STATE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_REDIRECT_URI)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_TOKEN_TYPE)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_LOGIN_TICKET_ID)); assertNull(mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyFailIfGrantingTicketNull() throws Exception { final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(null); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertNull(modelAndView);/* w ww . ja va 2 s .c o m*/ assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus()); assertEquals(CONTENT_TYPE, mockResponse.getContentType()); final ObjectMapper mapper = new ObjectMapper(); final String expected = "{\"error\":\"" + OAuthConstants.INVALID_GRANT + "\",\"error_description\":\"" + OAuthConstants.EXPIRED_TGT_DESCRIPTION + "\"}"; final JsonNode expectedObj = mapper.readTree(expected); final JsonNode receivedObj = mapper.readTree(mockResponse.getContentAsString()); assertEquals(expectedObj.get("error").asText(), receivedObj.get("error").asText()); assertEquals(expectedObj.get("error_description").asText(), receivedObj.get("error_description").asText()); }