Add tests
This commit is contained in:
parent
1ac45e27c6
commit
7d4bb8b9cb
|
@ -3,6 +3,8 @@ package ca.uhn.fhir.jpa.dao.dstu2;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.config.TestDstu2Config;
|
||||
import ca.uhn.fhir.jpa.dao.*;
|
||||
import ca.uhn.fhir.jpa.dao.data.IResourceIndexedSearchParamStringDao;
|
||||
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
|
||||
|
@ -134,6 +136,10 @@ protected IFhirResourceDao<MedicationAdministration> myMedicationAdministrationD
|
|||
@Qualifier("mySubstanceDaoDstu2")
|
||||
protected IFhirResourceDao<Substance> mySubstanceDao;
|
||||
@Autowired
|
||||
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||
@Autowired
|
||||
protected IResourceTableDao myResourceTableDao;
|
||||
@Autowired
|
||||
@Qualifier("mySystemDaoDstu2")
|
||||
protected IFhirSystemDao<Bundle, MetaDt> mySystemDao;
|
||||
@Autowired
|
||||
|
|
|
@ -60,6 +60,43 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
|
|||
assertEquals(18, resp.getEntry().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionWhichFailsPersistsNothing() {
|
||||
|
||||
// Run a transaction which points to that practitioner
|
||||
// in a field that isn't allowed to refer to a practitioner
|
||||
Bundle input = new Bundle();
|
||||
input.setType(BundleTypeEnum.TRANSACTION);
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.setId("PT");
|
||||
pt.setActive(true);
|
||||
pt.addName().addFamily("FAMILY");
|
||||
input.addEntry()
|
||||
.setResource(pt)
|
||||
.getRequest().setMethod(HTTPVerbEnum.PUT).setUrl("Patient/PT");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setId("OBS");
|
||||
obs.getCode().addCoding().setSystem("foo").setCode("bar");
|
||||
obs.addPerformer().setReference("Practicioner/AAAAA");
|
||||
input.addEntry()
|
||||
.setResource(obs)
|
||||
.getRequest().setMethod(HTTPVerbEnum.PUT).setUrl("Observation/OBS");
|
||||
|
||||
try {
|
||||
mySystemDao.transaction(mySrd, input);
|
||||
fail();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
assertThat(e.getMessage(), containsString("Resource type 'Practicioner' is not valid for this path"));
|
||||
}
|
||||
|
||||
assertThat(myResourceTableDao.findAll(), empty());
|
||||
assertThat(myResourceIndexedSearchParamStringDao.findAll(), empty());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Per a message on the mailing list
|
||||
*/
|
||||
|
|
|
@ -167,6 +167,8 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
|||
@Qualifier("myResourceProvidersDstu3")
|
||||
protected Object myResourceProviders;
|
||||
@Autowired
|
||||
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||
@Autowired
|
||||
protected IResourceTableDao myResourceTableDao;
|
||||
@Autowired
|
||||
protected IResourceTagDao myResourceTagDao;
|
||||
|
|
|
@ -62,6 +62,43 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|||
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionWhichFailsPersistsNothing() {
|
||||
|
||||
// Run a transaction which points to that practitioner
|
||||
// in a field that isn't allowed to refer to a practitioner
|
||||
Bundle input = new Bundle();
|
||||
input.setType(BundleType.TRANSACTION);
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.setId("PT");
|
||||
pt.setActive(true);
|
||||
pt.addName().setFamily("FAMILY");
|
||||
input.addEntry()
|
||||
.setResource(pt)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl("Patient/PT");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setId("OBS");
|
||||
obs.getCode().addCoding().setSystem("foo").setCode("bar");
|
||||
obs.addPerformer().setReference("Practicioner/AAAAA");
|
||||
input.addEntry()
|
||||
.setResource(obs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation/OBS");
|
||||
|
||||
try {
|
||||
mySystemDao.transaction(mySrd, input);
|
||||
fail();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
assertThat(e.getMessage(), containsString("Resource type 'Practicioner' is not valid for this path"));
|
||||
}
|
||||
|
||||
assertThat(myResourceTableDao.findAll(), empty());
|
||||
assertThat(myResourceIndexedSearchParamStringDao.findAll(), empty());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Bundle createInputTransactionWithPlaceholderIdInMatchUrl(HTTPVerb theVerb) {
|
||||
|
||||
Patient pat = new Patient();
|
||||
|
|
|
@ -1,21 +1,35 @@
|
|||
package ca.uhn.fhir.jpa.dao.r4;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.config.TestR4Config;
|
||||
import ca.uhn.fhir.jpa.dao.*;
|
||||
import ca.uhn.fhir.jpa.dao.data.*;
|
||||
import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4;
|
||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
||||
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
||||
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
|
||||
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hibernate.search.jpa.FullTextEntityManager;
|
||||
import org.hibernate.search.jpa.Search;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -27,33 +41,23 @@ import org.springframework.transaction.TransactionDefinition;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.config.TestR4Config;
|
||||
import ca.uhn.fhir.jpa.dao.*;
|
||||
import ca.uhn.fhir.jpa.dao.data.*;
|
||||
import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||
import ca.uhn.fhir.jpa.provider.r4.JpaSystemProviderR4;
|
||||
import ca.uhn.fhir.jpa.search.*;
|
||||
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
|
||||
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import javax.persistence.EntityManager;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes= {TestR4Config.class})
|
||||
@ContextConfiguration(classes = {TestR4Config.class})
|
||||
public abstract class BaseJpaR4Test extends BaseJpaTest {
|
||||
|
||||
private static JpaValidationSupportChainR4 ourJpaValidationSupportChainR4;
|
||||
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
|
||||
|
||||
@Autowired
|
||||
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||
@Autowired
|
||||
protected IResourceIndexedCompositeStringUniqueDao myResourceIndexedCompositeStringUniqueDao;
|
||||
@Autowired
|
||||
|
@ -112,8 +116,6 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
|
|||
protected IFhirResourceDao<ImmunizationRecommendation> myImmunizationRecommendationDao;
|
||||
protected IServerInterceptor myInterceptor;
|
||||
@Autowired
|
||||
private JpaValidationSupportChainR4 myJpaValidationSupportChainR4;
|
||||
@Autowired
|
||||
@Qualifier("myLocationDaoR4")
|
||||
protected IFhirResourceDao<Location> myLocationDao;
|
||||
@Autowired
|
||||
|
@ -214,6 +216,8 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
|
|||
@Autowired
|
||||
@Qualifier("myValueSetDaoR4")
|
||||
protected IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> myValueSetDao;
|
||||
@Autowired
|
||||
private JpaValidationSupportChainR4 myJpaValidationSupportChainR4;
|
||||
|
||||
@After()
|
||||
public void afterCleanupDao() {
|
||||
|
|
|
@ -1665,13 +1665,13 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
|||
//@formatter:off
|
||||
/*
|
||||
* Transaction Order, per the spec:
|
||||
*
|
||||
*
|
||||
* Process any DELETE interactions
|
||||
* Process any POST interactions
|
||||
* Process any PUT interactions
|
||||
* Process any GET interactions
|
||||
*
|
||||
* This test creates a transaction bundle that includes
|
||||
*
|
||||
* This test creates a transaction bundle that includes
|
||||
* these four operations in the reverse order and verifies
|
||||
* that they are invoked correctly.
|
||||
*/
|
||||
|
@ -2110,6 +2110,42 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionWhichFailsPersistsNothing() {
|
||||
|
||||
// Run a transaction which points to that practitioner
|
||||
// in a field that isn't allowed to refer to a practitioner
|
||||
Bundle input = new Bundle();
|
||||
input.setType(BundleType.TRANSACTION);
|
||||
|
||||
Patient pt = new Patient();
|
||||
pt.setId("PT");
|
||||
pt.setActive(true);
|
||||
pt.addName().setFamily("FAMILY");
|
||||
input.addEntry()
|
||||
.setResource(pt)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl("Patient/PT");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setId("OBS");
|
||||
obs.getCode().addCoding().setSystem("foo").setCode("bar");
|
||||
obs.addPerformer().setReference("Practicioner/AAAAA");
|
||||
input.addEntry()
|
||||
.setResource(obs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl("Observation/OBS");
|
||||
|
||||
try {
|
||||
mySystemDao.transaction(mySrd, input);
|
||||
fail();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
assertThat(e.getMessage(), containsString("Resource type 'Practicioner' is not valid for this path"));
|
||||
}
|
||||
|
||||
assertThat(myResourceTableDao.findAll(), empty());
|
||||
assertThat(myResourceIndexedSearchParamStringDao.findAll(), empty());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Format changed, source isn't valid
|
||||
*/
|
||||
|
@ -2455,7 +2491,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
|||
IdType medOrderId1 = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
||||
|
||||
/*
|
||||
* Again!
|
||||
* Again!
|
||||
*/
|
||||
|
||||
bundle = new Bundle();
|
||||
|
|
Loading…
Reference in New Issue