forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEEL tests refactoring + some new corner cases (#7)
* Split FEELTest into separate test classes. * Added some FEEL lists corner cases. * Fixed typo.
- Loading branch information
Showing
15 changed files
with
732 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELConditionsAndLoopsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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 | ||
* | ||
* 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 KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.runtime; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
import org.junit.runners.Parameterized; | ||
|
||
public class FEELConditionsAndLoopsTest extends BaseFEELTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {0} ({1}) = {2}") | ||
public static Collection<Object[]> data() { | ||
final Object[][] cases = new Object[][] { | ||
// if expressions | ||
{ "if true then 10+5 else 10-5", BigDecimal.valueOf( 15 ) }, | ||
{ "if false then \"foo\" else \"bar\"", "bar" }, | ||
{ "if date(\"2016-08-02\") > date(\"2015-12-25\") then \"yey\" else \"nay\"", "yey" }, | ||
{ "if null then \"foo\" else \"bar\"", null }, | ||
|
||
// for | ||
{"for x in [ 10, 20, 30 ], y in [ 1, 2, 3 ] return x * y", | ||
Arrays.asList( 10, 20, 30, 20, 40, 60, 30, 60, 90 ).stream().map( x -> BigDecimal.valueOf( x ) ).collect( Collectors.toList() ) } | ||
|
||
}; | ||
return Arrays.asList( cases ); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELContextsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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 | ||
* | ||
* 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 KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.runtime; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import org.junit.runners.Parameterized; | ||
|
||
public class FEELContextsTest extends BaseFEELTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {0} ({1}) = {2}") | ||
public static Collection<Object[]> data() { | ||
final Object[][] cases = new Object[][] { | ||
{ "{ first name : \"Bob\", birthday : date(\"1978-09-12\"), salutation : \"Hello \"+first name }", | ||
new HashMap<String,Object>() {{ | ||
put( "first name", "Bob" ); | ||
put( "birthday", LocalDate.of(1978, 9, 12) ); | ||
put( "salutation", "Hello Bob" ); | ||
}} }, | ||
// nested contexts + qualified name | ||
{ "{ full name : { first name: \"Bob\", last name : \"Doe\" }, birthday : date(\"1978-09-12\"), salutation : \"Hello \"+full name.first name }", | ||
new HashMap<String,Object>() {{ | ||
put( "full name", new HashMap<String,Object>() {{ | ||
put( "first name", "Bob" ); | ||
put( "last name", "Doe" ); | ||
}} ); | ||
put( "birthday", LocalDate.of(1978, 9, 12) ); | ||
put( "salutation", "Hello Bob" ); | ||
}} }, | ||
// Example from spec. chapter "10.3.2.7 Ranges" | ||
{ "{ startdate: date(\"1978-09-12\"), enddate: date(\"1978-10-12\"), rangedates: [startdate..enddate] }", | ||
new HashMap<String,Object>() {{ | ||
put( "startdate", LocalDate.of(1978, 9, 12) ); | ||
put( "enddate", LocalDate.of(1978, 10, 13) ); | ||
put( "rangedates", "[\"1978-09-12\"..\"1978-10-12\"]" ); | ||
}} } | ||
}; | ||
return Arrays.asList( cases ); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELDateTimeDurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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 | ||
* | ||
* 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 KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.runtime; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.time.OffsetTime; | ||
import java.time.Period; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import org.junit.runners.Parameterized; | ||
|
||
public class FEELDateTimeDurationTest extends BaseFEELTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {0} ({1}) = {2}") | ||
public static Collection<Object[]> data() { | ||
final Object[][] cases = new Object[][] { | ||
// date/time/duration function invocations | ||
{ "date(\"2016-07-29\")", DateTimeFormatter.ISO_DATE.parse( "2016-07-29", LocalDate::from ) }, | ||
{ "date(\"-0105-07-29\")", DateTimeFormatter.ISO_DATE.parse( "-0105-07-29", LocalDate::from ) }, // 105 BC | ||
{ "date(\"2016-15-29\")", null }, | ||
{ "date(\"2016-12-48\")", null }, | ||
{ "date( 10 )", null }, | ||
{ "date( 2016, 8, 2 )", LocalDate.of( 2016, 8, 2 ) }, | ||
{ "date( -0105, 8, 2 )", LocalDate.of( -105, 8, 2 ) }, | ||
{ "date( 2016, 15, 2 )", null }, | ||
{ "date( 2016, 12, 48 )", null }, | ||
{ "date( date and time(\"2016-07-29T05:48:23.765-05:00\") )", LocalDate.of( 2016, 7, 29 ) }, | ||
{ "date( date and time(\"2016-07-29T05:48:23Z\") )", LocalDate.of( 2016, 7, 29 ) }, | ||
{ "time(\"23:59:00\")", DateTimeFormatter.ISO_TIME.parse( "23:59:00", LocalTime::from ) }, | ||
{ "time(\"05:48:23.765\")", DateTimeFormatter.ISO_TIME.parse( "05:48:23.765", LocalTime::from ) }, | ||
{ "time(\"23:59:00z\")", DateTimeFormatter.ISO_TIME.parse( "23:59:00z", OffsetTime::from ) }, | ||
{ "time(\"13:20:00-05:00\")", DateTimeFormatter.ISO_TIME.parse( "13:20:00-05:00", OffsetTime::from ) }, | ||
{ "time( 14, 52, 25, null )", LocalTime.of( 14, 52, 25 ) }, | ||
{ "time( 14, 52, 25, duration(\"PT5H\"))", OffsetTime.of( 14, 52, 25, 0, ZoneOffset.ofHours( 5 ) ) }, | ||
{ "time( date and time(\"2016-07-29T05:48:23Z\") )", OffsetTime.of( 5, 48, 23, 0, ZoneOffset.UTC ) }, | ||
{ "time( date and time(\"2016-07-29T05:48:23.765-05:00\") )", OffsetTime.of( 5, 48, 23, 765000000, ZoneOffset.ofHours( -5 ) ) }, | ||
{ "date and time(\"2016-07-29T05:48:23Z\")", ZonedDateTime.of(2016, 7, 29, 5, 48, 23, 0, ZoneId.of("Z").normalized()) }, | ||
{ "date and time(\"2016-07-29T05:48:23.765-05:00\")", DateTimeFormatter.ISO_DATE_TIME.parse( "2016-07-29T05:48:23.765-05:00", ZonedDateTime::from ) }, | ||
{ "date and time(date(\"2016-07-29\"), time(\"05:48:23.765-05:00\") )", DateTimeFormatter.ISO_DATE_TIME.parse( "2016-07-29T05:48:23.765-05:00", ZonedDateTime::from ) }, | ||
{ "duration( \"P2DT20H14M\" )", Duration.parse( "P2DT20H14M" ) }, | ||
{ "duration( \"P2Y2M\" )", Period.parse( "P2Y2M" ) }, | ||
{ "duration( \"P26M\" )", Period.parse( "P26M" ) }, | ||
{ "years and months duration( date(\"2011-12-22\"), date(\"2013-08-24\") )", Period.parse( "P1Y8M" ) } | ||
}; | ||
return Arrays.asList( cases ); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELExpressionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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 | ||
* | ||
* 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 KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.runtime; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import org.junit.runners.Parameterized; | ||
|
||
public class FEELExpressionsTest extends BaseFEELTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {0} ({1}) = {2}") | ||
public static Collection<Object[]> data() { | ||
final Object[][] cases = new Object[][] { | ||
// quantified expressions | ||
{ "some price in [ 80, 11, 110 ] satisfies price > 100", Boolean.TRUE }, | ||
{ "some price in [ 80, 11, 90 ] satisfies price > 100", Boolean.FALSE }, | ||
{ "some x in [ 5, 6, 7 ], y in [ 10, 11, 6 ] satisfies x > y", Boolean.TRUE }, | ||
{ "every price in [ 80, 11, 90 ] satisfies price > 10", Boolean.TRUE }, | ||
{ "every price in [ 80, 11, 90 ] satisfies price > 70", Boolean.FALSE }, | ||
{ "some x in [ 5, 6, 7 ], y in [ 10, 11, 12 ] satisfies x < y", Boolean.TRUE }, | ||
|
||
// path expressions | ||
{"{ full name: { first name: \"John\", last name: \"Doe\" } }.full name.last name", "Doe" }, | ||
|
||
// named parameters: in this case foo is null | ||
{"{ is minor : function( foo, person's age ) foo = null and person's age < 18, bob is minor : is minor( person's age : 16 ) }.bob is minor", Boolean.TRUE }, | ||
|
||
// unary test invocation | ||
{"{ is minor : < 18, bob is minor : is minor(16) }.bob is minor", Boolean.TRUE }, | ||
}; | ||
return Arrays.asList( cases ); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/FEELFunctionDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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 | ||
* | ||
* 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 KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.dmn.feel.runtime; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import org.junit.runners.Parameterized; | ||
|
||
public class FEELFunctionDefinitionTest extends BaseFEELTest { | ||
|
||
@Parameterized.Parameters(name = "{index}: {0} ({1}) = {2}") | ||
public static Collection<Object[]> data() { | ||
final Object[][] cases = new Object[][] { | ||
// function definition and invocation | ||
{"{ hello world : function() \"Hello World!\", message : hello world() }.message", "Hello World!" }, | ||
{"{ is minor : function( person's age ) person's age < 18, bob is minor : is minor( 16 ) }.bob is minor", Boolean.TRUE }, | ||
{"{ maximum : function( v1, v2 ) external { java : { class : \"java.lang.Math\", method signature: \"max(long,long)\" } }, the max : maximum( 10, 20 ) }.the max", | ||
BigDecimal.valueOf( 20 ) } | ||
}; | ||
return Arrays.asList( cases ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.