Merge pull request #879 from darktyco/issue-878-bundle-update-fix

Fixes issue #878 where resources in a bundle are updated even when no…
This commit is contained in:
James Agnew 2018-03-22 06:50:39 -04:00 committed by GitHub
commit b89e0e7020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 1 deletions

View File

@ -129,7 +129,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
HashSet<String> excludeElementsInEncoded = new HashSet<String>();
excludeElementsInEncoded.add("id");
excludeElementsInEncoded.add("meta");
excludeElementsInEncoded.add("*.meta");
EXCLUDE_ELEMENTS_IN_ENCODED = Collections.unmodifiableSet(excludeElementsInEncoded);
}

View File

@ -1193,6 +1193,62 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
}
@Test
public void testTransactionUpdateResourceNewVersionCreatedWhenDataChanges() {
Bundle request = new Bundle();
String patientId = "Patient/IShouldUpdate";
Patient p = new Patient();
p.addName().addFamily("Hello");
p.setId(patientId);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.PUT).setUrl(patientId);
Bundle initialBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, initialBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(initialBundleResponse));
Entry initialBundleResponseEntry = initialBundleResponse.getEntry().get(0);
assertEquals("201 Created", initialBundleResponseEntry.getResponse().getStatus());
assertThat(initialBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
p.addName().addFamily("AnotherName");
Bundle secondBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, secondBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(secondBundleResponse));
Entry secondBundleResponseEntry = secondBundleResponse.getEntry().get(0);
assertEquals("200 OK", secondBundleResponseEntry.getResponse().getStatus());
assertThat(secondBundleResponseEntry.getResponse().getEtag(), is(equalTo("2")));
}
@Test
public void testTransactionUpdateResourceNewVersionNotCreatedWhenDataNotChanged() {
Bundle request = new Bundle();
String patientId = "Patient/IShouldNotUpdate";
Patient p = new Patient();
p.addName().addFamily("Hello");
p.setId(patientId);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.PUT).setUrl(patientId);
Bundle initialBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, initialBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(initialBundleResponse));
Entry initialBundleResponseEntry = initialBundleResponse.getEntry().get(0);
assertEquals("201 Created", initialBundleResponseEntry.getResponse().getStatus());
assertThat(initialBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
Bundle secondBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, secondBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(secondBundleResponse));
Entry secondBundleResponseEntry = secondBundleResponse.getEntry().get(0);
assertEquals("200 OK", secondBundleResponseEntry.getResponse().getStatus());
assertThat(secondBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
}
@Test
public void testTransactionUpdateMatchUrlWithTwoMatch() {
String methodName = "testTransactionUpdateMatchUrlWithTwoMatch";