more work on multi-language rendering, and add test id to error message on comparison
This commit is contained in:
parent
c633eafef6
commit
a4055877c4
|
@ -40,6 +40,12 @@ public class BundleRenderer extends ResourceRenderer {
|
|||
super(context);
|
||||
}
|
||||
|
||||
|
||||
public BundleRenderer setMultiLangMode(boolean multiLangMode) {
|
||||
this.multiLangMode = multiLangMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
|
||||
XhtmlNode n = render((Bundle) r);
|
||||
|
|
|
@ -294,7 +294,7 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
|
|||
|
||||
addSupportedFormats(uList, conf);
|
||||
|
||||
uList.li().addText("Published on: " + conf.getDate());
|
||||
uList.li().addText("Published on: " + context.toStr(conf.getDateElement()));
|
||||
uList.li().addText("Published by: " + conf.getPublisherElement().asStringValue());
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ public class ParametersRenderer extends ResourceRenderer {
|
|||
super(context, rcontext);
|
||||
}
|
||||
|
||||
|
||||
public ParametersRenderer setMultiLangMode(boolean multiLangMode) {
|
||||
this.multiLangMode = multiLangMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(XhtmlNode x, Resource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
|
||||
x.h2().tx(/*!#*/"Parameters");
|
||||
|
|
|
@ -53,6 +53,7 @@ public abstract class ResourceRenderer extends DataRenderer {
|
|||
|
||||
protected ResourceContext rcontext;
|
||||
protected XVerExtensionManager xverManager;
|
||||
protected boolean multiLangMode;
|
||||
|
||||
|
||||
public ResourceRenderer(RenderingContext context) {
|
||||
|
@ -73,6 +74,16 @@ public abstract class ResourceRenderer extends DataRenderer {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMultiLangMode() {
|
||||
return multiLangMode;
|
||||
}
|
||||
|
||||
public ResourceRenderer setMultiLangMode(boolean multiLangMode) {
|
||||
this.multiLangMode = multiLangMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public XhtmlNode build(Resource dr) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
|
||||
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
|
||||
render(x, dr);
|
||||
|
@ -113,7 +124,7 @@ public abstract class ResourceRenderer extends DataRenderer {
|
|||
}
|
||||
}
|
||||
if (r.hasNarrative()) {
|
||||
r.injectNarrative(x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
|
||||
r.injectNarrative(this, x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
@ -170,7 +181,24 @@ public abstract class ResourceRenderer extends DataRenderer {
|
|||
public abstract String display(Resource r) throws UnsupportedEncodingException, IOException;
|
||||
public abstract String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException;
|
||||
|
||||
public static void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
|
||||
public void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
|
||||
r.getText().setUserData("renderer.generated", true);
|
||||
if (!r.hasText() || !r.getText().hasDiv()) {
|
||||
r.setText(new Narrative());
|
||||
r.getText().setStatus(status);
|
||||
}
|
||||
if (multiLangMode) {
|
||||
if (!r.getText().hasDiv()) {
|
||||
XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
|
||||
div.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
r.getText().setDiv(div);
|
||||
} else {
|
||||
r.getText().getDiv().getChildNodes().removeIf(c -> !"div".equals(c.getName()) || !c.hasAttribute("xml:lang"));
|
||||
}
|
||||
x.setAttribute("lang", context.getLang());
|
||||
x.setAttribute("xml:lang", context.getLang());
|
||||
r.getText().getDiv().getChildNodes().add(x);
|
||||
} else {
|
||||
if (!x.hasAttribute("xmlns"))
|
||||
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
if (r.hasLanguage()) {
|
||||
|
@ -178,15 +206,7 @@ public abstract class ResourceRenderer extends DataRenderer {
|
|||
x.setAttribute("lang", r.getLanguage());
|
||||
x.setAttribute("xml:lang", r.getLanguage());
|
||||
}
|
||||
r.getText().setUserData("renderer.generated", true);
|
||||
if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
|
||||
r.setText(new Narrative());
|
||||
r.getText().setDiv(x);
|
||||
r.getText().setStatus(status);
|
||||
} else {
|
||||
XhtmlNode n = r.getText().getDiv();
|
||||
n.clear();
|
||||
n.getChildNodes().addAll(x.getChildNodes());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class BaseWrappers {
|
|||
public Base getBase();
|
||||
public String getName();
|
||||
public void describe(XhtmlNode x) throws UnsupportedEncodingException, IOException;
|
||||
public void injectNarrative(XhtmlNode x, NarrativeStatus status) throws IOException;
|
||||
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) throws IOException;
|
||||
public BaseWrapper root();
|
||||
public PropertyWrapper getChildByName(String tail);
|
||||
public StructureDefinition getDefinition();
|
||||
|
|
|
@ -336,7 +336,7 @@ public class DOMWrappers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void injectNarrative(XhtmlNode x, NarrativeStatus status) {
|
||||
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) {
|
||||
if (!x.hasAttribute("xmlns"))
|
||||
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
Element le = XMLUtil.getNamedChild(wrapped, "language");
|
||||
|
|
|
@ -280,8 +280,8 @@ public class DirectWrappers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void injectNarrative(XhtmlNode x, NarrativeStatus status) {
|
||||
ResourceRenderer.inject((DomainResource) wrapped, x, status);
|
||||
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) {
|
||||
renderer.inject((DomainResource) wrapped, x, status);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@ import org.hl7.fhir.r5.model.Resource;
|
|||
import org.hl7.fhir.r5.model.Narrative.NarrativeStatus;
|
||||
import org.hl7.fhir.r5.model.StringType;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.renderers.ResourceRenderer;
|
||||
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
|
||||
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.PropertyWrapper;
|
||||
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.RendererWrapperImpl;
|
||||
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
|
||||
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.WrapperBaseImpl;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xhtml.NodeType;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
|
||||
|
@ -212,21 +214,14 @@ public class ElementWrappers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void injectNarrative(XhtmlNode x, NarrativeStatus status) throws IOException {
|
||||
if (!x.hasAttribute("xmlns"))
|
||||
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
String l = wrapped.getChildValue("language");
|
||||
if (!Utilities.noString(l)) {
|
||||
// use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
|
||||
x.setAttribute("lang", l);
|
||||
x.setAttribute("xml:lang", l);
|
||||
}
|
||||
public void injectNarrative(ResourceRenderer renderer, XhtmlNode x, NarrativeStatus status) throws IOException {
|
||||
org.hl7.fhir.r5.elementmodel.Element txt = wrapped.getNamedChild("text");
|
||||
if (txt == null) {
|
||||
txt = new org.hl7.fhir.r5.elementmodel.Element("text", wrapped.getProperty().getChild(null, "text"));
|
||||
int i = 0;
|
||||
while (i < wrapped.getChildren().size() && (wrapped.getChildren().get(i).getName().equals("id") || wrapped.getChildren().get(i).getName().equals("meta") || wrapped.getChildren().get(i).getName().equals("implicitRules") || wrapped.getChildren().get(i).getName().equals("language")))
|
||||
while (i < wrapped.getChildren().size() && (wrapped.getChildren().get(i).getName().equals("id") || wrapped.getChildren().get(i).getName().equals("meta") || wrapped.getChildren().get(i).getName().equals("implicitRules") || wrapped.getChildren().get(i).getName().equals("language"))) {
|
||||
i++;
|
||||
}
|
||||
if (i >= wrapped.getChildren().size())
|
||||
wrapped.getChildren().add(txt);
|
||||
else
|
||||
|
@ -243,9 +238,33 @@ public class ElementWrappers {
|
|||
div = new org.hl7.fhir.r5.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
|
||||
txt.getChildren().add(div);
|
||||
}
|
||||
div.setValue(new XhtmlComposer(XhtmlComposer.XML, context.isPretty()).compose(x));
|
||||
// now process the xhtml
|
||||
if (renderer.isMultiLangMode()) {
|
||||
XhtmlNode xd = div.getXhtml();
|
||||
if (xd == null) {
|
||||
xd = new XhtmlNode(NodeType.Element, "div");
|
||||
xd.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
div.setXhtml(xd);
|
||||
} else {
|
||||
xd.getChildNodes().removeIf(c -> !"div".equals(c.getName()) || !c.hasAttribute("xml:lang"));
|
||||
}
|
||||
x.setAttribute("lang", context.getLang());
|
||||
x.setAttribute("xml:lang", context.getLang());
|
||||
xd.getChildNodes().add(x);
|
||||
} else {
|
||||
if (!x.hasAttribute("xmlns")) {
|
||||
x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
|
||||
}
|
||||
String l = wrapped.getChildValue("language");
|
||||
if (!Utilities.noString(l)) {
|
||||
// use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues
|
||||
x.setAttribute("lang", l);
|
||||
x.setAttribute("xml:lang", l);
|
||||
}
|
||||
div.setXhtml(x);
|
||||
}
|
||||
div.setValue(new XhtmlComposer(XhtmlComposer.XML, context.isPretty()).compose(div.getXhtml()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseWrapper root() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.hl7.fhir.r5.context.IWorkerContext;
|
|||
import org.hl7.fhir.r5.elementmodel.Element;
|
||||
import org.hl7.fhir.r5.fhirpath.FHIRPathEngine.IEvaluationContext;
|
||||
import org.hl7.fhir.r5.model.Base;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
import org.hl7.fhir.r5.model.DomainResource;
|
||||
import org.hl7.fhir.r5.model.Extension;
|
||||
import org.hl7.fhir.r5.model.PrimitiveType;
|
||||
|
@ -207,7 +208,6 @@ public class RenderingContext extends RenderingI18nContext {
|
|||
private boolean showComments = false;
|
||||
|
||||
private FhirPublication targetVersion;
|
||||
private Locale locale;
|
||||
private ZoneId timeZoneId;
|
||||
private DateTimeFormatter dateTimeFormat;
|
||||
private DateTimeFormatter dateFormat;
|
||||
|
@ -279,7 +279,6 @@ public class RenderingContext extends RenderingI18nContext {
|
|||
res.dateYearFormat = dateYearFormat;
|
||||
res.dateYearMonthFormat = dateYearMonthFormat;
|
||||
res.targetVersion = targetVersion;
|
||||
res.locale = locale;
|
||||
res.showComments = showComments;
|
||||
res.copyButton = copyButton;
|
||||
res.pkp = pkp;
|
||||
|
@ -501,6 +500,7 @@ public class RenderingContext extends RenderingI18nContext {
|
|||
|
||||
public RenderingContext setLang(String lang) {
|
||||
this.lang = lang;
|
||||
setLocale(new Locale(lang));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -531,23 +531,6 @@ public class RenderingContext extends RenderingI18nContext {
|
|||
return mode == ResourceRendererMode.TECHNICAL;
|
||||
}
|
||||
|
||||
public boolean hasLocale() {
|
||||
return locale != null;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
if (locale == null) {
|
||||
return Locale.getDefault();
|
||||
} else {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* if the timezone is null, the rendering will default to the source timezone
|
||||
* in the resource
|
||||
|
@ -762,5 +745,9 @@ public class RenderingContext extends RenderingI18nContext {
|
|||
return nf.format(v);
|
||||
}
|
||||
|
||||
public String toStr(DateTimeType dt) {
|
||||
return dt.toHumanDisplay();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -32,10 +32,10 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
private static final boolean SHOW_DIFF = false;
|
||||
private JsonObject externals;
|
||||
|
||||
public String createNotEqualMessage(final String message, final String expected, final String actual) {
|
||||
public String createNotEqualMessage(String id, final String message, final String expected, final String actual) {
|
||||
return new StringBuilder()
|
||||
.append(message).append('\n')
|
||||
.append("Expected :").append(presentExpected(expected)).append('\n')
|
||||
.append("Expected:").append(presentExpected(expected)).append(" for "+id).append('\n')
|
||||
.append("Actual :").append("\""+actual+"\"").toString();
|
||||
}
|
||||
|
||||
|
@ -68,15 +68,15 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static String checkXMLIsSame(InputStream expected, InputStream actual) throws Exception {
|
||||
public static String checkXMLIsSame(String id, InputStream expected, InputStream actual) throws Exception {
|
||||
CompareUtilities self = new CompareUtilities();
|
||||
String result = self.compareXml(expected, actual);
|
||||
String result = self.compareXml(id, expected, actual);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String checkXMLIsSame(String expected, String actual) throws Exception {
|
||||
public static String checkXMLIsSame(String id, String expected, String actual) throws Exception {
|
||||
CompareUtilities self = new CompareUtilities();
|
||||
String result = self.compareXml(expected, actual);
|
||||
String result = self.compareXml(id, expected, actual);
|
||||
if (result != null && SHOW_DIFF) {
|
||||
String diff = getDiffTool();
|
||||
if (diff != null && new File(diff).exists() || Utilities.isToken(diff)) {
|
||||
|
@ -96,24 +96,24 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
private String compareXml(InputStream expected, InputStream actual) throws Exception {
|
||||
return compareElements("", loadXml(expected).getDocumentElement(), loadXml(actual).getDocumentElement());
|
||||
private String compareXml(String id, InputStream expected, InputStream actual) throws Exception {
|
||||
return compareElements(id, "", loadXml(expected).getDocumentElement(), loadXml(actual).getDocumentElement());
|
||||
}
|
||||
|
||||
private String compareXml(String expected, String actual) throws Exception {
|
||||
return compareElements("", loadXml(expected).getDocumentElement(), loadXml(actual).getDocumentElement());
|
||||
private String compareXml(String id, String expected, String actual) throws Exception {
|
||||
return compareElements(id, "", loadXml(expected).getDocumentElement(), loadXml(actual).getDocumentElement());
|
||||
}
|
||||
|
||||
private String compareElements(String path, Element expectedElement, Element actualElement) {
|
||||
private String compareElements(String id, String path, Element expectedElement, Element actualElement) {
|
||||
if (!namespacesMatch(expectedElement.getNamespaceURI(), actualElement.getNamespaceURI()))
|
||||
return createNotEqualMessage("Namespaces differ at " + path, expectedElement.getNamespaceURI(), actualElement.getNamespaceURI());
|
||||
return createNotEqualMessage(id, "Namespaces differ at " + path, expectedElement.getNamespaceURI(), actualElement.getNamespaceURI());
|
||||
if (!expectedElement.getLocalName().equals(actualElement.getLocalName()))
|
||||
return createNotEqualMessage("Names differ at " + path , expectedElement.getLocalName(), actualElement.getLocalName());
|
||||
return createNotEqualMessage(id, "Names differ at " + path , expectedElement.getLocalName(), actualElement.getLocalName());
|
||||
path = path + "/" + expectedElement.getLocalName();
|
||||
String s = compareAttributes(path, expectedElement.getAttributes(), actualElement.getAttributes());
|
||||
String s = compareAttributes(id, path, expectedElement.getAttributes(), actualElement.getAttributes());
|
||||
if (!Utilities.noString(s))
|
||||
return s;
|
||||
s = compareAttributes(path, expectedElement.getAttributes(), actualElement.getAttributes());
|
||||
s = compareAttributes(id, path, expectedElement.getAttributes(), actualElement.getAttributes());
|
||||
if (!Utilities.noString(s))
|
||||
return s;
|
||||
|
||||
|
@ -123,12 +123,12 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
actualChild = skipBlankText(actualChild);
|
||||
while (expectedChild != null && actualChild != null) {
|
||||
if (expectedChild.getNodeType() != actualChild.getNodeType())
|
||||
return createNotEqualMessage("node type mismatch in children of " + path, Short.toString(expectedElement.getNodeType()), Short.toString(actualElement.getNodeType()));
|
||||
return createNotEqualMessage(id, "node type mismatch in children of " + path, Short.toString(expectedElement.getNodeType()), Short.toString(actualElement.getNodeType()));
|
||||
if (expectedChild.getNodeType() == Node.TEXT_NODE) {
|
||||
if (!normalise(expectedChild.getTextContent()).equals(normalise(actualChild.getTextContent())))
|
||||
return createNotEqualMessage("Text differs at " + path, normalise(expectedChild.getTextContent()).toString(), normalise(actualChild.getTextContent()).toString());
|
||||
return createNotEqualMessage(id, "Text differs at " + path, normalise(expectedChild.getTextContent()).toString(), normalise(actualChild.getTextContent()).toString());
|
||||
} else if (expectedChild.getNodeType() == Node.ELEMENT_NODE) {
|
||||
s = compareElements(path, (Element) expectedChild, (Element) actualChild);
|
||||
s = compareElements(id, path, (Element) expectedChild, (Element) actualChild);
|
||||
if (!Utilities.noString(s))
|
||||
return s;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return result;
|
||||
}
|
||||
|
||||
private String compareAttributes(String path, NamedNodeMap expected, NamedNodeMap actual) {
|
||||
private String compareAttributes(String id, String path, NamedNodeMap expected, NamedNodeMap actual) {
|
||||
for (int i = 0; i < expected.getLength(); i++) {
|
||||
|
||||
Node expectedNode = expected.item(i);
|
||||
|
@ -167,7 +167,7 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
byte[] b1 = unBase64(expectedNode.getTextContent());
|
||||
byte[] b2 = unBase64(actualNode.getTextContent());
|
||||
if (!sameBytes(b1, b2))
|
||||
return createNotEqualMessage("Attributes differ at " + path, normalise(expectedNode.getTextContent()).toString(), normalise(actualNode.getTextContent()).toString()) ;
|
||||
return createNotEqualMessage(id, "Attributes differ at " + path, normalise(expectedNode.getTextContent()).toString(), normalise(actualNode.getTextContent()).toString()) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,14 +213,14 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return builder.parse(fn);
|
||||
}
|
||||
|
||||
public static String checkJsonSrcIsSame(String expected, String actual, JsonObject externals) throws FileNotFoundException, IOException {
|
||||
return checkJsonSrcIsSame(expected, actual, true, externals);
|
||||
public static String checkJsonSrcIsSame(String id, String expected, String actual, JsonObject externals) throws FileNotFoundException, IOException {
|
||||
return checkJsonSrcIsSame(id, expected, actual, true, externals);
|
||||
}
|
||||
|
||||
public static String checkJsonSrcIsSame(String expectedString, String actualString, boolean showDiff, JsonObject externals) throws FileNotFoundException, IOException {
|
||||
public static String checkJsonSrcIsSame(String id, String expectedString, String actualString, boolean showDiff, JsonObject externals) throws FileNotFoundException, IOException {
|
||||
CompareUtilities self = new CompareUtilities();
|
||||
self.externals = externals;
|
||||
String result = self.compareJsonSrc(expectedString, actualString);
|
||||
String result = self.compareJsonSrc(id, expectedString, actualString);
|
||||
if (result != null && SHOW_DIFF && showDiff) {
|
||||
String diff = null;
|
||||
if (System.getProperty("os.name").contains("Linux"))
|
||||
|
@ -253,9 +253,9 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String checkJsonIsSame(String expected, String actual) throws FileNotFoundException, IOException {
|
||||
public static String checkJsonIsSame(String id, String expected, String actual) throws FileNotFoundException, IOException {
|
||||
CompareUtilities self = new CompareUtilities();
|
||||
String result = self.compareJson(expected, actual);
|
||||
String result = self.compareJson(id, expected, actual);
|
||||
if (result != null && SHOW_DIFF) {
|
||||
String diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
|
||||
List<String> command = new ArrayList<String>();
|
||||
|
@ -269,26 +269,26 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return result;
|
||||
}
|
||||
|
||||
private String compareJsonSrc(String expected, String actual) throws FileNotFoundException, IOException {
|
||||
private String compareJsonSrc(String id, String expected, String actual) throws FileNotFoundException, IOException {
|
||||
JsonObject actualJsonObject = JsonParser.parseObject(actual);
|
||||
JsonObject expectedJsonObject = JsonParser.parseObject(expected);
|
||||
return compareObjects("", expectedJsonObject, actualJsonObject);
|
||||
return compareObjects(id, "", expectedJsonObject, actualJsonObject);
|
||||
}
|
||||
|
||||
private String compareJson(String expected, String actual) throws FileNotFoundException, IOException {
|
||||
private String compareJson(String id, String expected, String actual) throws FileNotFoundException, IOException {
|
||||
JsonObject actualJsonObject = JsonParser.parseObject(TextFile.fileToString(actual));
|
||||
JsonObject expectedJsonObject = JsonParser.parseObject(TextFile.fileToString(expected));
|
||||
return compareObjects("", expectedJsonObject, actualJsonObject);
|
||||
return compareObjects(id, "", expectedJsonObject, actualJsonObject);
|
||||
}
|
||||
|
||||
private String compareObjects(String path, JsonObject expectedJsonObject, JsonObject actualJsonObject) {
|
||||
private String compareObjects(String id, String path, JsonObject expectedJsonObject, JsonObject actualJsonObject) {
|
||||
List<String> optionals = listOptionals(expectedJsonObject);
|
||||
List<String> countOnlys = listCountOnlys(expectedJsonObject);
|
||||
for (JsonProperty en : actualJsonObject.getProperties()) {
|
||||
String n = en.getName();
|
||||
if (!n.equals("fhir_comments")) {
|
||||
if (expectedJsonObject.has(n)) {
|
||||
String s = compareNodes(path + '.' + n, expectedJsonObject.get(n), en.getValue(), countOnlys.contains(n));
|
||||
String s = compareNodes(id, path + '.' + n, expectedJsonObject.get(n), en.getValue(), countOnlys.contains(n));
|
||||
if (!Utilities.noString(s))
|
||||
return s;
|
||||
} else
|
||||
|
@ -327,10 +327,10 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return res;
|
||||
}
|
||||
|
||||
private String compareNodes(String path, JsonElement expectedJsonElement, JsonElement actualJsonElement, boolean countOnly) {
|
||||
private String compareNodes(String id, String path, JsonElement expectedJsonElement, JsonElement actualJsonElement, boolean countOnly) {
|
||||
if (!(expectedJsonElement instanceof JsonPrimitive && actualJsonElement instanceof JsonPrimitive)) {
|
||||
if (actualJsonElement.getClass() != expectedJsonElement.getClass()) {
|
||||
return createNotEqualMessage("properties differ at " + path, expectedJsonElement.getClass().getName(), actualJsonElement.getClass().getName());
|
||||
return createNotEqualMessage(id, "properties differ at " + path, expectedJsonElement.getClass().getName(), actualJsonElement.getClass().getName());
|
||||
}
|
||||
}
|
||||
if (actualJsonElement instanceof JsonPrimitive) {
|
||||
|
@ -338,24 +338,24 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
JsonPrimitive expectedJsonPrimitive = (JsonPrimitive) expectedJsonElement;
|
||||
if (actualJsonPrimitive.isJsonBoolean() && expectedJsonPrimitive.isJsonBoolean()) {
|
||||
if (actualJsonPrimitive.asBoolean() != expectedJsonPrimitive.asBoolean())
|
||||
return createNotEqualMessage("boolean property values differ at " + path , expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
return createNotEqualMessage(id, "boolean property values differ at " + path , expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
} else if (actualJsonPrimitive.isJsonString() && expectedJsonPrimitive.isJsonString()) {
|
||||
String actualJsonString = actualJsonPrimitive.asString();
|
||||
String expectedJsonString = expectedJsonPrimitive.asString();
|
||||
if (!(actualJsonString.contains("<div") && expectedJsonString.contains("<div")))
|
||||
if (!matches(actualJsonString, expectedJsonString))
|
||||
if (!sameBytes(unBase64(actualJsonString), unBase64(expectedJsonString)))
|
||||
return createNotEqualMessage("string property values differ at " + path, expectedJsonString, actualJsonString);
|
||||
return createNotEqualMessage(id, "string property values differ at " + path, expectedJsonString, actualJsonString);
|
||||
} else if (actualJsonPrimitive.isJsonNumber() && expectedJsonPrimitive.isJsonNumber()) {
|
||||
if (!actualJsonPrimitive.asString().equals(expectedJsonPrimitive.asString()))
|
||||
return createNotEqualMessage("number property values differ at " + path, expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
return createNotEqualMessage(id, "number property values differ at " + path, expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
} else if (expectedJsonElement instanceof JsonNull) {
|
||||
return actualJsonPrimitive instanceof JsonNull ? null : createNotEqualMessage("null Properties differ at " + path, "null", actualJsonPrimitive.asString());
|
||||
return actualJsonPrimitive instanceof JsonNull ? null : createNotEqualMessage(id, "null Properties differ at " + path, "null", actualJsonPrimitive.asString());
|
||||
} else {
|
||||
return createNotEqualMessage("property types differ at " + path, expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
return createNotEqualMessage(id, "property types differ at " + path, expectedJsonPrimitive.asString(), actualJsonPrimitive.asString());
|
||||
}
|
||||
} else if (actualJsonElement instanceof JsonObject) {
|
||||
String s = compareObjects(path, (JsonObject) expectedJsonElement, (JsonObject) actualJsonElement);
|
||||
String s = compareObjects(id, path, (JsonObject) expectedJsonElement, (JsonObject) actualJsonElement);
|
||||
if (!Utilities.noString(s))
|
||||
return s;
|
||||
} else if (actualJsonElement instanceof JsonArray) {
|
||||
|
@ -366,14 +366,14 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
int es = expectedArray.size();
|
||||
if (countOnly) {
|
||||
if (as != es) {
|
||||
return createNotEqualMessage("array item count differs at " + path, Integer.toString(es), Integer.toString(as));
|
||||
return createNotEqualMessage(id, "array item count differs at " + path, Integer.toString(es), Integer.toString(as));
|
||||
}
|
||||
} else {
|
||||
int expectedMin = countExpectedMin(expectedArray);
|
||||
int oc = optionalCount(expectedArray);
|
||||
|
||||
if (as > es || as < expectedMin)
|
||||
return createNotEqualMessage("array item count differs at " + path, Integer.toString(es), Integer.toString(as));
|
||||
return createNotEqualMessage(id, "array item count differs at " + path, Integer.toString(es), Integer.toString(as));
|
||||
int c = 0;
|
||||
for (int i = 0; i < es; i++) {
|
||||
if (c >= as) {
|
||||
|
@ -383,7 +383,7 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return "One or more array items did not match at "+path+" starting at index "+i;
|
||||
}
|
||||
}
|
||||
String s = compareNodes(path + "[" + Integer.toString(i) + "]", expectedArray.get(i), actualArray.get(c), false);
|
||||
String s = compareNodes(id, path + "[" + Integer.toString(i) + "]", expectedArray.get(i), actualArray.get(c), false);
|
||||
if (!Utilities.noString(s) && !isOptional(expectedArray.get(i))) {
|
||||
return s;
|
||||
}
|
||||
|
@ -478,13 +478,13 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
return list;
|
||||
}
|
||||
|
||||
public static String checkTextIsSame(String expected, String actual) throws FileNotFoundException, IOException {
|
||||
return checkTextIsSame(expected, actual, true);
|
||||
public static String checkTextIsSame(String id, String expected, String actual) throws FileNotFoundException, IOException {
|
||||
return checkTextIsSame(id, expected, actual, true);
|
||||
}
|
||||
|
||||
public static String checkTextIsSame(String expectedString, String actualString, boolean showDiff) throws FileNotFoundException, IOException {
|
||||
public static String checkTextIsSame(String id, String expectedString, String actualString, boolean showDiff) throws FileNotFoundException, IOException {
|
||||
CompareUtilities self = new CompareUtilities();
|
||||
String result = self.compareText(expectedString, actualString);
|
||||
String result = self.compareText(id, expectedString, actualString);
|
||||
if (result != null && SHOW_DIFF && showDiff) {
|
||||
String diff = null;
|
||||
if (System.getProperty("os.name").contains("Linux"))
|
||||
|
@ -518,13 +518,13 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||
}
|
||||
|
||||
|
||||
private String compareText(String expectedString, String actualString) {
|
||||
private String compareText(String id, String expectedString, String actualString) {
|
||||
for (int i = 0; i < Integer.min(expectedString.length(), actualString.length()); i++) {
|
||||
if (expectedString.charAt(i) != actualString.charAt(i))
|
||||
return createNotEqualMessage("Strings differ at character " + Integer.toString(i), charWithContext(expectedString, i), charWithContext(actualString, i));
|
||||
return createNotEqualMessage(id, "Strings differ at character " + Integer.toString(i), charWithContext(expectedString, i), charWithContext(actualString, i));
|
||||
}
|
||||
if (expectedString.length() != actualString.length())
|
||||
return createNotEqualMessage("Strings differ in length but match to the end of the shortest.", Integer.toString(expectedString.length()), Integer.toString(actualString.length()));
|
||||
return createNotEqualMessage(id, "Strings differ in length but match to the end of the shortest.", Integer.toString(expectedString.length()), Integer.toString(actualString.length()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class GeneratedPEModelTest {
|
|||
Observation tgt = tp.build(ctxt);
|
||||
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "pe-instance-gen.xml")), tgt);
|
||||
|
||||
String msg = CompareUtilities.checkXMLIsSame(TestingUtilities.loadTestResourceStream("r5", "profiles", "pe-instance.xml"), new FileInputStream(Utilities.path("[tmp]", "pe-instance-gen.xml")));
|
||||
String msg = CompareUtilities.checkXMLIsSame("PEGEN", TestingUtilities.loadTestResourceStream("r5", "profiles", "pe-instance.xml"), new FileInputStream(Utilities.path("[tmp]", "pe-instance-gen.xml")));
|
||||
Assertions.assertNull(msg, msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ public class PETests {
|
|||
private void checkGeneratedJava(String name) throws FileNotFoundException, IOException {
|
||||
String actual = Utilities.normalize(TextFile.fileToString(Utilities.path("[tmp]", name+".java")));
|
||||
String expected = Utilities.normalize(TestingUtilities.loadTestResource("r5", "profiles", name+".java"));
|
||||
String msg = CompareUtilities.checkTextIsSame(expected, actual);
|
||||
String msg = CompareUtilities.checkTextIsSame(name, expected, actual);
|
||||
if (msg != null) {
|
||||
Assertions.fail("Generated code for "+name+" is different: "+msg);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public class SQLOnFhirTests {
|
|||
sortResults(rows);
|
||||
String expS = JsonParser.compose(exp, true);
|
||||
String rowS = JsonParser.compose(rows, true);
|
||||
String c = CompareUtilities.checkJsonSrcIsSame(expS, rowS, null);
|
||||
String c = CompareUtilities.checkJsonSrcIsSame(name, expS, rowS, null);
|
||||
Assertions.assertNull(c, c);
|
||||
} else if (test.testCase.has("expectCount")) {
|
||||
Assertions.assertEquals(test.testCase.asInteger("expectCount"), results.size());
|
||||
|
|
|
@ -67,10 +67,10 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
|
||||
Resource parsedResource = stream != null ? new XmlParser().parse(stream) : null;
|
||||
|
||||
testResource(parsedResource, output, source, operation);
|
||||
testResource(name, parsedResource, output, source, operation);
|
||||
}
|
||||
|
||||
private void testResource(Resource resource, String output, String source, String operation) throws IOException, EGraphEngine, EGraphQLException {
|
||||
private void testResource(String id, Resource resource, String output, String source, String operation) throws IOException, EGraphEngine, EGraphQLException {
|
||||
GraphQLEngine gql = new GraphQLEngine(TestingUtilities.getSharedWorkerContext());
|
||||
gql.setServices(this);
|
||||
if (resource != null)
|
||||
|
@ -97,7 +97,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", source), new FileOutputStream(CompareUtilities.tempFile("graphql", source)));
|
||||
IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", output), new FileOutputStream(CompareUtilities.tempFile("graphql", output)));
|
||||
TextFile.stringToFile(str.toString(), CompareUtilities.tempFile("graphql", output+".out"));
|
||||
msg = CompareUtilities.checkJsonIsSame(CompareUtilities.tempFile("graphql", output), CompareUtilities.tempFile("graphql", output+".out"));
|
||||
msg = CompareUtilities.checkJsonIsSame(id, CompareUtilities.tempFile("graphql", output), CompareUtilities.tempFile("graphql", output+".out"));
|
||||
Assertions.assertTrue(Utilities.noString(msg), msg);
|
||||
}
|
||||
else
|
||||
|
@ -106,7 +106,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceReverseHistory() throws Exception {
|
||||
public void testReferenceReverseHistory(String id) throws Exception {
|
||||
String context = "Patient/example/$graphql";
|
||||
String source = "reference-reverse.gql";
|
||||
String output="reference-reverse-history.json";
|
||||
|
@ -119,7 +119,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
//Rather than duplicate the entire resource we modify the ID with a _history path
|
||||
parsedResource.setId("example/_history/1");
|
||||
|
||||
testResource(parsedResource, output, source, null);
|
||||
testResource(id, parsedResource, output, source, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -263,7 +263,7 @@ public class NarrativeGenerationTests {
|
|||
String actualFileName = CompareUtilities.tempFile("narrative", test.getId() + ".actual.html");
|
||||
TextFile.stringToFile(expected, expectedFileName);
|
||||
TextFile.stringToFile(actual, actualFileName);
|
||||
String msg = CompareUtilities.checkXMLIsSame(expectedFileName, actualFileName);
|
||||
String msg = CompareUtilities.checkXMLIsSame(id, expectedFileName, actualFileName);
|
||||
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||
|
||||
if (test.isMeta()) {
|
||||
|
@ -274,7 +274,7 @@ public class NarrativeGenerationTests {
|
|||
actual = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
||||
actualFileName = CompareUtilities.tempFile("narrative", test.getId() + "-meta.actual.html");
|
||||
TextFile.stringToFile(actual, actualFileName);
|
||||
msg = CompareUtilities.checkXMLIsSame(expectedFileName, actualFileName);
|
||||
msg = CompareUtilities.checkXMLIsSame(id, expectedFileName, actualFileName);
|
||||
Assertions.assertTrue(msg == null, "Meta output does not match expected: "+msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class ParsingTests {
|
|||
r = new XmlParser().parse(b);
|
||||
b = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeBytes(r);
|
||||
String output = new String(b);
|
||||
String msg = CompareUtilities.checkJsonSrcIsSame(src, output, null);
|
||||
String msg = CompareUtilities.checkJsonSrcIsSame(name, src, output, null);
|
||||
Assertions.assertTrue(msg == null, msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ResourceToElementTest {
|
|||
Element e = p.parse(res);
|
||||
new org.hl7.fhir.r5.elementmodel.XmlParser(ctxt).compose(e, new FileOutputStream(src), OutputStyle.PRETTY, null);
|
||||
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dst), res);
|
||||
String msg = CompareUtilities.checkXMLIsSame(src, dst);
|
||||
String msg = CompareUtilities.checkXMLIsSame(filename, src, dst);
|
||||
Assertions.assertNull(msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ public class VocabTests {
|
|||
String actualFileName = CompareUtilities.tempFile("vocab", test.getId() + ".actual.html");
|
||||
TextFile.stringToFile(expected, expectedFileName);
|
||||
TextFile.stringToFile(actual, actualFileName);
|
||||
String msg = CompareUtilities.checkXMLIsSame(expectedFileName, actualFileName);
|
||||
String msg = CompareUtilities.checkXMLIsSame(test.id, expectedFileName, actualFileName);
|
||||
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||
} else {
|
||||
Assertions.fail("Expansion Failed: "+outcome.getError());
|
||||
|
|
|
@ -50,7 +50,7 @@ public class CompareUtilitiesTests implements ResourceLoaderTests {
|
|||
|
||||
@ParameterizedTest
|
||||
@MethodSource("getCompareXMLParams")
|
||||
public void testCompareXML(String expectedFileName, String actualFileName, String expectedOutputFileName) throws Exception {
|
||||
public void testCompareXML(String id, String expectedFileName, String actualFileName, String expectedOutputFileName) throws Exception {
|
||||
final String expectedXMLPath = ROOT_XML_TEST_PATH.resolve(expectedFileName).toString();
|
||||
final String actualXMLPath = ROOT_XML_TEST_PATH.resolve(actualFileName).toString();
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class CompareUtilitiesTests implements ResourceLoaderTests {
|
|||
InputStream expectedXMLStream = classLoader.getResourceAsStream(expectedXMLPath);
|
||||
InputStream actualXMLStream = classLoader.getResourceAsStream(actualXMLPath);
|
||||
|
||||
final String actualOutput = CompareUtilities.checkXMLIsSame(expectedXMLStream, actualXMLStream);
|
||||
final String actualOutput = CompareUtilities.checkXMLIsSame(id, expectedXMLStream, actualXMLStream);
|
||||
|
||||
if (expectedOutputFileName == null) {
|
||||
assertNull(actualOutput);
|
||||
|
@ -87,11 +87,11 @@ public class CompareUtilitiesTests implements ResourceLoaderTests {
|
|||
|
||||
@ParameterizedTest
|
||||
@MethodSource("getCompareJSONParams")
|
||||
public void testCompareJSON(String expectedFileName, String actualFileName, String expectedOutputFileName) throws IOException {
|
||||
public void testCompareJSON(String id, String expectedFileName, String actualFileName, String expectedOutputFileName) throws IOException {
|
||||
final String expectedJSONPath = ROOT_JSON_TEST_PATH.resolve(expectedFileName).toString();
|
||||
final String actualJSONPath = ROOT_JSON_TEST_PATH.resolve(actualFileName).toString();
|
||||
|
||||
final String actualOutput = CompareUtilities.checkJsonSrcIsSame(getResourceAsString(expectedJSONPath), getResourceAsString(actualJSONPath), false, null);
|
||||
final String actualOutput = CompareUtilities.checkJsonSrcIsSame(id, getResourceAsString(expectedJSONPath), getResourceAsString(actualJSONPath), false, null);
|
||||
if (expectedOutputFileName == null) {
|
||||
assertNull(actualOutput);
|
||||
} else {
|
||||
|
|
|
@ -20,7 +20,7 @@ public abstract class I18nBase {
|
|||
|
||||
public static final String PLURAL_SUFFIX = "PLURAL";
|
||||
public static final String KEY_DELIMITER = "_";
|
||||
private Locale locale;
|
||||
protected Locale locale;
|
||||
private ResourceBundle messages;
|
||||
private PluralRules pluralRules;
|
||||
private boolean warnAboutMissingMessages = true;
|
||||
|
|
|
@ -195,11 +195,11 @@ public class TxTester {
|
|||
String lang = test.asString("Content-Language");
|
||||
String msg = null;
|
||||
if (test.asString("operation").equals("expand")) {
|
||||
msg = expand(tx, setup, req, resp, fp, lang, profile, ext);
|
||||
msg = expand(test.str("name"), tx, setup, req, resp, fp, lang, profile, ext);
|
||||
} else if (test.asString("operation").equals("validate-code")) {
|
||||
msg = validate(tx, setup, req, resp, fp, lang, profile, ext);
|
||||
msg = validate(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext);
|
||||
} else if (test.asString("operation").equals("cs-validate-code")) {
|
||||
msg = validateCS(tx, setup, req, resp, fp, lang, profile, ext);
|
||||
msg = validateCS(test.str("name"),tx, setup, req, resp, fp, lang, profile, ext);
|
||||
} else {
|
||||
throw new Exception("Unknown Operation "+test.asString("operation"));
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ public class TxTester {
|
|||
return new URI(server).getHost();
|
||||
}
|
||||
|
||||
private String expand(ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
private String expand(String id, ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
for (Resource r : setup) {
|
||||
p.addParameter().setName("tx-resource").setResource(r);
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ public class TxTester {
|
|||
TxTesterScrubbers.scrubOO(oo, tight);
|
||||
vsj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
}
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, vsj, false, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, vsj, false, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(vsj, fp);
|
||||
|
@ -273,7 +273,7 @@ public class TxTester {
|
|||
return diff;
|
||||
}
|
||||
|
||||
private String validate(ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
private String validate(String id, ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
for (Resource r : setup) {
|
||||
p.addParameter().setName("tx-resource").setResource(r);
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ public class TxTester {
|
|||
oo.setText(null);
|
||||
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
}
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, pj, false, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, pj, false, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(pj, fp);
|
||||
|
@ -298,7 +298,7 @@ public class TxTester {
|
|||
return diff;
|
||||
}
|
||||
|
||||
private String validateCS(ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
private String validateCS(String id, ITerminologyClient tx, List<Resource> setup, Parameters p, String resp, String fp, String lang, Parameters profile, JsonObject ext) throws IOException {
|
||||
for (Resource r : setup) {
|
||||
p.addParameter().setName("tx-resource").setResource(r);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ public class TxTester {
|
|||
oo.setText(null);
|
||||
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
}
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, pj, false, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, pj, false, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(pj, fp);
|
||||
|
|
|
@ -123,6 +123,8 @@ public class ComparisonTests {
|
|||
if (content.has("use-test") && !content.asBoolean("use-test"))
|
||||
return;
|
||||
|
||||
String id = name;
|
||||
|
||||
if (context == null) {
|
||||
System.out.println("---- Load R5 ----------------------------------------------------------------");
|
||||
context = TestingUtilities.getSharedWorkerContext();
|
||||
|
@ -175,7 +177,7 @@ public class ComparisonTests {
|
|||
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Concepts") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
|
||||
checkOutcomes(csc.getMessages(), content);
|
||||
new CodeSystemRenderer(lrc).render(right);
|
||||
checkOutput(content.getJsonObject("version").asString("filename"), right);
|
||||
checkOutput(id, content.getJsonObject("version").asString("filename"), right);
|
||||
} else if (left instanceof ValueSet && right instanceof ValueSet) {
|
||||
ValueSetComparer cs = new ValueSetComparer(session);
|
||||
ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
|
||||
|
@ -189,7 +191,7 @@ public class ComparisonTests {
|
|||
TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Definition") + xml2 + BREAK + hd("Expansion") + xml3 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
|
||||
checkOutcomes(csc.getMessages(), content);
|
||||
new ValueSetRenderer(lrc).render(right);
|
||||
checkOutput(content.getJsonObject("version").asString("filename"), right);
|
||||
checkOutput(id, content.getJsonObject("version").asString("filename"), right);
|
||||
} else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
|
||||
ProfileUtilities utils = new ProfileUtilities(context, null, null);
|
||||
genSnapshot(utils, (StructureDefinition) left);
|
||||
|
@ -209,11 +211,11 @@ public class ComparisonTests {
|
|||
|
||||
lrc.setStructureMode(StructureDefinitionRendererMode.DATA_DICT);
|
||||
new StructureDefinitionRenderer(lrc).render(right);
|
||||
checkOutput(content.getJsonObject("version").asString("filename-dd"), right);
|
||||
checkOutput(id, content.getJsonObject("version").asString("filename-dd"), right);
|
||||
|
||||
lrc.setStructureMode(StructureDefinitionRendererMode.SUMMARY);
|
||||
new StructureDefinitionRenderer(lrc).render(right);
|
||||
checkOutput(content.getJsonObject("version").asString("filename-tree"), right);
|
||||
checkOutput(id, content.getJsonObject("version").asString("filename-tree"), right);
|
||||
} else if (left instanceof CapabilityStatement && right instanceof CapabilityStatement) {
|
||||
CapabilityStatementComparer pc = new CapabilityStatementComparer(session);
|
||||
CapabilityStatementComparison csc = pc.compare((CapabilityStatement) left, (CapabilityStatement) right);
|
||||
|
@ -231,7 +233,7 @@ public class ComparisonTests {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkOutput(String name, CanonicalResource right) throws Exception {
|
||||
private void checkOutput(String id, String name, CanonicalResource right) throws Exception {
|
||||
String output = prefix+ new XhtmlComposer(false, true).compose(right.getText().getDiv()) + suffix;
|
||||
String an = Utilities.path("[tmp]", "comparison", name);
|
||||
TextFile.stringToFile(output, an);
|
||||
|
@ -239,7 +241,7 @@ public class ComparisonTests {
|
|||
String en = Utilities.path("[tmp]", "comparison", Utilities.changeFileExt(name, ".expected.html"));
|
||||
TextFile.stringToFile(expected, en);
|
||||
|
||||
String msg = CompareUtilities.checkXMLIsSame(en, an);
|
||||
String msg = CompareUtilities.checkXMLIsSame(id, en, an);
|
||||
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||
|
||||
}
|
||||
|
|
|
@ -147,17 +147,17 @@ public class TerminologyServiceTests {
|
|||
engine.getContext().setExpansionParameters((org.hl7.fhir.r5.model.Parameters) loadResource("parameters-default.json"));
|
||||
}
|
||||
if (setup.test.asString("operation").equals("expand")) {
|
||||
expand(engine, req, resp, setup.test.asString("Content-Language"), fp, ext);
|
||||
expand(setup.test.str("name"), engine, req, resp, setup.test.asString("Content-Language"), fp, ext);
|
||||
} else if (setup.test.asString("operation").equals("validate-code")) {
|
||||
validate(engine, setup.test.asString("name"), req, resp, setup.test.asString("Content-Language"), fp, ext, false);
|
||||
validate(setup.test.str("name"), engine, setup.test.asString("name"), req, resp, setup.test.asString("Content-Language"), fp, ext, false);
|
||||
} else if (setup.test.asString("operation").equals("cs-validate-code")) {
|
||||
validate(engine, setup.test.asString("name"), req, resp, setup.test.asString("Content-Language"), fp, ext, true);
|
||||
validate(setup.test.str("name"), engine, setup.test.asString("name"), req, resp, setup.test.asString("Content-Language"), fp, ext, true);
|
||||
} else {
|
||||
Assertions.fail("Unknown Operation "+setup.test.asString("operation"));
|
||||
}
|
||||
}
|
||||
|
||||
private void expand(ValidationEngine engine, Resource req, String resp, String lang, String fp, JsonObject ext) throws IOException {
|
||||
private void expand(String id, ValidationEngine engine, Resource req, String resp, String lang, String fp, JsonObject ext) throws IOException {
|
||||
org.hl7.fhir.r5.model.Parameters p = ( org.hl7.fhir.r5.model.Parameters) req;
|
||||
ValueSet vs = engine.getContext().fetchResource(ValueSet.class, p.getParameterValue("url").primitiveValue());
|
||||
boolean hierarchical = p.hasParameter("excludeNested") ? p.getParameterBool("excludeNested") == false : true;
|
||||
|
@ -176,7 +176,7 @@ public class TerminologyServiceTests {
|
|||
TxTesterSorters.sortValueSet(vse.getValueset());
|
||||
TxTesterScrubbers.scrubVS(vse.getValueset(), false);
|
||||
String vsj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(vse.getValueset());
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, vsj, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, vsj, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(vsj, fp);
|
||||
|
@ -225,7 +225,7 @@ public class TerminologyServiceTests {
|
|||
TxTesterScrubbers.scrubOO(oo, false);
|
||||
|
||||
String ooj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, ooj, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, ooj, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(ooj, fp);
|
||||
|
@ -243,7 +243,7 @@ public class TerminologyServiceTests {
|
|||
}
|
||||
}
|
||||
|
||||
private void validate(ValidationEngine engine, String name, Resource req, String resp, String lang, String fp, JsonObject ext, boolean isCS) throws JsonSyntaxException, FileNotFoundException, IOException {
|
||||
private void validate(String id, ValidationEngine engine, String name, Resource req, String resp, String lang, String fp, JsonObject ext, boolean isCS) throws JsonSyntaxException, FileNotFoundException, IOException {
|
||||
org.hl7.fhir.r5.model.Parameters p = (org.hl7.fhir.r5.model.Parameters) req;
|
||||
ValueSet vs = null;
|
||||
String vsurl = null;
|
||||
|
@ -324,7 +324,7 @@ public class TerminologyServiceTests {
|
|||
TxTesterScrubbers.scrubOO(oo, false);
|
||||
|
||||
String pj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, pj, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, pj, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(pj, fp);
|
||||
|
@ -395,7 +395,7 @@ public class TerminologyServiceTests {
|
|||
TxTesterScrubbers.scrubParams(res);
|
||||
|
||||
String pj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(res);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(resp, pj, ext);
|
||||
String diff = CompareUtilities.checkJsonSrcIsSame(id, resp, pj, ext);
|
||||
if (diff != null) {
|
||||
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
|
||||
TextFile.stringToFile(pj, fp);
|
||||
|
|
|
@ -120,11 +120,11 @@ public class StructureMappingTests {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
if (output.endsWith("json")) {
|
||||
msg = CompareUtilities.checkJsonSrcIsSame(s.toString(), outputJson, null);
|
||||
msg = CompareUtilities.checkJsonSrcIsSame(name, s.toString(), outputJson, null);
|
||||
} else {
|
||||
TextFile.bytesToFile(s.toByteArray(), fileOutputRes);
|
||||
TextFile.bytesToFile(outputJson.getBytes(), fileOutputResOrig);
|
||||
msg = CompareUtilities.checkXMLIsSame(new FileInputStream(fileOutputResOrig), new FileInputStream(fileOutputRes));
|
||||
msg = CompareUtilities.checkXMLIsSame(name, new FileInputStream(fileOutputResOrig), new FileInputStream(fileOutputRes));
|
||||
}
|
||||
if (!Utilities.noString(msg)) {
|
||||
System.out.print(s.toString());
|
||||
|
|
Loading…
Reference in New Issue