Search in sources :

Example 1 with Resources

use of org.springframework.boot.autoconfigure.web.WebProperties.Resources in project spring-boot by spring-projects.

the class DefaultErrorViewResolverTests method setup.

@BeforeEach
void setup() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.refresh();
    this.resourcesProperties = new Resources();
    TemplateAvailabilityProviders templateAvailabilityProviders = new TestTemplateAvailabilityProviders(this.templateAvailabilityProvider);
    this.resolver = new DefaultErrorViewResolver(applicationContext, this.resourcesProperties, templateAvailabilityProviders);
}
Also used : TemplateAvailabilityProviders(org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Resources(org.springframework.boot.autoconfigure.web.WebProperties.Resources) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Resources

use of org.springframework.boot.autoconfigure.web.WebProperties.Resources in project spring-boot by spring-projects.

the class LocalDevToolsAutoConfigurationTests method resourceCachePeriodIsZero.

@Test
void resourceCachePeriodIsZero() throws Exception {
    this.context = getContext(() -> initializeAndRun(WebResourcesConfig.class));
    Resources properties = this.context.getBean(WebProperties.class).getResources();
    assertThat(properties.getCache().getPeriod()).isZero();
}
Also used : Resources(org.springframework.boot.autoconfigure.web.WebProperties.Resources) WebProperties(org.springframework.boot.autoconfigure.web.WebProperties) Test(org.junit.jupiter.api.Test)

Example 3 with Resources

use of org.springframework.boot.autoconfigure.web.WebProperties.Resources 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 4 with Resources

use of org.springframework.boot.autoconfigure.web.WebProperties.Resources 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

Resources (org.springframework.boot.autoconfigure.web.WebProperties.Resources)4 Test (org.junit.jupiter.api.Test)3 ErrorProperties (org.springframework.boot.autoconfigure.web.ErrorProperties)2 AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)2 ErrorAttributes (org.springframework.boot.web.reactive.error.ErrorAttributes)2 ApplicationContext (org.springframework.context.ApplicationContext)2 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 TemplateAvailabilityProviders (org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders)1 WebProperties (org.springframework.boot.autoconfigure.web.WebProperties)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 MediaType (org.springframework.http.MediaType)1 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)1 ServerRequest (org.springframework.web.reactive.function.server.ServerRequest)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1