Search in sources :

Example 6 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampConditionalPutConflict.

@Test
public void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
    Instant oneMinuteAgo = currentDate.minusSeconds(60);
    long millis = oneMinuteAgo.toEpochMilli();
    MockServerWebExchange exchange = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).toExchange();
    assertTrue(exchange.checkNotModified(currentDate));
    assertEquals(412, exchange.getResponse().getStatusCode().value());
    assertEquals(-1, exchange.getResponse().getHeaders().getLastModified());
}
Also used : Instant(java.time.Instant) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 7 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedETagWeakStrong.

@Test
public void checkNotModifiedETagWeakStrong() {
    String eTag = "\"Foo\"";
    String weakEtag = String.format("W/%s", eTag);
    MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).toExchange();
    assertTrue(exchange.checkNotModified(weakEtag));
    assertEquals(304, exchange.getResponse().getStatusCode().value());
    assertEquals(weakEtag, exchange.getResponse().getHeaders().getETag());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 8 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampWithLengthPart.

@Test
public void checkNotModifiedTimestampWithLengthPart() throws Exception {
    long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
    String header = "Wed, 09 Apr 2014 09:57:42 GMT; length=13774";
    MockServerWebExchange exchange = get("/").header("If-Modified-Since", header).toExchange();
    assertTrue(exchange.checkNotModified(Instant.ofEpochMilli(epochTime)));
    assertEquals(304, exchange.getResponse().getStatusCode().value());
    assertEquals(epochTime, exchange.getResponse().getHeaders().getLastModified());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 9 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedHeaderAlreadySet.

@Test
public void checkNotModifiedHeaderAlreadySet() {
    MockServerWebExchange exchange = get("/").ifModifiedSince(currentDate.toEpochMilli()).toExchange();
    exchange.getResponse().getHeaders().add("Last-Modified", CURRENT_TIME);
    assertTrue(exchange.checkNotModified(currentDate));
    assertEquals(304, exchange.getResponse().getStatusCode().value());
    assertEquals(1, exchange.getResponse().getHeaders().get("Last-Modified").size());
    assertEquals(CURRENT_TIME, exchange.getResponse().getHeaders().getFirst("Last-Modified"));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 10 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestamp.

@Test
public void checkNotModifiedTimestamp() throws Exception {
    MockServerWebExchange exchange = get("/").ifModifiedSince(currentDate.toEpochMilli()).toExchange();
    assertTrue(exchange.checkNotModified(currentDate));
    assertEquals(304, exchange.getResponse().getStatusCode().value());
    assertEquals(currentDate.toEpochMilli(), exchange.getResponse().getHeaders().getLastModified());
}
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