-
Notifications
You must be signed in to change notification settings - Fork 50
test: improve gherkin test suite only relying on the newest version, with data loading #1578
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b3c267
test: improve gherkin test suite only relying on the newest version, …
aepfli c7355a9
Update src/test/java/dev/openfeature/sdk/e2e/steps/ContextSteps.java
aepfli 04e3230
Update src/test/java/dev/openfeature/sdk/testutils/jackson/CelContext…
aepfli c57e3da
test: improve gherkin test suite only relying on the newest version, …
aepfli 71951f8
Update src/test/java/dev/openfeature/sdk/e2e/steps/FlagStepDefinition…
aepfli cf34c77
Update src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java
aepfli f3512f9
test: improve gherkin test suite only relying on the newest version, …
aepfli e097032
fixup: add provider-status tests
aepfli 017611b
fixup: update spec
aepfli 4a3faf1
fixup: add missing steps and adapt to new spec steps
aepfli ec58624
Merge branch 'main' into feat/improve-inmemmory-update-gherkin-tests
aepfli 1a5ffa8
Merge branch 'main' into feat/improve-inmemmory-update-gherkin-tests
aepfli af30a35
fix: race condition?
aepfli 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 hidden or 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
Submodule spec
updated
26 files
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
54 changes: 54 additions & 0 deletions
54
src/test/java/dev/openfeature/sdk/testutils/jackson/CelContextEvaluator.java
This file contains hidden or 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,54 @@ | ||
package dev.openfeature.sdk.testutils.jackson; | ||
|
||
import dev.cel.common.types.SimpleType; | ||
import dev.cel.compiler.CelCompiler; | ||
import dev.cel.compiler.CelCompilerFactory; | ||
import dev.cel.runtime.CelRuntime; | ||
import dev.cel.runtime.CelRuntimeFactory; | ||
import dev.openfeature.sdk.EvaluationContext; | ||
import dev.openfeature.sdk.providers.memory.ContextEvaluator; | ||
import dev.openfeature.sdk.providers.memory.Flag; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CelContextEvaluator<T> implements ContextEvaluator<T> { | ||
private final CelRuntime.Program program; | ||
|
||
public CelContextEvaluator(String expression) { | ||
try { | ||
CelRuntime celRuntime = | ||
CelRuntimeFactory.standardCelRuntimeBuilder().build(); | ||
CelCompiler celCompiler = CelCompilerFactory.standardCelCompilerBuilder() | ||
.addVar("customer", SimpleType.STRING) | ||
.addVar("email", SimpleType.STRING) | ||
.addVar("dummy", SimpleType.STRING) | ||
.setResultType(SimpleType.STRING) | ||
// Add other variables you expect | ||
aepfli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.build(); | ||
|
||
var ast = celCompiler.compile(expression).getAst(); | ||
this.program = celRuntime.createProgram(ast); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to compile CEL expression: " + expression, e); | ||
} | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public T evaluate(Flag flag, EvaluationContext evaluationContext) { | ||
try { | ||
Map<String, Object> objectMap = new HashMap<>(Map.of("email", "")); | ||
if (evaluationContext != null) { | ||
// Evaluate with context | ||
objectMap.putAll(evaluationContext.asObjectMap()); | ||
aepfli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Object result = program.eval(objectMap); | ||
|
||
String stringResult = (String) result; | ||
return (T) flag.getVariants().get(stringResult); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/dev/openfeature/sdk/testutils/jackson/ContextEvaluatorDeserializer.java
This file contains hidden or 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,25 @@ | ||
package dev.openfeature.sdk.testutils.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import dev.openfeature.sdk.providers.memory.ContextEvaluator; | ||
import java.io.IOException; | ||
|
||
public class ContextEvaluatorDeserializer extends JsonDeserializer<ContextEvaluator<?>> { | ||
@Override | ||
public ContextEvaluator<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
JsonNode node = p.getCodec().readTree(p); | ||
|
||
if (node.isTextual()) { | ||
return new CelContextEvaluator<>(node.asText()); | ||
} | ||
|
||
if (node.isObject() && node.has("expression")) { | ||
return new CelContextEvaluator<>(node.get("expression").asText()); | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.