use of javax.servlet.Filter in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable.
@Test
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());
verify(context.getBean(CounterService.class)).increment("status.404.knownPath.someVariable");
verify(context.getBean(GaugeService.class)).submit(eq("response.knownPath.someVariable"), anyDouble());
context.close();
}
use of javax.servlet.Filter in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithTemplateVariable.
@Test
public void recordsHttpInteractionsWithTemplateVariable() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
verify(context.getBean(CounterService.class)).increment("status.200.templateVarTest.someVariable");
verify(context.getBean(GaugeService.class)).submit(eq("response.templateVarTest.someVariable"), anyDouble());
context.close();
}
use of javax.servlet.Filter in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithWildcardMapping.
@Test
public void recordsHttpInteractionsWithWildcardMapping() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
mvc.perform(get("/wildcardMapping/foo")).andExpect(status().isOk());
verify(context.getBean(CounterService.class)).increment("status.200.wildcardMapping.star");
verify(context.getBean(GaugeService.class)).submit(eq("response.wildcardMapping.star"), anyDouble());
context.close();
}
use of javax.servlet.Filter in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method records404HttpInteractionsAsSingleMetric.
@Test
public void records404HttpInteractionsAsSingleMetric() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
Filter filter = context.getBean(Filter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());
mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());
verify(context.getBean(CounterService.class), times(2)).increment("status.404.unmapped");
verify(context.getBean(GaugeService.class), times(2)).submit(eq("response.unmapped"), anyDouble());
context.close();
}
use of javax.servlet.Filter in project spring-boot by spring-projects.
the class ManagementWebSecurityAutoConfigurationTests method realmSameForManagement.
// gh-2466
@Test
public void realmSameForManagement() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(AuthenticationConfig.class, SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, AuditAutoConfiguration.class);
this.context.refresh();
Filter filter = this.context.getBean("springSecurityFilterChain", Filter.class);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).addFilters(filter).build();
// no user (Main)
mockMvc.perform(MockMvcRequestBuilders.get("/home")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(springAuthenticateRealmHeader());
// invalid user (Main)
mockMvc.perform(MockMvcRequestBuilders.get("/home").header("authorization", "Basic xxx")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(springAuthenticateRealmHeader());
// no user (Management)
mockMvc.perform(MockMvcRequestBuilders.get("/beans")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(springAuthenticateRealmHeader());
// invalid user (Management)
mockMvc.perform(MockMvcRequestBuilders.get("/beans").header("authorization", "Basic xxx")).andExpect(MockMvcResultMatchers.status().isUnauthorized()).andExpect(springAuthenticateRealmHeader());
}
Aggregations