From 7e6616c60b62cac38bf1ca3c49200b4a5301bcf3 Mon Sep 17 00:00:00 2001 From: Troy Biesterfeld <60481063+tbieste@users.noreply.github.com> Date: Wed, 17 Nov 2021 10:15:42 -0600 Subject: [PATCH] Issue #2981 - Update testcases to handle date with 0 milliseconds field (#2996) * Issue #2981 - Update testcases to handle date with 0 milliseconds field Signed-off-by: Troy Biesterfeld --- .../com/ibm/fhir/search/date/DateTimeHandlerTest.java | 11 +++++++++++ .../ibm/fhir/search/test/ChainParameterParseTest.java | 8 ++++++++ .../fhir/search/test/RevChainParameterParseTest.java | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/fhir-search/src/test/java/com/ibm/fhir/search/date/DateTimeHandlerTest.java b/fhir-search/src/test/java/com/ibm/fhir/search/date/DateTimeHandlerTest.java index aa76db27b9b..83d1a424b6b 100644 --- a/fhir-search/src/test/java/com/ibm/fhir/search/date/DateTimeHandlerTest.java +++ b/fhir-search/src/test/java/com/ibm/fhir/search/date/DateTimeHandlerTest.java @@ -697,6 +697,17 @@ public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSec assertEquals(upperBound.toString(), "2019-10-11T11:00:00.123456Z"); } + @Test + public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSecondsZeroNanos() + throws FHIRSearchException { + String v = "2019-10-11T11:00:00.000000000"; + TemporalAccessor value = DateTimeHandler.parse(v); + Instant lowerBound = DateTimeHandler.generateLowerBound(null, value, v); + Instant upperBound = DateTimeHandler.generateUpperBound(null, value, v); + assertEquals(lowerBound.toString(), "2019-10-11T11:00:00Z"); + assertEquals(upperBound.toString(), "2019-10-11T11:00:00Z"); + } + @Test public void testGenerateLowerUpperBoundWithNonNullPrefix() throws FHIRSearchException { String v = "2019"; diff --git a/fhir-search/src/test/java/com/ibm/fhir/search/test/ChainParameterParseTest.java b/fhir-search/src/test/java/com/ibm/fhir/search/test/ChainParameterParseTest.java index 7085d2afd64..dc16083c507 100644 --- a/fhir-search/src/test/java/com/ibm/fhir/search/test/ChainParameterParseTest.java +++ b/fhir-search/src/test/java/com/ibm/fhir/search/test/ChainParameterParseTest.java @@ -14,6 +14,7 @@ import java.math.BigDecimal; import java.time.Instant; +import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; @@ -308,6 +309,13 @@ public void testValidChainWithDateSearchParameter() throws Exception { FHIRSearchContext searchContext; Class resourceType = ClinicalImpression.class; Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); + // If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query, + // which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond. + // For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes + // milliseconds in the search query. + if (now.get(ChronoField.MILLI_OF_SECOND) == 0) { + now = now.plusMillis(1); + } String queryString = "&investigation:RiskAssessment.date=" + now.toString(); queryParameters.put("investigation:RiskAssessment.date", Collections.singletonList(now.toString())); diff --git a/fhir-search/src/test/java/com/ibm/fhir/search/test/RevChainParameterParseTest.java b/fhir-search/src/test/java/com/ibm/fhir/search/test/RevChainParameterParseTest.java index 27619889c7a..77227bb192f 100644 --- a/fhir-search/src/test/java/com/ibm/fhir/search/test/RevChainParameterParseTest.java +++ b/fhir-search/src/test/java/com/ibm/fhir/search/test/RevChainParameterParseTest.java @@ -14,6 +14,7 @@ import java.math.BigDecimal; import java.time.Instant; +import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; @@ -587,6 +588,13 @@ public void testValidReverseChainWithDateSearchParameter() throws Exception { FHIRSearchContext searchContext; Class resourceType = Patient.class; Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); + // If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query, + // which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond. + // For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes + // milliseconds in the search query. + if (now.get(ChronoField.MILLI_OF_SECOND) == 0) { + now = now.plusMillis(1); + } String queryString = "&_has:RiskAssessment:subject:date=" + now.toString(); queryParameters.put("_has:RiskAssessment:subject:date", Collections.singletonList(now.toString()));