You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "yesamer (via GitHub)" <gi...@apache.org> on 2024/09/16 09:35:51 UTC
[PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
yesamer opened a new pull request, #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
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
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.
-->
**Thank you for submitting this pull request**
**NOTE!:** Double-check the target branch for this PR.
The default is `main` so it will target Drools 8 / Kogito.
**Ports** If a forward-port or a backport is needed, paste the forward port PR here
* [link](https://www.example.com)
**Issue**: _(please edit the GitHub Issues link if it exists)_
* [link](https://www.example.com)
**referenced Pull Requests**: _(please edit the URLs of referenced pullrequests if they exist)_
* paste the link(s) from GitHub here
* link 2
* link 3 etc.
<details>
<summary>
How to replicate CI configuration locally?
</summary>
Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use [build-chain tool](https://github.com/kiegroup/github-action-build-chain) to handle cross repository builds and be sure that we always use latest version of the code for each repository.
[build-chain tool](https://github.com/kiegroup/github-action-build-chain) is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See [local execution](https://github.com/kiegroup/github-action-build-chain#local-execution) details to get more information about it.
</details>
<details>
<summary>
How to retest this PR or trigger a specific build:
</summary>
- for <b>pull request and downstream checks</b>
- Push a new commit to the PR. An empty commit would be enough.
- for a <b>full downstream build</b>
- for <b>github actions</b> job: add the label `run_fdb`
- for <b>Jenkins PR check only</b>
- If you are an ASF committer for KIE podling, login to Jenkins (https://ci-builds.apache.org/job/KIE/job/drools/), go to the specific PR job, and click on `Build Now` button.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio merged PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "pibizza (via GitHub)" <gi...@apache.org>.
pibizza commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762769446
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
Review Comment:
@yesamer Yes, that makes sense. Feel free to keep the code as it is in that case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762801851
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern), expectedResult);
}
- @Test
- void invokeWithFlagDotAll() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar", "s"), true);
+ private static Object[][] invokeWithoutFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", true },
+ { "foobar", "^fo*b", true },
+ { "abracadabra", "bra", true },
+ { "abracadabra", "bra", true },
+ { "(?xi)[hello world()]", "hello", true }
+ };
}
- @Test
- void invokeWithFlagMultiline() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "^bar", "m"), true);
+ @ParameterizedTest
+ @MethodSource("invokeNullOrEmptyFlagsMatchTestData")
+ void invokeNullOrEmptyFlagsMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern, flags), expectedResult);
}
- @Test
- void invokeWithFlagCaseInsensitive() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "k","i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "K","i"), true);
+ private static Object[][] invokeNullOrEmptyFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", null, true },
+ { "foobar", "^fo*b", null, true },
+ { "abracadabra", "bra", null, true },
+ { "abracadabra", "bra", "", true },
+ { "(?xi)[hello world()]", "hello", null, true }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeInvalidRegexTestData")
+ void invokeInvalidRegexTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Done
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement), expectedErrorEventClass);
}
- @Test
- void invokeNullWithFlags() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null),
- InvalidParametersEvent.class);
-
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, "s"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"),
- InvalidParametersEvent.class);
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, InvalidParametersEvent.class },
+ { null, "test", null, InvalidParametersEvent.class },
+ { null, "test", "ttt", InvalidParametersEvent.class },
+ { null, null, "ttt", InvalidParametersEvent.class }
+ };
}
- @Test
- void invokeWithoutFlagsPatternMatches() {
- FunctionTestUtil.assertResult(replaceFunction.invoke("testString", "^test", "ttt"), "tttString");
- FunctionTestUtil.assertResult(replaceFunction.invoke("testStringtest", "^test", "ttt"), "tttStringtest");
+ @ParameterizedTest
+ @MethodSource("invokeNullWithFlagsTestData")
+ void invokeNullWithFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeNullWithFlagsTestData() {
+ return new Object[][] {
+ { null, null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, null, InvalidParametersEvent.class },
+ { null, "test", null, null, InvalidParametersEvent.class },
+ { null, "test", "ttt", null, InvalidParametersEvent.class },
+ { null, null, "ttt", null, InvalidParametersEvent.class },
+ { null, null, null, "s", InvalidParametersEvent.class },
+ { "testString", null, null, "s", InvalidParametersEvent.class },
+ { "testString", "test", null, "s", InvalidParametersEvent.class },
+ { null, "test", null, "s", InvalidParametersEvent.class },
+ { null, "test", "ttt", "s", InvalidParametersEvent.class },
+ { null, null, "ttt", "s", InvalidParametersEvent.class },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762801100
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
Review Comment:
Done
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#issuecomment-2357628566
Failures on runtimes are unrelated to these PR changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762712260
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
Review Comment:
@pibizza Thank you for the review! I'm aware that all the cases you reported are managing constants, but I did that to ease a future extension of those tests. It's just a case some of them are currently constant values. Does make sense?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762582264
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @Test
+ void executeMatchesFunctionTest() {
+ Boolean retrieved = XQueryImplUtil.executeMatchesFunction("test", "^test", "i");
Review Comment:
@gitgabrio Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "pibizza (via GitHub)" <gi...@apache.org>.
pibizza commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762657372
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern), expectedResult);
}
- @Test
- void invokeWithFlagDotAll() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar", "s"), true);
+ private static Object[][] invokeWithoutFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", true },
+ { "foobar", "^fo*b", true },
+ { "abracadabra", "bra", true },
+ { "abracadabra", "bra", true },
+ { "(?xi)[hello world()]", "hello", true }
+ };
}
- @Test
- void invokeWithFlagMultiline() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "^bar", "m"), true);
+ @ParameterizedTest
+ @MethodSource("invokeNullOrEmptyFlagsMatchTestData")
+ void invokeNullOrEmptyFlagsMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
Review Comment:
Inline parameter expected result. it is always going to be true.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern), expectedResult);
}
- @Test
- void invokeWithFlagDotAll() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar", "s"), true);
+ private static Object[][] invokeWithoutFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", true },
+ { "foobar", "^fo*b", true },
+ { "abracadabra", "bra", true },
+ { "abracadabra", "bra", true },
+ { "(?xi)[hello world()]", "hello", true }
+ };
}
- @Test
- void invokeWithFlagMultiline() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "^bar", "m"), true);
+ @ParameterizedTest
+ @MethodSource("invokeNullOrEmptyFlagsMatchTestData")
+ void invokeNullOrEmptyFlagsMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern, flags), expectedResult);
}
- @Test
- void invokeWithFlagCaseInsensitive() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "k","i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "K","i"), true);
+ private static Object[][] invokeNullOrEmptyFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", null, true },
+ { "foobar", "^fo*b", null, true },
+ { "abracadabra", "bra", null, true },
+ { "abracadabra", "bra", "", true },
+ { "(?xi)[hello world()]", "hello", null, true }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeInvalidRegexTestData")
+ void invokeInvalidRegexTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeInvalidRegexTestData() {
+ return new Object[][] {
+ { "testString", "(?=\\\\s)", null, InvalidParametersEvent.class },
+ { "fo\nbar", "(?iU)(?iU)(ab)[|cd]", null, InvalidParametersEvent.class },
+ { "fo\nbar", "(?x)(?i)hello world", "i", InvalidParametersEvent.class },
+ { "fo\nbar", "(?xi)hello world", null, InvalidParametersEvent.class },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsNotMatchTestData")
+ void invokeWithoutFlagsNotMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern, flags), expectedResult);
+ }
+
+ private static Object[][] invokeWithoutFlagsNotMatchTestData() {
+ return new Object[][] {
+ { "test", "testt", null, false },
+ { "foobar", "^fo*bb", null, false },
+ { "h", "(.)\3", null, false },
+ { "h", "(.)\2", null, false },
+ { "input", "\3", null, false }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeWithFlagCaseInsensitiveTestData")
+ void invokeWithoutFlagsPatternTest(String input, String pattern, String flags, Boolean expectedResult) {
Review Comment:
Inline parameter expectedResult. it is always going to be true.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
Review Comment:
Inline parameter expected result. it is always going to be true.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement), expectedErrorEventClass);
}
- @Test
- void invokeNullWithFlags() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null),
- InvalidParametersEvent.class);
-
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, "s"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"),
- InvalidParametersEvent.class);
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, InvalidParametersEvent.class },
+ { null, "test", null, InvalidParametersEvent.class },
+ { null, "test", "ttt", InvalidParametersEvent.class },
+ { null, null, "ttt", InvalidParametersEvent.class }
+ };
}
- @Test
- void invokeWithoutFlagsPatternMatches() {
- FunctionTestUtil.assertResult(replaceFunction.invoke("testString", "^test", "ttt"), "tttString");
- FunctionTestUtil.assertResult(replaceFunction.invoke("testStringtest", "^test", "ttt"), "tttStringtest");
+ @ParameterizedTest
+ @MethodSource("invokeNullWithFlagsTestData")
+ void invokeNullWithFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeNullWithFlagsTestData() {
+ return new Object[][] {
+ { null, null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, null, InvalidParametersEvent.class },
+ { null, "test", null, null, InvalidParametersEvent.class },
+ { null, "test", "ttt", null, InvalidParametersEvent.class },
+ { null, null, "ttt", null, InvalidParametersEvent.class },
+ { null, null, null, "s", InvalidParametersEvent.class },
+ { "testString", null, null, "s", InvalidParametersEvent.class },
+ { "testString", "test", null, "s", InvalidParametersEvent.class },
+ { null, "test", null, "s", InvalidParametersEvent.class },
+ { null, "test", "ttt", "s", InvalidParametersEvent.class },
+ { null, null, "ttt", "s", InvalidParametersEvent.class },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern), expectedResult);
}
- @Test
- void invokeWithFlagDotAll() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar", "s"), true);
+ private static Object[][] invokeWithoutFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", true },
+ { "foobar", "^fo*b", true },
+ { "abracadabra", "bra", true },
+ { "abracadabra", "bra", true },
+ { "(?xi)[hello world()]", "hello", true }
+ };
}
- @Test
- void invokeWithFlagMultiline() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "^bar", "m"), true);
+ @ParameterizedTest
+ @MethodSource("invokeNullOrEmptyFlagsMatchTestData")
+ void invokeNullOrEmptyFlagsMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern, flags), expectedResult);
}
- @Test
- void invokeWithFlagCaseInsensitive() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "k","i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "K","i"), true);
+ private static Object[][] invokeNullOrEmptyFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", null, true },
+ { "foobar", "^fo*b", null, true },
+ { "abracadabra", "bra", null, true },
+ { "abracadabra", "bra", "", true },
+ { "(?xi)[hello world()]", "hello", null, true }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeInvalidRegexTestData")
+ void invokeInvalidRegexTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeInvalidRegexTestData() {
+ return new Object[][] {
+ { "testString", "(?=\\\\s)", null, InvalidParametersEvent.class },
+ { "fo\nbar", "(?iU)(?iU)(ab)[|cd]", null, InvalidParametersEvent.class },
+ { "fo\nbar", "(?x)(?i)hello world", "i", InvalidParametersEvent.class },
+ { "fo\nbar", "(?xi)hello world", null, InvalidParametersEvent.class },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsNotMatchTestData")
+ void invokeWithoutFlagsNotMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
Review Comment:
Inline parameter expectedResult. it is always going to be false.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement), expectedErrorEventClass);
}
- @Test
- void invokeNullWithFlags() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null),
- InvalidParametersEvent.class);
-
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, "s"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"),
- InvalidParametersEvent.class);
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, InvalidParametersEvent.class },
+ { null, "test", null, InvalidParametersEvent.class },
+ { null, "test", "ttt", InvalidParametersEvent.class },
+ { null, null, "ttt", InvalidParametersEvent.class }
+ };
}
- @Test
- void invokeWithoutFlagsPatternMatches() {
- FunctionTestUtil.assertResult(replaceFunction.invoke("testString", "^test", "ttt"), "tttString");
- FunctionTestUtil.assertResult(replaceFunction.invoke("testStringtest", "^test", "ttt"), "tttStringtest");
+ @ParameterizedTest
+ @MethodSource("invokeNullWithFlagsTestData")
+ void invokeNullWithFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @ParameterizedTest
+ @MethodSource("executeMatchesFunctionTestData")
+ void executeMatchesFunctionTest(String input, String pattern, String flags, boolean expected) {
+ assertThat(XQueryImplUtil.executeMatchesFunction(input, pattern, flags)).isEqualTo(expected);
+ }
+
+ private static Object[][] executeMatchesFunctionTestData() {
+ return new Object[][] {
+ { "test", "^test", "i", true },
+ { "fo\nbar", "o.b", null, false },
+ { "TEST", "test", "i", true },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeMatchesFunctionInvokingExceptionTestData")
+ void executeMatchesFunctionInvokingExceptionTest(String input, String pattern, String flags,
+ Class<?> expectedException, String exceptionMessage) {
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction(input, pattern, flags))
+ .isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+ }
+
+ private static Object[][] executeMatchesFunctionInvokingExceptionTestData() {
+ return new Object[][] {
+ { "test", "^test", "g", IllegalArgumentException.class, "Unrecognized flag" },
+ { "test", "(?=\\s)", null, IllegalArgumentException.class, "No expression before quantifier" },
+ { "test", "(.)\\2", "i", IllegalArgumentException.class, "invalid backreference \\2" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeReplaceFunctionTestData")
+ void executeReplaceFunctionTest(String input, String pattern, String replacement, String flags, String expected) {
+ assertThat(XQueryImplUtil.executeReplaceFunction(input, pattern, replacement, flags)).isEqualTo(expected);
+ }
+
+ private static Object[][] executeReplaceFunctionTestData() {
+ return new Object[][] {
+ { "testString", "^test", "ttt", "", "tttString" },
+ { "fo\nbar", "o.b", "ttt", "s", "ftttar" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeReplaceFunctionInvokingExceptionTestData")
+ void executeReplaceFunctionInvokingExceptionTest(String input, String pattern, String replacement, String flags,
+ Class<?> expectedException, String exceptionMessage) {
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction(input, pattern, replacement, flags))
+ .isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+ }
+
+ private static Object[][] executeReplaceFunctionInvokingExceptionTestData() {
+ return new Object[][] {
+ { "fo\nbar", "o.b", "ttt", "g", IllegalArgumentException.class, "Unrecognized flag" },
+ { "test", "(?=\\s)", "ttt", null, IllegalArgumentException.class, "No expression before quantifier" },
+ { "test", "(.)\\2", "ttt", null, IllegalArgumentException.class, "invalid backreference \\2" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("evaluateXQueryExpressionValidParametersTestData")
+ void evaluateXQueryExpressionValidParametersTest(String expression, Class<?> returnTypeClass, Object expectedResult) {
+ assertThat(XQueryImplUtil.evaluateXQueryExpression(expression, returnTypeClass)).isEqualTo(expectedResult);
+
+ }
+
+ private static Object[][] evaluateXQueryExpressionValidParametersTestData() {
+ return new Object[][] {
+ { "matches('test', '^test', 'i')", Boolean.class, true },
+ { "matches('fo\\nbar', 'o.b', '')", Boolean.class, false },
+ { "replace('testString', '^test', 'ttt', '')", String.class, "tttString" }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("evaluateXQueryExpressionInvalidParametersTestData")
+ void evaluateXQueryExpressionInvalidParametersTest(String expression, Class<?> returnTypeClass, Class<?> expectedException) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be UnsupportedOperationException.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/MatchesFunctionTest.java:
##########
@@ -19,116 +19,146 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-import java.security.InvalidParameterException;
-import java.util.regex.PatternSyntaxException;
-
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException;
-import static org.mockito.Mockito.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class MatchesFunctionTest {
- @Test
- void invokeNull() {
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, null, null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags(null, "test", null));
- assertThatExceptionOfType(InvalidParameterException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("test", null, null));
+ private static final MatchesFunction matchesFunction = MatchesFunction.INSTANCE;
+
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern), expectedErrorEventClass);
}
- @Test
- void invokeUnsupportedFlags() {
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("foobar", "fo.bar", "g"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "p"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "X"));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", " "));
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", "iU"));
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, InvalidParametersEvent.class },
+ { null, "test", InvalidParametersEvent.class },
+ { "test", null, InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "test",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*b",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra", ""), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("abracadabra", "bra",null), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("(?xi)[hello world()]", "hello",null), true);
+ @ParameterizedTest
+ @MethodSource("invokeUnsupportedFlagsTestData")
+ void invokeUnsupportedFlagsTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(matchesFunction.invoke(input, pattern, flags), expectedErrorEventClass);
+ }
+
+ private static Object[][] invokeUnsupportedFlagsTestData() {
+ return new Object[][] {
+ { "foobar", "fo.bar", "g", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "p", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "X", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU", InvalidParametersEvent.class },
+ { "abracadabra", "bra", "iU asd", InvalidParametersEvent.class },
+ };
}
- @Test
- void invokeWithoutFlagsNotMatch() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("test", "testt",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^fo*bb",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("h", "(.)\2",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("input", "\3",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?iU)(?iU)(ab)[|cd]",null), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?x)(?i)hello world","i"), false);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "(?xi)hello world",null), false);
+ @ParameterizedTest
+ @MethodSource("invokeWithoutFlagsMatchTestData")
+ void invokeWithoutFlagsMatchTest(String input, String pattern, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern), expectedResult);
}
- @Test
- void invokeWithFlagDotAll() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "fo.bar", "s"), true);
+ private static Object[][] invokeWithoutFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", true },
+ { "foobar", "^fo*b", true },
+ { "abracadabra", "bra", true },
+ { "abracadabra", "bra", true },
+ { "(?xi)[hello world()]", "hello", true }
+ };
}
- @Test
- void invokeWithFlagMultiline() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("fo\nbar", "^bar", "m"), true);
+ @ParameterizedTest
+ @MethodSource("invokeNullOrEmptyFlagsMatchTestData")
+ void invokeNullOrEmptyFlagsMatchTest(String input, String pattern, String flags, Boolean expectedResult) {
+ FunctionTestUtil.assertResult(matchesFunction.invoke(input, pattern, flags), expectedResult);
}
- @Test
- void invokeWithFlagCaseInsensitive() {
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("foobar", "^Fo*bar", "i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "k","i"), true);
- FunctionTestUtil.assertResult(MatchesFunction.matchFunctionWithFlags("\u212A", "K","i"), true);
+ private static Object[][] invokeNullOrEmptyFlagsMatchTestData() {
+ return new Object[][] {
+ { "test", "test", null, true },
+ { "foobar", "^fo*b", null, true },
+ { "abracadabra", "bra", null, true },
+ { "abracadabra", "bra", "", true },
+ { "(?xi)[hello world()]", "hello", null, true }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("invokeInvalidRegexTestData")
+ void invokeInvalidRegexTest(String input, String pattern, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
Review Comment:
Inline parameter expectedErrorEventClass. it is always going to be InvalidParametersEvent.class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1760854719
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @Test
+ void executeMatchesFunctionTest() {
+ Boolean retrieved = XQueryImplUtil.executeMatchesFunction("test", "^test", "i");
+ assertThat(retrieved).isTrue();
+
+ retrieved = XQueryImplUtil.executeMatchesFunction("fo\nbar", "o.b", null);
+ assertThat(retrieved).isFalse();
+
+ retrieved = XQueryImplUtil.executeMatchesFunction("TEST", "test", "i");
+ assertThat(retrieved).isTrue();
+ }
+
+ @Test
+ void executeMatchesFunctionInvokingException(){
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "^test", "g"))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Unrecognized flag");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "(?=\\s)", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("No expression before quantifier");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "(.)\\2", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("invalid backreference \\2");
+ }
+
+ @Test
+ void executeReplaceFunctionTest() {
+ String retrieved = XQueryImplUtil.executeReplaceFunction("testString", "^test", "ttt", "");
+ assertThat(retrieved).isNotNull().isEqualTo("tttString");
+
+ retrieved = XQueryImplUtil.executeReplaceFunction("fo\nbar", "o.b", "ttt", "s");
+ assertThat(retrieved).isNotNull().isEqualTo("ftttar");
+ }
+
+ @Test
+ void executeReplaceFunctionInvokingException(){
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("fo\nbar", "o.b", "ttt", "g"))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Unrecognized flag");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("test", "(?=\\s)", "ttt", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("No expression before quantifier");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("test", "(.)\\2", "ttt", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("invalid backreference \\2");
+ }
+
+}
Review Comment:
Good point
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "kie-ci3 (via GitHub)" <gi...@apache.org>.
kie-ci3 commented on PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#issuecomment-2352543135
**PR job** `#1` was: **UNSTABLE**
Possible explanation: This should be test failures
<details>
<summary><b>Reproducer</b></summary>
build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u https://github.com/apache/incubator-kie-drools/pull/6085 --skipParallelCheckout
NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
</details>
Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6085/1/display/redirect
**Test results:**
- PASSED: 22180
- FAILED: 1
Those are the test failures:
<details>
<summary><a href="https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6085/1/testReport/org.kie.maven.plugin.it/kie-maven-plugin-test-kjar-2/kie_maven_plugin_test_kjar_2/">org.kie.maven.plugin.it.kie-maven-plugin-test-kjar-2.kie-maven-plugin-test-kjar-2</a></summary>
The build exited with code 143. See /home/jenkins/jenkins-agent/workspace/llrequest_jobs_drools-pr_PR-6085/kogito-pipelines/bc/apache_incubator-kie-drools/kie-maven-plugin/target/it/kie-maven-plugin-test-kjar-2/build.log for details.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#issuecomment-2354809298
@gitgabrio Tests fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762809455
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
Review Comment:
Done
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @ParameterizedTest
+ @MethodSource("executeMatchesFunctionTestData")
+ void executeMatchesFunctionTest(String input, String pattern, String flags, boolean expected) {
+ assertThat(XQueryImplUtil.executeMatchesFunction(input, pattern, flags)).isEqualTo(expected);
+ }
+
+ private static Object[][] executeMatchesFunctionTestData() {
+ return new Object[][] {
+ { "test", "^test", "i", true },
+ { "fo\nbar", "o.b", null, false },
+ { "TEST", "test", "i", true },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeMatchesFunctionInvokingExceptionTestData")
+ void executeMatchesFunctionInvokingExceptionTest(String input, String pattern, String flags,
+ Class<?> expectedException, String exceptionMessage) {
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction(input, pattern, flags))
+ .isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+ }
+
+ private static Object[][] executeMatchesFunctionInvokingExceptionTestData() {
+ return new Object[][] {
+ { "test", "^test", "g", IllegalArgumentException.class, "Unrecognized flag" },
+ { "test", "(?=\\s)", null, IllegalArgumentException.class, "No expression before quantifier" },
+ { "test", "(.)\\2", "i", IllegalArgumentException.class, "invalid backreference \\2" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeReplaceFunctionTestData")
+ void executeReplaceFunctionTest(String input, String pattern, String replacement, String flags, String expected) {
+ assertThat(XQueryImplUtil.executeReplaceFunction(input, pattern, replacement, flags)).isEqualTo(expected);
+ }
+
+ private static Object[][] executeReplaceFunctionTestData() {
+ return new Object[][] {
+ { "testString", "^test", "ttt", "", "tttString" },
+ { "fo\nbar", "o.b", "ttt", "s", "ftttar" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("executeReplaceFunctionInvokingExceptionTestData")
+ void executeReplaceFunctionInvokingExceptionTest(String input, String pattern, String replacement, String flags,
+ Class<?> expectedException, String exceptionMessage) {
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction(input, pattern, replacement, flags))
+ .isInstanceOf(expectedException).hasMessageContaining(exceptionMessage);
+ }
+
+ private static Object[][] executeReplaceFunctionInvokingExceptionTestData() {
+ return new Object[][] {
+ { "fo\nbar", "o.b", "ttt", "g", IllegalArgumentException.class, "Unrecognized flag" },
+ { "test", "(?=\\s)", "ttt", null, IllegalArgumentException.class, "No expression before quantifier" },
+ { "test", "(.)\\2", "ttt", null, IllegalArgumentException.class, "invalid backreference \\2" },
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("evaluateXQueryExpressionValidParametersTestData")
+ void evaluateXQueryExpressionValidParametersTest(String expression, Class<?> returnTypeClass, Object expectedResult) {
+ assertThat(XQueryImplUtil.evaluateXQueryExpression(expression, returnTypeClass)).isEqualTo(expectedResult);
+
+ }
+
+ private static Object[][] evaluateXQueryExpressionValidParametersTestData() {
+ return new Object[][] {
+ { "matches('test', '^test', 'i')", Boolean.class, true },
+ { "matches('fo\\nbar', 'o.b', '')", Boolean.class, false },
+ { "replace('testString', '^test', 'ttt', '')", String.class, "tttString" }
+ };
+ }
+
+ @ParameterizedTest
+ @MethodSource("evaluateXQueryExpressionInvalidParametersTestData")
+ void evaluateXQueryExpressionInvalidParametersTest(String expression, Class<?> returnTypeClass, Class<?> expectedException) {
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1760851120
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @Test
+ void executeMatchesFunctionTest() {
+ Boolean retrieved = XQueryImplUtil.executeMatchesFunction("test", "^test", "i");
+ assertThat(retrieved).isTrue();
+
+ retrieved = XQueryImplUtil.executeMatchesFunction("fo\nbar", "o.b", null);
+ assertThat(retrieved).isFalse();
+
+ retrieved = XQueryImplUtil.executeMatchesFunction("TEST", "test", "i");
+ assertThat(retrieved).isTrue();
+ }
+
+ @Test
+ void executeMatchesFunctionInvokingException(){
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "^test", "g"))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Unrecognized flag");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "(?=\\s)", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("No expression before quantifier");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeMatchesFunction("test", "(.)\\2", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("invalid backreference \\2");
+ }
+
+ @Test
+ void executeReplaceFunctionTest() {
+ String retrieved = XQueryImplUtil.executeReplaceFunction("testString", "^test", "ttt", "");
+ assertThat(retrieved).isNotNull().isEqualTo("tttString");
+
+ retrieved = XQueryImplUtil.executeReplaceFunction("fo\nbar", "o.b", "ttt", "s");
+ assertThat(retrieved).isNotNull().isEqualTo("ftttar");
+ }
+
+ @Test
+ void executeReplaceFunctionInvokingException(){
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("fo\nbar", "o.b", "ttt", "g"))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Unrecognized flag");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("test", "(?=\\s)", "ttt", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("No expression before quantifier");
+
+ assertThatThrownBy(() -> XQueryImplUtil.executeReplaceFunction("test", "(.)\\2", "ttt", null))
+ .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("invalid backreference \\2");
+ }
+
+}
Review Comment:
Could you please introduce a test for XQueryImplUtil.evaluateXQueryExpression, to verify that expected exception is thrown when Class<T> expectedTypeResult is neither Boolean nor String ?
Thanks!
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/util/XQueryImplUtilTest.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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
+ *
+ * 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.util;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class XQueryImplUtilTest {
+
+ @Test
+ void executeMatchesFunctionTest() {
+ Boolean retrieved = XQueryImplUtil.executeMatchesFunction("test", "^test", "i");
Review Comment:
Please take notice of [this](https://github.com/apache/incubator-kie-drools/pull/6083#pullrequestreview-2306164537) comment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#discussion_r1762803499
##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/runtime/functions/ReplaceFunctionTest.java:
##########
@@ -19,62 +19,88 @@
package org.kie.dmn.feel.runtime.functions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import org.kie.dmn.feel.runtime.events.InvalidParametersEvent;
class ReplaceFunctionTest {
private static final ReplaceFunction replaceFunction = ReplaceFunction.INSTANCE;
- @Test
- void invokeNull() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt"), InvalidParametersEvent.class);
+ @ParameterizedTest
+ @MethodSource("invokeNullTestData")
+ void invokeNullTest(String input, String pattern, String replacement, Class<?> expectedErrorEventClass) {
+ FunctionTestUtil.assertResultError(replaceFunction.invoke(input, pattern, replacement), expectedErrorEventClass);
}
- @Test
- void invokeNullWithFlags() {
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", null),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", null),
- InvalidParametersEvent.class);
-
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, null, "s"), InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", null, null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke("testString", "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", null, "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, "test", "ttt", "s"),
- InvalidParametersEvent.class);
- FunctionTestUtil.assertResultError(replaceFunction.invoke(null, null, "ttt", "s"),
- InvalidParametersEvent.class);
+ private static Object[][] invokeNullTestData() {
+ return new Object[][] {
+ { null, null, null, InvalidParametersEvent.class },
+ { "testString", null, null, InvalidParametersEvent.class },
+ { "testString", "test", null, InvalidParametersEvent.class },
+ { null, "test", null, InvalidParametersEvent.class },
+ { null, "test", "ttt", InvalidParametersEvent.class },
+ { null, null, "ttt", InvalidParametersEvent.class }
+ };
}
- @Test
- void invokeWithoutFlagsPatternMatches() {
- FunctionTestUtil.assertResult(replaceFunction.invoke("testString", "^test", "ttt"), "tttString");
- FunctionTestUtil.assertResult(replaceFunction.invoke("testStringtest", "^test", "ttt"), "tttStringtest");
+ @ParameterizedTest
+ @MethodSource("invokeNullWithFlagsTestData")
+ void invokeNullWithFlagsTest(String input, String pattern, String replacement, String flags, Class<?> expectedErrorEventClass) {
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#1448: `matches()` function wrongly behaves [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on PR #6085:
URL: https://github.com/apache/incubator-kie-drools/pull/6085#issuecomment-2355011844
@pibizza I applied your suggestion in all the places where I'm sure the parameter will always be a constant (basically all the exceptions). Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org