This commit is contained in:
jamesagnew 2019-06-18 05:40:00 -04:00
parent 9e9be00088
commit c7798fee48
3 changed files with 59 additions and 42 deletions

View File

@ -748,7 +748,12 @@ public class RestfulServerUtils {
} }
if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) { 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()) { if (fullId != null && fullId.hasVersionIdPart()) {
String versionIdPart = fullId.getVersionIdPart(); String versionIdPart = fullId.getVersionIdPart();
response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart)); response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart));
@ -758,6 +763,7 @@ public class RestfulServerUtils {
} }
} }
} }
}
// Binary handling // Binary handling
String contentType; String contentType;

View File

@ -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 @Test
public void testUpdateWithoutConditionalUrl() throws Exception { public void testUpdateWithoutConditionalUrl() throws Exception {

View File

@ -1,6 +1,9 @@
package ca.uhn.fhir.rest.server; package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.containsString; 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.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
@ -8,6 +11,7 @@ import static org.junit.Assert.assertThat;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import ca.uhn.fhir.model.primitive.InstantDt;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse; 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 final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(UpdateDstu3Test.class);
private static int ourPort; private static int ourPort;
private static Server ourServer; private static Server ourServer;
private static InstantType ourSetLastUpdated;
@Before @Before
public void before() { public void before() {
ourConditionalUrl = null; ourConditionalUrl = null;
ourId = 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 @Test
@ -180,7 +219,11 @@ public class UpdateDstu3Test {
return new MethodOutcome(id, oo, true); 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;
} }
} }