Skip to content

Commit 7e6616c

Browse files
authored
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 <[email protected]>
1 parent 6b5f17b commit 7e6616c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

fhir-search/src/test/java/com/ibm/fhir/search/date/DateTimeHandlerTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@ public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSec
697697
assertEquals(upperBound.toString(), "2019-10-11T11:00:00.123456Z");
698698
}
699699

700+
@Test
701+
public void testGenerateLowerUpperBoundWithNullPrefixYearMonthDayHoursMinutesSecondsZeroNanos()
702+
throws FHIRSearchException {
703+
String v = "2019-10-11T11:00:00.000000000";
704+
TemporalAccessor value = DateTimeHandler.parse(v);
705+
Instant lowerBound = DateTimeHandler.generateLowerBound(null, value, v);
706+
Instant upperBound = DateTimeHandler.generateUpperBound(null, value, v);
707+
assertEquals(lowerBound.toString(), "2019-10-11T11:00:00Z");
708+
assertEquals(upperBound.toString(), "2019-10-11T11:00:00Z");
709+
}
710+
700711
@Test
701712
public void testGenerateLowerUpperBoundWithNonNullPrefix() throws FHIRSearchException {
702713
String v = "2019";

fhir-search/src/test/java/com/ibm/fhir/search/test/ChainParameterParseTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.math.BigDecimal;
1616
import java.time.Instant;
17+
import java.time.temporal.ChronoField;
1718
import java.time.temporal.ChronoUnit;
1819
import java.util.ArrayList;
1920
import java.util.Collections;
@@ -308,6 +309,13 @@ public void testValidChainWithDateSearchParameter() throws Exception {
308309
FHIRSearchContext searchContext;
309310
Class<ClinicalImpression> resourceType = ClinicalImpression.class;
310311
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
312+
// If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query,
313+
// which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond.
314+
// For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes
315+
// milliseconds in the search query.
316+
if (now.get(ChronoField.MILLI_OF_SECOND) == 0) {
317+
now = now.plusMillis(1);
318+
}
311319
String queryString = "&investigation:RiskAssessment.date=" + now.toString();
312320

313321
queryParameters.put("investigation:RiskAssessment.date", Collections.singletonList(now.toString()));

fhir-search/src/test/java/com/ibm/fhir/search/test/RevChainParameterParseTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.math.BigDecimal;
1616
import java.time.Instant;
17+
import java.time.temporal.ChronoField;
1718
import java.time.temporal.ChronoUnit;
1819
import java.util.ArrayList;
1920
import java.util.Collections;
@@ -587,6 +588,13 @@ public void testValidReverseChainWithDateSearchParameter() throws Exception {
587588
FHIRSearchContext searchContext;
588589
Class<Patient> resourceType = Patient.class;
589590
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
591+
// If the Instant has a millseconds value of exactly 0, then the toString() will not include milliseconds in the search query,
592+
// which will cause the lower/upper bound to include all milliseconds within the second, instead of just the exact millisecond.
593+
// For the purpose of this testcase, just ensure that there is a non-0 value for milliseconds, so the toString() includes
594+
// milliseconds in the search query.
595+
if (now.get(ChronoField.MILLI_OF_SECOND) == 0) {
596+
now = now.plusMillis(1);
597+
}
590598
String queryString = "&_has:RiskAssessment:subject:date=" + now.toString();
591599

592600
queryParameters.put("_has:RiskAssessment:subject:date", Collections.singletonList(now.toString()));

0 commit comments

Comments
 (0)