2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
4
import static org .junit .jupiter .api .Assertions .assertTrue ;
5
+ import static org .mockito .ArgumentMatchers .any ;
5
6
import static org .mockito .ArgumentMatchers .argThat ;
6
7
import static org .mockito .Mockito .mock ;
7
8
import static org .mockito .Mockito .when ;
12
13
import org .junit .jupiter .api .BeforeAll ;
13
14
import org .junit .jupiter .api .Test ;
14
15
16
+ import dev .openfeature .flagd .grpc .Schema .ResolveBooleanRequest ;
15
17
import dev .openfeature .flagd .grpc .Schema .ResolveBooleanResponse ;
16
18
import dev .openfeature .flagd .grpc .Schema .ResolveFloatResponse ;
17
19
import dev .openfeature .flagd .grpc .Schema .ResolveIntResponse ;
@@ -145,11 +147,12 @@ void context_is_parsed_and_passed_to_grpc_service() {
145
147
}};
146
148
final String STRUCT_ATTR_INNER_VALUE = "struct-inner-value" ;
147
149
final Structure STRUCT_ATTR_VALUE = new Structure ().add (STRUCT_ATTR_INNER_KEY , STRUCT_ATTR_INNER_VALUE );
150
+ final String STATIC = "STATIC" ;
148
151
149
152
ResolveBooleanResponse booleanResponse = ResolveBooleanResponse .newBuilder ()
150
153
.setValue (true )
151
154
.setVariant (BOOL_VARIANT )
152
- .setReason (DEFAULT .toString ())
155
+ .setReason (STATIC .toString ())
153
156
.build ();
154
157
155
158
ServiceBlockingStub serviceBlockingStubMock = mock (ServiceBlockingStub .class );
@@ -177,6 +180,23 @@ void context_is_parsed_and_passed_to_grpc_service() {
177
180
FlagEvaluationDetails <Boolean > booleanDetails = api .getClient ().getBooleanDetails (FLAG_KEY , false , context );
178
181
assertTrue (booleanDetails .getValue ());
179
182
assertEquals (BOOL_VARIANT , booleanDetails .getVariant ());
180
- assertEquals (DEFAULT , booleanDetails .getReason ());
183
+ assertEquals (DEFAULT , booleanDetails .getReason ()); // reason should be converted from STATIC -> DEFAULT
184
+ }
185
+
186
+ @ Test
187
+ void reason_mapped_correctly_if_unknown () {
188
+ ResolveBooleanResponse badReasonResponse = ResolveBooleanResponse .newBuilder ()
189
+ .setValue (true )
190
+ .setVariant (BOOL_VARIANT )
191
+ .setReason ("NOT_A_REAL_REASON" ) // set an invalid reason string
192
+ .build ();
193
+
194
+ ServiceBlockingStub serviceBlockingStubMock = mock (ServiceBlockingStub .class );
195
+ when (serviceBlockingStubMock .resolveBoolean (any (ResolveBooleanRequest .class ))).thenReturn (badReasonResponse );
196
+
197
+ OpenFeatureAPI .getInstance ().setProvider (new FlagdProvider (serviceBlockingStubMock ));
198
+
199
+ FlagEvaluationDetails <Boolean > booleanDetails = api .getClient ().getBooleanDetails (FLAG_KEY , false , new EvaluationContext ());
200
+ assertEquals (Reason .UNKNOWN , booleanDetails .getReason ()); // reason should be converted to UNKNOWN
181
201
}
182
202
}
0 commit comments