Search in sources :

Example 6 with MockFilterConfig

use of cn.taketoday.mock.web.MockFilterConfig in project today-infrastructure by TAKETODAY.

the class ServletWebServerApplicationContextTests method delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames.

@Test
void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames() {
    addWebServerFactoryBean();
    DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean("filterBean");
    this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer));
    BeanDefinition filterBeanDefinition = beanDefinition(new IllegalStateException("Create FilterBean Failure"));
    filterBeanDefinition.setLazyInit(true);
    this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
    this.context.refresh();
    ServletContext servletContext = getWebServerFactory().getServletContext();
    then(servletContext).should(atMost(1)).addFilter(anyString(), this.filterCaptor.capture());
    // Up to this point the filterBean should not have been created, calling
    // the delegate proxy will trigger creation and an exception
    assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> {
        this.filterCaptor.getValue().init(new MockFilterConfig());
        this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
    }).havingRootCause().isInstanceOf(IllegalStateException.class).withMessageContaining("Create FilterBean Failure");
}
Also used : DelegatingFilterProxyRegistrationBean(cn.taketoday.framework.web.servlet.DelegatingFilterProxyRegistrationBean) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockHttpServletRequest(cn.taketoday.mock.web.MockHttpServletRequest) ServletContext(jakarta.servlet.ServletContext) AbstractBeanDefinition(cn.taketoday.beans.factory.support.AbstractBeanDefinition) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) MockFilterChain(cn.taketoday.mock.web.MockFilterChain) MockHttpServletResponse(cn.taketoday.mock.web.MockHttpServletResponse) MockFilterConfig(cn.taketoday.mock.web.MockFilterConfig) Test(org.junit.jupiter.api.Test)

Aggregations

MockFilterChain (cn.taketoday.mock.web.MockFilterChain)6 MockFilterConfig (cn.taketoday.mock.web.MockFilterConfig)6 MockHttpServletRequest (cn.taketoday.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (cn.taketoday.mock.web.MockHttpServletResponse)6 Test (org.junit.jupiter.api.Test)6 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)4 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)2 AbstractBeanDefinition (cn.taketoday.beans.factory.support.AbstractBeanDefinition)2 CapturedOutput (cn.taketoday.framework.test.system.CapturedOutput)2 OutputCaptureExtension (cn.taketoday.framework.test.system.OutputCaptureExtension)2 ErrorPage (cn.taketoday.framework.web.server.ErrorPage)2 DelegatingFilterProxyRegistrationBean (cn.taketoday.framework.web.servlet.DelegatingFilterProxyRegistrationBean)2 ErrorPageFilter (cn.taketoday.framework.web.servlet.support.ErrorPageFilter)2 HttpStatus (cn.taketoday.http.HttpStatus)2 MockRequestDispatcher (cn.taketoday.mock.web.MockRequestDispatcher)2 MissingRequestParameterException (cn.taketoday.web.bind.MissingRequestParameterException)2 DeferredResult (cn.taketoday.web.context.async.DeferredResult)2 StandardServletAsyncWebRequest (cn.taketoday.web.context.async.StandardServletAsyncWebRequest)2 WebAsyncManager (cn.taketoday.web.context.async.WebAsyncManager)2 WebAsyncUtils (cn.taketoday.web.context.async.WebAsyncUtils)2