fix failing test

This commit is contained in:
Grahame Grieve 2019-09-15 20:42:21 +10:00
parent 863c7ae6ac
commit 9d164ef153
5 changed files with 112 additions and 24 deletions

1
.gitignore vendored
View File

@ -292,3 +292,4 @@ local.properties
/org.hl7.fhir.r4b /org.hl7.fhir.r4b
/org.hl7.fhir.r5/src/test/resources/gen/gen.xml /org.hl7.fhir.r5/src/test/resources/gen/gen.xml
/org.hl7.fhir.r5/src/test/resources/graphql/*.out /org.hl7.fhir.r5/src/test/resources/graphql/*.out
/org.hl7.fhir.validation/src/test/resources/comparison/output

View File

@ -117,9 +117,11 @@ public class CapabilityStatementUtilities {
this.context = context; this.context = context;
this.folder = folder; this.folder = folder;
this.keygen = keygen; this.keygen = keygen;
String f = Utilities.path(folder, "comparison.zip"); if (!new File(Utilities.path(folder, "conparison-zip-marker.bin")).exists()) {
download("http://fhir.org/archive/comparison.zip", f); String f = Utilities.path(folder, "comparison.zip");
unzip(f, folder); download("https://www.fhir.org/archive/comparison.zip", f);
unzip(f, folder);
}
} }
/** /**
@ -440,7 +442,7 @@ public class CapabilityStatementUtilities {
union.setProfile(sdL.getUrl()); union.setProfile(sdL.getUrl());
} else if (folder != null) { } else if (folder != null) {
try { try {
ProfileComparer pc = new ProfileComparer(context, keygen); ProfileComparer pc = new ProfileComparer(context, keygen, folder);
pc.setId("api-ep."+type); pc.setId("api-ep."+type);
pc.setTitle("Comparison - "+selfName+" vs "+otherName); pc.setTitle("Comparison - "+selfName+" vs "+otherName);
pc.setLeftName(selfName+": "+sdL.present()); pc.setLeftName(selfName+": "+sdL.present());
@ -449,7 +451,7 @@ public class CapabilityStatementUtilities {
pc.setRightLink(sdR.getUserString("path")); pc.setRightLink(sdR.getUserString("path"));
pc.compareProfiles(sdL, sdR); pc.compareProfiles(sdL, sdR);
System.out.println("Generate Comparison between "+pc.getLeftName()+" and "+pc.getRightName()); System.out.println("Generate Comparison between "+pc.getLeftName()+" and "+pc.getRightName());
pc.generate(folder); pc.generate();
for (ProfileComparison cmp : pc.getComparisons()) { for (ProfileComparison cmp : pc.getComparisons()) {
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, cmp.getSubset().fhirType()+"-"+cmp.getSubset().getId()+".xml")), cmp.getSubset()); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(folder, cmp.getSubset().fhirType()+"-"+cmp.getSubset().getId()+".xml")), cmp.getSubset());

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.r5.conformance; package org.hl7.fhir.r5.conformance;
import java.io.BufferedOutputStream;
/*- /*-
* #%L * #%L
* org.hl7.fhir.r5 * org.hl7.fhir.r5
@ -22,7 +24,11 @@ package org.hl7.fhir.r5.conformance;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +38,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
@ -100,16 +107,96 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
private IWorkerContext context; private IWorkerContext context;
private KeyGenerator keygen; private KeyGenerator keygen;
private String folder;
public ProfileComparer(IWorkerContext context, KeyGenerator keygen) { public ProfileComparer(IWorkerContext context, KeyGenerator keygen, String folder) throws IOException {
super(); super();
this.context = context; this.context = context;
this.keygen = keygen; this.keygen = keygen;
this.folder = folder;
if (!new File(Utilities.path(folder, "conparison-zip-marker.bin")).exists()) {
String f = Utilities.path(folder, "comparison.zip");
download("https://www.fhir.org/archive/comparison.zip", f);
unzip(f, folder);
}
} }
public ProfileComparer(IWorkerContext context) { private void download(String address, String filename) throws IOException {
URL url = new URL(address);
URLConnection c = url.openConnection();
InputStream s = c.getInputStream();
FileOutputStream f = new FileOutputStream(filename);
transfer(s, f, 1024);
f.close();
}
public static void transfer(InputStream in, OutputStream out, int buffer) throws IOException {
byte[] read = new byte[buffer]; // Your buffer size.
while (0 < (buffer = in.read(read)))
out.write(read, 0, buffer);
}
/**
* Size of the buffer to read/write data
*/
private static final int BUFFER_SIZE = 4096;
/**
* Extracts a zip file specified by the zipFilePath to a directory specified by
* destDirectory (will be created if does not exists)
* @param zipFilePath
* @param destDirectory
* @throws IOException
*/
public void unzip(String zipFilePath, String destDirectory) throws IOException {
File destDir = new File(destDirectory);
if (!destDir.exists()) {
destDir.mkdir();
}
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null) {
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
// if the entry is a file, extracts it
extractFile(zipIn, filePath);
} else {
// if the entry is a directory, make the directory
File dir = new File(filePath);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
/**
* Extracts a zip entry (file entry)
* @param zipIn
* @param filePath
* @throws IOException
*/
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
public ProfileComparer(IWorkerContext context, String folder) throws IOException {
super(); super();
this.context = context; this.context = context;
this.folder = folder;
if (!new File(Utilities.path(folder, "conparison-zip-marker.bin")).exists()) {
String f = Utilities.path(folder, "comparison.zip");
download("https://www.fhir.org/archive/comparison.zip", f);
unzip(f, folder);
}
} }
private static final int BOTH_NULL = 0; private static final int BOTH_NULL = 0;
@ -1431,9 +1518,9 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
} }
public String generate(String dest) throws IOException { public String generate() throws IOException {
for (ValueSet vs : valuesets) { for (ValueSet vs : valuesets) {
vs.setUserData("path", dest+"/"+getId()+"-vs-"+vs.getId()+".html"); vs.setUserData("path", folder+"/"+getId()+"-vs-"+vs.getId()+".html");
} }
// ok, all compared; now produce the output // ok, all compared; now produce the output
// first page we produce is simply the index // first page we produce is simply the index
@ -1442,8 +1529,8 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
vars.put("left", genPCLink(getLeftName(), getLeftLink())); vars.put("left", genPCLink(getLeftName(), getLeftLink()));
vars.put("right", genPCLink(getRightName(), getRightLink())); vars.put("right", genPCLink(getRightName(), getRightLink()));
vars.put("table", genPCTable()); vars.put("table", genPCTable());
vars.put("valuesets", genValueSets(dest+"/"+getId()+"-vs")); vars.put("valuesets", genValueSets(folder+"/"+getId()+"-vs"));
producePage(summaryTemplate(), Utilities.path(dest, getId()+".html"), vars); producePage(summaryTemplate(), Utilities.path(folder, getId()+".html"), vars);
System.out.println(" .. profiles"); System.out.println(" .. profiles");
// then we produce a comparison page for each pair // then we produce a comparison page for each pair
@ -1453,15 +1540,15 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
vars.put("left", genPCLink(getLeftName(), getLeftLink())); vars.put("left", genPCLink(getLeftName(), getLeftLink()));
vars.put("right", genPCLink(getRightName(), getRightLink())); vars.put("right", genPCLink(getRightName(), getRightLink()));
vars.put("messages", genCmpMessages(cmp)); vars.put("messages", genCmpMessages(cmp));
vars.put("subset", genCompModel(cmp.getSubset(), "intersection", getId()+"."+cmp.getId(), "", dest)); vars.put("subset", genCompModel(cmp.getSubset(), "intersection", getId()+"."+cmp.getId(), "", folder));
vars.put("superset", genCompModel(cmp.getSuperset(), "union", getId()+"."+cmp.getId(), "", dest)); vars.put("superset", genCompModel(cmp.getSuperset(), "union", getId()+"."+cmp.getId(), "", folder));
producePage(singleTemplate(), Utilities.path(dest, getId()+"."+cmp.getId()+".html"), vars); producePage(singleTemplate(), Utilities.path(folder, getId()+"."+cmp.getId()+".html"), vars);
} }
// // and also individual pages for each pair outcome // // and also individual pages for each pair outcome
// // then we produce value set pages for each value set // // then we produce value set pages for each value set
// //
// // TODO Auto-generated method stub // // TODO Auto-generated method stub
return Utilities.path(dest, getId()+".html"); return Utilities.path(folder, getId()+".html");
} }
@ -1480,13 +1567,11 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
} }
private String summaryTemplate() throws IOException { private String summaryTemplate() throws IOException {
return TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\source\\template-comparison-set.html"); return TextFile.fileToString(Utilities.path(folder, "template-comparison-set.html"));
// return cachedFetch("04a9d69a-47f2-4250-8645-bf5d880a8eaa-1.fhir-template", "http://build.fhir.org/template-comparison-set.html.template");
} }
private String singleTemplate() throws IOException { private String singleTemplate() throws IOException {
return TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\source\\template-comparison.html"); return TextFile.fileToString(Utilities.path(folder, "template-comparison.html"));
// return cachedFetch("04a9d69a-47f2-4250-8645-bf5d880a8eaa-1.fhir-template", "http://build.fhir.org/template-comparison-set.html.template");
} }
private String cachedFetch(String id, String source) throws IOException { private String cachedFetch(String id, String source) throws IOException {

View File

@ -296,12 +296,12 @@ public class Validator {
if (resLeft != null && resRight != null) { if (resLeft != null && resRight != null) {
if (resLeft instanceof StructureDefinition && resRight instanceof StructureDefinition) { if (resLeft instanceof StructureDefinition && resRight instanceof StructureDefinition) {
System.out.println("Comparing StructureDefinitions "+left+" to "+right); System.out.println("Comparing StructureDefinitions "+left+" to "+right);
ProfileComparer pc = new ProfileComparer(validator.getContext()); ProfileComparer pc = new ProfileComparer(validator.getContext(), dest);
StructureDefinition sdL = (StructureDefinition) resLeft; StructureDefinition sdL = (StructureDefinition) resLeft;
StructureDefinition sdR = (StructureDefinition) resRight; StructureDefinition sdR = (StructureDefinition) resRight;
pc.compareProfiles(sdL, sdR); pc.compareProfiles(sdL, sdR);
System.out.println("Generating output to "+dest+"..."); System.out.println("Generating output to "+dest+"...");
File htmlFile = new File(pc.generate(dest)); File htmlFile = new File(pc.generate());
Desktop.getDesktop().browse(htmlFile.toURI()); Desktop.getDesktop().browse(htmlFile.toURI());
System.out.println("Done"); System.out.println("Done");
} else if (resLeft instanceof CapabilityStatement && resRight instanceof CapabilityStatement) { } else if (resLeft instanceof CapabilityStatement && resRight instanceof CapabilityStatement) {

View File

@ -34,7 +34,7 @@ public class ProfileComparisonTests {
// ok now set up the comparison // ok now set up the comparison
StructureDefinition sdL = ve.getContext().fetchResource(StructureDefinition.class, left); StructureDefinition sdL = ve.getContext().fetchResource(StructureDefinition.class, left);
ProfileComparer pc = new ProfileComparer(ve.getContext(), new KeyGenerator("http://fhir.org/temp/"+UUID.randomUUID().toString().toLowerCase())); ProfileComparer pc = new ProfileComparer(ve.getContext(), new KeyGenerator("http://fhir.org/temp/"+UUID.randomUUID().toString().toLowerCase()), dest);
if (sdL == null) { if (sdL == null) {
System.out.println("Unable to locate left profile " +left); System.out.println("Unable to locate left profile " +left);
} else { } else {
@ -47,7 +47,7 @@ public class ProfileComparisonTests {
System.out.println("Generating output..."); System.out.println("Generating output...");
File htmlFile = null; File htmlFile = null;
try { try {
htmlFile = new File(pc.generate(dest)); htmlFile = new File(pc.generate());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;