-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parent onFailure configuration (#14)
Today, if an expression evaluation fails, it is only possible to set a behavior at the expression level, which means that in the grouped expression, each of them needs to have its own `onFailure` attribute set. Within this change, the `onFailure` on the parent expression is now respected, so, if the evaluation of any expression fails, the parent configuration will be used when the expression doesn't override its default throwing behavior.
- Loading branch information
Showing
6 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/test/kotlin/com/rapatao/projects/ruleset/engine/cases/OnFailureCases.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package com.rapatao.projects.ruleset.engine.cases | ||
|
||
import com.rapatao.projects.ruleset.engine.types.Expression | ||
import com.rapatao.projects.ruleset.engine.types.OnFailure | ||
import com.rapatao.projects.ruleset.engine.types.builder.equalsTo | ||
import org.junit.jupiter.params.provider.Arguments | ||
|
||
object OnFailureCases { | ||
|
||
fun cases(): List<Arguments> = anyMatchCases() + allMatchCases() + noneMatchCases() | ||
|
||
private fun anyMatchCases(): List<Arguments> = listOf( | ||
Arguments.of( | ||
Expression( | ||
anyMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.THROW, | ||
anyMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.FALSE, | ||
anyMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
false, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.TRUE, | ||
anyMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
true, | ||
false, | ||
), | ||
) | ||
|
||
private fun allMatchCases(): List<Arguments> = listOf( | ||
Arguments.of( | ||
Expression( | ||
allMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.THROW, | ||
allMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.FALSE, | ||
allMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
false, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.TRUE, | ||
allMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
true, | ||
false, | ||
), | ||
) | ||
|
||
private fun noneMatchCases(): List<Arguments> = listOf( | ||
Arguments.of( | ||
Expression( | ||
noneMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.THROW, | ||
noneMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
true, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.FALSE, | ||
noneMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
false, | ||
false, | ||
), | ||
Arguments.of( | ||
Expression( | ||
onFailure = OnFailure.TRUE, | ||
noneMatch = listOf( | ||
"item.non.existing.field" equalsTo 10, | ||
) | ||
), | ||
true, | ||
false, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters