Add round trip tests and add fix for round-tripping issue
This commit is contained in:
parent
4e730ea052
commit
eb228bd1e3
|
@ -436,10 +436,12 @@ public class JavaParserJsonGenerator extends JavaBaseGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) {
|
if (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) {
|
||||||
composer.append(" openArray(\""+name+"\");\r\n");
|
composer.append(" if (anyHasValue(element.get"+upFirst(getElementName(name, false))+"())) {\r\n");
|
||||||
composer.append(" for ("+(tn.contains("(") ? stn : upFirst(tn))+" e : element.get"+upFirst(getElementName(name, false))+"()) \r\n");
|
composer.append(" openArray(\""+name+"\");\r\n");
|
||||||
composer.append(" "+comp+"Core(null, e, true);\r\n");
|
composer.append(" for ("+(tn.contains("(") ? stn : upFirst(tn))+" e : element.get"+upFirst(getElementName(name, false))+"()) \r\n");
|
||||||
composer.append(" closeArray();\r\n");
|
composer.append(" "+comp+"Core(null, e, e != element.get"+upFirst(getElementName(name, false))+"().get(element.get"+upFirst(getElementName(name, false))+"().size()-1));\r\n");
|
||||||
|
composer.append(" closeArray();\r\n");
|
||||||
|
composer.append(" }\r\n");
|
||||||
composer.append(" if (anyHasExtras(element.get"+upFirst(getElementName(name, false))+"())) {\r\n");
|
composer.append(" if (anyHasExtras(element.get"+upFirst(getElementName(name, false))+"())) {\r\n");
|
||||||
composer.append(" openArray(\"_"+name+"\");\r\n");
|
composer.append(" openArray(\"_"+name+"\");\r\n");
|
||||||
composer.append(" for ("+(stn.contains("(") ? stn : upFirst(stn))+" e : element.get"+upFirst(getElementName(name, false))+"()) \r\n");
|
composer.append(" for ("+(stn.contains("(") ? stn : upFirst(stn))+" e : element.get"+upFirst(getElementName(name, false))+"()) \r\n");
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -72,6 +72,7 @@ import org.hl7.fhir.r5.model.DataType;
|
||||||
import org.hl7.fhir.r5.model.DomainResource;
|
import org.hl7.fhir.r5.model.DomainResource;
|
||||||
import org.hl7.fhir.r5.model.Element;
|
import org.hl7.fhir.r5.model.Element;
|
||||||
import org.hl7.fhir.r5.model.IdType;
|
import org.hl7.fhir.r5.model.IdType;
|
||||||
|
import org.hl7.fhir.r5.model.PrimitiveType;
|
||||||
import org.hl7.fhir.r5.model.Resource;
|
import org.hl7.fhir.r5.model.Resource;
|
||||||
import org.hl7.fhir.r5.model.StringType;
|
import org.hl7.fhir.r5.model.StringType;
|
||||||
import org.hl7.fhir.utilities.TextFile;
|
import org.hl7.fhir.utilities.TextFile;
|
||||||
|
@ -324,11 +325,19 @@ public abstract class JsonParserBase extends ParserBase implements IParser {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
protected boolean anyHasExtras(List<? extends Element> list) {
|
protected boolean anyHasExtras(List<? extends Element> list) {
|
||||||
for (Element e : list) {
|
for (Element e : list) {
|
||||||
if (e.hasExtension() || !Utilities.noString(e.getId()))
|
if (e.hasExtension() || !Utilities.noString(e.getId()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean anyHasValue(List<? extends PrimitiveType> list) {
|
||||||
|
for (PrimitiveType e : list) {
|
||||||
|
if (e.hasValue())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean makeComments(Element element) {
|
protected boolean makeComments(Element element) {
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
package org.hl7.fhir.r5.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
|
import org.hl7.fhir.exceptions.DefinitionException;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
|
import org.hl7.fhir.exceptions.PathEngineException;
|
||||||
|
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||||
|
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
|
||||||
|
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
|
||||||
|
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||||
|
import org.hl7.fhir.r5.formats.JsonParser;
|
||||||
|
import org.hl7.fhir.r5.formats.XmlParser;
|
||||||
|
import org.hl7.fhir.r5.model.Base;
|
||||||
|
import org.hl7.fhir.r5.model.Bundle;
|
||||||
|
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent;
|
||||||
|
import org.hl7.fhir.r5.model.ExpressionNode.CollectionStatus;
|
||||||
|
import org.hl7.fhir.r5.model.Resource;
|
||||||
|
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||||
|
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||||
|
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
|
||||||
|
import org.hl7.fhir.r5.renderers.RendererFactory;
|
||||||
|
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
|
||||||
|
import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode;
|
||||||
|
import org.hl7.fhir.r5.model.TypeDetails;
|
||||||
|
import org.hl7.fhir.r5.model.ValueSet;
|
||||||
|
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||||
|
import org.hl7.fhir.r5.utils.FHIRPathEngine;
|
||||||
|
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
|
||||||
|
import org.hl7.fhir.r5.utils.IResourceValidator;
|
||||||
|
import org.hl7.fhir.r5.utils.XVerExtensionManager;
|
||||||
|
import org.hl7.fhir.utilities.TextFile;
|
||||||
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
import org.hl7.fhir.utilities.cache.NpmPackage;
|
||||||
|
import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
|
||||||
|
import org.hl7.fhir.utilities.cache.ToolsVersion;
|
||||||
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
|
||||||
|
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ParsingTests {
|
||||||
|
|
||||||
|
private static NpmPackage npm;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setUp() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream<Arguments> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
|
||||||
|
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||||
|
npm = pcm.loadPackage("hl7.fhir.r5.examples", "4.5.0");
|
||||||
|
List<Arguments> objects = new ArrayList<>();
|
||||||
|
List<String> names = npm.list("package");
|
||||||
|
for (String n : names) {
|
||||||
|
if (!n.contains("manifest.json") && !n.contains("xver-") && !n.contains("uml.json") && !n.contains("package-min-ver.json")) {
|
||||||
|
objects.add(Arguments.of(n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objects.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@ParameterizedTest(name = "{index}: file {0}")
|
||||||
|
@MethodSource("data")
|
||||||
|
public void test(String name) throws Exception {
|
||||||
|
System.out.println(name);
|
||||||
|
byte[] b = TextFile.streamToBytes(npm.load("package", name));
|
||||||
|
String src = new String(b);
|
||||||
|
Resource r = new JsonParser().parse(b);
|
||||||
|
b = new XmlParser().composeBytes(r);
|
||||||
|
r = new XmlParser().parse(b);
|
||||||
|
b = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeBytes(r);
|
||||||
|
String output = new String(b);
|
||||||
|
String msg = TestingUtilities.checkJsonSrcIsSame(src, output);
|
||||||
|
Assertions.assertTrue(msg == null, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue