本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.getSession方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.getSession方法的具體用法?Java MockHttpServletRequest.getSession怎麽用?Java MockHttpServletRequest.getSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mock.web.MockHttpServletRequest
的用法示例。
在下文中一共展示了MockHttpServletRequest.getSession方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyOK
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyOK() throws Exception {
clearAllServices();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
((OAuth20WrapperController) oauth20WrapperController)
.getServicesManager().save(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
final Controller c = ((OAuth20WrapperController) oauth20WrapperController).getAuthorizeController();
((OAuth20AuthorizeController) c).setLoginUrl(CAS_URL);
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
final MockHttpServletRequest reqSvc = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
reqSvc.setServerName(CAS_SERVER);
reqSvc.setServerPort(CAS_PORT);
reqSvc.setScheme(CAS_SCHEME);
final URL url = new URL(OAuthUtils.addParameter(CAS_URL, "service", reqSvc.getRequestURL().toString()));
final URL url2 = new URL(redirectView.getUrl());
assertEquals(url, url2);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:37,代碼來源:OAuth20AuthorizeControllerTests.java
示例2: verifyOKWithState
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyOKWithState() throws Exception {
clearAllServices();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.STATE, STATE);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
((OAuth20WrapperController) oauth20WrapperController)
.getServicesManager().save(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
final Controller c = ((OAuth20WrapperController) oauth20WrapperController).getAuthorizeController();
((OAuth20AuthorizeController) c).setLoginUrl(CAS_URL);
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
assertEquals(STATE, session.getAttribute(OAuthConstants.OAUTH20_STATE));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
final MockHttpServletRequest reqSvc = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
reqSvc.setServerName(CAS_SERVER);
reqSvc.setServerPort(CAS_PORT);
reqSvc.setScheme(CAS_SCHEME);
final URL url = new URL(OAuthUtils.addParameter(CAS_URL, "service", reqSvc.getRequestURL().toString()));
final URL url2 = new URL(redirectView.getUrl());
assertEquals(url, url2);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:41,代碼來源:OAuth20AuthorizeControllerTests.java
示例3: verifyOK
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyOK() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final ServicesManager servicesManager = mock(ServicesManager.class);
final List<RegisteredService> services = new ArrayList<>();
services.add(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
when(servicesManager.getAllServices()).thenReturn(services);
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.setLoginUrl(CAS_URL);
oauth20WrapperController.setServicesManager(servicesManager);
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
final MockHttpServletRequest reqSvc = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
reqSvc.setServerName(CAS_SERVER);
reqSvc.setServerPort(CAS_PORT);
reqSvc.setScheme(CAS_SCHEME);
final URL url = new URL(OAuthUtils.addParameter(CAS_URL, "service", reqSvc.getRequestURL().toString()));
final URL url2 = new URL(redirectView.getUrl());
assertEquals(url, url2);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:36,代碼來源:OAuth20AuthorizeControllerTests.java
示例4: verifyOKWithState
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyOKWithState() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.STATE, STATE);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final ServicesManager servicesManager = mock(ServicesManager.class);
final List<RegisteredService> services = new ArrayList<>();
services.add(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
when(servicesManager.getAllServices()).thenReturn(services);
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.setLoginUrl(CAS_URL);
oauth20WrapperController.setServicesManager(servicesManager);
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
assertEquals(STATE, session.getAttribute(OAuthConstants.OAUTH20_STATE));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
final MockHttpServletRequest reqSvc = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
reqSvc.setServerName(CAS_SERVER);
reqSvc.setServerPort(CAS_PORT);
reqSvc.setScheme(CAS_SCHEME);
final URL url = new URL(OAuthUtils.addParameter(CAS_URL, "service", reqSvc.getRequestURL().toString()));
final URL url2 = new URL(redirectView.getUrl());
assertEquals(url, url2);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:38,代碼來源:OAuth20AuthorizeControllerTests.java
示例5: testOK
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testOK() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final ServicesManager servicesManager = mock(ServicesManager.class);
final List<RegisteredService> services = new ArrayList<RegisteredService>();
services.add(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
when(servicesManager.getAllServices()).thenReturn(services);
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.setLoginUrl(CAS_URL);
oauth20WrapperController.setServicesManager(servicesManager);
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
assertEquals(
OAuthUtils.addParameter(CAS_URL, "service", CAS_URL + CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL),
redirectView.getUrl());
}
示例6: testOKWithState
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testOKWithState() throws Exception {
final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
+ OAuthConstants.AUTHORIZE_URL);
mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuthConstants.STATE, STATE);
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final ServicesManager servicesManager = mock(ServicesManager.class);
final List<RegisteredService> services = new ArrayList<RegisteredService>();
services.add(getRegisteredService(REDIRECT_URI, SERVICE_NAME));
when(servicesManager.getAllServices()).thenReturn(services);
final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
oauth20WrapperController.setLoginUrl(CAS_URL);
oauth20WrapperController.setServicesManager(servicesManager);
oauth20WrapperController.afterPropertiesSet();
final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
final HttpSession session = mockRequest.getSession();
assertEquals(REDIRECT_URI, session.getAttribute(OAuthConstants.OAUTH20_CALLBACKURL));
assertEquals(SERVICE_NAME, session.getAttribute(OAuthConstants.OAUTH20_SERVICE_NAME));
assertEquals(STATE, session.getAttribute(OAuthConstants.OAUTH20_STATE));
final View view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
final RedirectView redirectView = (RedirectView) view;
assertEquals(
OAuthUtils.addParameter(CAS_URL, "service", CAS_URL + CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL),
redirectView.getUrl());
}