From e03fe1644f0318790c006fdd4b99e12d0406857e Mon Sep 17 00:00:00 2001 From: Luke deGruchy Date: Wed, 25 Oct 2023 13:47:42 -0400 Subject: [PATCH] Add parameterized tests for CqlTypesOperatorsTest, which fails on the Newfoundland workstation due a flaw in the bugfix. --- .../cqf/cql/engine/runtime/DateTime.java | 1 + .../cqf/cql/engine/execution/CqlTestBase.java | 16 + .../engine/execution/CqlTimezoneTests.java | 66 +--- .../execution/CqlTypesOperatorsTest.java | 372 +++++++++--------- 4 files changed, 211 insertions(+), 244 deletions(-) diff --git a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/runtime/DateTime.java b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/runtime/DateTime.java index b07b26f64..06c607634 100644 --- a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/runtime/DateTime.java +++ b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/runtime/DateTime.java @@ -131,6 +131,7 @@ else if (i == 6) { final int totalMinutesModulo60 = totalMinutes % 60; final int minutes = totalMinutesModulo60 == 0 +// final int minutes = totalMinutesModulo60 != 500000 ? new BigDecimal("60").multiply(offset.remainder(BigDecimal.ONE)) .intValue() : Math.abs(totalMinutesModulo60); // This is for a half hour or 45 minute timezone, such as Newfoundland, Canada dateString.append(ZoneOffset.ofHoursMinutes(offset.intValue(), diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTestBase.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTestBase.java index f16e105f2..c697ca570 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTestBase.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTestBase.java @@ -5,8 +5,24 @@ import org.cqframework.cql.cql2elm.*; import org.hl7.elm.r1.Library; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; public class CqlTestBase { + static final String NORTH_AMERICA_MOUNTAIN = "America/Denver"; // This is the baseline: Normal hour on the hour timezone + static final String NEWFOUNDLAND = "America/St_Johns"; + static final String INDIA = "Asia/Kolkata"; + static final String AUSTRALIA_NORTHERN_TERRITORY = "Australia/Darwin"; + static final String AUSTRALIA_EUCLA= "Australia/Eucla"; + static final String AUSTRALIA_BROKEN_HILL = "Australia/Broken_Hill"; + static final String AUSTRALIA_LORD_HOWE = "Australia/Lord_Howe"; + static final String AUSTRALIA_SOUTH = "Australia/Adelaide"; + static final String INDIAN_COCOS = "Indian/Cocos"; + static final String PACIFIC_CHATHAM = "Pacific/Chatham"; + + @DataProvider + static Object[][] timezones() { + return new Object[][] {{NORTH_AMERICA_MOUNTAIN},{NEWFOUNDLAND},{INDIA},{AUSTRALIA_NORTHERN_TERRITORY},{AUSTRALIA_EUCLA},{AUSTRALIA_BROKEN_HILL},{AUSTRALIA_LORD_HOWE},{AUSTRALIA_SOUTH},{INDIAN_COCOS},{PACIFIC_CHATHAM}}; + } private static ModelManager modelManager; protected static ModelManager getModelManager() { diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTimezoneTests.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTimezoneTests.java index 66cd418e7..87bc1e343 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTimezoneTests.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTimezoneTests.java @@ -1,8 +1,5 @@ package org.opencds.cqf.cql.engine.execution; -import org.cqframework.cql.cql2elm.CqlCompilerOptions; -import org.cqframework.cql.cql2elm.LibraryManager; -import org.cqframework.cql.cql2elm.ModelManager; import org.hl7.elm.r1.VersionedIdentifier; import org.testng.annotations.*; import org.testng.asserts.SoftAssert; @@ -10,28 +7,10 @@ import java.util.TimeZone; @SuppressWarnings("removal") -public class CqlTimezoneTests { - private static final String NORTH_AMERICA_MOUNTAIN = "America/Denver"; // This is the baseline: Normal hour on the hour timezone - private static final String NEWFOUNDLAND = "America/St_Johns"; - private static final String INDIA = "Asia/Kolkata"; - private static final String AUSTRALIA_NORTHERN_TERRITORY = "Australia/Darwin"; - private static final String AUSTRALIA_EUCLA= "Australia/Eucla"; - private static final String AUSTRALIA_BROKEN_HILL = "Australia/Broken_Hill"; - private static final String AUSTRALIA_LORD_HOWE = "Australia/Lord_Howe"; - private static final String AUSTRALIA_SOUTH = "Australia/Adelaide"; - - private static final String INDIAN_COCOS = "Indian/Cocos"; - private static final String PACIFIC_CHATHAM = "Pacific/Chatham"; - - private static ModelManager modelManager; +public class CqlTimezoneTests extends CqlTestBase { private static final VersionedIdentifier library = new VersionedIdentifier().withId("CqlTimezoneTests"); - @DataProvider - private static Object[][] timezones() { - return new Object[][] {{NORTH_AMERICA_MOUNTAIN},{NEWFOUNDLAND},{INDIA},{AUSTRALIA_NORTHERN_TERRITORY},{AUSTRALIA_EUCLA},{AUSTRALIA_BROKEN_HILL},{AUSTRALIA_LORD_HOWE},{AUSTRALIA_SOUTH},{INDIAN_COCOS},{PACIFIC_CHATHAM}}; - } - @Test(dataProvider = "timezones") public void testExpressionsProblematicForWeirdTimezones(String timezone) { final String oldTz = System.getProperty("user.timezone"); @@ -39,52 +18,21 @@ public void testExpressionsProblematicForWeirdTimezones(String timezone) { TimeZone.setDefault(TimeZone.getTimeZone(timezone)); try { - final Environment localEnvironment = new Environment(getLibraryManager()); - final CqlEngine localEngine = new CqlEngine(localEnvironment); final SoftAssert softAssert = new SoftAssert(); - evaluateExpression(localEngine, "After_SameHour", false, softAssert); - evaluateExpression(localEngine, "SameAs_SameHour", true, softAssert); - evaluateExpression(localEngine, "SameOrAfter_HourBefore", false, softAssert); - evaluateExpression(localEngine, "SameOrBefore_SameHour", true, softAssert); + evaluateExpression("After_SameHour", false, softAssert); + evaluateExpression("SameAs_SameHour", true, softAssert); + evaluateExpression("SameOrAfter_HourBefore", false, softAssert); + evaluateExpression("SameOrBefore_SameHour", true, softAssert); softAssert.assertAll(); } finally { TimeZone.setDefault(TimeZone.getTimeZone(oldTz)); } } - protected static LibraryManager getLibraryManager() { - return getLibraryManager(createOptionsMin()); - } - - protected static LibraryManager getLibraryManager(CqlCompilerOptions compilerOptions) { - var manager = new LibraryManager(getModelManager(), compilerOptions); - manager.getLibrarySourceLoader().registerProvider(new TestLibrarySourceProvider()); - - return manager; - } - protected static ModelManager getModelManager() { - if (modelManager == null) { - modelManager = new ModelManager(); - } - - return modelManager; - } - - private static CqlCompilerOptions createOptionsMin() { - CqlCompilerOptions result = new CqlCompilerOptions(); - result.setOptions(CqlCompilerOptions.Options.EnableDateRangeOptimization, - CqlCompilerOptions.Options.EnableLocators, - CqlCompilerOptions.Options.EnableResultTypes, - CqlCompilerOptions.Options.DisableListDemotion, - CqlCompilerOptions.Options.DisableListPromotion, - CqlCompilerOptions.Options.DisableMethodInvocation); - - return result; - } - private static void evaluateExpression(CqlEngine localEngine, String DateTimeSameOrBeforeTodayTrue1, boolean expectedResult, SoftAssert softAssert) { - Object result = localEngine.expression(library, DateTimeSameOrBeforeTodayTrue1).value(); + private void evaluateExpression(String DateTimeSameOrBeforeTodayTrue1, boolean expectedResult, SoftAssert softAssert) { + Object result = engine.expression(library, DateTimeSameOrBeforeTodayTrue1).value(); softAssert.assertEquals(result, expectedResult); } } diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTypesOperatorsTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTypesOperatorsTest.java index 27faf2a6b..5f4af2a66 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTypesOperatorsTest.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTypesOperatorsTest.java @@ -13,277 +13,279 @@ import static org.hamcrest.Matchers.is; public class CqlTypesOperatorsTest extends CqlTestBase { + @Test(dataProvider = "timezones") + public void test_all_types_operators(String timezone) { + final String oldTz = System.getProperty("user.timezone"); + // This is the ONLY thing that will work. System.setProperty() and -Duser.timezone do NOT work + TimeZone.setDefault(TimeZone.getTimeZone(timezone)); - @Test - public void test_all_types_operators() { + try { + EvaluationResult evaluationResult; - Set set = new HashSet<>(); - EvaluationResult evaluationResult; + evaluationResult = engine.evaluate(toElmIdentifier("CqlTypeOperatorsTest")); + Object result; - evaluationResult = engine.evaluate(toElmIdentifier("CqlTypeOperatorsTest")); - Object result; + result = evaluationResult.forExpression("AsQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("45.5")).withUnit("g"))); - result = evaluationResult.forExpression("AsQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("45.5")).withUnit("g"))); + result = evaluationResult.forExpression("CastAsQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("45.5")).withUnit("g"))); - result = evaluationResult.forExpression("CastAsQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("45.5")).withUnit("g"))); + result = evaluationResult.forExpression("AsDateTime").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); - result = evaluationResult.forExpression("AsDateTime").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); + result = evaluationResult.forExpression("IntegerToDecimal").value(); + assertThat(result, is(new BigDecimal(5))); - result = evaluationResult.forExpression("IntegerToDecimal").value(); - assertThat(result, is(new BigDecimal(5))); + result = evaluationResult.forExpression("IntegerToString").value(); + assertThat(result, is("5")); - result = evaluationResult.forExpression("IntegerToString").value(); - assertThat(result, is("5")); + result = evaluationResult.forExpression("StringToDateTime").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); - result = evaluationResult.forExpression("StringToDateTime").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); + result = evaluationResult.forExpression("StringToTime").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Time(14, 30, 0, 0))); - result = evaluationResult.forExpression("StringToTime").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Time(14, 30, 0, 0))); + result = evaluationResult.forExpression("ConvertQuantity").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Quantity().withValue(new BigDecimal("0.005")).withUnit("g"))); - result = evaluationResult.forExpression("ConvertQuantity").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Quantity().withValue(new BigDecimal("0.005")).withUnit("g"))); + result = evaluationResult.forExpression("ConvertSyntax").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Quantity().withValue(new BigDecimal("0.005")).withUnit("g"))); - result = evaluationResult.forExpression("ConvertSyntax").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Quantity().withValue(new BigDecimal("0.005")).withUnit("g"))); + result = evaluationResult.forExpression("ConvertsToBooleanTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToBooleanTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToBooleanFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToBooleanFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToBooleanNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToBooleanNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToDateTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDateTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDateFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDateFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDateNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToDateNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToDateTimeStringTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDateTimeStringTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDateTimeDateTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDateTimeDateTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDateTimeFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDateTimeFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDateTimeNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToDateTimeNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToDecimalTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDecimalTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDecimalFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToDecimalFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToDecimalNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToDecimalNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToIntegerTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToIntegerTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToIntegerLong").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToIntegerLong").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToIntegerFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToIntegerFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToIntegerNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToIntegerNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToLongTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToLongTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToLongFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToLongFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToLongNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToLongNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToQuantityStringTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToQuantityStringTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToQuantityStringFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToQuantityStringFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToQuantityIntegerTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToQuantityIntegerTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToQuantityDecimalTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToQuantityDecimalTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToQuantityRatioTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToQuantityRatioTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToQuantityNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToQuantityNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToStringBoolean").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringBoolean").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringInteger").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringInteger").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringLong").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringLong").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringDecimal").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringDecimal").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringQuantity").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringQuantity").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringRatio").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringRatio").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringDate").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringDate").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringDateTime").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringDateTime").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringTime").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToStringTime").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToStringNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToStringNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("ConvertsToTimeTrue").value(); + Assert.assertTrue((Boolean) result); - result = evaluationResult.forExpression("ConvertsToTimeTrue").value(); - Assert.assertTrue((Boolean) result); + result = evaluationResult.forExpression("ConvertsToTimeFalse").value(); + Assert.assertFalse((Boolean) result); - result = evaluationResult.forExpression("ConvertsToTimeFalse").value(); - Assert.assertFalse((Boolean) result); + result = evaluationResult.forExpression("ConvertsToTimeNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ConvertsToTimeNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("IntegerIsInteger").value(); + assertThat(result, is(true)); - result = evaluationResult.forExpression("IntegerIsInteger").value(); - assertThat(result, is(true)); + result = evaluationResult.forExpression("StringIsInteger").value(); + assertThat(result, is(false)); - result = evaluationResult.forExpression("StringIsInteger").value(); - assertThat(result, is(false)); + result = evaluationResult.forExpression("StringNoToBoolean").value(); + assertThat(result, is(false)); - result = evaluationResult.forExpression("StringNoToBoolean").value(); - assertThat(result, is(false)); + result = evaluationResult.forExpression("CodeToConcept1").value(); + Assert.assertTrue(((Concept) result).equivalent(new Concept().withCode(new Code().withCode("8480-6")))); - result = evaluationResult.forExpression("CodeToConcept1").value(); - Assert.assertTrue(((Concept) result).equivalent(new Concept().withCode(new Code().withCode("8480-6")))); + result = evaluationResult.forExpression("ToDateTime0").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1))); - result = evaluationResult.forExpression("ToDateTime0").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1))); + result = evaluationResult.forExpression("ToDateTime1").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); - result = evaluationResult.forExpression("ToDateTime1").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); + result = evaluationResult.forExpression("ToDateTime2").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1, 12, 5))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); - result = evaluationResult.forExpression("ToDateTime2").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1, 12, 5))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); + result = evaluationResult.forExpression("ToDateTime3").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1, 12, 5, 5, 955))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); - result = evaluationResult.forExpression("ToDateTime3").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(null, 2014, 1, 1, 12, 5, 5, 955))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); + result = evaluationResult.forExpression("ToDateTime4").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal("1.5"), 2014, 1, 1, 12, 5, 5, 955))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("1.5"))); - result = evaluationResult.forExpression("ToDateTime4").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal("1.5"), 2014, 1, 1, 12, 5, 5, 955))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("1.5"))); + result = evaluationResult.forExpression("ToDateTime5").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal("-1.25"), 2014, 1, 1, 12, 5, 5, 955))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-1.25"))); - result = evaluationResult.forExpression("ToDateTime5").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal("-1.25"), 2014, 1, 1, 12, 5, 5, 955))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-1.25"))); + result = evaluationResult.forExpression("ToDateTime6").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal(0), 2014, 1, 1, 12, 5, 5, 955))); + // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); - result = evaluationResult.forExpression("ToDateTime6").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new DateTime(new BigDecimal(0), 2014, 1, 1, 12, 5, 5, 955))); - // assertThat(((DateTime)result).getTimezoneOffset(), is(new BigDecimal("-7"))); + result = evaluationResult.forExpression("ToDateTimeMalformed").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ToDateTimeMalformed").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("String25D5ToDecimal").value(); + assertThat(result, is(new BigDecimal("25.5"))); - result = evaluationResult.forExpression("String25D5ToDecimal").value(); - assertThat(result, is(new BigDecimal("25.5"))); + result = evaluationResult.forExpression("StringNeg25ToInteger").value(); + assertThat(result, is(-25)); - result = evaluationResult.forExpression("StringNeg25ToInteger").value(); - assertThat(result, is(-25)); + result = evaluationResult.forExpression("String123ToLong").value(); + assertThat(result, is(123L)); - result = evaluationResult.forExpression("String123ToLong").value(); - assertThat(result, is(123L)); + result = evaluationResult.forExpression("String5D5CMToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("5.5")).withUnit("cm"))); - result = evaluationResult.forExpression("String5D5CMToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("5.5")).withUnit("cm"))); + result = evaluationResult.forExpression("StringInvalidToQuantityNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("StringInvalidToQuantityNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("String100PerMinPerSqMeterToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("100")).withUnit("daL/min/m2"))); - result = evaluationResult.forExpression("String100PerMinPerSqMeterToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("100")).withUnit("daL/min/m2"))); + result = evaluationResult.forExpression("String100UnitPer10BillionToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("100")).withUnit("U/10*10{cells}"))); - result = evaluationResult.forExpression("String100UnitPer10BillionToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("100")).withUnit("U/10*10{cells}"))); + result = evaluationResult.forExpression("String60DayPer7DayToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("d/(7.d)"))); - result = evaluationResult.forExpression("String60DayPer7DayToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("d/(7.d)"))); + result = evaluationResult.forExpression("String60EhrlichPer100gmToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("{EhrlichU}/100.g"))); - result = evaluationResult.forExpression("String60EhrlichPer100gmToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("{EhrlichU}/100.g"))); + result = evaluationResult.forExpression("StringPercentToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("%"))); - result = evaluationResult.forExpression("StringPercentToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("60")).withUnit("%"))); + result = evaluationResult.forExpression("StringPercentWithoutQuoteToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("70")).withUnit("%"))); - result = evaluationResult.forExpression("StringPercentWithoutQuoteToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("70")).withUnit("%"))); + result = evaluationResult.forExpression("StringPercentWithTabToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("80")).withUnit("%"))); - result = evaluationResult.forExpression("StringPercentWithTabToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("80")).withUnit("%"))); + result = evaluationResult.forExpression("StringPercentWithMultiSpacesToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("90")).withUnit("%"))); - result = evaluationResult.forExpression("StringPercentWithMultiSpacesToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("90")).withUnit("%"))); + result = evaluationResult.forExpression("StringPercentWithSpacesUnitToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("10")).withUnit("ml"))); - result = evaluationResult.forExpression("StringPercentWithSpacesUnitToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("10")).withUnit("ml"))); + result = evaluationResult.forExpression("StringPercentWithQuoteUnitToQuantity").value(); + Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("20")).withUnit("ml"))); - result = evaluationResult.forExpression("StringPercentWithQuoteUnitToQuantity").value(); - Assert.assertTrue(((Quantity) result).equal(new Quantity().withValue(new BigDecimal("20")).withUnit("ml"))); + result = evaluationResult.forExpression("ToRatioIsValid").value(); + Assert.assertTrue(((Ratio) result).getNumerator().equal(new Quantity().withValue(new BigDecimal("1.0")).withUnit("mg"))); + Assert.assertTrue(((Ratio) result).getDenominator().equal(new Quantity().withValue(new BigDecimal("2.0")).withUnit("mg"))); - result = evaluationResult.forExpression("ToRatioIsValid").value(); - Assert.assertTrue(((Ratio) result).getNumerator().equal(new Quantity().withValue(new BigDecimal("1.0")).withUnit("mg"))); - Assert.assertTrue(((Ratio) result).getDenominator().equal(new Quantity().withValue(new BigDecimal("2.0")).withUnit("mg"))); + result = evaluationResult.forExpression("ToRatioIsNull").value(); + Assert.assertNull(result); - result = evaluationResult.forExpression("ToRatioIsNull").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("IntegerNeg5ToString").value(); + assertThat(result, is("-5")); - result = evaluationResult.forExpression("IntegerNeg5ToString").value(); - assertThat(result, is("-5")); + result = evaluationResult.forExpression("LongNeg5ToString").value(); + assertThat(result, is("-5")); - result = evaluationResult.forExpression("LongNeg5ToString").value(); - assertThat(result, is("-5")); + result = evaluationResult.forExpression("Decimal18D55ToString").value(); + assertThat(result, is("18.55")); - result = evaluationResult.forExpression("Decimal18D55ToString").value(); - assertThat(result, is("18.55")); - - result = evaluationResult.forExpression("Quantity5D5CMToString").value(); - assertThat(result, is("5.5 'cm'")); - - result = evaluationResult.forExpression("BooleanTrueToString").value(); - assertThat(result, is("true")); - - result = evaluationResult.forExpression("ToTime1").value(); - Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Time(14, 30, 0, 0))); - - result = evaluationResult.forExpression("ToTimeMalformed").value(); - Assert.assertNull(result); + result = evaluationResult.forExpression("Quantity5D5CMToString").value(); + assertThat(result, is("5.5 'cm'")); + result = evaluationResult.forExpression("BooleanTrueToString").value(); + assertThat(result, is("true")); + result = evaluationResult.forExpression("ToTime1").value(); + Assert.assertTrue(EquivalentEvaluator.equivalent(result, new Time(14, 30, 0, 0))); + result = evaluationResult.forExpression("ToTimeMalformed").value(); + Assert.assertNull(result); + } finally { + TimeZone.setDefault(TimeZone.getTimeZone(oldTz)); + } } }