Fix failing tests
This commit is contained in:
parent
b0b98a9a28
commit
09eb52ed27
|
@ -98,6 +98,10 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
return profile;
|
||||
}
|
||||
|
||||
public void flushCaches() {
|
||||
myWrappedWorkerContext = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "best practice" warning level (default is {@link BestPracticeWarningLevel#Hint}).
|
||||
* <p>
|
||||
|
@ -183,8 +187,6 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
myStructureDefintion = theStructureDefintion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected List<ValidationMessage> validate(final FhirContext theCtx, String theInput, EncodingEnum theEncoding) {
|
||||
|
||||
WorkerContextWrapper wrappedWorkerContext = myWrappedWorkerContext;
|
||||
|
@ -507,13 +509,13 @@ public class FhirInstanceValidator extends BaseValidatorBridge implements IValid
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return myWrap.getVersion();
|
||||
public UcumService getUcumService() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UcumService getUcumService() {
|
||||
throw new UnsupportedOperationException();
|
||||
public String getVersion() {
|
||||
return myWrap.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package org.hl7.fhir.dstu3.hapi.validation;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu2.composite.PeriodDt;
|
||||
import ca.uhn.fhir.model.dstu2.valueset.ProcedureStatusEnum;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.util.StopWatch;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
|
@ -27,7 +23,6 @@ import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent;
|
|||
import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent;
|
||||
import org.hl7.fhir.dstu3.utils.FHIRPathEngine;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.rules.TestWatcher;
|
||||
|
@ -35,8 +30,6 @@ import org.junit.runner.Description;
|
|||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
@ -74,54 +67,6 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
myValidConcepts.add(theSystem + "___" + theCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStress() throws IOException {
|
||||
|
||||
String input = IOUtils.toString(new FileReader("/home/james/Downloads/history.json"));
|
||||
|
||||
FhirValidator val = ourCtx.newValidator();
|
||||
val.registerValidatorModule(new FhirInstanceValidator(myDefaultValidationSupport));
|
||||
|
||||
val.validateWithResult(input);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
int loops = 100;
|
||||
for (int i = 0; i < loops; i++) {
|
||||
val.validateWithResult(input);
|
||||
}
|
||||
|
||||
ourLog.info("Validated {} times AVG {}ms/val", loops, sw.getMillisPerOperation(loops));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #873
|
||||
*/
|
||||
@Test
|
||||
public void testCompareTimesWithDifferentTimezones() {
|
||||
Procedure procedure = new Procedure();
|
||||
procedure.setStatus(Procedure.ProcedureStatus.COMPLETED);
|
||||
procedure.getSubject().setReference("Patient/1");
|
||||
procedure.getCode().setText("Some proc");
|
||||
|
||||
Period period = new Period();
|
||||
period.setStartElement(new DateTimeType("2000-01-01T00:00:01+05:00"));
|
||||
period.setEndElement(new DateTimeType("2000-01-01T00:00:00+04:00"));
|
||||
assertThat(period.getStart().getTime(), lessThan(period.getEnd().getTime()));
|
||||
procedure.setPerformed(period);
|
||||
|
||||
FhirValidator val = ourCtx.newValidator();
|
||||
val.registerValidatorModule(new FhirInstanceValidator(myDefaultValidationSupport));
|
||||
|
||||
ValidationResult result = val.validateWithResult(procedure);
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void before() {
|
||||
|
@ -278,6 +223,33 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* See #873
|
||||
*/
|
||||
@Test
|
||||
public void testCompareTimesWithDifferentTimezones() {
|
||||
Procedure procedure = new Procedure();
|
||||
procedure.setStatus(Procedure.ProcedureStatus.COMPLETED);
|
||||
procedure.getSubject().setReference("Patient/1");
|
||||
procedure.getCode().setText("Some proc");
|
||||
|
||||
Period period = new Period();
|
||||
period.setStartElement(new DateTimeType("2000-01-01T00:00:01+05:00"));
|
||||
period.setEndElement(new DateTimeType("2000-01-01T00:00:00+04:00"));
|
||||
assertThat(period.getStart().getTime(), lessThan(period.getEnd().getTime()));
|
||||
procedure.setPerformed(period);
|
||||
|
||||
FhirValidator val = ourCtx.newValidator();
|
||||
val.registerValidatorModule(new FhirInstanceValidator(myDefaultValidationSupport));
|
||||
|
||||
ValidationResult result = val.validateWithResult(procedure);
|
||||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome());
|
||||
ourLog.info(encoded);
|
||||
|
||||
assertTrue(result.isSuccessful());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #531
|
||||
*/
|
||||
|
@ -330,6 +302,25 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
assertEquals(0, outcome.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* An invalid local reference should not cause a ServiceException.
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidLocalReference() {
|
||||
Questionnaire resource = new Questionnaire();
|
||||
resource.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
QuestionnaireItemComponent item = new QuestionnaireItemComponent();
|
||||
item.setLinkId("linkId-1");
|
||||
item.setType(QuestionnaireItemType.CHOICE);
|
||||
item.setOptions(new Reference("#invalid-ref"));
|
||||
resource.addItem(item);
|
||||
|
||||
ValidationResult output = myVal.validateWithResult(resource);
|
||||
List<SingleValidationMessage> nonInfo = logResultsAndReturnNonInformationalOnes(output);
|
||||
assertThat(nonInfo, hasSize(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNoTerminologyChecks() {
|
||||
assertFalse(myInstanceVal.isNoTerminologyChecks());
|
||||
|
@ -534,7 +525,6 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValidateRawJsonResource() {
|
||||
//@formatter:off
|
||||
|
@ -764,25 +754,6 @@ public class FhirInstanceValidatorDstu3Test {
|
|||
assertThat(nonInfo, empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* An invalid local reference should not cause a ServiceException.
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidLocalReference() {
|
||||
Questionnaire resource = new Questionnaire();
|
||||
resource.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
QuestionnaireItemComponent item = new QuestionnaireItemComponent();
|
||||
item.setLinkId("linkId-1");
|
||||
item.setType(QuestionnaireItemType.CHOICE);
|
||||
item.setOptions(new Reference("#invalid-ref"));
|
||||
resource.addItem(item);
|
||||
|
||||
ValidationResult output = myVal.validateWithResult(resource);
|
||||
List<SingleValidationMessage> nonInfo = logResultsAndReturnNonInformationalOnes(output);
|
||||
assertThat(nonInfo, hasSize(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* See #370
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ import static org.junit.Assert.*;
|
|||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class QuestionnaireResponseValidatorDstu3Test {
|
||||
|
@ -86,11 +87,9 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
|||
codeSystem.setContent(CodeSystemContentMode.COMPLETE);
|
||||
codeSystem.setUrl("http://codesystems.com/system");
|
||||
codeSystem.addConcept().setCode("code0");
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq("http://codesystems.com/system"))).thenReturn(codeSystem);
|
||||
|
||||
ValueSet options = new ValueSet();
|
||||
options.getCompose().addInclude().setSystem("http://codesystems.com/system").addConcept().setCode("code0");
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options);
|
||||
|
||||
int itemCnt = 16;
|
||||
QuestionnaireItemType[] questionnaireItemTypes = new QuestionnaireItemType[itemCnt];
|
||||
|
@ -132,7 +131,16 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
|||
for (int i = 0; i < itemCnt; i++) {
|
||||
if (questionnaireItemTypes[i] == null) continue;
|
||||
String linkId = "link" + i;
|
||||
|
||||
reset(myValSupport);
|
||||
Questionnaire q = new Questionnaire();
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class),
|
||||
eq("http://example.com/Questionnaire/q1"))).thenReturn(q);
|
||||
when(myValSupport.fetchCodeSystem(any(FhirContext.class), eq("http://codesystems.com/system"))).thenReturn(codeSystem);
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(ValueSet.class), eq("http://somevalueset"))).thenReturn(options);
|
||||
myInstanceVal.flushCaches();
|
||||
|
||||
q.getItem().clear();
|
||||
QuestionnaireItemComponent questionnaireItemComponent =
|
||||
q.addItem().setLinkId(linkId).setRequired(true).setType(questionnaireItemTypes[i]);
|
||||
if (i == 10 || i == 11) {
|
||||
|
@ -147,9 +155,6 @@ public class QuestionnaireResponseValidatorDstu3Test {
|
|||
qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1");
|
||||
qa.addItem().setLinkId(linkId).addAnswer().setValue(answerValues[i]);
|
||||
|
||||
when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class),
|
||||
eq(qa.getQuestionnaire().getReference()))).thenReturn(q);
|
||||
|
||||
ValidationResult errors = myVal.validateWithResult(qa);
|
||||
|
||||
ourLog.info(errors.toString());
|
||||
|
|
Loading…
Reference in New Issue