Search in sources :

Example 31 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class DispatcherHandlerTests method preFlightRequest.

@Test
void preFlightRequest() {
    WebHandler webHandler = mock(WebHandler.class);
    HandlerMapping handlerMapping = mock(HandlerMapping.class);
    given((handlerMapping).getHandler(any())).willReturn(Mono.just(webHandler));
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBean("handlerMapping", HandlerMapping.class, () -> handlerMapping);
    context.registerBean(HandlerAdapter.class, SimpleHandlerAdapter::new);
    context.registerBean(HandlerResultHandler.class, StringHandlerResultHandler::new);
    context.refresh();
    MockServerHttpRequest request = MockServerHttpRequest.options("/").header(HttpHeaders.ORIGIN, "https://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    new DispatcherHandler(context).handle(exchange).block(Duration.ofSeconds(0));
    verifyNoInteractions(webHandler);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) WebHandler(org.springframework.web.server.WebHandler) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) SimpleHandlerAdapter(org.springframework.web.reactive.result.SimpleHandlerAdapter) Test(org.junit.jupiter.api.Test)

Example 32 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class WebSocketAnnotationMethodMessageHandlerTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.applicationContext = new StaticApplicationContext();
    this.applicationContext.registerSingleton("controller", TestController.class);
    this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
    this.applicationContext.refresh();
    SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
    SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);
    this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
    this.messageHandler.setApplicationContext(this.applicationContext);
    this.messageHandler.afterPropertiesSet();
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) SimpMessageSendingOperations(org.springframework.messaging.simp.SimpMessageSendingOperations) SubscribableChannel(org.springframework.messaging.SubscribableChannel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 33 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-boot by spring-projects.

the class EndpointRequestTests method assertMatcher.

private RequestMatcherAssert assertMatcher(ServerWebExchangeMatcher matcher, PathMappedEndpoints pathMappedEndpoints) {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBean(WebEndpointProperties.class);
    if (pathMappedEndpoints != null) {
        context.registerBean(PathMappedEndpoints.class, () -> pathMappedEndpoints);
        WebEndpointProperties properties = context.getBean(WebEndpointProperties.class);
        if (!properties.getBasePath().equals(pathMappedEndpoints.getBasePath())) {
            properties.setBasePath(pathMappedEndpoints.getBasePath());
        }
    }
    return assertThat(new RequestMatcherAssert(context, matcher));
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) WebEndpointProperties(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties)

Example 34 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-boot by spring-projects.

the class DelegatingApplicationContextInitializerTests method noInitializers.

@Test
void noInitializers() {
    StaticApplicationContext context = new StaticApplicationContext();
    this.initializer.initialize(context);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 35 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-boot by spring-projects.

the class WelcomePageRouterFunctionFactoryTests method setup.

@BeforeEach
void setup() {
    this.applicationContext = new StaticApplicationContext();
    this.applicationContext.refresh();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

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