Search in sources :

Example 6 with AnnotationConfigReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext in project spring-boot by spring-projects.

the class MustacheAutoConfigurationTests method loadWithReactive.

private void loadWithReactive(Class<?> config) {
    this.reactiveWebContext = new AnnotationConfigReactiveWebApplicationContext();
    TestPropertyValues.of("spring.mustache.prefix=classpath:/mustache-templates/").applyTo(this.reactiveWebContext);
    if (config != null) {
        this.reactiveWebContext.register(config);
    }
    this.reactiveWebContext.register(BaseConfiguration.class);
    this.reactiveWebContext.refresh();
}
Also used : AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)

Example 7 with AnnotationConfigReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerTests method nonStandardErrorStatusCodeShouldNotFail.

@Test
void nonStandardErrorStatusCodeShouldNotFail() {
    ErrorAttributes errorAttributes = mock(ErrorAttributes.class);
    given(errorAttributes.getErrorAttributes(any(), any())).willReturn(getErrorAttributes());
    Resources resourceProperties = new Resources();
    ErrorProperties errorProperties = new ErrorProperties();
    ApplicationContext context = new AnnotationConfigReactiveWebApplicationContext();
    DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler(errorAttributes, resourceProperties, errorProperties, context);
    setupViewResolver(exceptionHandler);
    ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/some-other-path").accept(MediaType.TEXT_HTML));
    exceptionHandler.handle(exchange, new RuntimeException()).block();
}
Also used : ErrorAttributes(org.springframework.boot.web.reactive.error.ErrorAttributes) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ErrorProperties(org.springframework.boot.autoconfigure.web.ErrorProperties) Resources(org.springframework.boot.autoconfigure.web.WebProperties.Resources) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 8 with AnnotationConfigReactiveWebApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext in project spring-boot by spring-projects.

the class DefaultErrorWebExceptionHandlerTests method acceptsTextHtmlShouldNotConsiderMediaAllEvenWithQuality.

@Test
void acceptsTextHtmlShouldNotConsiderMediaAllEvenWithQuality() {
    ErrorAttributes errorAttributes = mock(ErrorAttributes.class);
    Resources resourceProperties = new Resources();
    ErrorProperties errorProperties = new ErrorProperties();
    ApplicationContext context = new AnnotationConfigReactiveWebApplicationContext();
    DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler(errorAttributes, resourceProperties, errorProperties, context);
    MediaType allWithQuality = new MediaType(MediaType.ALL.getType(), MediaType.ALL.getSubtype(), 0.9);
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").accept(allWithQuality));
    List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders();
    ServerRequest request = ServerRequest.create(exchange, readers);
    assertThat(exceptionHandler.acceptsTextHtml().test(request)).isFalse();
}
Also used : ErrorAttributes(org.springframework.boot.web.reactive.error.ErrorAttributes) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ErrorProperties(org.springframework.boot.autoconfigure.web.ErrorProperties) MediaType(org.springframework.http.MediaType) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Resources(org.springframework.boot.autoconfigure.web.WebProperties.Resources) ServerRequest(org.springframework.web.reactive.function.server.ServerRequest) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) Test(org.junit.jupiter.api.Test)

Aggregations

AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)8 Test (org.junit.jupiter.api.Test)7 Tomcat (org.apache.catalina.startup.Tomcat)3 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)3 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)3 HttpServer (reactor.netty.http.server.HttpServer)3 Server (org.eclipse.jetty.server.Server)2 ErrorProperties (org.springframework.boot.autoconfigure.web.ErrorProperties)2 Resources (org.springframework.boot.autoconfigure.web.WebProperties.Resources)2 ErrorAttributes (org.springframework.boot.web.reactive.error.ErrorAttributes)2 ApplicationContext (org.springframework.context.ApplicationContext)2 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)2 Undertow (io.undertow.Undertow)1 JettyReactiveWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory)1 NettyReactiveWebServerFactory (org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory)1 UndertowReactiveWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory)1 MediaType (org.springframework.http.MediaType)1 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)1