Search in sources :

Example 46 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class FilteringWebHandlerTests method handleErrorFromFilter.

@Test
public void handleErrorFromFilter() throws Exception {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerHttpResponse response = new MockServerHttpResponse();
    TestExceptionHandler exceptionHandler = new TestExceptionHandler();
    WebHttpHandlerBuilder.webHandler(new StubWebHandler()).filter(new ExceptionFilter()).exceptionHandler(exceptionHandler).build().handle(request, response).block();
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(exceptionHandler.ex).isNotNull();
    assertThat(exceptionHandler.ex.getMessage()).isEqualTo("boo");
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 47 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveMissingAcceptLanguageHeaderWithDefault.

@Test
public void resolveMissingAcceptLanguageHeaderWithDefault() {
    this.resolver.setDefaultLocale(US);
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(US);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 48 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method defaultLocale.

@Test
public void defaultLocale() {
    this.resolver.setDefaultLocale(JAPANESE);
    MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(JAPANESE);
    request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(US).build();
    exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(US);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 49 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveEmptyAcceptLanguageHeader.

@Test
public void resolveEmptyAcceptLanguageHeader() {
    MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isNull();
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 50 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class AcceptHeaderLocaleContextResolverTests method resolveEmptyAcceptLanguageHeaderWithDefault.

@Test
public void resolveEmptyAcceptLanguageHeaderWithDefault() {
    this.resolver.setDefaultLocale(US);
    MockServerHttpRequest request = MockServerHttpRequest.get("/").header(HttpHeaders.ACCEPT_LANGUAGE, "").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(this.resolver.resolveLocaleContext(exchange).getLocale()).isEqualTo(US);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)182 Test (org.junit.jupiter.api.Test)160 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)101 Mono (reactor.core.publisher.Mono)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)50 Collections (java.util.Collections)48 StepVerifier (reactor.test.StepVerifier)46 HttpHeaders (org.springframework.http.HttpHeaders)39 Flux (reactor.core.publisher.Flux)37 MediaType (org.springframework.http.MediaType)34 ServerWebExchange (org.springframework.web.server.ServerWebExchange)34 MultiValueMap (org.springframework.util.MultiValueMap)33 HttpStatus (org.springframework.http.HttpStatus)31 StandardCharsets (java.nio.charset.StandardCharsets)29 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)29 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)27 ClassPathResource (org.springframework.core.io.ClassPathResource)25 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)24 Optional (java.util.Optional)23