Commit 131a24d
committed
test: improve gherkin test suite only relying on the newest version, with data loading
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
diff --git c/src/test/java/dev/openfeature/sdk/e2e/steps/ContextSteps.java i/src/test/java/dev/openfeature/sdk/e2e/steps/ContextSteps.java
index e4cd603..121b567 100644
--- c/src/test/java/dev/openfeature/sdk/e2e/steps/ContextSteps.java
+++ i/src/test/java/dev/openfeature/sdk/e2e/steps/ContextSteps.java
@@ -114,9 +114,9 @@ public class ContextSteps {
public void a_context_containing_a_key_with_type_and_with_value(String key, String type, String value)
throws ClassNotFoundException, InstantiationException {
Map<String, Value> map = state.context.asMap();
- Map<String, Value> map = state.context.asMap();
map.put(key, new Value(Utils.convert(value, type)));
state.context = new MutableContext(state.context.getTargetingKey(), map);
+ }
@given("a context containing a targeting key with value {string}")
public void a_context_containing_a_targeting_key_with_value(String string) {
diff --git c/src/test/java/dev/openfeature/sdk/testutils/jackson/CelContextEvaluator.java i/src/test/java/dev/openfeature/sdk/testutils/jackson/CelContextEvaluator.java
index 20f3f5f..138c23f 100644
--- c/src/test/java/dev/openfeature/sdk/testutils/jackson/CelContextEvaluator.java
+++ i/src/test/java/dev/openfeature/sdk/testutils/jackson/CelContextEvaluator.java
@@ -46,7 +46,6 @@ public class CelContextEvaluator<T> implements ContextEvaluator<T> {
// Evaluate with context, overriding defaults.
objectMap.putAll(evaluationContext.asObjectMap());
}
- }
Object result = program.eval(objectMap);
diff --git c/src/test/java/dev/openfeature/sdk/testutils/jackson/VariantsMapDeserializer.java i/src/test/java/dev/openfeature/sdk/testutils/jackson/VariantsMapDeserializer.java
index 339d8c8..9a63f58 100644
--- c/src/test/java/dev/openfeature/sdk/testutils/jackson/VariantsMapDeserializer.java
+++ i/src/test/java/dev/openfeature/sdk/testutils/jackson/VariantsMapDeserializer.java
@@ -50,6 +50,7 @@ public class VariantsMapDeserializer extends JsonDeserializer<Map<String, Object
}
private Object convertJsonNodeToValue(JsonNode node) throws InstantiationException {
+
if (node.isNull()) {
return null;
} else if (node.isBoolean()) {
@@ -60,25 +61,8 @@ public class VariantsMapDeserializer extends JsonDeserializer<Map<String, Object
return node.asDouble();
} else if (node.isTextual()) {
return node.asText();
- } else if (node.isArray()) {
- List<Object> list = new ArrayList<>();
- for (JsonNode item : node) {
- list.add(convertJsonNodeToValue(item));
- }
- return list;
} else if (node.isObject()) {
- Map<String, Value> map = new HashMap<>();
- Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
- while (fields.hasNext()) {
- Map.Entry<String, JsonNode> field = fields.next();
- Object o = convertJsonNodeToValue(field.getValue());
- if (o instanceof Value) {
- map.put(field.getKey(), (Value) o);
- } else {
- map.put(field.getKey(), new Value(o));
- }
- }
- return new Value(new MutableStructure(map));
+ return Value.objectToValue(node);
}
throw new IllegalArgumentException("Unsupported JSON node type: " + node.getNodeType());
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
diff --git c/src/test/java/dev/openfeature/sdk/e2e/Utils.java i/src/test/java/dev/openfeature/sdk/e2e/Utils.java
index 1500d99..565968c 100644
--- c/src/test/java/dev/openfeature/sdk/e2e/Utils.java
+++ i/src/test/java/dev/openfeature/sdk/e2e/Utils.java
@@ -7,6 +7,8 @@ import java.util.Objects;
public final class Utils {
+ public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
private Utils() {}
public static Object convert(String value, String type) {
@@ -27,7 +29,7 @@ public final class Utils {
return Long.parseLong(value);
case "object":
try {
- return Value.objectToValue(new ObjectMapper().readValue(value, Object.class));
+ return Value.objectToValue(OBJECT_MAPPER.readValue(value, Object.class));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
diff --git c/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java i/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java
index 78a2fc5..13fe32f 100644
--- c/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java
+++ i/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java
@@ -17,6 +17,8 @@ import java.util.Map;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
+import static dev.openfeature.sdk.e2e.Utils.OBJECT_MAPPER;
+
/**
* Test flags utils.
*/
@@ -41,7 +43,8 @@ public class TestFlagsUtils {
*/
public static synchronized Map<String, Flag<?>> buildFlags() {
if (flags == null) {
- ObjectMapper objectMapper = new ObjectMapper();
+ if (flags == null) {
+ ObjectMapper objectMapper = OBJECT_MAPPER;
objectMapper.configure(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION.mappedFeature(), true);
objectMapper.addMixIn(Flag.class, InMemoryFlagMixin.class);
objectMapper.addMixIn(Flag.FlagBuilder.class, InMemoryFlagMixin.FlagBuilderMixin.class);
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>1 parent cf34c77 commit 131a24d
File tree
4 files changed
+10
-4
lines changed- src/test/java/dev/openfeature/sdk
- e2e
- testutils
- jackson
4 files changed
+10
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
0 commit comments