Search in sources :

Example 1 with AnnotationConfigServletWebApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext in project today-infrastructure by TAKETODAY.

the class ConditionalOnWebApplicationTests method testWebApplicationWithServletContext.

@Test
void testWebApplicationWithServletContext() {
    AnnotationConfigServletWebApplicationContext ctx = new AnnotationConfigServletWebApplicationContext();
    ctx.register(AnyWebApplicationConfiguration.class, ServletWebApplicationConfiguration.class, ReactiveWebApplicationConfiguration.class);
    ctx.setServletContext(new MockServletContext());
    ctx.refresh();
    this.context = ctx;
    assertThat(this.context.getBeansOfType(String.class)).containsExactly(entry("any", "any"), entry("servlet", "servlet"));
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(cn.taketoday.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotationConfigServletWebApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext in project today-infrastructure by TAKETODAY.

the class ResourceUrlProviderJavaConfigTests method setup.

@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(WebConfig.class);
    context.refresh();
    this.request = new MockHttpServletRequest("GET", "/");
    this.request.setContextPath("/myapp");
    this.response = new MockHttpServletResponse();
    this.filterChain = new MockFilterChain(this.servlet);
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) MockServletContext(cn.taketoday.web.mock.MockServletContext) MockHttpServletResponse(cn.taketoday.web.mock.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with AnnotationConfigServletWebApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext in project today-infrastructure by TAKETODAY.

the class ResourceUrlProviderTests method initializeOnCurrentContext.

@Test
@SuppressWarnings("resource")
void initializeOnCurrentContext() {
    AnnotationConfigServletWebApplicationContext parentContext = new AnnotationConfigServletWebApplicationContext();
    parentContext.setServletContext(new MockServletContext());
    parentContext.register(ParentHandlerMappingConfiguration.class);
    AnnotationConfigServletWebApplicationContext childContext = new AnnotationConfigServletWebApplicationContext();
    childContext.setParent(parentContext);
    childContext.setServletContext(new MockServletContext());
    childContext.register(HandlerMappingConfiguration.class);
    parentContext.refresh();
    childContext.refresh();
    ResourceUrlProvider parentUrlProvider = parentContext.getBean(ResourceUrlProvider.class);
    assertThat(parentUrlProvider.getHandlerMap()).isEmpty();
    assertThat(parentUrlProvider.isAutodetect()).isTrue();
    ResourceUrlProvider childUrlProvider = childContext.getBean(ResourceUrlProvider.class);
    assertThat(childUrlProvider.getHandlerMap()).containsOnlyKeys("/resources/**");
    assertThat(childUrlProvider.isAutodetect()).isFalse();
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(cn.taketoday.web.mock.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 4 with AnnotationConfigServletWebApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext in project today-infrastructure by TAKETODAY.

the class GroovyMarkupViewTests method createViewWithUrl.

private GroovyMarkupView createViewWithUrl(String viewUrl) throws Exception {
    AnnotationConfigServletWebApplicationContext ctx = new AnnotationConfigServletWebApplicationContext();
    ctx.register(GroovyMarkupConfiguration.class);
    ctx.refresh();
    GroovyMarkupView view = new GroovyMarkupView();
    view.setUrl(viewUrl);
    view.setApplicationContext(ctx);
    view.afterPropertiesSet();
    return view;
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext)

Example 5 with AnnotationConfigServletWebApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext in project today-infrastructure by TAKETODAY.

the class ParameterResolverRegistryTests method lookupStrategy.

@Test
void lookupStrategy() {
    try (AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext()) {
        context.setServletContext(new MockServletContext());
        context.refresh();
        ParameterResolvingRegistry registry = new ParameterResolvingRegistry();
        registry.setApplicationContext(context);
        // register defaults
        registry.registerDefaultStrategies();
        ParameterResolvingStrategy strategy = registry.findStrategy(testUser);
        assertThat(strategy).isNotNull().isInstanceOf(DataBinderParameterResolver.class);
        // mock
        testConverterParameterResolver(registry, int.class);
        testConverterParameterResolver(registry, long.class);
        testConverterParameterResolver(registry, float.class);
        testConverterParameterResolver(registry, short.class);
        testConverterParameterResolver(registry, double.class);
        testConverterParameterResolver(registry, boolean.class);
        testConverterParameterResolver(registry, String.class);
        testConverterParameterResolver(registry, Integer.class);
        testConverterParameterResolver(registry, Long.class);
        testConverterParameterResolver(registry, Short.class);
        testConverterParameterResolver(registry, Double.class);
        testConverterParameterResolver(registry, Boolean.class);
        testConverterParameterResolver(registry, Float.class);
    }
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(cn.taketoday.web.mock.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

AnnotationConfigServletWebApplicationContext (cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext)31 Test (org.junit.jupiter.api.Test)16 MockServletContext (cn.taketoday.web.mock.MockServletContext)9 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)9 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)3 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)3 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)3 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)3 MethodParameter (cn.taketoday.core.MethodParameter)2 MockServletContext (cn.taketoday.mock.web.MockServletContext)2 MockResolvableMethodParameter (cn.taketoday.web.handler.MockResolvableMethodParameter)2 DispatcherServlet (cn.taketoday.web.servlet.DispatcherServlet)2 Method (java.lang.reflect.Method)2