use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.
the class WebApplicationObjectSupportTests method testWebApplicationObjectSupportWithWrongContext.
@Test
@SuppressWarnings("resource")
public void testWebApplicationObjectSupportWithWrongContext() {
StaticApplicationContext ac = new StaticApplicationContext();
ac.registerBeanDefinition("test", new RootBeanDefinition(TestWebApplicationObject.class));
WebApplicationObjectSupport wao = (WebApplicationObjectSupport) ac.getBean("test");
assertThatIllegalStateException().isThrownBy(wao::getWebApplicationContext);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.
the class ModelInitializerTests method setup.
@BeforeEach
public void setup() {
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
ArgumentResolverConfigurer resolverConfigurer = new ArgumentResolverConfigurer();
resolverConfigurer.addCustomResolver(new ModelMethodArgumentResolver(adapterRegistry));
ControllerMethodResolver methodResolver = new ControllerMethodResolver(resolverConfigurer, adapterRegistry, new StaticApplicationContext(), Collections.emptyList());
this.modelInitializer = new ModelInitializer(methodResolver, adapterRegistry);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.
the class GroovyMarkupConfigurerTests method setup.
@BeforeEach
public void setup() throws Exception {
this.applicationContext = new StaticApplicationContext();
this.configurer = new GroovyMarkupConfigurer();
this.configurer.setResourceLoaderPath(RESOURCE_LOADER_PATH);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.
the class HandlerMethodMappingTests method detectHandlerMethodsInAncestorContexts.
@Test
public void detectHandlerMethodsInAncestorContexts() {
StaticApplicationContext cxt = new StaticApplicationContext();
cxt.registerSingleton("myHandler", MyHandler.class);
AbstractHandlerMethodMapping<String> mapping1 = new MyHandlerMethodMapping();
mapping1.setApplicationContext(new StaticApplicationContext(cxt));
mapping1.afterPropertiesSet();
assertThat(mapping1.getHandlerMethods().size()).isEqualTo(0);
AbstractHandlerMethodMapping<String> mapping2 = new MyHandlerMethodMapping();
mapping2.setDetectHandlerMethodsInAncestorContexts(true);
mapping2.setApplicationContext(new StaticApplicationContext(cxt));
mapping2.afterPropertiesSet();
assertThat(mapping2.getHandlerMethods().size()).isEqualTo(2);
}
use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.
the class DispatcherHandlerTests method handlerMappingOrder.
@Test
void handlerMappingOrder() {
HandlerMapping hm1 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
HandlerMapping hm2 = mock(HandlerMapping.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) hm1).getOrder()).willReturn(1);
given(((Ordered) hm2).getOrder()).willReturn(2);
given((hm1).getHandler(any())).willReturn(Mono.just((Supplier<String>) () -> "1"));
given((hm2).getHandler(any())).willReturn(Mono.just((Supplier<String>) () -> "2"));
StaticApplicationContext context = new StaticApplicationContext();
context.registerBean("b2", HandlerMapping.class, () -> hm2);
context.registerBean("b1", HandlerMapping.class, () -> hm1);
context.registerBean(HandlerAdapter.class, SupplierHandlerAdapter::new);
context.registerBean(HandlerResultHandler.class, StringHandlerResultHandler::new);
context.refresh();
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
assertThat(exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(5))).isEqualTo("1");
}
Aggregations