Search in sources :

Example 1 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedTimestampWithLengthPart.

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

Example 2 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedETagWithSeparatorChars.

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

Example 3 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedMultipleETags.

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

Example 4 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedInvalidIfNoneMatchHeader.

// SPR-14559
@Test
public void checkNotModifiedInvalidIfNoneMatchHeader() {
    String eTag = "\"etagvalue\"";
    MockServerWebExchange exchange = get("/").ifNoneMatch("missingquotes").toExchange();
    assertFalse(exchange.checkNotModified(eTag));
    assertNull(exchange.getResponse().getStatusCode());
    assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 5 with MockServerWebExchange

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

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedETagAndModifiedTimestamp.

// SPR-14224
@Test
public void checkNotModifiedETagAndModifiedTimestamp() {
    String eTag = "\"Foo\"";
    Instant oneMinuteAgo = currentDate.minusSeconds(60);
    MockServerWebExchange exchange = get("/").ifNoneMatch(eTag).ifModifiedSince(oneMinuteAgo.toEpochMilli()).toExchange();
    assertTrue(exchange.checkNotModified(eTag, currentDate));
    assertEquals(304, exchange.getResponse().getStatusCode().value());
    assertEquals(eTag, exchange.getResponse().getHeaders().getETag());
    assertEquals(currentDate.toEpochMilli(), exchange.getResponse().getHeaders().getLastModified());
}
Also used : Instant(java.time.Instant) 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