use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class NoSpringSecurityMvcEndpointSecurityInterceptorTests method setup.
@Before
public void setup() throws Exception {
this.roles = Arrays.asList("SUPER_HERO");
this.securityInterceptor = new MvcEndpointSecurityInterceptor(true, this.roles);
this.endpoint = new TestEndpoint("a");
this.mvcEndpoint = new TestMvcEndpoint(this.endpoint);
this.handlerMethod = new HandlerMethod(this.mvcEndpoint, "invoke");
this.servletContext = new MockServletContext();
this.request = new MockHttpServletRequest(this.servletContext);
this.response = mock(HttpServletResponse.class);
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class SitePreferenceAutoConfigurationTests method sitePreferenceHandlerInterceptorRegistered.
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, SitePreferenceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class DeviceResolverAutoConfigurationTests method deviceResolverHandlerInterceptorRegistered.
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors).hasAtLeastOneElementOfType(DeviceResolverHandlerInterceptor.class);
}
use of org.springframework.mock.web.MockHttpServletRequest 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.MockHttpServletRequest in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method doesNotRecordRolledUpMetricsIfConfigured.
@Test
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.filter.gauge-submissions=", "endpoints.metrics.filter.counter-submissions=");
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
return null;
}
}).given(chain).doFilter(request, response);
filter.doFilter(request, response, chain);
verify(context.getBean(GaugeService.class), never()).submit(anyString(), anyDouble());
verify(context.getBean(CounterService.class), never()).increment(anyString());
context.close();
}
Aggregations