use of org.springframework.core.Ordered in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletAndFilterBeans.
@Test
void servletAndFilterBeans() {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
Filter filter1 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter1).getOrder()).willReturn(1);
Filter filter2 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter2).getOrder()).willReturn(2);
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.registerBeanDefinition("filterBean2", beanDefinition(filter2));
this.context.registerBeanDefinition("filterBean1", beanDefinition(filter1));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
ServletContext servletContext = factory.getServletContext();
InOrder ordered = inOrder(servletContext);
then(factory.getServletContext()).should().addServlet("servletBean", servlet);
then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/");
then(factory.getServletContext()).should(ordered).addFilter("filterBean1", filter1);
then(factory.getServletContext()).should(ordered).addFilter("filterBean2", filter2);
then(factory.getRegisteredFilter(0).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
then(factory.getRegisteredFilter(1).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
}
use of org.springframework.core.Ordered in project spring-boot by spring-projects.
the class DispatcherTests method ordersMappers.
@Test
void ordersMappers() throws Exception {
HandlerMapper mapper1 = mock(HandlerMapper.class, withSettings().extraInterfaces(Ordered.class));
HandlerMapper mapper2 = mock(HandlerMapper.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) mapper1).getOrder()).willReturn(1);
given(((Ordered) mapper2).getOrder()).willReturn(2);
List<HandlerMapper> mappers = Arrays.asList(mapper2, mapper1);
Dispatcher dispatcher = new Dispatcher(AccessManager.PERMIT_ALL, mappers);
dispatcher.handle(this.serverRequest, this.serverResponse);
InOrder inOrder = inOrder(mapper1, mapper2);
then(mapper1).should(inOrder).getHandler(this.serverRequest);
then(mapper2).should(inOrder).getHandler(this.serverRequest);
}
use of org.springframework.core.Ordered in project spring-boot by spring-projects.
the class SpringBootDependencyInjectionTestExecutionListenerTests method orderShouldBeSameAsDependencyInjectionTestExecutionListener.
@Test
void orderShouldBeSameAsDependencyInjectionTestExecutionListener() {
Ordered injectionListener = new DependencyInjectionTestExecutionListener();
assertThat(this.reportListener.getOrder()).isEqualTo(injectionListener.getOrder());
}
use of org.springframework.core.Ordered in project spring-cloud-gateway by spring-cloud.
the class GatewayFilterSpec method filter.
public GatewayFilterSpec filter(GatewayFilter gatewayFilter, int order) {
if (gatewayFilter instanceof Ordered) {
this.routeBuilder.filter(gatewayFilter);
log.warn("GatewayFilter already implements ordered " + gatewayFilter.getClass() + "ignoring order parameter: " + order);
return this;
}
this.routeBuilder.filter(new OrderedGatewayFilter(gatewayFilter, order));
return this;
}
use of org.springframework.core.Ordered in project spring-cloud-gateway by spring-cloud.
the class GatewayFilterSpecTests method testFilter.
private void testFilter(Class<? extends GatewayFilter> type, GatewayFilter gatewayFilter, int order) {
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
Route.Builder routeBuilder = Route.builder().id("123").uri("abc:123").predicate(exchange -> true);
RouteLocatorBuilder.Builder routes = new RouteLocatorBuilder(context).routes();
GatewayFilterSpec spec = new GatewayFilterSpec(routeBuilder, routes);
spec.filter(gatewayFilter);
Route route = routeBuilder.build();
assertThat(route.getFilters()).hasSize(1);
GatewayFilter filter = route.getFilters().get(0);
assertThat(filter).isInstanceOf(type);
Ordered ordered = (Ordered) filter;
assertThat(ordered.getOrder()).isEqualTo(order);
}
Aggregations