Test fix
This commit is contained in:
parent
9e9be00088
commit
c7798fee48
|
@ -748,7 +748,12 @@ public class RestfulServerUtils {
|
|||
}
|
||||
|
||||
if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) {
|
||||
if (theRequestDetails.getRequestType() == RequestTypeEnum.GET) {
|
||||
if (theRequestDetails.getRestOperationType() != null) {
|
||||
switch (theRequestDetails.getRestOperationType()) {
|
||||
case CREATE:
|
||||
case UPDATE:
|
||||
case READ:
|
||||
case VREAD:
|
||||
if (fullId != null && fullId.hasVersionIdPart()) {
|
||||
String versionIdPart = fullId.getVersionIdPart();
|
||||
response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart));
|
||||
|
@ -758,6 +763,7 @@ public class RestfulServerUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Binary handling
|
||||
String contentType;
|
||||
|
|
|
@ -118,38 +118,6 @@ public class UpdateDstu2Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReturnsETagAndUpdate() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.setId("123");
|
||||
patient.addIdentifier().setValue("002");
|
||||
ourSetLastUpdated = new InstantDt("2002-04-22T11:22:33.022Z");
|
||||
|
||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/123");
|
||||
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
ourLog.info("Response was:\n{}", status);
|
||||
|
||||
assertThat(responseContent, is(not(emptyString())));
|
||||
|
||||
Patient actualPatient = (Patient) ourCtx.newXmlParser().parseResource(responseContent);
|
||||
assertEquals(patient.getId().getIdPart(), actualPatient.getId().getIdPart());
|
||||
assertEquals(patient.getIdentifier().get(0).getValue(), actualPatient.getIdentifier().get(0).getValue());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals(null, status.getFirstHeader("location"));
|
||||
assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue());
|
||||
assertEquals("W/\"002\"", status.getFirstHeader(Constants.HEADER_ETAG_LC).getValue());
|
||||
assertEquals("Mon, 22 Apr 2002 11:22:33 GMT", status.getFirstHeader(Constants.HEADER_LAST_MODIFIED_LOWERCASE).getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWithoutConditionalUrl() throws Exception {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.hamcrest.text.IsEmptyString.emptyString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
@ -8,6 +11,7 @@ import static org.junit.Assert.assertThat;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
|
@ -38,11 +42,46 @@ public class UpdateDstu3Test {
|
|||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(UpdateDstu3Test.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static InstantType ourSetLastUpdated;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourConditionalUrl = null;
|
||||
ourId = null;
|
||||
ourSetLastUpdated = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateReturnsETagAndUpdate() throws Exception {
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.setId("123");
|
||||
patient.addIdentifier().setValue("002");
|
||||
ourSetLastUpdated = new InstantType("2002-04-22T11:22:33.022Z");
|
||||
|
||||
HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/123");
|
||||
httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
|
||||
|
||||
HttpResponse status = ourClient.execute(httpPost);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
ourLog.info("Response was:\n{}", status);
|
||||
|
||||
assertThat(responseContent, is(not(emptyString())));
|
||||
|
||||
Patient actualPatient = (Patient) ourCtx.newXmlParser().parseResource(responseContent);
|
||||
assertEquals(patient.getIdElement().getIdPart(), actualPatient.getIdElement().getIdPart());
|
||||
assertEquals(patient.getIdentifier().get(0).getValue(), actualPatient.getIdentifier().get(0).getValue());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
assertEquals(null, status.getFirstHeader("location"));
|
||||
assertEquals("http://localhost:" + ourPort + "/Patient/123/_history/002", status.getFirstHeader("content-location").getValue());
|
||||
assertEquals("W/\"002\"", status.getFirstHeader(Constants.HEADER_ETAG_LC).getValue());
|
||||
assertEquals("Mon, 22 Apr 2002 11:22:33 GMT", status.getFirstHeader(Constants.HEADER_LAST_MODIFIED_LOWERCASE).getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -180,7 +219,11 @@ public class UpdateDstu3Test {
|
|||
return new MethodOutcome(id, oo, true);
|
||||
}
|
||||
|
||||
return new MethodOutcome(id, oo);
|
||||
thePatient.getMeta().setLastUpdatedElement(ourSetLastUpdated);
|
||||
|
||||
MethodOutcome retVal = new MethodOutcome(id, oo);
|
||||
retVal.setResource(thePatient);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue