mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-05 19:09:11 +00:00
add test instance factory to validator
This commit is contained in:
parent
62f95eb15c
commit
637d0a26cc
org.hl7.fhir.validation/src
main/java/org/hl7/fhir/validation
test/java/org/hl7/fhir/generation/tests
@ -138,6 +138,7 @@ public class ValidatorCli {
|
||||
new VersionTask(),
|
||||
new CodeGenTask(),
|
||||
new TxPackTask(),
|
||||
new InstanceFactoryTask(),
|
||||
defaultCliTask);
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,10 @@ public class CliContext {
|
||||
@SerializedName("map")
|
||||
private
|
||||
String map = null;
|
||||
@JsonProperty("source")
|
||||
@SerializedName("source")
|
||||
private
|
||||
String source = null;
|
||||
@JsonProperty("output")
|
||||
@SerializedName("output")
|
||||
private
|
||||
@ -364,6 +368,19 @@ public class CliContext {
|
||||
return this;
|
||||
}
|
||||
|
||||
@SerializedName("source")
|
||||
@JsonProperty("source")
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@SerializedName("source")
|
||||
@JsonProperty("source")
|
||||
public CliContext setSource(String source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@SerializedName("langTransform")
|
||||
@JsonProperty("langTransform")
|
||||
|
73
org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java
73
org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java
@ -9,7 +9,14 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryMXBean;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -24,14 +31,20 @@ import org.hl7.fhir.r5.elementmodel.LanguageUtils;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.elementmodel.ValidatedFragment;
|
||||
import org.hl7.fhir.r5.fhirpath.FHIRPathEngine;
|
||||
import org.hl7.fhir.r5.formats.IParser;
|
||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||
import org.hl7.fhir.r5.liquid.BaseTableWrapper;
|
||||
import org.hl7.fhir.r5.liquid.GlobalObject.GlobalObjectRandomFunction;
|
||||
import org.hl7.fhir.r5.liquid.LiquidEngine;
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.ConceptMap;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
import org.hl7.fhir.r5.model.OperationOutcome;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureMap;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
@ -44,6 +57,8 @@ import org.hl7.fhir.r5.renderers.spreadsheets.ValueSetSpreadsheetGenerator;
|
||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
||||
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.InternalLogEvent;
|
||||
import org.hl7.fhir.r5.terminologies.utilities.TerminologyCache;
|
||||
import org.hl7.fhir.r5.testfactory.TestDataFactory;
|
||||
import org.hl7.fhir.r5.testfactory.TestDataHostServices;
|
||||
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
|
||||
import org.hl7.fhir.utilities.FhirPublication;
|
||||
import org.hl7.fhir.utilities.SystemExitManager;
|
||||
@ -58,12 +73,23 @@ import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerSession;
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TranslationUnit;
|
||||
import org.hl7.fhir.utilities.i18n.PoGetTextProducer;
|
||||
import org.hl7.fhir.utilities.i18n.XLIFFProducer;
|
||||
import org.hl7.fhir.utilities.json.model.JsonObject;
|
||||
import org.hl7.fhir.utilities.json.parser.JsonParser;
|
||||
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
|
||||
import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.hl7.fhir.validation.*;
|
||||
import org.hl7.fhir.validation.IgLoader;
|
||||
import org.hl7.fhir.validation.ResourceChecker;
|
||||
import org.hl7.fhir.validation.ValidationEngine;
|
||||
import org.hl7.fhir.validation.ValidationRecord;
|
||||
import org.hl7.fhir.validation.ValidatorUtils;
|
||||
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
|
||||
import org.hl7.fhir.validation.cli.model.*;
|
||||
import org.hl7.fhir.validation.cli.model.CliContext;
|
||||
import org.hl7.fhir.validation.cli.model.FileInfo;
|
||||
import org.hl7.fhir.validation.cli.model.ValidatedFragments;
|
||||
import org.hl7.fhir.validation.cli.model.ValidationOutcome;
|
||||
import org.hl7.fhir.validation.cli.model.ValidationRequest;
|
||||
import org.hl7.fhir.validation.cli.model.ValidationResponse;
|
||||
import org.hl7.fhir.validation.cli.renderers.CSVRenderer;
|
||||
import org.hl7.fhir.validation.cli.renderers.CompactRenderer;
|
||||
import org.hl7.fhir.validation.cli.renderers.DefaultRenderer;
|
||||
@ -77,8 +103,6 @@ import org.hl7.fhir.validation.instance.advisor.BasePolicyAdvisorForFullValidati
|
||||
import org.hl7.fhir.validation.instance.advisor.JsonDrivenPolicyAdvisor;
|
||||
import org.hl7.fhir.validation.instance.advisor.TextDrivenPolicyAdvisor;
|
||||
|
||||
import kotlin.NotImplementedError;
|
||||
|
||||
public class ValidationService {
|
||||
|
||||
private final SessionCache sessionCache;
|
||||
@ -900,4 +924,43 @@ public class ValidationService {
|
||||
}
|
||||
}
|
||||
|
||||
public void instanceFactory(CliContext cliContext, ValidationEngine validationEngine) throws IOException {
|
||||
boolean ok = true;
|
||||
if (cliContext.getSource() == null) {
|
||||
System.out.println("Must specify a source (-version)");
|
||||
ok = false;
|
||||
} else if (!new File(cliContext.getSource()).exists()) {
|
||||
System.out.println("Factory source '"+cliContext.getSource()+"' not found");
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
System.out.println("Preparing to execute");
|
||||
|
||||
FHIRPathEngine fpe = new FHIRPathEngine(validationEngine.getContext());
|
||||
TestDataHostServices hs = new TestDataHostServices(validationEngine.getContext(), new DateTimeType(new Date()), new StringType(VersionUtilities.getSpecUrl(validationEngine.getContext().getVersion())));
|
||||
hs.registerFunction(new GlobalObjectRandomFunction());
|
||||
hs.registerFunction(new BaseTableWrapper.TableColumnFunction());
|
||||
hs.registerFunction(new BaseTableWrapper.TableDateColumnFunction());
|
||||
hs.registerFunction(new TestDataFactory.CellLookupFunction());
|
||||
hs.registerFunction(new TestDataFactory.TableLookupFunction());
|
||||
fpe.setHostServices(hs);
|
||||
LiquidEngine liquid = new LiquidEngine(validationEngine.getContext(), hs);
|
||||
|
||||
String path = Utilities.getDirectoryForFile(cliContext.getSource());
|
||||
String log = Utilities.path(path, "log");
|
||||
Utilities.createDirectory(log);
|
||||
|
||||
JsonObject json = JsonParser.parseObjectFromFile(cliContext.getSource());
|
||||
for (JsonObject fact : json.forceArray("factories").asJsonObjects()) {
|
||||
TestDataFactory tdf = new TestDataFactory(validationEngine.getContext(), fact, liquid, fpe, "http://hl7.org/fhir/test", path, log);
|
||||
tdf.setTesting(true); // no randomness
|
||||
System.out.println("Execute Test Data Factory '"+tdf.getName()+"'. Log in "+Utilities.path(log, tdf.statedLog()));
|
||||
tdf.execute();
|
||||
}
|
||||
|
||||
System.out.println("Done");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
43
org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/InstanceFactoryTask.java
Normal file
43
org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/tasks/InstanceFactoryTask.java
Normal file
@ -0,0 +1,43 @@
|
||||
package org.hl7.fhir.validation.cli.tasks;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.hl7.fhir.utilities.TimeTracker;
|
||||
import org.hl7.fhir.validation.ValidationEngine;
|
||||
import org.hl7.fhir.validation.cli.model.CliContext;
|
||||
import org.hl7.fhir.validation.cli.services.ValidationService;
|
||||
import org.hl7.fhir.validation.cli.utils.EngineMode;
|
||||
|
||||
public class InstanceFactoryTask extends ValidationEngineTask {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "instance-factory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Excecute Instance Factory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecuteTask(CliContext cliContext, String[] args) {
|
||||
return cliContext.getMode() == EngineMode.FACTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printHelp(PrintStream out) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeTask(ValidationService validationService, ValidationEngine validationEngine, CliContext cliContext, String[] args, TimeTracker tt, TimeTracker.Session tts) throws Exception {
|
||||
validationService.instanceFactory(cliContext, validationEngine);
|
||||
}
|
||||
|
||||
}
|
@ -15,5 +15,6 @@ public enum EngineMode {
|
||||
RUN_TESTS,
|
||||
INSTALL,
|
||||
CODEGEN,
|
||||
TX_PACK
|
||||
TX_PACK,
|
||||
FACTORY
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ public class Params {
|
||||
public static final String NO_NATIVE = "-no-native";
|
||||
public static final String COMPILE = "-compile";
|
||||
public static final String CODEGEN = "-codegen";
|
||||
public static final String FACTORY = "-factory";
|
||||
public static final String TRANSFORM = "-transform";
|
||||
public static final String FORMAT = "-format";
|
||||
public static final String LANG_TRANSFORM = "-lang-transform";
|
||||
@ -356,6 +357,9 @@ public class Params {
|
||||
cliContext.setMode(EngineMode.COMPILE);
|
||||
} else if (args[i].equals(CODEGEN)) {
|
||||
cliContext.setMode(EngineMode.CODEGEN);
|
||||
} else if (args[i].equals(FACTORY)) {
|
||||
cliContext.setMode(EngineMode.FACTORY);
|
||||
cliContext.setSource(args[++i]);
|
||||
} else if (args[i].equals(NARRATIVE)) {
|
||||
cliContext.setMode(EngineMode.NARRATIVE);
|
||||
} else if (args[i].equals(SPREADSHEET)) {
|
||||
|
@ -82,7 +82,7 @@ public class TestInstanceGenerationTester {
|
||||
for (JsonObject fact : json.forceArray("factories").asJsonObjects()) {
|
||||
TestDataFactory tdf = new TestDataFactory(context, fact, liquid, fpe, "http://hl7.org/fhir/test", path, log);
|
||||
tdf.setTesting(true); // no randomness
|
||||
System.out.println("Execute Test Data Factory '"+tdf.getName()+"'. Output in "+tdf.statedLog());
|
||||
System.out.println("Execute Test Data Factory '"+tdf.getName()+"'. Log in "+tdf.statedLog());
|
||||
tdf.execute();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user