From 0dcf64cb7028661f52aee6c203dc0382f3d1549f Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 17 Sep 2020 17:04:42 +1000 Subject: [PATCH] Add test cases for wildcard versions --- .../org/hl7/fhir/r5/utils/FHIRPathEngine.java | 2 +- .../hl7/fhir/utilities/VersionUtilities.java | 2 +- .../cache/FilesystemPackageCacheManager.java | 19 +++++++++++-------- .../utilities/tests/PackageCacheTests.java | 10 ++++++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index 4a71849c6..5b6c553ff 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -4588,7 +4588,7 @@ public class FHIRPathEngine { } private boolean canConvertToBoolean(Base item) { - return (item.isBooleanPrimitive); + return (item.isBooleanPrimitive()); } private List funcTrace(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index 91e8d46b2..c90530f2a 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -240,7 +240,7 @@ public class VersionUtilities { public static boolean isMajMinOrLaterPatch(String test, String current) { String t = getMajMin(test); String c = getMajMin(current); - if (c.compareTo(t) == 0) { + if (c != null && c.compareTo(t) == 0) { String pt = getPatch(test); String pc = getPatch(current); if (pt==null || "x".equals(pt)) { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java index 4415901af..4d6b9f11d 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/FilesystemPackageCacheManager.java @@ -311,14 +311,17 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple String foundPackage = null; String foundVersion = null; for (String f : sorted(new File(cacheFolder).list())) { - if (f.equals(id + "#" + version) || (Utilities.noString(version) && f.startsWith(id + "#"))) { - return loadPackageInfo(Utilities.path(cacheFolder, f)); - } - if (version!=null && version.endsWith(".x") && f.contains("#")) { - String[] parts = f.split("#"); - if (parts[0].equals(id) && VersionUtilities.isMajMinOrLaterPatch((foundVersion!=null ? foundVersion : version),parts[1])) { - foundVersion = parts[1]; - foundPackage = f; + File cf = new File(Utilities.path(cacheFolder, f)); + if (cf.isDirectory()) { + if (f.equals(id + "#" + version) || (Utilities.noString(version) && f.startsWith(id + "#"))) { + return loadPackageInfo(Utilities.path(cacheFolder, f)); + } + if (version != null && version.endsWith(".x") && f.contains("#")) { + String[] parts = f.split("#"); + if (parts[0].equals(id) && VersionUtilities.isMajMinOrLaterPatch((foundVersion!=null ? foundVersion : version),parts[1])) { + foundVersion = parts[1]; + foundPackage = f; + } } } } diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java index 4f42035eb..8e8289fbd 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/PackageCacheTests.java @@ -37,4 +37,14 @@ public class PackageCacheTests { list = cache.listPackages(); Assertions.assertFalse(list.isEmpty()); } + + @Test + public void testPatchWildCard() throws IOException { + FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION); + cache.clear(); + Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.0").version(), "3.1.0"); + Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.1").version(), "3.1.1"); + Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.x").version(), "3.1.1"); + Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.0.x").version(), "3.0.1"); + } } \ No newline at end of file