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"));
}
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);
}
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();
}
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;
}
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);
}
}
Aggregations