Fix tests

This commit is contained in:
jamesagnew 2018-01-08 08:51:29 -05:00
parent 19c6369175
commit b420d02f2a
1 changed files with 55 additions and 41 deletions

View File

@ -51,20 +51,20 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Patient p = new Patient(); Patient p = new Patient();
p.addName().addFamily("PATIENT"); p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong(); Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
ArgumentCaptor<RequestDetails> detailsCapt; ArgumentCaptor<RequestDetails> detailsCapt;
ArgumentCaptor<IBaseResource> tableCapt; ArgumentCaptor<IBaseResource> tableCapt;
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class); detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
tableCapt = ArgumentCaptor.forClass(IBaseResource.class); tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
assertNotNull(tableCapt.getValue().getIdElement().getIdPart()); assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong()); assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class); detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
tableCapt = ArgumentCaptor.forClass(IBaseResource.class); tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
/* /*
* Not do a conditional create * Not do a conditional create
*/ */
@ -77,9 +77,9 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
tableCapt = ArgumentCaptor.forClass(IBaseResource.class); tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
} }
@Test @Test
public void testJpaDelete() { public void testJpaDelete() {
Patient p = new Patient(); Patient p = new Patient();
@ -87,25 +87,25 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong(); Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
myPatientDao.delete(new IdDt("Patient", id), mySrd); myPatientDao.delete(new IdDt("Patient", id), mySrd);
ArgumentCaptor<RequestDetails> detailsCapt; ArgumentCaptor<RequestDetails> detailsCapt;
ArgumentCaptor<IBaseResource> tableCapt; ArgumentCaptor<IBaseResource> tableCapt;
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class); detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
tableCapt = ArgumentCaptor.forClass(IBaseResource.class); tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
assertNotNull(tableCapt.getValue().getIdElement().getIdPart()); assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong()); assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
} }
/* /*
* ***************************************************** * *****************************************************
* Note that non JPA specific operations get tested in individual * Note that non JPA specific operations get tested in individual
* operation test methods too * operation test methods too
* ***************************************************** * *****************************************************
*/ */
@Test @Test
public void testJpaUpdate() { public void testJpaUpdate() {
Patient p = new Patient(); Patient p = new Patient();
@ -120,13 +120,13 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
ArgumentCaptor<RequestDetails> detailsCapt; ArgumentCaptor<RequestDetails> detailsCapt;
ArgumentCaptor<IBaseResource> tableCapt; ArgumentCaptor<IBaseResource> tableCapt;
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class); detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
tableCapt = ArgumentCaptor.forClass(IBaseResource.class); tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
assertNotNull(tableCapt.getValue().getIdElement().getIdPart()); assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong()); assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
/* /*
* Now do a conditional update * Now do a conditional update
*/ */
@ -158,7 +158,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture()); verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
assertEquals(id2, tableCapt.getAllValues().get(3).getIdElement().getIdPartAsLong()); assertEquals(id2, tableCapt.getAllValues().get(3).getIdElement().getIdPartAsLong());
} }
@Test @Test
@ -179,12 +179,13 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
p.addName().addFamily("PATIENT"); p.addName().addFamily("PATIENT");
IIdType id = myPatientDao.create(p, mySrd).getId(); IIdType id = myPatientDao.create(p, mySrd).getId();
assertEquals(1L, id.getVersionIdPartAsLong().longValue()); assertEquals(1L, id.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@Test @Test
public void testRequestOperationDelete() { public void testRequestOperationDelete() {
Patient p = new Patient(); Patient p = new Patient();
@ -203,17 +204,19 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
IIdType newId = myPatientDao.delete(new IdDt("Patient/" + id), mySrd).getId(); IIdType newId = myPatientDao.delete(new IdDt("Patient/" + id), mySrd).getId();
assertEquals(2L, newId.getVersionIdPartAsLong().longValue()); assertEquals(2L, newId.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourcePreDelete(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceDeleted(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceDeleted(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@Test @Test
public void testRequestOperationDeleteMulti() { public void testRequestOperationDeleteMulti() {
myDaoConfig.setAllowMultipleDelete(true); myDaoConfig.setAllowMultipleDelete(true);
Patient p = new Patient(); Patient p = new Patient();
p.addName().addFamily("PATIENT"); p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong(); Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
@ -235,8 +238,10 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
String oo = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome()); String oo = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome());
ourLog.info(oo); ourLog.info(oo);
assertThat(oo, containsString("deleted 2 resource(s)")); assertThat(oo, containsString("deleted 2 resource(s)"));
verify(myRequestOperationCallback, times(2)).resourcePreDelete(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class)); verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@ -258,16 +263,17 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Bundle xactBundle = new Bundle(); Bundle xactBundle = new Bundle();
xactBundle.setType(BundleTypeEnum.TRANSACTION); xactBundle.setType(BundleTypeEnum.TRANSACTION);
xactBundle xactBundle
.addEntry() .addEntry()
.setResource(p) .setResource(p)
.getRequest() .getRequest()
.setUrl("Patient") .setUrl("Patient")
.setMethod(HTTPVerbEnum.POST); .setMethod(HTTPVerbEnum.POST);
Bundle resp = mySystemDao.transaction(mySrd, xactBundle); Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation());
assertEquals(1L, newId.getVersionIdPartAsLong().longValue()); assertEquals(1L, newId.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@ -290,16 +296,18 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Bundle xactBundle = new Bundle(); Bundle xactBundle = new Bundle();
xactBundle.setType(BundleTypeEnum.TRANSACTION); xactBundle.setType(BundleTypeEnum.TRANSACTION);
xactBundle xactBundle
.addEntry() .addEntry()
.getRequest() .getRequest()
.setUrl("Patient/" + id) .setUrl("Patient/" + id)
.setMethod(HTTPVerbEnum.DELETE); .setMethod(HTTPVerbEnum.DELETE);
Bundle resp = mySystemDao.transaction(mySrd, xactBundle); Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation());
assertEquals(2L, newId.getVersionIdPartAsLong().longValue()); assertEquals(2L, newId.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourcePreDelete(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceDeleted(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceDeleted(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@ -307,7 +315,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
@Test @Test
public void testRequestOperationTransactionDeleteMulti() { public void testRequestOperationTransactionDeleteMulti() {
myDaoConfig.setAllowMultipleDelete(true); myDaoConfig.setAllowMultipleDelete(true);
Patient p = new Patient(); Patient p = new Patient();
p.addName().addFamily("PATIENT"); p.addName().addFamily("PATIENT");
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong(); Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
@ -328,14 +336,16 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Bundle xactBundle = new Bundle(); Bundle xactBundle = new Bundle();
xactBundle.setType(BundleTypeEnum.TRANSACTION); xactBundle.setType(BundleTypeEnum.TRANSACTION);
xactBundle xactBundle
.addEntry() .addEntry()
.getRequest() .getRequest()
.setUrl("Patient?name=PATIENT") .setUrl("Patient?name=PATIENT")
.setMethod(HTTPVerbEnum.DELETE); .setMethod(HTTPVerbEnum.DELETE);
Bundle resp = mySystemDao.transaction(mySrd, xactBundle); Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
assertNotNull(resp); assertNotNull(resp);
verify(myRequestOperationCallback, times(2)).resourcePreDelete(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class)); verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@ -361,18 +371,20 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
Bundle xactBundle = new Bundle(); Bundle xactBundle = new Bundle();
xactBundle.setType(BundleTypeEnum.TRANSACTION); xactBundle.setType(BundleTypeEnum.TRANSACTION);
xactBundle xactBundle
.addEntry() .addEntry()
.setResource(p) .setResource(p)
.getRequest() .getRequest()
.setUrl("Patient/" + id) .setUrl("Patient/" + id)
.setMethod(HTTPVerbEnum.PUT); .setMethod(HTTPVerbEnum.PUT);
Bundle resp = mySystemDao.transaction(mySrd, xactBundle); Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation()); IdDt newId = new IdDt(resp.getEntry().get(0).getResponse().getLocation());
assertEquals(2L, newId.getVersionIdPartAsLong().longValue()); assertEquals(2L, newId.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreUpdate(any(IBaseResource.class), any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class), any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class), any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }
@ -398,7 +410,9 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
assertEquals(2L, newId.getVersionIdPartAsLong().longValue()); assertEquals(2L, newId.getVersionIdPartAsLong().longValue());
verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreUpdate(any(IBaseResource.class), any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class), any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceUpdated(any(IBaseResource.class), any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourcePreCreate(any(IBaseResource.class));
verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class)); verify(myRequestOperationCallback, times(1)).resourceCreated(any(IBaseResource.class));
verifyNoMoreInteractions(myRequestOperationCallback); verifyNoMoreInteractions(myRequestOperationCallback);
} }