Search in sources :

Example 41 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ResourceWebHandlerTests method partialContentSuffixRangeLargeSuffix.

@Test
public void partialContentSuffixRangeLargeSuffix() {
    MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=-11").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    setPathWithinHandlerMapping(exchange, "foo.txt");
    this.handler.handle(exchange).block(TIMEOUT);
    assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
    assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
    assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(10);
    assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 0-9/10");
    assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
    assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
    assertResponseBody(exchange, "Some text.");
}
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 42 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method consumesParseError.

@Test
public void consumesParseError() throws Exception {
    MockServerWebExchange exchange = postExchange("01");
    ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
    assertThat(condition.getMatchingCondition(exchange)).isNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 43 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method getMatchingCondition.

@Test
public void getMatchingCondition() throws Exception {
    MockServerWebExchange exchange = postExchange("text/plain");
    ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain", "application/xml");
    ConsumesRequestCondition result = condition.getMatchingCondition(exchange);
    assertConditions(result, "text/plain");
    condition = new ConsumesRequestCondition("application/xml");
    result = condition.getMatchingCondition(exchange);
    assertThat(result).isNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 44 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method consumesSingleNoMatch.

@Test
public void consumesSingleNoMatch() throws Exception {
    MockServerWebExchange exchange = postExchange("application/xml");
    ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
    assertThat(condition.getMatchingCondition(exchange)).isNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 45 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method compareToSingle.

@Test
public void compareToSingle() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
    ConsumesRequestCondition condition1 = new ConsumesRequestCondition("text/plain");
    ConsumesRequestCondition condition2 = new ConsumesRequestCondition("text/*");
    int result = condition1.compareTo(condition2, exchange);
    assertThat(result < 0).as("Invalid comparison result: " + result).isTrue();
    result = condition2.compareTo(condition1, exchange);
    assertThat(result > 0).as("Invalid comparison result: " + result).isTrue();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10