Add a disabled test

This commit is contained in:
jamesagnew 2020-05-20 17:26:14 -04:00
parent 9aaf5ccd63
commit b044d05332
5 changed files with 91 additions and 12 deletions

View File

@ -584,7 +584,6 @@
<properties>
<skip-hib4>false</skip-hib4>
<jackson.version>2.7.1</jackson.version>
</properties>
@ -804,12 +803,6 @@
</reporting>
<profiles>
<profile>
<id>JENKINS</id>
<properties>
<skip-hib4>true</skip-hib4>
</properties>
</profile>
<profile>
<id>NOPARALLEL</id>
<build>

View File

@ -9,6 +9,7 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.time.DateUtils;
@ -89,6 +90,7 @@ class VersionSpecificWorkerContextWrapper extends I18nBase implements IWorkerCon
if (canonical instanceof StructureDefinition) {
if (((StructureDefinition) canonical).getSnapshot().isEmpty()) {
fetched = myValidationSupport.generateSnapshot(myValidationSupport, fetched, "", null, "");
Validate.isTrue(fetched != null, "StructureDefinition %s has no snapshot, and no snapshot generator is configured", key.getUri());
canonical = myModelConverter.toCanonical(fetched);
}
}

View File

@ -19,6 +19,7 @@ import org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService;
import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.exceptions.FHIRException;
@ -116,6 +117,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
private FhirValidator myVal;
private ArrayList<String> myValidConcepts;
private Set<String> myValidSystems = new HashSet<>();
private Map<String, StructureDefinition> myStructureDefinitionMap = new HashMap<>();
private CachingValidationSupport myValidationSupport;
private void addValidConcept(String theSystem, String theCode) {
@ -149,7 +151,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
IValidationSupport mockSupport = mock(IValidationSupport.class);
when(mockSupport.getFhirContext()).thenReturn(ourCtx);
ValidationSupportChain chain = new ValidationSupportChain(myDefaultValidationSupport, mockSupport, new InMemoryTerminologyServerValidationSupport(ourCtx), new CommonCodeSystemsTerminologyService(ourCtx));
ValidationSupportChain chain = new ValidationSupportChain(myDefaultValidationSupport, mockSupport, new InMemoryTerminologyServerValidationSupport(ourCtx), new CommonCodeSystemsTerminologyService(ourCtx), new SnapshotGeneratingValidationSupport(ourCtx));
myValidationSupport = new CachingValidationSupport(chain);
myInstanceVal = new FhirInstanceValidator(myValidationSupport);
@ -187,7 +189,9 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
IBaseResource retVal;
Class<IBaseResource> clazz = (Class<IBaseResource>) theInvocation.getArguments()[0];
String id = theInvocation.getArgument(1, String.class);
if ("Questionnaire/q_jon".equals(id)) {
if (myStructureDefinitionMap.containsKey(id)) {
retVal = myStructureDefinitionMap.get(id);
} else if ("Questionnaire/q_jon".equals(id)) {
retVal = ourCtx.newJsonParser().parseResource(loadResource("/q_jon.json"));
} else {
retVal = myDefaultValidationSupport.fetchResource(clazz, id);
@ -236,7 +240,13 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
when(mockSupport.fetchStructureDefinition(nullable(String.class))).thenAnswer(new Answer<IBaseResource>() {
@Override
public IBaseResource answer(InvocationOnMock theInvocation) {
IBaseResource retVal = myDefaultValidationSupport.fetchStructureDefinition((String) theInvocation.getArguments()[0]);
String id = (String) theInvocation.getArguments()[0];
IBaseResource retVal;
if (myStructureDefinitionMap.containsKey(id)) {
retVal = myStructureDefinitionMap.get(id);
} else {
retVal = myDefaultValidationSupport.fetchStructureDefinition(id);
}
ourLog.debug("fetchStructureDefinition({}) : {}", new Object[]{theInvocation.getArguments()[0], retVal});
return retVal;
}
@ -244,7 +254,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
when(mockSupport.fetchAllStructureDefinitions()).thenAnswer(new Answer<List<StructureDefinition>>() {
@Override
public List<StructureDefinition> answer(InvocationOnMock theInvocation) {
List<StructureDefinition> retVal = myDefaultValidationSupport.fetchAllStructureDefinitions();
List<StructureDefinition> retVal =new ArrayList<>(myDefaultValidationSupport.fetchAllStructureDefinitions());
retVal.addAll(myStructureDefinitionMap.values());
ourLog.debug("fetchAllStructureDefinitions()", new Object[]{});
return retVal;
}
@ -392,7 +403,26 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
List<SingleValidationMessage> all = logResultsAndReturnAll(result);
assertTrue(result.isSuccessful());
}
/**
* TODO: unignore when https://github.com/hapifhir/org.hl7.fhir.core/pull/201 is merged
*/
@Test
@Ignore
public void testValidateFixedBindingOnQuantity() throws IOException {
StructureDefinition sd = loadResource(ourCtx, StructureDefinition.class, "/r4/bbl-fixed-binding-structuredef.json");
myStructureDefinitionMap.put("http://example.org/fhir/StructureDefinition/MyObservation", sd);
Observation obs = loadResource(ourCtx, Observation.class, "/r4/bbl-fixed-binding-observation.json");
FhirValidator val = ourCtx.newValidator();
val.registerValidatorModule(new FhirInstanceValidator(myValidationSupport));
ValidationResult result = val.validateWithResult(obs);
logResultsAndReturnAll(result);
assertFalse(result.isSuccessful());
}
/**
* See #1676 - We should ignore schema location
*/

View File

@ -0,0 +1,23 @@
{
"resourceType": "Observation",
"effectiveDateTime": "2019-11-01T12:41:50+00:00",
"meta": {
"profile": [
"http://example.org/fhir/StructureDefinition/MyObservation"
]
},
"status": "final",
"code": {
"coding": [
{
"code": "aabbcc",
"system": "http://example.org"
}
]
},
"valueQuantity": {
"code": "whatever",
"system": "http://unitsofmeasure.org",
"value": 18
}
}

View File

@ -0,0 +1,31 @@
{
"resourceType": "StructureDefinition",
"url": "http://example.org/fhir/StructureDefinition/MyObservation",
"name": "MyObservation",
"id": "MyObservation",
"status": "draft",
"fhirVersion": "4.0.1",
"kind": "resource",
"abstract": false,
"type": "Observation",
"baseDefinition": "http://hl7.org/fhir/StructureDefinition/Observation",
"derivation": "constraint",
"differential": {
"element": [
{
"id": "Observation.value[x]",
"path": "Observation.value[x]",
"min": 1,
"type": [
{
"code": "Quantity"
}
],
"binding": {
"strength": "required",
"valueSet": "http://hl7.org/fhir/ValueSet/account-type"
}
}
]
}
}