use of org.springframework.mock.web.MockHttpSession in project ORCID-Source by ORCID.
the class FundingsControllerTest method testGetFundingsJson.
@Test
public void testGetFundingsJson() {
when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
request.setSession(session);
request.addPreferredLocale(new Locale("us", "EN"));
List<FundingForm> fundings = fundingController.getFundingsJson(request, "1");
assertNotNull(fundings);
assertEquals(1, fundings.size());
FundingForm funding = fundings.get(0);
List<Contributor> contributors = funding.getContributors();
Contributor contributor = contributors.get(0);
assertNull(contributor.getEmail());
assertEquals("Jaylen Kessler", contributor.getCreditName().getValue());
contributor = contributors.get(1);
assertNull(contributor.getEmail());
assertEquals("John Smith", contributor.getCreditName().getValue());
contributor = contributors.get(2);
assertNull(contributor.getEmail());
assertEquals("Credit Name", contributor.getCreditName().getValue());
// contributor is an ORCID user with private name
contributor = contributors.get(3);
assertNull(contributor.getEmail());
assertNull(contributor.getCreditName().getValue());
}
use of org.springframework.mock.web.MockHttpSession in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifyStartAuthentication.
@Test
public void verifyStartAuthentication() throws Exception {
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
final MockHttpSession mockSession = new MockHttpSession();
mockRequest.setSession(mockSession);
final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
when(servletExternalContext.getNativeResponse()).thenReturn(mockResponse);
final MockRequestContext mockRequestContext = new MockRequestContext();
mockRequestContext.setExternalContext(servletExternalContext);
mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.getService(MY_SERVICE));
final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
final TwitterClient twitterClient = new TwitterClient("3nJPbVTVRZWAyUgoUKQ8UA", "h6LZyZJmcW46Vu8R47MYfeXTSYGI30EqnWaSwVhFkbA");
final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients, null, mock(CentralAuthenticationService.class), "theme", "locale", false);
final Event event = action.execute(mockRequestContext);
assertEquals("error", event.getId());
assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
final Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration> urls = (Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration>) flowScope.get(DelegatedClientAuthenticationAction.PAC4J_URLS);
assertFalse(urls.isEmpty());
assertSame(2, urls.size());
}
use of org.springframework.mock.web.MockHttpSession in project spring-security by spring-projects.
the class HelloWorldApplicationTests method loginUserValidateLogout.
@Test
public void loginUserValidateLogout() throws Exception {
// @formatter:off
MvcResult mvcResult = this.mockMvc.perform(formLogin().user("user").password("password")).andExpect(authenticated()).andReturn();
// @formatter:on
MockHttpSession httpSession = (MockHttpSession) mvcResult.getRequest().getSession(false);
// @formatter:off
this.mockMvc.perform(post("/logout").with(csrf()).session(httpSession)).andExpect(unauthenticated());
this.mockMvc.perform(get("/user/index").session(httpSession)).andExpect(unauthenticated()).andExpect(status().is3xxRedirection());
// @formatter:on
}
use of org.springframework.mock.web.MockHttpSession in project spring-security-oauth by spring-projects.
the class HttpSessionOAuthRememberMeServicesTests method testNoTokensRemembered.
@Test
public void testNoTokensRemembered() {
MockHttpSession mockHttpSession = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setSession(mockHttpSession);
HttpSessionOAuthRememberMeServices oAuthRememberMeService = new HttpSessionOAuthRememberMeServices();
Map<String, OAuthConsumerToken> tokens = new HashMap<String, OAuthConsumerToken>();
oAuthRememberMeService.rememberTokens(tokens, request, response);
Assert.assertEquals(0, oAuthRememberMeService.loadRememberedTokens(request, response).size());
}
use of org.springframework.mock.web.MockHttpSession in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerScopeIntegrationTests method setUp.
@Before
public void setUp() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
}
Aggregations