diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index a948ba214..2badb07ec 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -7459,7 +7459,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat public ValidationResult checkCodeOnServer(NodeStack stack, ValueSet valueset, CodeableConcept cc) throws CheckCodeOnServerException { codingObserver.seeCode(stack, cc); try { - return checkForInactive(filterOutSpecials(stack.getLiteralPath(), valueset, context.validateCode(baseOptions.withLanguage(stack.getWorkingLang()), cc, valueset)), cc); + String workingLang = stack.getWorkingLang() != null ? stack.getWorkingLang() : context.getLocale().toString(); + return checkForInactive(filterOutSpecials(stack.getLiteralPath(), valueset, context.validateCode(baseOptions.withLanguage(workingLang), cc, valueset)), cc); } catch (Exception e) { throw new CheckCodeOnServerException(e); } diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTest.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTest.java deleted file mode 100644 index 402b9b1aa..000000000 --- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.hl7.fhir.validation.instance; - -class InstanceValidatorTest { - - - -} \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTests.java new file mode 100644 index 000000000..30294121b --- /dev/null +++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/instance/InstanceValidatorTests.java @@ -0,0 +1,57 @@ +package org.hl7.fhir.validation.instance; + +import org.hl7.fhir.r5.terminologies.utilities.ValidationResult; +import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.utilities.validation.ValidationOptions; +import org.hl7.fhir.r5.context.IWorkerContext; +import org.hl7.fhir.r5.model.CodeableConcept; +import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.validation.instance.utils.NodeStack; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Collections; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +class InstanceValidatorTests { + + @Test + public void testCheckCodeOnServerNoStackLocale() throws InstanceValidator.CheckCodeOnServerException { + NodeStack stack =mock(NodeStack.class); + testCheckCodeOnServer(stack, "ko_KR"); + } + + @Test + public void testCheckCodeOnServerStackLocale() throws InstanceValidator.CheckCodeOnServerException { + NodeStack stack =mock(NodeStack.class); + when(stack.getWorkingLang()).thenReturn("fr-CA"); + testCheckCodeOnServer(stack, "fr-CA"); + } + + private void testCheckCodeOnServer(NodeStack stack, String expectedLocale) throws InstanceValidator.CheckCodeOnServerException { + IWorkerContext context = mock(IWorkerContext.class); + when(context.getLocale()).thenReturn(Locale.KOREA); + when(context.getVersion()).thenReturn("5.0.1"); + InstanceValidator instanceValidator = new InstanceValidator(context, null, null); + + + when(context.validateCode((ValidationOptions) any(ValidationOptions.class), (CodeableConcept) any(CodeableConcept.class), (ValueSet)any(ValueSet.class))).thenReturn(new ValidationResult(ValidationMessage.IssueSeverity.NULL, "Blah!", Collections.emptyList())); + + CodeableConcept codeableConcept = mock(CodeableConcept.class); + ValueSet valueSet = mock(ValueSet.class); + instanceValidator.checkCodeOnServer(stack, valueSet, codeableConcept); + + ArgumentCaptor validationOptionsArgumentCaptor = ArgumentCaptor.forClass(ValidationOptions.class); + verify(context).validateCode(validationOptionsArgumentCaptor.capture(), eq(codeableConcept), eq(valueSet)); + + ValidationOptions options = validationOptionsArgumentCaptor.getValue(); + + Assertions.assertEquals(expectedLocale, options.getLanguages().getSource()); + } + +} \ No newline at end of file