Search in sources :

Example 56 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedETagAndNotModifiedTimestamp.

@Test
void checkModifiedETagAndNotModifiedTimestamp() throws Exception {
    String currentETag = "\"Foo\"";
    String oldEtag = "\"Bar\"";
    long time = currentDate.toEpochMilli();
    MockServerHttpRequest request = get("/").ifNoneMatch(oldEtag).ifModifiedSince(time).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(currentETag, currentDate)).isFalse();
    assertThat(exchange.getResponse().getStatusCode()).isNull();
    assertThat(exchange.getResponse().getHeaders().getETag()).isEqualTo(currentETag);
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(time);
}
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 57 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampConditionalPutConflict.

@Test
void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
    Instant oneMinuteAgo = currentDate.minusSeconds(60);
    long millis = oneMinuteAgo.toEpochMilli();
    MockServerHttpRequest request = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(currentDate)).isTrue();
    assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(412);
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(-1);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) Instant(java.time.Instant) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 58 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedTimestampWithLengthPart.

@Test
void checkModifiedTimestampWithLengthPart() throws Exception {
    long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
    String header = "Tue, 08 Apr 2014 09:57:42 GMT; length=13774";
    MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(Instant.ofEpochMilli(epochTime))).isFalse();
    assertThat(exchange.getResponse().getStatusCode()).isNull();
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(epochTime);
}
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 59 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestamp.

@Test
void checkNotModifiedTimestamp() throws Exception {
    MockServerHttpRequest request = get("/").ifModifiedSince(currentDate.toEpochMilli()).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(currentDate)).isTrue();
    assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(304);
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(currentDate.toEpochMilli());
}
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 60 with MockServerHttpRequest

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.

the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampWithLengthPart.

@Test
void checkNotModifiedTimestampWithLengthPart() throws Exception {
    long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
    String header = "Wed, 09 Apr 2014 09:57:42 GMT; length=13774";
    MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    assertThat(exchange.checkNotModified(Instant.ofEpochMilli(epochTime))).isTrue();
    assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(304);
    assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(epochTime);
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)182 Test (org.junit.jupiter.api.Test)160 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)101 Mono (reactor.core.publisher.Mono)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)50 Collections (java.util.Collections)48 StepVerifier (reactor.test.StepVerifier)46 HttpHeaders (org.springframework.http.HttpHeaders)39 Flux (reactor.core.publisher.Flux)37 MediaType (org.springframework.http.MediaType)34 ServerWebExchange (org.springframework.web.server.ServerWebExchange)34 MultiValueMap (org.springframework.util.MultiValueMap)33 HttpStatus (org.springframework.http.HttpStatus)31 StandardCharsets (java.nio.charset.StandardCharsets)29 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)29 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)27 ClassPathResource (org.springframework.core.io.ClassPathResource)25 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)24 Optional (java.util.Optional)23