Search in sources :

Example 51 with MockServerWebExchange

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

the class ResourceWebHandlerTests method missingResourcePath.

@Test
public void missingResourcePath() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    setPathWithinHandlerMapping(exchange, "");
    this.handler.handle(exchange).block(TIMEOUT);
    assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 52 with MockServerWebExchange

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

the class ResourceWebHandlerTests method directory.

@Test
public void directory() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    setPathWithinHandlerMapping(exchange, "js/");
    this.handler.handle(exchange).block(TIMEOUT);
    assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 53 with MockServerWebExchange

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

the class ResourceWebHandlerTests method partialContentByteRangeNoEnd.

@Test
public void partialContentByteRangeNoEnd() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=9-").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 54 with MockServerWebExchange

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

the class ResourceWebHandlerTests method partialContentSuffixRangeLargeSuffix.

@Test
public void partialContentSuffixRangeLargeSuffix() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=-11").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(10, exchange.getResponse().getHeaders().getContentLength());
    assertEquals("bytes 0-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, "Some text.");
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 55 with MockServerWebExchange

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

the class ResourceWebHandlerTests method noPathWithinHandlerMappingAttribute.

@Test(expected = IllegalStateException.class)
public void noPathWithinHandlerMappingAttribute() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    this.handler.handle(exchange).block(TIMEOUT);
}
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