@Test public void testFilterOrdering() { load(); List<RegisteredFilter> registeredFilters = this.context .getBean(MockEmbeddedServletContainerFactory.class).getContainer() .getRegisteredFilters(); List<Filter> filters = new ArrayList<Filter>(registeredFilters.size()); for (RegisteredFilter registeredFilter : registeredFilters) { filters.add(registeredFilter.getFilter()); } Iterator<Filter> iterator = filters.iterator(); assertThat(iterator.next()).isInstanceOf(OrderedCharacterEncodingFilter.class); assertThat(iterator.next()).isInstanceOf(SessionRepositoryFilter.class); assertThat(iterator.next()).isInstanceOf(Filter.class); assertThat(iterator.next()).isInstanceOf(Filter.class); assertThat(iterator.next()).isInstanceOf(OrderedRequestContextFilter.class); assertThat(iterator.next()).isInstanceOf(FilterChainProxy.class); }
private void loadWeb(Class<?>... config) { AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); if (config.length > 0) { context.register(config); } context.register(DataSourcePoolMetadataProvidersConfiguration.class, CacheStatisticsAutoConfiguration.class, PublicMetricsAutoConfiguration.class, MockEmbeddedServletContainerFactory.class); context.refresh(); this.context = context; }
private void verifyContext() { MockEmbeddedServletContainerFactory containerFactory = getContainerFactory(); Servlet servlet = this.context.getBean( DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class); verify(containerFactory.getServletContext()).addServlet("dispatcherServlet", servlet); }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof ConfigurableEmbeddedServletContainer) { MockEmbeddedServletContainerFactory containerFactory = (MockEmbeddedServletContainerFactory) bean; assertThat(containerFactory.getServletContext()).isNull(); } return bean; }
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof ConfigurableEmbeddedServletContainer) { MockEmbeddedServletContainerFactory containerFactory = (MockEmbeddedServletContainerFactory) bean; assertNull(containerFactory.getServletContext()); } return bean; }
@Bean public EmbeddedServletContainerFactory containerFactory() { return new MockEmbeddedServletContainerFactory(); }
@Bean public MockEmbeddedServletContainerFactory containerFactory() { return new MockEmbeddedServletContainerFactory(); }
@Bean public MockEmbeddedServletContainerFactory embeddedServletContainerFactory() { return new MockEmbeddedServletContainerFactory(); }
private MockEmbeddedServletContainerFactory getContainerFactory() { return this.context.getBean(MockEmbeddedServletContainerFactory.class); }