List of usage examples for org.springframework.mock.web MockHttpServletRequest setSession
public void setSession(HttpSession session)
From source file:com.ideabase.repository.test.webservice.RESTfulControllerTest.java
/** * Test get request for retrieving an item. * @throws Exception/*from ww w . j a v a2s. c o m*/ */ public void testGetOperation() throws Exception { final Integer userId = TestCaseRepositoryHelper.fixCreateUser(mUserService, "hasan", "hasankhan"); final List<Integer> parentItemIds = new ArrayList<Integer>(); parentItemIds.add(userId); final List<Integer> itemIds = TestCaseRepositoryHelper.fixCreateItems(mRepositoryService, 10, "blog", parentItemIds); // Execute successful login request. final Subject subject = getSubjectFromASuccessfulRequest(); // Create a new servlet request. final MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/service/get/" + itemIds.get(0) + ".xml"); request.setMethod(METHOD_GET); // set parameters request.addParameter(WebConstants.PARAM_LOAD_RELATED_ITEMS, "true"); request.addParameter(WebConstants.PARAM_RELATION_TYPES, "blog, user"); request.addParameter(WebConstants.PARAM_MAX, "1"); // set session id final MockHttpSession session = new MockHttpSession(); session.setAttribute(WebConstants.SESSION_ATTR_USER_SUBJECT, subject); request.setSession(session); final MockHttpServletResponse response = new MockHttpServletResponse(); // Execute controller final ModelAndView modelAndView = mRestfulController.handleRequest(request, response); // Verify response assertNull("Model and view is ignored.", modelAndView); LOG.debug("Response - " + response.getContentAsString()); final boolean stateTrue = response.getContentAsString().indexOf("false") == -1; assertTrue("This action should not return false", stateTrue); assertEquals("Response status is not 200.", RESTfulControllerImpl.STATUS_OK_200, response.getStatus()); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyNoPromptWithExistingToken() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())) .thenReturn(true);/*from www .j a v a 2 s. c o m*/ when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(false); 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_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.ONLINE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl() .endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL + "?action=allow")); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyNoPromptWithoutExistingToken() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())) .thenReturn(false);//ww w. java 2s. com when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(true); 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_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.ONLINE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); 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(scopeMap.hashCode(), map.get("scopeMap").hashCode()); assertEquals(scopeMap.keySet(), 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);//from w w w . j a v a 2s . co 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()); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyFailIfGrantingTicketExpired() throws Exception { final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(true); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); 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);/* ww w . java 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()); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyOK() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); 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.setCentralOAuthService(centralOAuthService); 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(scopeMap.hashCode(), map.get("scopeMap").hashCode()); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:com.ideabase.repository.test.webservice.RESTfulControllerTest.java
public void testGetTermTagCloudByQuery() throws Exception { // create some dummy data TestCaseRepositoryHelper.fixCreateItems(mRepositoryService, 5); final Integer userId = TestCaseRepositoryHelper.fixCreateUser(mUserService, "hasan", "hasankhan"); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); // set http request parameters request.setRequestURI("/service/tagcloud/query.xml"); request.setMethod(METHOD_GET);//from w w w .jav a2s . c o m request.setParameter("query", "name:fox"); request.setParameter("max", "50"); request.setParameter("select", "name"); // fix login state final Subject subject = getSubjectFromASuccessfulRequest(); final MockHttpSession session = new MockHttpSession(); session.setAttribute(WebConstants.SESSION_ATTR_USER_SUBJECT, subject); request.setSession(session); final ModelAndView modelAndView = mRestfulController.handleRequest(request, response); // verify response final String responseContent = response.getContentAsString(); assertNotNull(responseContent); LOG.debug("Response content - " + responseContent); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyAutoPromptWithExistingToken() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); when(centralOAuthService.isAccessToken(TokenType.OFFLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())) .thenReturn(false);//w w w .java 2 s . c om when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(true); 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_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, "auto"); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertTrue(modelAndView.getView() instanceof RedirectView); final RedirectView redirectView = (RedirectView) modelAndView.getView(); assertTrue(redirectView.getUrl() .endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL + "?action=allow")); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyAutoPromptWithoutExistingToken() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); when(centralOAuthService.isAccessToken(TokenType.ONLINE, CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())) .thenReturn(true);//from w w w . j a v a 2 s .c om when(centralOAuthService.isRefreshToken(CLIENT_ID, PRINCIPAL_ID, scopeMap.keySet())).thenReturn(false); 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_CLIENT_ID, CLIENT_ID); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, "auto"); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); 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(scopeMap.hashCode(), map.get("scopeMap").hashCode()); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyBypassPromptIsTrue() throws Exception { final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); 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); mockSession.putValue(OAuthConstants.BYPASS_APPROVAL_PROMPT, true); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); 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 ww . ja v a 2 s . c o m .endsWith(CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_ACTION_URL + "?action=allow")); }