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.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.config.TestDstu2Config;
|
import ca.uhn.fhir.jpa.config.TestDstu2Config;
|
||||||
import ca.uhn.fhir.jpa.dao.*;
|
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.ResourceIndexedSearchParamString;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
|
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
|
||||||
|
@ -134,6 +136,10 @@ protected IFhirResourceDao<MedicationAdministration> myMedicationAdministrationD
|
||||||
@Qualifier("mySubstanceDaoDstu2")
|
@Qualifier("mySubstanceDaoDstu2")
|
||||||
protected IFhirResourceDao<Substance> mySubstanceDao;
|
protected IFhirResourceDao<Substance> mySubstanceDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||||
|
@Autowired
|
||||||
|
protected IResourceTableDao myResourceTableDao;
|
||||||
|
@Autowired
|
||||||
@Qualifier("mySystemDaoDstu2")
|
@Qualifier("mySystemDaoDstu2")
|
||||||
protected IFhirSystemDao<Bundle, MetaDt> mySystemDao;
|
protected IFhirSystemDao<Bundle, MetaDt> mySystemDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -60,6 +60,43 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
|
||||||
assertEquals(18, resp.getEntry().size());
|
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
|
* Per a message on the mailing list
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -167,6 +167,8 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
||||||
@Qualifier("myResourceProvidersDstu3")
|
@Qualifier("myResourceProvidersDstu3")
|
||||||
protected Object myResourceProviders;
|
protected Object myResourceProviders;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||||
|
@Autowired
|
||||||
protected IResourceTableDao myResourceTableDao;
|
protected IResourceTableDao myResourceTableDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected IResourceTagDao myResourceTagDao;
|
protected IResourceTagDao myResourceTagDao;
|
||||||
|
|
|
@ -62,6 +62,43 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
||||||
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
|
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) {
|
private Bundle createInputTransactionWithPlaceholderIdInMatchUrl(HTTPVerb theVerb) {
|
||||||
|
|
||||||
Patient pat = new Patient();
|
Patient pat = new Patient();
|
||||||
|
|
|
@ -1,21 +1,35 @@
|
||||||
package ca.uhn.fhir.jpa.dao.r4;
|
package ca.uhn.fhir.jpa.dao.r4;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import static org.mockito.Mockito.mock;
|
import ca.uhn.fhir.jpa.config.TestR4Config;
|
||||||
|
import ca.uhn.fhir.jpa.dao.*;
|
||||||
import java.io.IOException;
|
import ca.uhn.fhir.jpa.dao.data.*;
|
||||||
import java.io.InputStream;
|
import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
|
||||||
import java.util.Map;
|
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||||
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import javax.persistence.EntityManager;
|
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.apache.commons.io.IOUtils;
|
||||||
import org.hibernate.search.jpa.FullTextEntityManager;
|
import org.hibernate.search.jpa.FullTextEntityManager;
|
||||||
import org.hibernate.search.jpa.Search;
|
import org.hibernate.search.jpa.Search;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
import org.hl7.fhir.r4.hapi.ctx.IValidationSupport;
|
||||||
import org.hl7.fhir.r4.model.*;
|
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.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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.annotation.Transactional;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import javax.persistence.EntityManager;
|
||||||
import ca.uhn.fhir.jpa.config.TestR4Config;
|
import java.io.IOException;
|
||||||
import ca.uhn.fhir.jpa.dao.*;
|
import java.io.InputStream;
|
||||||
import ca.uhn.fhir.jpa.dao.data.*;
|
import java.util.Map;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
|
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
import static org.junit.Assert.*;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import static org.mockito.Mockito.mock;
|
||||||
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;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes= {TestR4Config.class})
|
@ContextConfiguration(classes = {TestR4Config.class})
|
||||||
public abstract class BaseJpaR4Test extends BaseJpaTest {
|
public abstract class BaseJpaR4Test extends BaseJpaTest {
|
||||||
|
|
||||||
private static JpaValidationSupportChainR4 ourJpaValidationSupportChainR4;
|
private static JpaValidationSupportChainR4 ourJpaValidationSupportChainR4;
|
||||||
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
|
private static IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> ourValueSetDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected IResourceIndexedSearchParamStringDao myResourceIndexedSearchParamStringDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected IResourceIndexedCompositeStringUniqueDao myResourceIndexedCompositeStringUniqueDao;
|
protected IResourceIndexedCompositeStringUniqueDao myResourceIndexedCompositeStringUniqueDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -112,8 +116,6 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
|
||||||
protected IFhirResourceDao<ImmunizationRecommendation> myImmunizationRecommendationDao;
|
protected IFhirResourceDao<ImmunizationRecommendation> myImmunizationRecommendationDao;
|
||||||
protected IServerInterceptor myInterceptor;
|
protected IServerInterceptor myInterceptor;
|
||||||
@Autowired
|
@Autowired
|
||||||
private JpaValidationSupportChainR4 myJpaValidationSupportChainR4;
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("myLocationDaoR4")
|
@Qualifier("myLocationDaoR4")
|
||||||
protected IFhirResourceDao<Location> myLocationDao;
|
protected IFhirResourceDao<Location> myLocationDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -214,6 +216,8 @@ public abstract class BaseJpaR4Test extends BaseJpaTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("myValueSetDaoR4")
|
@Qualifier("myValueSetDaoR4")
|
||||||
protected IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> myValueSetDao;
|
protected IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> myValueSetDao;
|
||||||
|
@Autowired
|
||||||
|
private JpaValidationSupportChainR4 myJpaValidationSupportChainR4;
|
||||||
|
|
||||||
@After()
|
@After()
|
||||||
public void afterCleanupDao() {
|
public void afterCleanupDao() {
|
||||||
|
|
|
@ -1665,13 +1665,13 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
/*
|
/*
|
||||||
* Transaction Order, per the spec:
|
* Transaction Order, per the spec:
|
||||||
*
|
*
|
||||||
* Process any DELETE interactions
|
* Process any DELETE interactions
|
||||||
* Process any POST interactions
|
* Process any POST interactions
|
||||||
* Process any PUT interactions
|
* Process any PUT interactions
|
||||||
* Process any GET 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
|
* these four operations in the reverse order and verifies
|
||||||
* that they are invoked correctly.
|
* 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
|
* 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());
|
IdType medOrderId1 = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Again!
|
* Again!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bundle = new Bundle();
|
bundle = new Bundle();
|
||||||
|
|
Loading…
Reference in New Issue