1
1
package dev .openfeature .contrib .providers .flipt ;
2
2
3
- import com .flipt .api .FliptApiClient ;
4
- import com .flipt .api .FliptApiClientBuilder ;
5
- import com .flipt .api .core .Environment ;
3
+ import io .flipt .api .FliptClient ;
4
+ import io .flipt .api .FliptClient .FliptClientBuilder ;
6
5
import com .github .tomakehurst .wiremock .client .WireMock ;
7
6
import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
8
7
import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
@@ -71,22 +70,22 @@ public void shutdown() {
71
70
72
71
private void mockFliptAPI (String url , String resourceName , String flagKey ) {
73
72
stubFor (
74
- post (urlEqualTo (url ))
75
- .withHeader ("Content-Type" , equalTo ("application/json" ))
76
- .withRequestBody (WireMock .containing (flagKey ))
77
- .willReturn (
78
- aResponse ()
79
- .withStatus (200 )
80
- .withHeader ("Content-Type" , "application/json" )
81
- .withBody (readResourceFileContent (resourceName ))));
73
+ post (urlEqualTo (url ))
74
+ .withHeader ("Content-Type" , equalTo ("application/json" ))
75
+ .withRequestBody (WireMock .containing (flagKey ))
76
+ .willReturn (
77
+ aResponse ()
78
+ .withStatus (200 )
79
+ .withHeader ("Content-Type" , "application/json" )
80
+ .withBody (readResourceFileContent (resourceName ))));
82
81
}
83
82
84
83
@ SneakyThrows
85
84
private FliptProvider buildFliptProvider () {
86
- FliptApiClientBuilder fliptApiClientBuilder = FliptApiClient .builder ().url (apiUrl ). environment ( Environment . custom ( apiUrl ) );
85
+ FliptClientBuilder fliptApiClientBuilder = FliptClient .builder ().url (apiUrl );
87
86
FliptProviderConfig fliptProviderConfig = FliptProviderConfig .builder ()
88
- . fliptApiClientBuilder (fliptApiClientBuilder )
89
- .build ();
87
+ . fliptClientBuilder (fliptApiClientBuilder )
88
+ .build ();
90
89
return new FliptProvider (fliptProviderConfig );
91
90
}
92
91
@@ -112,7 +111,7 @@ void getStringVariantEvaluation() {
112
111
MutableContext evaluationContext = new MutableContext ();
113
112
evaluationContext .setTargetingKey (TARGETING_KEY );
114
113
assertEquals (VARIANT_FLAG_VALUE , fliptProvider .getStringEvaluation (VARIANT_FLAG_NAME , "" ,
115
- evaluationContext ).getValue ());
114
+ evaluationContext ).getValue ());
116
115
assertEquals (VARIANT_FLAG_VALUE , client .getStringValue (VARIANT_FLAG_NAME , "" , evaluationContext ));
117
116
assertEquals ("fallback_str" , client .getStringValue ("non-existing" , "fallback_str" , evaluationContext ));
118
117
}
@@ -124,7 +123,7 @@ void getIntegerEvaluation() {
124
123
evaluationContext .setTargetingKey (TARGETING_KEY );
125
124
evaluationContext .add ("userId" , "int" );
126
125
assertEquals (INT_FLAG_VALUE , fliptProvider .getIntegerEvaluation (INT_FLAG_NAME , 1 ,
127
- evaluationContext ).getValue ());
126
+ evaluationContext ).getValue ());
128
127
assertEquals (INT_FLAG_VALUE , client .getIntegerValue (INT_FLAG_NAME , 1 , evaluationContext ));
129
128
assertEquals (1 , client .getIntegerValue ("non-existing" , 1 , evaluationContext ));
130
129
@@ -139,7 +138,7 @@ void getDoubleEvaluation() {
139
138
evaluationContext .setTargetingKey (TARGETING_KEY );
140
139
evaluationContext .add ("userId" , "double" );
141
140
assertEquals (DOUBLE_FLAG_VALUE , fliptProvider .getDoubleEvaluation (DOUBLE_FLAG_NAME , 1.1 ,
142
- evaluationContext ).getValue ());
141
+ evaluationContext ).getValue ());
143
142
assertEquals (DOUBLE_FLAG_VALUE , client .getDoubleValue (DOUBLE_FLAG_NAME , 1.1 , evaluationContext ));
144
143
assertEquals (1.1 , client .getDoubleValue ("non-existing" , 1.1 , evaluationContext ));
145
144
@@ -153,7 +152,8 @@ void getStringEvaluationByUser() {
153
152
MutableContext evaluationContext = new MutableContext ();
154
153
evaluationContext .setTargetingKey (TARGETING_KEY );
155
154
evaluationContext .add ("userId" , "111" );
156
- assertEquals (VARIANT_FLAG_VALUE , fliptProvider .getStringEvaluation (USERS_FLAG_NAME , "" , evaluationContext ).getValue ());
155
+ assertEquals (VARIANT_FLAG_VALUE ,
156
+ fliptProvider .getStringEvaluation (USERS_FLAG_NAME , "" , evaluationContext ).getValue ());
157
157
assertEquals (VARIANT_FLAG_VALUE , client .getStringValue (USERS_FLAG_NAME , "" , evaluationContext ));
158
158
evaluationContext .add ("userId" , "2" );
159
159
assertEquals ("" , client .getStringValue (USERS_FLAG_NAME , "" , evaluationContext ));
@@ -165,10 +165,11 @@ void getEvaluationMetadataTest() {
165
165
MutableContext evaluationContext = new MutableContext ();
166
166
evaluationContext .setTargetingKey (TARGETING_KEY );
167
167
ProviderEvaluation <String > stringEvaluation = fliptProvider .getStringEvaluation (VARIANT_FLAG_NAME , "" ,
168
- evaluationContext );
168
+ evaluationContext );
169
169
ImmutableMetadata flagMetadata = stringEvaluation .getFlagMetadata ();
170
170
assertEquals ("attachment-1" , flagMetadata .getString ("variant-attachment" ));
171
- FlagEvaluationDetails <String > nonExistingFlagEvaluation = client .getStringDetails ("non-existing" , "" , evaluationContext );
171
+ FlagEvaluationDetails <String > nonExistingFlagEvaluation = client .getStringDetails ("non-existing" , "" ,
172
+ evaluationContext );
172
173
assertEquals (null , nonExistingFlagEvaluation .getFlagMetadata ().getBoolean ("variant-attachment" ));
173
174
}
174
175
@@ -179,11 +180,13 @@ void shouldThrowIfNotInitialized() {
179
180
assertEquals (ProviderState .NOT_READY , asyncInitfliptProvider .getState ());
180
181
181
182
// ErrorCode.PROVIDER_NOT_READY should be returned when evaluated via the client
182
- assertThrows (ProviderNotReadyError .class , ()-> asyncInitfliptProvider .getBooleanEvaluation ("fail_not_initialized" , false , new ImmutableContext ()));
183
- assertThrows (ProviderNotReadyError .class , ()-> asyncInitfliptProvider .getStringEvaluation ("fail_not_initialized" , "" , new ImmutableContext ()));
183
+ assertThrows (ProviderNotReadyError .class , () -> asyncInitfliptProvider
184
+ .getBooleanEvaluation ("fail_not_initialized" , false , new ImmutableContext ()));
185
+ assertThrows (ProviderNotReadyError .class ,
186
+ () -> asyncInitfliptProvider .getStringEvaluation ("fail_not_initialized" , "" , new ImmutableContext ()));
184
187
185
188
asyncInitfliptProvider .initialize (null );
186
- assertThrows (GeneralError .class , ()-> asyncInitfliptProvider .initialize (null ));
189
+ assertThrows (GeneralError .class , () -> asyncInitfliptProvider .initialize (null ));
187
190
188
191
asyncInitfliptProvider .shutdown ();
189
192
}
@@ -197,8 +200,10 @@ void shouldThrowIfErrorEvent() {
197
200
asyncInitfliptProvider .emitProviderError (ProviderEventDetails .builder ().build ());
198
201
199
202
// ErrorCode.PROVIDER_NOT_READY should be returned when evaluated via the client
200
- assertThrows (GeneralError .class , ()-> asyncInitfliptProvider .getBooleanEvaluation ("fail" , false , new ImmutableContext ()));
201
- assertThrows (GeneralError .class , ()-> asyncInitfliptProvider .getStringEvaluation ("fail" , "" , new ImmutableContext ()));
203
+ assertThrows (GeneralError .class ,
204
+ () -> asyncInitfliptProvider .getBooleanEvaluation ("fail" , false , new ImmutableContext ()));
205
+ assertThrows (GeneralError .class ,
206
+ () -> asyncInitfliptProvider .getStringEvaluation ("fail" , "" , new ImmutableContext ()));
202
207
203
208
asyncInitfliptProvider .shutdown ();
204
209
}
0 commit comments