parent
320042a0ad
commit
9ec63bc1b9
|
@ -19,13 +19,13 @@ import org.mockito.Spy;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class SimpleWorkerContextTests {
|
public class SimpleWorkerContextTests {
|
||||||
|
@ -64,6 +64,15 @@ public class SimpleWorkerContextTests {
|
||||||
@Mock
|
@Mock
|
||||||
Parameters expParameters;
|
Parameters expParameters;
|
||||||
|
|
||||||
|
public static final TerminologyCapabilities terminologyCapabilities = new TerminologyCapabilities();
|
||||||
|
static { terminologyCapabilities.getExpansion().setParameter(Arrays.asList());}
|
||||||
|
|
||||||
|
public static final CapabilityStatement.CapabilityStatementSoftwareComponent software = new CapabilityStatement.CapabilityStatementSoftwareComponent();
|
||||||
|
static { software.setVersion("dummyVersion"); }
|
||||||
|
|
||||||
|
public static final CapabilityStatement capabilitiesStatement = new CapabilityStatement();
|
||||||
|
static { capabilitiesStatement.setSoftware(software);}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeEach() {
|
public void beforeEach() {
|
||||||
context.txCache = terminologyCache;
|
context.txCache = terminologyCache;
|
||||||
|
@ -357,4 +366,50 @@ 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 testInitializationWithCache() {
|
||||||
|
|
||||||
|
Mockito.doReturn(true).when(terminologyCache).hasTerminologyCapabilities();
|
||||||
|
Mockito.doReturn(true).when(terminologyCache).hasCapabilityStatement();
|
||||||
|
|
||||||
|
Mockito.doReturn(terminologyCapabilities).when(terminologyCache).getTerminologyCapabilities();
|
||||||
|
Mockito.doReturn(capabilitiesStatement).when(terminologyCache).getCapabilityStatement();
|
||||||
|
|
||||||
|
String actual = context.connectToTSServer(terminologyClient, null);
|
||||||
|
|
||||||
|
assertEquals("dummyVersion", actual);
|
||||||
|
|
||||||
|
Mockito.verify(terminologyCache).getTerminologyCapabilities();
|
||||||
|
Mockito.verify(terminologyCache).getCapabilityStatement();
|
||||||
|
|
||||||
|
Mockito.verify(terminologyClient, times(0)).getTerminologyCapabilities();
|
||||||
|
Mockito.verify(terminologyClient, times(0)).getCapabilitiesStatementQuick();
|
||||||
|
|
||||||
|
Mockito.verify(context).setTxCaps(terminologyCapabilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInitializationWithClient() {
|
||||||
|
|
||||||
|
Mockito.doReturn(false).when(terminologyCache).hasTerminologyCapabilities();
|
||||||
|
Mockito.doReturn(false).when(terminologyCache).hasCapabilityStatement();
|
||||||
|
|
||||||
|
Mockito.doReturn(terminologyCapabilities).when(terminologyClient).getTerminologyCapabilities();
|
||||||
|
Mockito.doReturn(capabilitiesStatement).when(terminologyClient).getCapabilitiesStatementQuick();
|
||||||
|
|
||||||
|
String actual = context.connectToTSServer(terminologyClient, null);
|
||||||
|
|
||||||
|
assertEquals("dummyVersion", actual);
|
||||||
|
|
||||||
|
Mockito.verify(terminologyCache, times(0)).getTerminologyCapabilities();
|
||||||
|
Mockito.verify(terminologyCache, times(0)).getCapabilityStatement();
|
||||||
|
|
||||||
|
Mockito.verify(terminologyClient).getTerminologyCapabilities();
|
||||||
|
Mockito.verify(terminologyClient).getCapabilitiesStatementQuick();
|
||||||
|
|
||||||
|
Mockito.verify(context).setTxCaps(terminologyCapabilities);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@ package org.hl7.fhir.r5.context;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.hl7.fhir.r5.formats.IParser;
|
import org.hl7.fhir.r5.formats.IParser;
|
||||||
import org.hl7.fhir.r5.model.CodeableConcept;
|
import org.hl7.fhir.r5.model.*;
|
||||||
import org.hl7.fhir.r5.model.Coding;
|
|
||||||
import org.hl7.fhir.r5.model.ValueSet;
|
|
||||||
import org.hl7.fhir.r5.terminologies.ValueSetExpander;
|
import org.hl7.fhir.r5.terminologies.ValueSetExpander;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -84,6 +82,15 @@ public class TerminologyCacheTests {
|
||||||
ValueSet valueSet = new ValueSet();
|
ValueSet valueSet = new ValueSet();
|
||||||
valueSet.setUrl("dummyValueSetURL");
|
valueSet.setUrl("dummyValueSetURL");
|
||||||
|
|
||||||
|
TerminologyCapabilities terminologyCapabilities = new TerminologyCapabilities();
|
||||||
|
terminologyCapabilities.getExpansion().setParameter(Arrays.asList());
|
||||||
|
|
||||||
|
CapabilityStatement.CapabilityStatementSoftwareComponent software = new CapabilityStatement.CapabilityStatementSoftwareComponent();
|
||||||
|
software.setVersion("dummyVersion");
|
||||||
|
|
||||||
|
CapabilityStatement capabilityStatement = new CapabilityStatement();
|
||||||
|
capabilityStatement.setSoftware(software);
|
||||||
|
|
||||||
Coding coding = new Coding();
|
Coding coding = new Coding();
|
||||||
coding.setCode("dummyCode");
|
coding.setCode("dummyCode");
|
||||||
|
|
||||||
|
@ -95,6 +102,9 @@ public class TerminologyCacheTests {
|
||||||
// Add dummy results to the cache
|
// Add dummy results to the cache
|
||||||
TerminologyCache terminologyCacheA = new TerminologyCache(lock, tempCacheDirectory.toString());
|
TerminologyCache terminologyCacheA = new TerminologyCache(lock, tempCacheDirectory.toString());
|
||||||
|
|
||||||
|
terminologyCacheA.cacheTerminologyCapabilities(terminologyCapabilities);
|
||||||
|
terminologyCacheA.cacheCapabilityStatement(capabilityStatement);
|
||||||
|
|
||||||
IWorkerContext.ValidationResult codingResultA = new IWorkerContext.ValidationResult(ValidationMessage.IssueSeverity.INFORMATION, "dummyInfo");
|
IWorkerContext.ValidationResult codingResultA = new IWorkerContext.ValidationResult(ValidationMessage.IssueSeverity.INFORMATION, "dummyInfo");
|
||||||
TerminologyCache.CacheToken codingTokenA = terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
TerminologyCache.CacheToken codingTokenA = terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
||||||
coding, valueSet);
|
coding, valueSet);
|
||||||
|
@ -111,6 +121,9 @@ public class TerminologyCacheTests {
|
||||||
terminologyCacheA.cacheExpansion(expansionTokenA, expansionOutcomeA, true);
|
terminologyCacheA.cacheExpansion(expansionTokenA, expansionOutcomeA, true);
|
||||||
// Check that the in-memory cache is returning what we put in
|
// Check that the in-memory cache is returning what we put in
|
||||||
{
|
{
|
||||||
|
assertEquals(terminologyCapabilities, terminologyCacheA.getTerminologyCapabilities());
|
||||||
|
assertEquals(capabilityStatement, terminologyCacheA.getCapabilityStatement());
|
||||||
|
|
||||||
assertValidationResultEquals(codingResultA, terminologyCacheA.getValidation(codingTokenA));
|
assertValidationResultEquals(codingResultA, terminologyCacheA.getValidation(codingTokenA));
|
||||||
assertValidationResultEquals(codeableConceptResultA, terminologyCacheA.getValidation(codeableConceptTokenA));
|
assertValidationResultEquals(codeableConceptResultA, terminologyCacheA.getValidation(codeableConceptTokenA));
|
||||||
assertExpansionOutcomeEquals(expansionOutcomeA,terminologyCacheA.getExpansion(expansionTokenA));
|
assertExpansionOutcomeEquals(expansionOutcomeA,terminologyCacheA.getExpansion(expansionTokenA));
|
||||||
|
@ -120,6 +133,9 @@ public class TerminologyCacheTests {
|
||||||
{
|
{
|
||||||
TerminologyCache terminologyCacheB = new TerminologyCache(lock, tempCacheDirectory.toString());
|
TerminologyCache terminologyCacheB = new TerminologyCache(lock, tempCacheDirectory.toString());
|
||||||
|
|
||||||
|
assertCanonicalResourceEquals(terminologyCapabilities, terminologyCacheB.getTerminologyCapabilities());
|
||||||
|
assertCanonicalResourceEquals(capabilityStatement, terminologyCacheB.getCapabilityStatement());
|
||||||
|
|
||||||
assertValidationResultEquals(codingResultA, terminologyCacheB.getValidation(terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
assertValidationResultEquals(codingResultA, terminologyCacheB.getValidation(terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
||||||
coding, valueSet)));
|
coding, valueSet)));
|
||||||
assertValidationResultEquals(codeableConceptResultA, terminologyCacheB.getValidation(terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
assertValidationResultEquals(codeableConceptResultA, terminologyCacheB.getValidation(terminologyCacheA.generateValidationToken(CacheTestUtils.validationOptions,
|
||||||
|
@ -129,6 +145,10 @@ public class TerminologyCacheTests {
|
||||||
deleteTempCacheDirectory(tempCacheDirectory);
|
deleteTempCacheDirectory(tempCacheDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertCanonicalResourceEquals(CanonicalResource a, CanonicalResource b) {
|
||||||
|
assertTrue(a.equalsDeep(b));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertValidationResultEquals(IWorkerContext.ValidationResult a, IWorkerContext.ValidationResult b) {
|
private void assertValidationResultEquals(IWorkerContext.ValidationResult a, IWorkerContext.ValidationResult b) {
|
||||||
assertEquals(a.getSeverity(), b.getSeverity());
|
assertEquals(a.getSeverity(), b.getSeverity());
|
||||||
assertEquals(a.getMessage(), b.getMessage());
|
assertEquals(a.getMessage(), b.getMessage());
|
||||||
|
|
Loading…
Reference in New Issue