Skip to content

Commit d0c6222

Browse files
committed
chore: recommit changes without submodule updates
Signed-off-by: Mark Phelps <[email protected]>
1 parent cd7a61a commit d0c6222

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

providers/flipt/src/main/java/dev/openfeature/contrib/providers/flipt/FliptProvider.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
123123

124124
@Override
125125
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx) {
126-
ProviderEvaluation<Value> valueProviderEvaluation = getObjectEvaluation(key, new Value(defaultValue), ctx);
126+
ProviderEvaluation<Value> valueProviderEvaluation =
127+
evaluateVariant(String.class, key, new Value(defaultValue), ctx);
127128
return ProviderEvaluation.<String>builder()
128129
.value(valueProviderEvaluation.getValue().asString())
129130
.variant(valueProviderEvaluation.getVariant())
@@ -135,7 +136,8 @@ public ProviderEvaluation<String> getStringEvaluation(String key, String default
135136

136137
@Override
137138
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx) {
138-
ProviderEvaluation<Value> valueProviderEvaluation = getObjectEvaluation(key, new Value(defaultValue), ctx);
139+
ProviderEvaluation<Value> valueProviderEvaluation =
140+
evaluateVariant(Integer.class, key, new Value(defaultValue), ctx);
139141
Integer value = getIntegerValue(valueProviderEvaluation, defaultValue);
140142
return ProviderEvaluation.<Integer>builder()
141143
.value(value)
@@ -157,7 +159,8 @@ private static Integer getIntegerValue(ProviderEvaluation<Value> valueProviderEv
157159

158160
@Override
159161
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx) {
160-
ProviderEvaluation<Value> valueProviderEvaluation = getObjectEvaluation(key, new Value(defaultValue), ctx);
162+
ProviderEvaluation<Value> valueProviderEvaluation =
163+
evaluateVariant(Double.class, key, new Value(defaultValue), ctx);
161164
Double value = getDoubleValue(valueProviderEvaluation, defaultValue);
162165
return ProviderEvaluation.<Double>builder()
163166
.value(value)
@@ -179,12 +182,18 @@ private static Double getDoubleValue(ProviderEvaluation<Value> valueProviderEval
179182

180183
@Override
181184
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx) {
185+
return evaluateVariant(Value.class, key, defaultValue, ctx);
186+
}
187+
188+
private <T> ProviderEvaluation<Value> evaluateVariant(Class<T> clazz, String key, Value defaultValue,
189+
EvaluationContext ctx) {
182190
if (!ProviderState.READY.equals(state)) {
183191
if (ProviderState.NOT_READY.equals(state)) {
184192
throw new ProviderNotReadyError(PROVIDER_NOT_YET_INITIALIZED);
185193
}
186194
throw new GeneralError(UNKNOWN_ERROR);
187195
}
196+
188197
Map<String, String> contextMap = ContextTransformer.transform(ctx);
189198
EvaluationRequest request = EvaluationRequest.builder().namespaceKey(fliptProviderConfig.getNamespace())
190199
.flagKey(key).entityId(ctx.getTargetingKey()).context(contextMap).build();
@@ -209,7 +218,10 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
209218
ImmutableMetadata.ImmutableMetadataBuilder flagMetadataBuilder = ImmutableMetadata.builder();
210219
if (response.getVariantAttachment() != null && !response.getVariantAttachment().isEmpty()) {
211220
flagMetadataBuilder.addString("variant-attachment", response.getVariantAttachment());
212-
value = new Value(response.getVariantAttachment());
221+
222+
if (clazz.isAssignableFrom(Value.class)) {
223+
value = new Value(response.getVariantAttachment());
224+
}
213225
}
214226

215227
return ProviderEvaluation.<Value>builder()

providers/flipt/src/test/java/dev/openfeature/contrib/providers/flipt/FliptProviderTest.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
import com.github.tomakehurst.wiremock.client.WireMock;
66
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
77
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
8+
import dev.openfeature.sdk.Client;
9+
import dev.openfeature.sdk.FlagEvaluationDetails;
10+
import dev.openfeature.sdk.ImmutableContext;
11+
import dev.openfeature.sdk.ImmutableMetadata;
12+
import dev.openfeature.sdk.MutableContext;
13+
import dev.openfeature.sdk.OpenFeatureAPI;
14+
import dev.openfeature.sdk.ProviderEvaluation;
15+
import dev.openfeature.sdk.ProviderEventDetails;
16+
import dev.openfeature.sdk.ProviderState;
17+
import dev.openfeature.sdk.Value;
818
import dev.openfeature.sdk.exceptions.GeneralError;
919
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
1020
import lombok.SneakyThrows;
@@ -16,8 +26,6 @@
1626
import java.net.URL;
1727
import java.nio.file.Files;
1828
import java.nio.file.Paths;
19-
import java.util.HashMap;
20-
import java.util.Map;
2129

2230
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
2331
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -46,7 +54,6 @@ class FliptProviderTest {
4654

4755
private static FliptProvider fliptProvider;
4856
private static Client client;
49-
5057
private String apiUrl;
5158

5259
@BeforeAll
@@ -167,6 +174,24 @@ void getEvaluationMetadataTest() {
167174
assertNull(nonExistingFlagEvaluation.getFlagMetadata().getBoolean("variant-attachment"));
168175
}
169176

177+
@SneakyThrows
178+
@Test
179+
void getObjectEvaluationTest() {
180+
mockFliptAPI("/evaluate/v1/variant", "variant-object.json", OBJECT_FLAG_NAME);
181+
MutableContext evaluationContext = new MutableContext();
182+
evaluationContext.setTargetingKey(TARGETING_KEY);
183+
evaluationContext.add("userId", "object");
184+
185+
Value expectedValue = new Value("{\"key1\":\"value1\",\"key2\":42,\"key3\":true}");
186+
Value emptyValue = new Value();
187+
188+
assertEquals(expectedValue, client.getObjectValue(OBJECT_FLAG_NAME, emptyValue, evaluationContext));
189+
assertEquals(emptyValue, client.getObjectValue("non-existing", emptyValue, evaluationContext));
190+
191+
// non-object flag value
192+
assertEquals(emptyValue, client.getObjectValue(VARIANT_FLAG_NAME, emptyValue, evaluationContext));
193+
}
194+
170195
@SneakyThrows
171196
@Test
172197
void shouldThrowIfNotInitialized() {

0 commit comments

Comments
 (0)