Testing Part 5

This commit is contained in:
dotasek 2022-01-24 18:16:10 -05:00
parent 1715574a7e
commit b5e9a7aa1e
2 changed files with 83 additions and 8 deletions

View File

@ -724,10 +724,13 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
//TESTME //TESTME
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical, boolean incompleteOk, Parameters p) { public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean hierarchical, boolean incompleteOk, Parameters pIn) {
if (p == null) { if (pIn == null) {
throw new Error(formatMessage(I18nConstants.NO_PARAMETERS_PROVIDED_TO_EXPANDVS)); throw new Error(formatMessage(I18nConstants.NO_PARAMETERS_PROVIDED_TO_EXPANDVS));
} }
Parameters p = pIn.copy();
if (vs.hasExpansion()) { if (vs.hasExpansion()) {
return new ValueSetExpansionOutcome(vs.copy()); return new ValueSetExpansionOutcome(vs.copy());
} }
@ -741,7 +744,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
codeSystemsUsed.add(inc.getSystem()); codeSystemsUsed.add(inc.getSystem());
} }
CacheToken cacheToken = txCache.generateExpandToken(vs, heirarchical); CacheToken cacheToken = txCache.generateExpandToken(vs, hierarchical);
ValueSetExpansionOutcome res; ValueSetExpansionOutcome res;
if (cacheOk) { if (cacheOk) {
res = txCache.getExpansion(cacheToken); res = txCache.getExpansion(cacheToken);
@ -750,7 +753,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
} }
} }
p.setParameter("includeDefinition", false); p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !heirarchical); p.setParameter("excludeNested", !hierarchical);
if (incompleteOk) { if (incompleteOk) {
p.setParameter("incomplete-ok", true); p.setParameter("incomplete-ok", true);
} }
@ -758,7 +761,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
List<String> allErrors = new ArrayList<>(); List<String> allErrors = new ArrayList<>();
// ok, first we try to expand locally // ok, first we try to expand locally
ValueSetExpanderSimple vse = new ValueSetExpanderSimple(this); ValueSetExpanderSimple vse = constructValueSetExpanderSimple();
try { try {
res = vse.expand(vs, p); res = vse.expand(vs, p);
allErrors.addAll(vse.getAllErrors()); allErrors.addAll(vse.getAllErrors());
@ -1000,6 +1003,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return res; return res;
} }
protected ValueSetExpanderSimple constructValueSetExpanderSimple() {
return new ValueSetExpanderSimple(this);
}
protected ValueSetCheckerSimple constructValueSetCheckerSimple( ValidationOptions options, ValueSet vs, ValidationContextCarrier ctxt) { protected ValueSetCheckerSimple constructValueSetCheckerSimple( ValidationOptions options, ValueSet vs, ValidationContextCarrier ctxt) {
return new ValueSetCheckerSimple(options, vs, this, ctxt); return new ValueSetCheckerSimple(options, vs, this, ctxt);
} }

View File

@ -4,8 +4,10 @@ import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.terminologies.TerminologyClient; import org.hl7.fhir.r5.terminologies.TerminologyClient;
import org.hl7.fhir.r5.terminologies.ValueSetCheckerSimple; import org.hl7.fhir.r5.terminologies.ValueSetCheckerSimple;
import org.hl7.fhir.r5.terminologies.ValueSetExpander; import org.hl7.fhir.r5.terminologies.ValueSetExpander;
import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple;
import org.hl7.fhir.r5.utils.validation.ValidationContextCarrier; import org.hl7.fhir.r5.utils.validation.ValidationContextCarrier;
import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.graphql.Value;
import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -26,6 +28,7 @@ import static org.mockito.Mockito.times;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class SimpleWorkerContextTests { public class SimpleWorkerContextTests {
private static final String DUMMY_URL = "dummyUrl";
@Spy @Spy
SimpleWorkerContext context; SimpleWorkerContext context;
@ -45,11 +48,14 @@ public class SimpleWorkerContextTests {
IWorkerContext.ValidationResult expectedValidationResult; IWorkerContext.ValidationResult expectedValidationResult;
@Mock @Mock
ValueSetExpander.ValueSetExpansionOutcome expectedExansionResult; ValueSetExpander.ValueSetExpansionOutcome expectedExpansionResult;
@Mock @Mock
ValueSetCheckerSimple valueSetCheckerSimple; ValueSetCheckerSimple valueSetCheckerSimple;
@Mock
ValueSetExpanderSimple valueSetExpanderSimple;
@Mock @Mock
Parameters pIn; Parameters pIn;
@ -79,6 +85,19 @@ public class SimpleWorkerContextTests {
} }
} }
public class ParametersMatcher implements ArgumentMatcher<Parameters> {
private Parameters left;
ParametersMatcher(Parameters left) {
this.left = left;
}
@Override
public boolean matches(Parameters right) {
return true;
}
}
@Test @Test
public void testValidateCodingWithCache() throws IOException { public void testValidateCodingWithCache() throws IOException {
ValidationOptions validationOptions = new ValidationOptions().guessSystem().setVersionFlexible(false); ValidationOptions validationOptions = new ValidationOptions().guessSystem().setVersionFlexible(false);
@ -211,11 +230,11 @@ public class SimpleWorkerContextTests {
vs.getCompose().getInclude().add(inc); vs.getCompose().getInclude().add(inc);
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(argThat(new ValueSetMatcher(vs)),eq(true)); Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(argThat(new ValueSetMatcher(vs)),eq(true));
Mockito.doReturn(expectedExansionResult).when(terminologyCache).getExpansion(cacheToken); Mockito.doReturn(expectedExpansionResult).when(terminologyCache).getExpansion(cacheToken);
ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(inc, true); ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(inc, true);
assertEquals(expectedExansionResult, actualExpansionResult); assertEquals(expectedExpansionResult, actualExpansionResult);
Mockito.verify(terminologyCache).getExpansion(cacheToken); Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache, times(0)).cacheExpansion(any(), any(), anyBoolean()); Mockito.verify(terminologyCache, times(0)).cacheExpansion(any(), any(), anyBoolean());
@ -247,4 +266,53 @@ public class SimpleWorkerContextTests {
Mockito.verify(terminologyCache).getExpansion(cacheToken); Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache).cacheExpansion(cacheToken, actualExpansionResult,true); Mockito.verify(terminologyCache).cacheExpansion(cacheToken, actualExpansionResult,true);
} }
@Test
public void testExpandValueSet4ArgsWithCache() throws IOException {
ValueSet.ConceptSetComponent inc = new ValueSet.ConceptSetComponent();
ValueSet vs = new ValueSet();
vs.setUrl(DUMMY_URL);
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(vs,true);
Mockito.doReturn(expectedExpansionResult).when(terminologyCache).getExpansion(cacheToken);
Parameters pIn = new Parameters();
ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(vs, true, true, true, pIn);
assertEquals(expectedExpansionResult, actualExpansionResult);
Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache, times(0)).cacheExpansion(any(), any(), anyBoolean());
Mockito.verify(terminologyClient, times(0)).expandValueset(any(), any(), any());
}
@Test
public void testExpandValueSet4ArgsWithValueSetExpanderSimple() throws IOException {
ValueSet.ConceptSetComponent inc = new ValueSet.ConceptSetComponent();
ValueSet vs = new ValueSet();
vs.setUrl(DUMMY_URL);
Mockito.doReturn(cacheToken).when(terminologyCache).generateExpandToken(vs,true);
Parameters pIn = new Parameters();
Mockito.doReturn(vs).when(expectedExpansionResult).getValueset();
Mockito.doReturn(expectedExpansionResult).when(valueSetExpanderSimple).expand(eq(vs), argThat(new ParametersMatcher(pIn)));
Mockito.doReturn(valueSetExpanderSimple).when(context).constructValueSetExpanderSimple();
ValueSetExpander.ValueSetExpansionOutcome actualExpansionResult = context.expandVS(vs, true, true, true, pIn);
assertEquals(expectedExpansionResult, actualExpansionResult);
Mockito.verify(terminologyCache).getExpansion(cacheToken);
Mockito.verify(terminologyCache, times(0)).cacheExpansion(any(), any(), anyBoolean());
Mockito.verify(terminologyClient, times(0)).expandValueset(any(), any(), any());
}
} }