Search in sources :

Example 31 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class ResourceWebHandlerTests method partialContentSuffixRange.

@Test
public void partialContentSuffixRange() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=-1").toExchange();
    setPathWithinHandlerMapping(exchange, "foo.txt");
    this.handler.handle(exchange).block(TIMEOUT);
    assertEquals(HttpStatus.PARTIAL_CONTENT, exchange.getResponse().getStatusCode());
    assertEquals(MediaType.TEXT_PLAIN, exchange.getResponse().getHeaders().getContentType());
    assertEquals(1, exchange.getResponse().getHeaders().getContentLength());
    assertEquals("bytes 9-9/10", exchange.getResponse().getHeaders().getFirst("Content-Range"));
    assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
    assertEquals(1, exchange.getResponse().getHeaders().get("Accept-Ranges").size());
    assertResponseBody(exchange, ".");
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 32 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class ResourceWebHandlerTests method unsupportedHttpMethod.

@Test(expected = MethodNotAllowedException.class)
public void unsupportedHttpMethod() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.post("").toExchange();
    setPathWithinHandlerMapping(exchange, "foo.css");
    this.handler.handle(exchange).block(TIMEOUT);
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 33 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class HeadersRequestConditionTests method headerNotPresent.

@Test
public void headerNotPresent() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
    assertNotNull(condition.getMatchingCondition(exchange));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 34 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class HeadersRequestConditionTests method headerValueNoMatchNegated.

@Test
public void headerValueNoMatchNegated() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/").header("foo", "bar").toExchange();
    HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
    assertNull(condition.getMatchingCondition(exchange));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 35 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class ParamsRequestConditionTests method paramNotPresent.

@Test
public void paramNotPresent() throws Exception {
    MockServerWebExchange exchange = get("/").toExchange();
    assertNotNull(new ParamsRequestCondition("!foo").getMatchingCondition(exchange));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Aggregations

MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)135 Test (org.junit.Test)127 ClassPathResource (org.springframework.core.io.ClassPathResource)19 Resource (org.springframework.core.io.Resource)19 HandlerResult (org.springframework.web.reactive.HandlerResult)17 MethodParameter (org.springframework.core.MethodParameter)15 MediaType (org.springframework.http.MediaType)8 Instant (java.time.Instant)7 HttpHeaders (org.springframework.http.HttpHeaders)5 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)5 FileSystemResource (org.springframework.core.io.FileSystemResource)3 UrlResource (org.springframework.core.io.UrlResource)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3 CompositeContentTypeResolver (org.springframework.web.reactive.accept.CompositeContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Assert.assertSame (org.junit.Assert.assertSame)2 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)2