Use long for expires and lastModified in HeaderAssertions

This commit changes the type of parameters so that HeaderAssertions
can assert expires and lastModified properly.

Issue: SPR-17194
This commit is contained in:
Toshiaki Maki 2018-08-18 01:20:59 +09:00 committed by Rossen Stoyanchev
parent f87a37fd0d
commit d570f82456
2 changed files with 35 additions and 2 deletions

View File

@ -181,14 +181,14 @@ public class HeaderAssertions {
/**
* Expect an "Expires" header with the given value.
*/
public WebTestClient.ResponseSpec expires(int expires) {
public WebTestClient.ResponseSpec expires(long expires) {
return assertHeader("Expires", expires, getHeaders().getExpires());
}
/**
* Expect a "Last-Modified" header with the given value.
*/
public WebTestClient.ResponseSpec lastModified(int lastModified) {
public WebTestClient.ResponseSpec lastModified(long lastModified) {
return assertHeader("Last-Modified", lastModified, getHeaders().getLastModified());
}

View File

@ -17,6 +17,8 @@
package org.springframework.test.web.reactive.server;
import java.net.URI;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
@ -217,6 +219,37 @@ public class HeaderAssertionTests {
}
}
@Test
public void expires() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setExpires(expires);
HeaderAssertions assertions = headerAssertions(headers);
assertions.expires(expires.toInstant().toEpochMilli());
try {
assertions.expires(expires.toInstant().toEpochMilli() + 1);
fail("Wrong value expected");
}
catch (AssertionError error) {
// Expected
}
}
@Test
public void lastModified() {
HttpHeaders headers = new HttpHeaders();
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
headers.setLastModified(lastModified.toInstant().toEpochMilli());
HeaderAssertions assertions = headerAssertions(headers);
assertions.lastModified(lastModified.toInstant().toEpochMilli());
try {
assertions.lastModified(lastModified.toInstant().toEpochMilli() + 1);
fail("Wrong value expected");
}
catch (AssertionError error) {
// Expected
}
}
private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));