-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: The invocation of a non-existing function returns null #692
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bcd43ec
test: Adjust expected behavior of function invocation
saig0 10aae21
feat: Return null on function invocation
saig0 902239b
refactor: Rename test cases
saig0 f866321
test: New test case for function invocation
saig0 70bca2f
test: Verify reported failures
saig0 d2ca767
refactor: Use evaluation result matcher in test
saig0 b79573d
refactor: Replace internal test methods
saig0 0260126
refactor: Align failure message
saig0 133dc8f
refactor: Move test case
saig0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions
48
src/test/scala/org/camunda/feel/impl/EvaluationResultMatchers.scala
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,48 @@ | ||
package org.camunda.feel.impl | ||
|
||
import org.camunda.feel.api.{EvaluationFailure, EvaluationFailureType, EvaluationResult, FailedEvaluationResult, SuccessfulEvaluationResult} | ||
import org.scalatest.matchers.{MatchResult, Matcher} | ||
|
||
trait EvaluationResultMatchers { | ||
|
||
def returnResult(expectedResult: Any) = new EvaluationResultValueMatcher(expectedResult) | ||
|
||
def returnNull() = new EvaluationResultValueMatcher(expectedResult = null) | ||
|
||
def reportFailure(failureType: EvaluationFailureType, failureMessage: String) = | ||
new SuppressedFailureMatcher(EvaluationFailure(failureType, failureMessage)) | ||
|
||
class EvaluationResultValueMatcher(expectedResult: Any) extends Matcher[EvaluationResult] { | ||
override def apply(evaluationResult: EvaluationResult): MatchResult = { | ||
evaluationResult match { | ||
case SuccessfulEvaluationResult(result, _) => MatchResult( | ||
result == expectedResult, | ||
s"the evaluation didn't returned '$expectedResult' but '${evaluationResult.result}'", | ||
s"The evaluation returned '${evaluationResult.result}' as expected", | ||
) | ||
case FailedEvaluationResult(failure, _) => MatchResult( | ||
false, | ||
s"the evaluation didn't returned '$expectedResult' but failed with '${failure.message}'", | ||
s"the evaluation didn't returned '$expectedResult' but failed with '${failure.message}'", | ||
) | ||
} | ||
} | ||
} | ||
|
||
class SuppressedFailureMatcher(expectedFailure: EvaluationFailure) extends Matcher[EvaluationResult] { | ||
override def apply(evaluationResult: EvaluationResult): MatchResult = { | ||
val matchResult = (suppressedFailures: List[EvaluationFailure]) => MatchResult( | ||
suppressedFailures.contains(expectedFailure), | ||
s"the evaluation didn't report '$expectedFailure' but '$suppressedFailures'", | ||
s"the evaluation reported '$expectedFailure' as expected", | ||
) | ||
evaluationResult match { | ||
case SuccessfulEvaluationResult(_, suppressedFailures) => matchResult(suppressedFailures) | ||
case FailedEvaluationResult(_, suppressedFailures) => matchResult(suppressedFailures) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
object EvaluationResultMatchers extends EvaluationResultMatchers |
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,70 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. Camunda licenses this file to you under the Apache License, | ||
* Version 2.0; 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.camunda.feel.impl | ||
|
||
import org.camunda.feel.api.{EvaluationResult, FeelEngineApi, FeelEngineBuilder, SuccessfulEvaluationResult, FailedEvaluationResult} | ||
import org.camunda.feel.context.Context | ||
import org.camunda.feel.syntaxtree.ValFunction | ||
|
||
trait FeelEngineTest { | ||
|
||
val engine: FeelEngineApi = FeelEngineBuilder() | ||
.withEnabledExternalFunctions(true) | ||
.build() | ||
|
||
def evaluateExpression( | ||
expression: String, | ||
variables: Map[String, Any] = Map(), | ||
functions: Map[String, ValFunction] = Map() | ||
): EvaluationResult = { | ||
val context = | ||
Context.StaticContext( | ||
variables = variables, | ||
functions = functions.map { case (n, f) => n -> List(f) }) | ||
|
||
engine.evaluateExpression(expression, context) | ||
} | ||
|
||
def evaluateUnaryTests( | ||
expression: String, | ||
inputValue: Any, | ||
variables: Map[String, Any] = Map(), | ||
functions: Map[String, ValFunction] = Map() | ||
): EvaluationResult = { | ||
val context = | ||
Context.StaticContext( | ||
variables = variables, | ||
functions = functions.map { case (n, f) => n -> List(f) }) | ||
|
||
engine.evaluateUnaryTests( | ||
expression = expression, | ||
inputValue = inputValue, | ||
context = context | ||
) | ||
} | ||
|
||
def evaluateFunction(function: String): ValFunction = { | ||
engine.evaluateExpression(function) match { | ||
case SuccessfulEvaluationResult(result: ValFunction, _) => result | ||
case SuccessfulEvaluationResult(result, _) => | ||
throw new AssertionError(s"Expected to return a function but was '$result'") | ||
case FailedEvaluationResult(failure, _) => | ||
throw new AssertionError(s"Expected to return a function but failed with '${failure.message}'") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it so much, made test cases way more readable 💪