From 5d262470e8ec47d2af35f0aabe55e8c969e992ac Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Fri, 9 Sep 2022 11:27:29 -0400 Subject: [PATCH] feat!: use value for object resolver Signed-off-by: Todd Baert --- .../dev/openfeature/javasdk/FeatureProvider.java | 2 +- .../java/dev/openfeature/javasdk/Features.java | 12 ++++++------ .../java/dev/openfeature/javasdk/NoOpProvider.java | 4 ++-- .../dev/openfeature/javasdk/OpenFeatureClient.java | 14 +++++++------- src/main/java/dev/openfeature/javasdk/Value.java | 2 +- .../openfeature/javasdk/AlwaysBrokenProvider.java | 2 +- .../openfeature/javasdk/DoSomethingProvider.java | 4 ++-- .../javasdk/FlagEvaluationSpecTest.java | 6 +++--- .../dev/openfeature/javasdk/NoOpProviderTest.java | 6 +++--- .../dev/openfeature/javasdk/ProviderSpecTest.java | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/dev/openfeature/javasdk/FeatureProvider.java b/src/main/java/dev/openfeature/javasdk/FeatureProvider.java index f67942143..0938185ed 100644 --- a/src/main/java/dev/openfeature/javasdk/FeatureProvider.java +++ b/src/main/java/dev/openfeature/javasdk/FeatureProvider.java @@ -21,5 +21,5 @@ default List getProviderHooks() { ProviderEvaluation getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx); - ProviderEvaluation getObjectEvaluation(String key, Structure defaultValue, EvaluationContext ctx); + ProviderEvaluation getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx); } diff --git a/src/main/java/dev/openfeature/javasdk/Features.java b/src/main/java/dev/openfeature/javasdk/Features.java index 61a1d3905..79bd403f3 100644 --- a/src/main/java/dev/openfeature/javasdk/Features.java +++ b/src/main/java/dev/openfeature/javasdk/Features.java @@ -57,19 +57,19 @@ FlagEvaluationDetails getIntegerDetails(String key, Integer defaultValu FlagEvaluationDetails getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options); - Structure getObjectValue(String key, Structure defaultValue); + Value getObjectValue(String key, Value defaultValue); - Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx); + Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx); - Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx, + Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options); - FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue); + FlagEvaluationDetails getObjectDetails(String key, Value defaultValue); - FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue, + FlagEvaluationDetails getObjectDetails(String key, Value defaultValue, EvaluationContext ctx); - FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue, + FlagEvaluationDetails getObjectDetails(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options); } diff --git a/src/main/java/dev/openfeature/javasdk/NoOpProvider.java b/src/main/java/dev/openfeature/javasdk/NoOpProvider.java index 35818a7ae..ad3c1c989 100644 --- a/src/main/java/dev/openfeature/javasdk/NoOpProvider.java +++ b/src/main/java/dev/openfeature/javasdk/NoOpProvider.java @@ -57,9 +57,9 @@ public ProviderEvaluation getDoubleEvaluation(String key, Double default } @Override - public ProviderEvaluation getObjectEvaluation(String key, Structure defaultValue, + public ProviderEvaluation getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) { - return ProviderEvaluation.builder() + return ProviderEvaluation.builder() .value(defaultValue) .variant(PASSED_IN_DEFAULT) .reason(Reason.DEFAULT) diff --git a/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java b/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java index 6b8d7f2b5..44c433966 100644 --- a/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java +++ b/src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java @@ -122,7 +122,7 @@ private ProviderEvaluation createProviderEvaluation( case DOUBLE: return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext); case OBJECT: - return provider.getObjectEvaluation(key, (Structure) defaultValue, invocationContext); + return provider.getObjectEvaluation(key, (Value) defaultValue, invocationContext); default: throw new GeneralError("Unknown flag type"); } @@ -257,34 +257,34 @@ public FlagEvaluationDetails getDoubleDetails(String key, Double default } @Override - public Structure getObjectValue(String key, Structure defaultValue) { + public Value getObjectValue(String key, Value defaultValue) { return getObjectDetails(key, defaultValue).getValue(); } @Override - public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx) { + public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx) { return getObjectDetails(key, defaultValue, ctx).getValue(); } @Override - public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx, + public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) { return getObjectDetails(key, defaultValue, ctx, options).getValue(); } @Override - public FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue) { + public FlagEvaluationDetails getObjectDetails(String key, Value defaultValue) { return getObjectDetails(key, defaultValue, null); } @Override - public FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue, + public FlagEvaluationDetails getObjectDetails(String key, Value defaultValue, EvaluationContext ctx) { return getObjectDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build()); } @Override - public FlagEvaluationDetails getObjectDetails(String key, Structure defaultValue, EvaluationContext ctx, + public FlagEvaluationDetails getObjectDetails(String key, Value defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) { return this.evaluateFlag(FlagValueType.OBJECT, key, defaultValue, ctx, options); } diff --git a/src/main/java/dev/openfeature/javasdk/Value.java b/src/main/java/dev/openfeature/javasdk/Value.java index 88ada5e29..1c55abc2d 100644 --- a/src/main/java/dev/openfeature/javasdk/Value.java +++ b/src/main/java/dev/openfeature/javasdk/Value.java @@ -7,7 +7,7 @@ import lombok.ToString; /** - * Values serve as a return type for provider objects. + * Values serve as a generic return type for structure data from providers. * Providers may deal in JSON, protobuf, XML or some other data-interchange format. * This intermediate representation provides a good medium of exchange. */ diff --git a/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java b/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java index cd172afc7..f69a14009 100644 --- a/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java +++ b/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java @@ -33,7 +33,7 @@ public ProviderEvaluation getDoubleEvaluation(String key, Double default } @Override - public ProviderEvaluation getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) { + public ProviderEvaluation getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) { throw new NotImplementedException("BORK"); } } diff --git a/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java b/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java index 91600e09b..1fd6d9dc2 100644 --- a/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java +++ b/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java @@ -44,9 +44,9 @@ public ProviderEvaluation getDoubleEvaluation(String key, Double default } @Override - public ProviderEvaluation getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) { + public ProviderEvaluation getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) { savedContext = invocationContext; - return ProviderEvaluation.builder() + return ProviderEvaluation.builder() .value(null) .build(); } diff --git a/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java b/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java index de58b4f01..2efeec12d 100644 --- a/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java +++ b/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTest.java @@ -115,9 +115,9 @@ private Client _client() { assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext())); assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext(), FlagEvaluationOptions.builder().build())); - assertEquals(null, c.getObjectValue(key, new Structure())); - assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext())); - assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext(), FlagEvaluationOptions.builder().build())); + assertEquals(null, c.getObjectValue(key, new Value())); + assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext())); + assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext(), FlagEvaluationOptions.builder().build())); } @Specification(number="1.4.1", text="The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns an evaluation details structure.") diff --git a/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java b/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java index 4a45860c8..0853a2956 100644 --- a/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java +++ b/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java @@ -30,10 +30,10 @@ public class NoOpProviderTest { assertEquals(0.4, eval.getValue()); } - @Test void structure() { + @Test void value() { NoOpProvider p = new NoOpProvider(); - Structure s = new Structure(); - ProviderEvaluation eval = p.getObjectEvaluation("key", s, null); + Value s = new Value(); + ProviderEvaluation eval = p.getObjectEvaluation("key", s, null); assertEquals(s, eval.getValue()); } } diff --git a/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java b/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java index 9151badf3..b5d0c5876 100644 --- a/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java +++ b/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java @@ -36,7 +36,7 @@ public class ProviderSpecTest { ProviderEvaluation boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext()); assertNotNull(boolean_result.getValue()); - ProviderEvaluation object_result = p.getObjectEvaluation("key", new Structure(), new EvaluationContext()); + ProviderEvaluation object_result = p.getObjectEvaluation("key", new Value(), new EvaluationContext()); assertNotNull(object_result.getValue()); }