Skip to content

Commit 3788ac4

Browse files
committed
fixup: add missing steps and adapt to new spec steps
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 017611b commit 3788ac4

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

spec

src/main/java/dev/openfeature/sdk/providers/memory/Flag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public class Flag<T> {
2020
private String defaultVariant;
2121
private ContextEvaluator<T> contextEvaluator;
2222
private ImmutableMetadata flagMetadata;
23+
private boolean disabled;
2324
}

src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.openfeature.sdk.providers.memory;
22

3+
import dev.openfeature.sdk.ErrorCode;
34
import dev.openfeature.sdk.EvaluationContext;
45
import dev.openfeature.sdk.EventProvider;
56
import dev.openfeature.sdk.Metadata;
@@ -97,36 +98,36 @@ public void updateFlag(String flagKey, Flag<?> newFlag) {
9798
@Override
9899
public ProviderEvaluation<Boolean> getBooleanEvaluation(
99100
String key, Boolean defaultValue, EvaluationContext evaluationContext) {
100-
return getEvaluation(key, evaluationContext, Boolean.class);
101+
return getEvaluation(key, defaultValue, evaluationContext, Boolean.class);
101102
}
102103

103104
@Override
104105
public ProviderEvaluation<String> getStringEvaluation(
105106
String key, String defaultValue, EvaluationContext evaluationContext) {
106-
return getEvaluation(key, evaluationContext, String.class);
107+
return getEvaluation(key, defaultValue, evaluationContext, String.class);
107108
}
108109

109110
@Override
110111
public ProviderEvaluation<Integer> getIntegerEvaluation(
111112
String key, Integer defaultValue, EvaluationContext evaluationContext) {
112-
return getEvaluation(key, evaluationContext, Integer.class);
113+
return getEvaluation(key, defaultValue, evaluationContext, Integer.class);
113114
}
114115

115116
@Override
116117
public ProviderEvaluation<Double> getDoubleEvaluation(
117118
String key, Double defaultValue, EvaluationContext evaluationContext) {
118-
return getEvaluation(key, evaluationContext, Double.class);
119+
return getEvaluation(key, defaultValue, evaluationContext, Double.class);
119120
}
120121

121122
@SneakyThrows
122123
@Override
123124
public ProviderEvaluation<Value> getObjectEvaluation(
124125
String key, Value defaultValue, EvaluationContext evaluationContext) {
125-
return getEvaluation(key, evaluationContext, Value.class);
126+
return getEvaluation(key, defaultValue, evaluationContext, Value.class);
126127
}
127128

128129
private <T> ProviderEvaluation<T> getEvaluation(
129-
String key, EvaluationContext evaluationContext, Class<?> expectedType) throws OpenFeatureError {
130+
String key, T defaultValue, EvaluationContext evaluationContext, Class<?> expectedType) throws OpenFeatureError {
130131
if (!ProviderState.READY.equals(state)) {
131132
if (ProviderState.NOT_READY.equals(state)) {
132133
throw new ProviderNotReadyError("provider not yet initialized");
@@ -140,6 +141,13 @@ private <T> ProviderEvaluation<T> getEvaluation(
140141
if (flag == null) {
141142
throw new FlagNotFoundError("flag " + key + " not found");
142143
}
144+
if (flag.isDisabled()) {
145+
return ProviderEvaluation.<T>builder()
146+
.reason(Reason.DISABLED.name())
147+
.value(defaultValue)
148+
.flagMetadata(flag.getFlagMetadata())
149+
.build();
150+
}
143151
T value;
144152
Reason reason = Reason.STATIC;
145153
if (flag.getContextEvaluator() != null) {

src/test/java/dev/openfeature/sdk/e2e/GherkinSpecTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
1717
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.sdk.e2e.steps")
1818
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
19-
@ExcludeTags({"deprecated", "reason-codes", "async", "immutability", "evaluation-options"})
19+
@ExcludeTags({"deprecated", "reason-codes-cached", "async", "immutability", "evaluation-options"})
2020
public class GherkinSpecTest {}

src/test/java/dev/openfeature/sdk/e2e/steps/FlagStepDefinitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public FlagStepDefinitions(State state) {
2424
this.state = state;
2525
}
2626

27-
@Given("a {}-flag with key {string} and a default value {string}")
27+
@Given("a {}-flag with key {string} and a fallback value {string}")
2828
public void givenAFlag(String type, String name, String defaultValue) {
2929
state.flag = new Flag(type, name, Utils.convert(defaultValue, type));
3030
}

0 commit comments

Comments
 (0)