Skip to content

Commit

Permalink
[incubator-kie-issues#1344] Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele-Cardosi committed Jun 28, 2024
1 parent 4029d40 commit 761c47e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,7 @@ public BlockStmt add(TemporalConstantNode n) {
Class fnClass = fn.getClass();
ClassOrInterfaceType fn_CT = parseClassOrInterfaceType(fnClass.getCanonicalName());
Expression fn_N = new NameExpr(fnClass.getCanonicalName());
if (fnClass.getPackageName().equals(EXTENDED_FUNCTION_PACKAGE)) {
addVariableDeclaratorWithWithFieldAccess(fn_CT, INSTANCE_S, fn_N);
} else {
addVariableDeclaratorWithObjectCreation(fn_CT,
NodeList.nodeList());
}
addVariableDeclaratorWithWithFieldAccess(fn_CT, INSTANCE_S, fn_N);
fnVariableNameExpression = new NameExpr(lastVariableName.get());
} else {
fnVariableNameExpression = new NullLiteralExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -27,18 +27,12 @@
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;

class DateTimeFunctionTest {

private DateAndTimeFunction dateTimeFunction;

@BeforeEach
void setUp() {
dateTimeFunction = new DateAndTimeFunction();
}
private static final DateAndTimeFunction dateTimeFunction = DateAndTimeFunction.INSTANCE;

@Test
void invokeParamStringNull() {
Expand All @@ -54,22 +48,33 @@ void invokeParamStringNotDateOrTime() {

@Test
void invokeParamStringDateTime() {
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07T10:20:30"), LocalDateTime.of(2017, 9, 7, 10, 20, 30));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("99999-12-31T11:22:33"), LocalDateTime.of(99999, 12, 31, 11, 22, 33));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-09-07T10:20:30"), LocalDateTime.of(2017, 9, 7, 10
, 20, 30));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("99999-12-31T11:22:33"), LocalDateTime.of(99999, 12, 31
, 11, 22, 33));
}

@Test
void invokeParamStringDateTimeZoned() {
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 0, ZoneId.of("Europe/Paris")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.987@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 987_000_000, ZoneId.of("Europe/Paris")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.123456789@Europe/Paris"), ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 123_456_789, ZoneId.of("Europe/Paris")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("999999999-12-31T23:59:59.999999999@Europe/Paris"), ZonedDateTime.of(999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneId.of("Europe/Paris")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30@Europe/Paris"),
ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 0, ZoneId.of("Europe/Paris")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.987@Europe/Paris"),
ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 987_000_000, ZoneId.of("Europe/Paris"
)));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2011-12-31T10:15:30.123456789@Europe/Paris"),
ZonedDateTime.of(2011, 12, 31, 10, 15, 30, 123_456_789, ZoneId.of("Europe/Paris"
)));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("999999999-12-31T23:59:59.999999999@Europe/Paris"),
ZonedDateTime.of(999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneId.of("Europe/Paris")));
}

@Test
void invokeParamStringDateOffset() {
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-12-31T23:59:59.999999999+02:00"), ZonedDateTime.of(2017, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("-999999999-12-31T23:59:59.999999999+02:00"), ZonedDateTime.of(-999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("2017-12-31T23:59:59.999999999+02:00"),
ZonedDateTime.of(2017, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of("+02:00")));
FunctionTestUtil.assertResult(dateTimeFunction.invoke("-999999999-12-31T23:59:59.999999999+02:00"),
ZonedDateTime.of(-999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.of(
"+02:00")));
}

@Test
Expand All @@ -79,14 +84,19 @@ void invokeParamStringDate() {

@Test
void invokeParamTemporalNulls() {
FunctionTestUtil.assertResultError(dateTimeFunction.invoke((Temporal) null, null), InvalidParametersEvent.class);
FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null, LocalTime.of(10, 6, 20)), InvalidParametersEvent.class);
FunctionTestUtil.assertResultError(dateTimeFunction.invoke(LocalDate.of(2017, 6, 12), null), InvalidParametersEvent.class);
FunctionTestUtil.assertResultError(dateTimeFunction.invoke((Temporal) null, null),
InvalidParametersEvent.class);
FunctionTestUtil.assertResultError(dateTimeFunction.invoke(null, LocalTime.of(10, 6, 20)),
InvalidParametersEvent.class);
FunctionTestUtil.assertResultError(dateTimeFunction.invoke(LocalDate.of(2017, 6, 12), null),
InvalidParametersEvent.class);
}

@Test
void invokeParamTemporalWrongTemporal() {
// reminder: 1st parameter accordingly to FEEL Spec Table 58 "date is a date or date time [...] creates a date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date` parameter, too]
// reminder: 1st parameter accordingly to FEEL Spec Table 58 "date is a date or date time [...] creates a
// date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date`
// parameter, too]
FunctionTestUtil.assertResultError(
dateTimeFunction.invoke(
LocalDate.of(2017, 6, 12),
Expand Down

0 comments on commit 761c47e

Please sign in to comment.