Search in sources :

Example 26 with StaticApplicationContext

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);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 27 with StaticApplicationContext

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);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with StaticApplicationContext

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);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with StaticApplicationContext

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);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 30 with StaticApplicationContext

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");
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Ordered(org.springframework.core.Ordered) Supplier(java.util.function.Supplier) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11