RYA-476 Fixes tests sensitive to DST spring forward. Closes #283
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/63fad1a2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/63fad1a2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/63fad1a2 Branch: refs/heads/master Commit: 63fad1a232967dd6e02b1242b53ad686c75660fa Parents: 4a1057d Author: David W. Lotts <[email protected]> Authored: Wed Mar 14 11:48:14 2018 -0400 Committer: David W. Lotts <[email protected]> Committed: Mon Mar 19 14:51:39 2018 -0400 ---------------------------------------------------------------------- .../rya/api/functions/DateTimeWithinPeriodTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/63fad1a2/common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java b/common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java index 0fb0f2a..ac27d1b 100644 --- a/common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java +++ b/common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java @@ -38,12 +38,13 @@ public class DateTimeWithinPeriodTest { private static final ValueFactory vf = new ValueFactoryImpl(); private static final Literal TRUE = vf.createLiteral(true); private static final Literal FALSE = vf.createLiteral(false); + private static final ZonedDateTime testThisTimeDate = ZonedDateTime.parse("2018-02-03T14:15:16+07:00"); @Test public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime zTime = ZonedDateTime.now(); + ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusSeconds(1); @@ -64,7 +65,7 @@ public class DateTimeWithinPeriodTest { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime zTime = ZonedDateTime.now(); + ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusMinutes(1); @@ -85,7 +86,7 @@ public class DateTimeWithinPeriodTest { public void testHours() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime zTime = ZonedDateTime.now(); + ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusHours(1); @@ -106,7 +107,7 @@ public class DateTimeWithinPeriodTest { public void testDays() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime zTime = ZonedDateTime.now(); + ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusDays(1); @@ -122,11 +123,12 @@ public class DateTimeWithinPeriodTest { assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne, vf.createLiteral(2), OWLTime.DAYS_URI)); } + // Note that this test fails if the week under test spans a DST when the USA springs forward. @Test public void testWeeks() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime zTime = ZonedDateTime.now(); + ZonedDateTime zTime = testThisTimeDate; String time = zTime.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = zTime.minusWeeks(1); @@ -151,7 +153,7 @@ public class DateTimeWithinPeriodTest { public void testTimeZone() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); - ZonedDateTime now = ZonedDateTime.now(); + ZonedDateTime now = testThisTimeDate; String time = now.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = now.withZoneSameInstant(ZoneId.of("Europe/London")); @@ -176,5 +178,4 @@ public class DateTimeWithinPeriodTest { assertEquals(TRUE, func.evaluate(vf, nowLocal, nowAsiaTZMinusOne, vf.createLiteral(2), OWLTime.DAYS_URI)); } - }
