|
4 | 4 |
|
5 | 5 | import dev.openfeature.contrib.providers.flagd.e2e.State;
|
6 | 6 | import dev.openfeature.sdk.FlagEvaluationDetails;
|
| 7 | +import dev.openfeature.sdk.ImmutableMetadata; |
7 | 8 | import dev.openfeature.sdk.Value;
|
8 | 9 | import io.cucumber.java.en.Given;
|
9 | 10 | import io.cucumber.java.en.Then;
|
10 | 11 | import io.cucumber.java.en.When;
|
| 12 | +import java.io.IOException; |
| 13 | +import java.lang.reflect.Field; |
| 14 | +import java.util.List; |
| 15 | +import java.util.Map; |
| 16 | +import lombok.extern.slf4j.Slf4j; |
11 | 17 | import org.junit.jupiter.api.parallel.Isolated;
|
12 | 18 |
|
| 19 | +@Slf4j |
13 | 20 | @Isolated()
|
14 | 21 | public class FlagSteps extends AbstractSteps {
|
15 | 22 |
|
@@ -54,6 +61,9 @@ public void the_flag_was_evaluated_with_details() throws InterruptedException {
|
54 | 61 |
|
55 | 62 | @Then("the resolved details value should be \"{}\"")
|
56 | 63 | public void the_resolved_details_value_should_be(String value) throws Throwable {
|
| 64 | + if (state.evaluation.getErrorCode() != null) { |
| 65 | + log.warn(state.evaluation.getErrorMessage()); |
| 66 | + } |
57 | 67 | assertThat(state.evaluation.getValue()).isEqualTo(Utils.convert(value, state.flag.type));
|
58 | 68 | }
|
59 | 69 |
|
@@ -84,4 +94,47 @@ public Flag(String type, String name, Object defaultValue) {
|
84 | 94 | this.type = type;
|
85 | 95 | }
|
86 | 96 | }
|
| 97 | + |
| 98 | + @Then("the resolved metadata is empty") |
| 99 | + @SuppressWarnings("unchecked") |
| 100 | + public void the_resolved_metadata_is_empty() throws NoSuchFieldException, IllegalAccessException { |
| 101 | + ImmutableMetadata flagMetadata = state.evaluation.getFlagMetadata(); |
| 102 | + |
| 103 | + Field metadataField = flagMetadata.getClass().getDeclaredField("metadata"); |
| 104 | + metadataField.setAccessible(true); |
| 105 | + Map<String, Object> metadataMap = (Map<String, Object>) metadataField.get(flagMetadata); |
| 106 | + assertThat(metadataMap).isEmpty(); |
| 107 | + } |
| 108 | + |
| 109 | + @Then("the resolved metadata should contain") |
| 110 | + @SuppressWarnings("unchecked") |
| 111 | + public void the_resolved_metadata_should_contain(io.cucumber.datatable.DataTable dataTable) |
| 112 | + throws IOException, ClassNotFoundException { |
| 113 | + |
| 114 | + ImmutableMetadata flagMetadata = state.evaluation.getFlagMetadata(); |
| 115 | + |
| 116 | + List<Map<String, String>> rows = dataTable.asMaps(String.class, String.class); |
| 117 | + for (Map<String, String> row : rows) { |
| 118 | + switch (row.get("metadata_type")) { |
| 119 | + case "String": |
| 120 | + assertThat(flagMetadata.getString(row.get("key"))) |
| 121 | + .isEqualTo(Utils.convert(row.get("value"), row.get("metadata_type"))); |
| 122 | + break; |
| 123 | + case "Boolean": |
| 124 | + assertThat(flagMetadata.getBoolean(row.get("key"))) |
| 125 | + .isEqualTo(Utils.convert(row.get("value"), row.get("metadata_type"))); |
| 126 | + break; |
| 127 | + case "Float": |
| 128 | + assertThat(flagMetadata.getDouble(row.get("key"))) |
| 129 | + .isEqualTo(Utils.convert(row.get("value"), row.get("metadata_type"))); |
| 130 | + break; |
| 131 | + case "Integer": |
| 132 | + assertThat(flagMetadata.getInteger(row.get("key"))) |
| 133 | + .isEqualTo(Utils.convert(row.get("value"), row.get("metadata_type"))); |
| 134 | + break; |
| 135 | + default: |
| 136 | + throw new AssertionError("type not supported"); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
87 | 140 | }
|
0 commit comments