Introduce new validator cliContext option disableDefaultResourceFetcher (#1526)

* introduce new cliContext option doNotFetchUnknownProfiles

* rename parameter to disable-default-resource-fetcher

* missed renaming a couple items

* review feedback
This commit is contained in:
Dylan Hall 2024-02-20 17:06:55 -05:00 committed by GitHub
parent 7761be6197
commit f1096a8ebd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 56 additions and 16 deletions

View File

@ -56,6 +56,8 @@ public class CliContext {
private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING;
@JsonProperty("allowDoubleQuotesInFHIRPath")
private boolean allowDoubleQuotesInFHIRPath = false;
@JsonProperty("disableDefaultResourceFetcher")
private boolean disableDefaultResourceFetcher = false;
@JsonProperty("checkIPSCodes")
private boolean checkIPSCodes;
@JsonProperty("langTransform")
@ -328,6 +330,17 @@ public class CliContext {
this.allowDoubleQuotesInFHIRPath = allowDoubleQuotesInFHIRPath;
}
@JsonProperty("disableDefaultResourceFetcher")
public boolean isDisableDefaultResourceFetcher() {
return disableDefaultResourceFetcher;
}
@JsonProperty("disableDefaultResourceFetcher")
public CliContext setDisableDefaultResourceFetcher(boolean disableDefaultResourceFetcher) {
this.disableDefaultResourceFetcher = disableDefaultResourceFetcher;
return this;
}
@JsonProperty("checkIPSCodes")
public boolean isCheckIPSCodes() {
return checkIPSCodes;

View File

@ -524,9 +524,11 @@ public class ValidationService {
validationEngine.setForPublication(cliContext.isForPublication());
validationEngine.setShowTimes(cliContext.isShowTimes());
validationEngine.setAllowExampleUrls(cliContext.isAllowExampleUrls());
if (!cliContext.isDisableDefaultResourceFetcher()) {
StandAloneValidatorFetcher fetcher = new StandAloneValidatorFetcher(validationEngine.getPcm(), validationEngine.getContext(), validationEngine);
validationEngine.setFetcher(fetcher);
validationEngine.getContext().setLocator(fetcher);
}
validationEngine.getBundleValidationRules().addAll(cliContext.getBundleValidationRules());
validationEngine.setJurisdiction(CodeSystemUtilities.readCoding(cliContext.getJurisdiction()));
TerminologyCache.setNoCaching(cliContext.isNoInternalCaching());

View File

@ -89,6 +89,7 @@ public class Params {
public static final String SRC_LANG = "-src-lang";
public static final String TGT_LANG = "-tgt-lang";
public static final String ALLOW_DOUBLE_QUOTES = "-allow-double-quotes-in-fhirpath";
public static final String DISABLE_DEFAULT_RESOURCE_FETCHER = "-disable-default-resource-fetcher";
public static final String CHECK_IPS_CODES = "-check-ips-codes";
public static final String BEST_PRACTICE = "-best-practice";
@ -270,6 +271,8 @@ public class Params {
cliContext.setNoExtensibleBindingMessages(true);
} else if (args[i].equals(ALLOW_DOUBLE_QUOTES)) {
cliContext.setAllowDoubleQuotesInFHIRPath(true);
} else if (args[i].equals(DISABLE_DEFAULT_RESOURCE_FETCHER)) {
cliContext.setDisableDefaultResourceFetcher(true);
} else if (args[i].equals(CHECK_IPS_CODES)) {
cliContext.setCheckIPSCodes(true);
} else if (args[i].equals(NO_UNICODE_BIDI_CONTROL_CHARS)) {

View File

@ -10,8 +10,10 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.endsWith;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -236,17 +238,43 @@ class ValidationServiceTest {
*/
@Test
public void buildValidationEngineTest() throws IOException, URISyntaxException {
final org.hl7.fhir.utilities.TimeTracker timeTracker = mock(org.hl7.fhir.utilities.TimeTracker.class);
final TimeTracker timeTracker = mock(TimeTracker.class);
final SimpleWorkerContext workerContext = mock(SimpleWorkerContext.class);
final ValidationEngine validationEngine = mock(ValidationEngine.class);
when(validationEngine.getContext()).thenReturn(workerContext);
final ValidationEngine mockValidationEngine = mock(ValidationEngine.class);
when(mockValidationEngine.getContext()).thenReturn(workerContext);
final ValidationEngine.ValidationEngineBuilder validationEngineBuilder = mock(ValidationEngine.ValidationEngineBuilder.class);;
final ValidationEngine.ValidationEngineBuilder mockValidationEngineBuilder = mock(ValidationEngine.ValidationEngineBuilder.class);;
final ValidationService validationService = createFakeValidationService(mockValidationEngineBuilder, mockValidationEngine);
final ValidationService validationService = new ValidationService() {
CliContext cliContext = new CliContext();
validationService.buildValidationEngine(cliContext, null, timeTracker);
verify(mockValidationEngine).setFetcher(notNull());
verify(mockValidationEngineBuilder).withUserAgent(eq("fhir/validator/" + VersionUtil.getVersion()));
}
@Test
public void buildValidationEngineDisableDefaultResourceFetcherTest() throws IOException, URISyntaxException {
final TimeTracker timeTracker = mock(TimeTracker.class);
final SimpleWorkerContext workerContext = mock(SimpleWorkerContext.class);
final ValidationEngine mockValidationEngine = mock(ValidationEngine.class);
when(mockValidationEngine.getContext()).thenReturn(workerContext);
final ValidationEngine.ValidationEngineBuilder mockValidationEngineBuilder = mock(ValidationEngine.ValidationEngineBuilder.class);;
final ValidationService validationService = createFakeValidationService(mockValidationEngineBuilder, mockValidationEngine);
CliContext cliContext = new CliContext();
cliContext.setDisableDefaultResourceFetcher(true);
validationService.buildValidationEngine(cliContext, null, timeTracker);
verify(mockValidationEngine, never()).setFetcher(any());
verify(mockValidationEngineBuilder).withUserAgent(eq("fhir/validator/" + VersionUtil.getVersion()));
}
private static ValidationService createFakeValidationService(ValidationEngine.ValidationEngineBuilder validationEngineBuilder, ValidationEngine validationEngine) {
return new ValidationService() {
@Override
protected ValidationEngine.ValidationEngineBuilder getValidationEngineBuilder() {
when(validationEngineBuilder.withTHO(anyBoolean())).thenReturn(validationEngineBuilder);
@ -268,11 +296,5 @@ class ValidationServiceTest {
//Don't care. Do nothing.
}
};
CliContext cliContext = new CliContext();
validationService.buildValidationEngine(cliContext, null, timeTracker);
verify(validationEngineBuilder).withUserAgent(eq("fhir/validator/" + VersionUtil.getVersion()));
}
}