fixing tests

This commit is contained in:
markiantorno 2020-04-29 14:40:46 -04:00
parent 368a45a150
commit 5893249747
10 changed files with 464 additions and 128 deletions

View File

@ -20,21 +20,15 @@ import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
import org.hl7.fhir.utilities.graphql.NameValue;
import org.hl7.fhir.utilities.graphql.Parser;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -42,8 +36,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import static org.junit.Assert.assertTrue;
public class GraphQLEngineTests implements IGraphQLStorageServices {
public static Stream<Arguments> data() throws IOException, ParserConfigurationException, SAXException {
@ -91,7 +83,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
msg = e.getMessage();
}
if (ok) {
assertTrue("Expected to fail, but didn't", !output.equals("$error"));
Assertions.assertTrue(!output.equals("$error"), "Expected to fail, but didn't");
StringBuilder str = new StringBuilder();
gql.getOutput().setWriteWrapper(false);
gql.getOutput().write(str, 0);
@ -99,10 +91,10 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "graphql", output), new FileOutputStream(TestingUtilities.tempFile("graphql", output)));
TextFile.stringToFile(str.toString(), TestingUtilities.tempFile("graphql", output+".out"));
msg = TestingUtilities.checkJsonIsSame(TestingUtilities.tempFile("graphql", output+".out"), TestingUtilities.tempFile("graphql", output));
assertTrue(msg, Utilities.noString(msg));
Assertions.assertTrue(Utilities.noString(msg), msg);
}
else
assertTrue("Error, but proper output was expected ("+msg+")", output.equals("$error"));
Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected ("+msg+")");
}
@Override

View File

@ -1,6 +1,14 @@
package org.hl7.fhir.r5.test;
import static org.junit.Assert.assertTrue;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.graphql.EGraphEngine;
import org.hl7.fhir.utilities.graphql.EGraphQLException;
import org.hl7.fhir.utilities.graphql.Package;
import org.hl7.fhir.utilities.graphql.Parser;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.FileNotFoundException;
import java.io.IOException;
@ -8,37 +16,24 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.graphql.EGraphEngine;
import org.hl7.fhir.utilities.graphql.EGraphQLException;
import org.hl7.fhir.utilities.graphql.Package;
import org.hl7.fhir.utilities.graphql.Parser;
import org.junit.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.assertTrue;
public class GraphQLParserTests {
public static Stream<Arguments> data() throws FileNotFoundException, IOException {
public static Stream<Arguments> data() throws IOException {
String src = TestingUtilities.loadTestResource("r5", "graphql", "parser-tests.gql");
String[] tests = src.split("###");
List<Arguments> objects = new ArrayList<>();
for (String s : tests) {
if (!Utilities.noString(s.trim())) {
int l = s.indexOf('\r');
objects.add(Arguments.of(s.substring(0, l), s.substring(l+2).trim()));
int l = s.indexOf('\r');
objects.add(Arguments.of(s.substring(0, l), s.substring(l + 2).trim()));
}
}
return objects.stream();
}
@ParameterizedTest(name = "{index}: {0}")
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);

View File

@ -2,11 +2,9 @@ package org.hl7.fhir.r5.test;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.Meta;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
public class MetaTest {
public static String TEST_SYSTEM = "TEST_SYSTEM";
public static String TEST_CODE = "TEST_CODE";
@ -15,12 +13,12 @@ public class MetaTest {
public void testMetaSecurity() {
Meta meta = new Meta();
Coding coding = meta.addSecurity().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
assertTrue(meta.hasSecurity());
assertNotNull(meta.getSecurity());
assertNotNull(meta.getSecurity(TEST_SYSTEM, TEST_CODE));
assertEquals(1, meta.getSecurity().size());
assertEquals(meta.getSecurity().get(0), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
assertEquals(meta.getSecurityFirstRep(), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
assertEquals(coding, meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertTrue(meta.hasSecurity());
Assertions.assertNotNull(meta.getSecurity());
Assertions.assertNotNull(meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertEquals(1, meta.getSecurity().size());
Assertions.assertEquals(meta.getSecurity().get(0), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertEquals(meta.getSecurityFirstRep(), meta.getSecurity(TEST_SYSTEM, TEST_CODE));
Assertions.assertEquals(coding, meta.getSecurity(TEST_SYSTEM, TEST_CODE));
}
}

View File

@ -1,6 +1,5 @@
package org.hl7.fhir.r5.test;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.DomainResource;
@ -23,7 +22,7 @@ public class NarrativeGeneratorTests {
private NarrativeGenerator gen;
@BeforeAll
public void setUp() throws FileNotFoundException, IOException, FHIRException, UcumException {
public void setUp() throws FHIRException {
gen = new NarrativeGenerator("", null, TestingUtilities.context());
}

View File

@ -1,7 +1,6 @@
package org.hl7.fhir.r5.test;
import org.apache.commons.io.IOUtils;
import org.fhir.ucum.UcumException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.formats.IParser;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
@ -20,7 +19,7 @@ import java.io.*;
public class ResourceRoundTripTests {
@Test
public void test() throws FileNotFoundException, IOException, FHIRException, EOperationOutcome, UcumException {
public void test() throws IOException, FHIRException, EOperationOutcome {
Resource res = new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"));
new NarrativeGenerator("", "", TestingUtilities.context()).generate((DomainResource) res, null);
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"), new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.xml")));

View File

@ -2,10 +2,9 @@ package org.hl7.fhir.r5.test;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.utils.SnomedExpressions;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertNotNull;
public class SnomedExpressionsTests {
@Test
@ -47,7 +46,7 @@ public class SnomedExpressionsTests {
}
private void p(String expression) throws FHIRException {
assertNotNull("must be present", SnomedExpressions.parse(expression));
Assertions.assertNotNull(SnomedExpressions.parse(expression), "must be present");
}

View File

@ -10,7 +10,6 @@ import org.hl7.fhir.r5.utils.StructureMapUtilities;
import org.hl7.fhir.r5.utils.StructureMapUtilities.ITransformerServices;
import org.hl7.fhir.utilities.cache.PackageCacheManager;
import org.hl7.fhir.utilities.cache.ToolsVersion;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -24,7 +23,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
static private SimpleWorkerContext context;
@BeforeAll
// @BeforeAll
static public void setUp() throws Exception {
PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));

View File

@ -1,11 +1,6 @@
package org.hl7.fhir.r5.test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import org.apache.commons.lang3.SystemUtils;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -14,6 +9,9 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
public class UtilitiesTests {
private static final String XHTML_SIMPLE = "<div>Some Text</div>";
@ -108,7 +106,7 @@ public class UtilitiesTests {
@Test
public void testXhtmlLangAttributes() throws IOException {
run(XHTML_SIMPLE);
run(XHTML_LANGS);
run(XHTML_LANGS);
}
public void run(String src) throws IOException {

View File

@ -1,11 +1,5 @@
package org.hl7.fhir.r5.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
@ -14,46 +8,51 @@ import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.utilities.Utilities;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ValidationTestConvertor {
/**
* @param args
* @throws FHIRException
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException, FHIRException {
SimpleWorkerContext context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
for (File f : new File("C:\\work\\org.hl7.fhir\\build\\tests\\validation-examples").listFiles()) {
if (f.getAbsolutePath().endsWith(".xml")) {
File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
if (!t.exists()) {
try {
System.out.print("Process "+f.getAbsolutePath());
Element e = Manager.parse(context, new FileInputStream(f), FhirFormat.XML);
Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
System.out.println(" .... success");
} catch (Exception e) {
System.out.println(" .... fail: "+e.getMessage());
}
}
}
if (f.getAbsolutePath().endsWith(".json")) {
if (!new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl")).exists()) {
File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
if (!t.exists()) {
try {
System.out.print("Process "+f.getAbsolutePath());
Element e = Manager.parse(context, new FileInputStream(f), FhirFormat.JSON);
Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
System.out.println(" .... success");
} catch (Exception e) {
System.out.println(" .... fail: "+e.getMessage());
}
}
}
}
}
}
/**
* @param args
* @throws FHIRException
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException, FHIRException {
SimpleWorkerContext context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
for (File f : new File("C:\\work\\org.hl7.fhir\\build\\tests\\validation-examples").listFiles()) {
if (f.getAbsolutePath().endsWith(".xml")) {
File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
if (!t.exists()) {
try {
System.out.print("Process " + f.getAbsolutePath());
Element e = Manager.parse(context, new FileInputStream(f), FhirFormat.XML);
Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
System.out.println(" .... success");
} catch (Exception e) {
System.out.println(" .... fail: " + e.getMessage());
}
}
}
if (f.getAbsolutePath().endsWith(".json")) {
if (!new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl")).exists()) {
File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
if (!t.exists()) {
try {
System.out.print("Process " + f.getAbsolutePath());
Element e = Manager.parse(context, new FileInputStream(f), FhirFormat.JSON);
Manager.compose(context, e, new FileOutputStream(t), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
System.out.println(" .... success");
} catch (Exception e) {
System.out.println(" .... fail: " + e.getMessage());
}
}
}
}
}
}
}