Skip to content

feat!: update sdk, absorb changes #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<!-- provided -->
<groupId>dev.openfeature</groupId>
<artifactId>javasdk</artifactId>
<!-- 0.1.0 or greater -->
<version>[0.1,)</version>
<!-- 0.2.0 or greater -->
<version>[0.2,)</version>
<!-- use the version provided at runtime -->
<scope>provided</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
}

@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue,
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
EvaluationContext ctx) {
ResolveObjectRequest request = ResolveObjectRequest.newBuilder()
.setFlagKey(key)
.setContext(this.convertContext(ctx))
.build();
ResolveObjectResponse r = this.serviceStub.resolveObject(request);
return ProviderEvaluation.<Structure>builder()
return ProviderEvaluation.<Value>builder()
.value(this.convertObjectResponse(r.getValue()))
.variant(r.getVariant())
.reason(this.mapReason(r.getReason()))
Expand All @@ -174,10 +174,10 @@ private Reason mapReason(String flagDreason) {
}

/**
* Recursively convert protobuf structure to openfeature structure.
* Recursively convert protobuf structure to openfeature value.
*/
private Structure convertObjectResponse(com.google.protobuf.Struct protobuf) {
return new Structure(this.convertProtobufMap(protobuf.getFieldsMap()).asStructure().asMap());
private Value convertObjectResponse(com.google.protobuf.Struct protobuf) {
return this.convertProtobufMap(protobuf.getFieldsMap());
}

/**
Expand Down Expand Up @@ -268,9 +268,7 @@ private com.google.protobuf.Value convertPrimitive(Value value) {
builder.setBoolValue(value.asBoolean());
} else if (value.isString()) {
builder.setStringValue(value.asString());
} else if (value.isInteger()) {
builder.setNumberValue(Double.valueOf(value.asInteger()));
} else if (value.isDouble()) {
} else if (value.isNumber()) {
builder.setNumberValue(value.asDouble());
} else {
builder.setNullValue(null);
Expand All @@ -290,7 +288,7 @@ private Value convertPrimitive(com.google.protobuf.Value protobuf) {
} else if (protobuf.hasNumberValue()) {
value = new Value(protobuf.getNumberValue());
} else {
value = new Value((Boolean) null);
value = new Value();
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ void resolvers_call_grpc_service_and_return_details() {
assertEquals(DOUBLE_VARIANT, floatDetails.getVariant());
assertEquals(DEFAULT, floatDetails.getReason());

FlagEvaluationDetails<Structure> objectDetails = api.getClient().getObjectDetails(FLAG_KEY, new Structure());
assertEquals(INNER_STRUCT_VALUE, objectDetails.getValue().asMap().get(INNER_STRUCT_KEY).asString());
FlagEvaluationDetails<Value> objectDetails = api.getClient().getObjectDetails(FLAG_KEY, new Value());
assertEquals(INNER_STRUCT_VALUE, objectDetails.getValue().asStructure()
.asMap().get(INNER_STRUCT_KEY).asString());
assertEquals(OBJECT_VARIANT, objectDetails.getVariant());
assertEquals(DEFAULT, objectDetails.getReason());
}
Expand Down Expand Up @@ -196,7 +197,8 @@ void reason_mapped_correctly_if_unknown() {

OpenFeatureAPI.getInstance().setProvider(new FlagdProvider(serviceBlockingStubMock));

FlagEvaluationDetails<Boolean> booleanDetails = api.getClient().getBooleanDetails(FLAG_KEY, false, new EvaluationContext());
FlagEvaluationDetails<Boolean> booleanDetails = api.getClient()
.getBooleanDetails(FLAG_KEY, false, new EvaluationContext());
assertEquals(Reason.UNKNOWN, booleanDetails.getReason()); // reason should be converted to UNKNOWN
}
}