fix bugs with inverted test for If-Modified-Since (impl and tests)
This commit is contained in:
parent
72245c00d0
commit
a4365f9b83
|
@ -161,7 +161,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
ifNoneMatch = ParameterUtil.parseETagValue(ifNoneMatch);
|
||||
if (responseResource.getIdElement() != null && responseResource.getIdElement().hasVersionIdPart()) {
|
||||
if (responseResource.getIdElement().getVersionIdPart().equals(ifNoneMatch)) {
|
||||
ourLog.debug("Returning HTTP 301 because request specified {}={}", Constants.HEADER_IF_NONE_MATCH, ifNoneMatch);
|
||||
ourLog.debug("Returning HTTP 304 because request specified {}={}", Constants.HEADER_IF_NONE_MATCH, ifNoneMatch);
|
||||
throw new NotModifiedException("Not Modified");
|
||||
}
|
||||
}
|
||||
|
@ -182,8 +182,8 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
lastModified = responseResource.getMeta().getLastUpdated();
|
||||
}
|
||||
|
||||
if (lastModified != null && lastModified.getTime() > ifModifiedSinceDate.getTime()) {
|
||||
ourLog.debug("Returning HTTP 301 because If-Modified-Since does not match");
|
||||
if (lastModified != null && lastModified.getTime() <= ifModifiedSinceDate.getTime()) {
|
||||
ourLog.debug("Returning HTTP 304 because If-Modified-Since does not match");
|
||||
throw new NotModifiedException("Not Modified");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,20 +57,38 @@ public class ReadDstu2Test {
|
|||
CloseableHttpResponse status;
|
||||
HttpGet httpGet;
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it has changed before the later time of 2012-01-01T13:00:00Z
|
||||
// so we expect a 304
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T13:00:00Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it has changed at the same time of 2012-01-01T12:12:12Z
|
||||
// so we expect a 304
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T12:12:12Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it has changed after the earlier time of 2012-01-01T10:00:00Z
|
||||
// so we expect a 200
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T10:00:00Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
|
|
@ -69,20 +69,38 @@ public class ReadDstu3Test {
|
|||
CloseableHttpResponse status;
|
||||
HttpGet httpGet;
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it hasn't changed after the later time of 2012-01-01T13:00:00Z
|
||||
// so we expect a 304 (Not Modified)
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T13:00:00Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it hasn't changed after the same time of 2012-01-01T12:12:12Z
|
||||
// so we expect a 304 (Not Modified)
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T12:12:12Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
||||
// Fixture was last modified at 2012-01-01T12:12:12Z
|
||||
// thus it has changed after the earlier time of 2012-01-01T10:00:00Z
|
||||
// so we expect a 200
|
||||
httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2");
|
||||
httpGet.addHeader(Constants.HEADER_IF_MODIFIED_SINCE, DateUtils.formatDate(new InstantDt("2012-01-01T10:00:00Z").getValue()));
|
||||
status = ourClient.execute(httpGet);
|
||||
try {
|
||||
assertEquals(304, status.getStatusLine().getStatusCode());
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(status);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue