Skip to content

Commit 4d97c54

Browse files
authored
feat: Adopt ConfigCat v9 (#644)
Signed-off-by: liran2000 <[email protected]>
1 parent 2755b68 commit 4d97c54

File tree

4 files changed

+166
-53
lines changed

4 files changed

+166
-53
lines changed

providers/configcat/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>dev.openfeature.contrib.providers</groupId>
1212
<artifactId>configcat</artifactId>
13-
<version>0.0.2</version> <!--x-release-please-version -->
13+
<version>0.1.0</version> <!--x-release-please-version -->
1414

1515
<name>configcat</name>
1616
<description>configcat provider for Java</description>
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>com.configcat</groupId>
2222
<artifactId>configcat-java-client</artifactId>
23-
<version>8.4.0</version>
23+
<version>9.0.0</version>
2424
</dependency>
2525

2626
<dependency>

providers/configcat/src/main/java/dev/openfeature/contrib/providers/configcat/ContextTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ContextTransformer {
1616

1717
protected static User transform(EvaluationContext ctx) {
1818
User.Builder userBuilder = User.newBuilder();
19-
Map<String, String> customMap = new HashMap<>();
19+
Map<String, Object> customMap = new HashMap<>();
2020
ctx.asObjectMap().forEach((k, v) -> {
2121
switch (k) {
2222
case CONTEXT_COUNTRY:

providers/configcat/src/test/java/dev/openfeature/contrib/providers/configcat/ConfigCatProviderTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dev.openfeature.sdk.exceptions.GeneralError;
1313
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
1414
import lombok.SneakyThrows;
15+
import lombok.extern.slf4j.Slf4j;
1516
import org.junit.jupiter.api.AfterAll;
1617
import org.junit.jupiter.api.BeforeAll;
1718
import org.junit.jupiter.api.Test;
@@ -26,6 +27,7 @@
2627
* ConfigCatProvider test, based on local config file evaluation.
2728
* Configuration file test by ConfigCat tests.
2829
*/
30+
@Slf4j
2931
class ConfigCatProviderTest {
3032

3133
public static final String FLAG_NAME = "enabledFeature";
@@ -43,7 +45,7 @@ class ConfigCatProviderTest {
4345

4446
@BeforeAll
4547
static void setUp() {
46-
String sdkKey = "test";
48+
String sdkKey = "configcat-sdk-1/TEST_KEY-0123456789012/1234567890123456789012";
4749
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey(sdkKey)
4850
.options(options ->
4951
options.flagOverrides(
@@ -182,7 +184,7 @@ void getStringEvaluationByUser() {
182184
@SneakyThrows
183185
@Test
184186
void shouldThrowIfNotInitialized() {
185-
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey("test").build();
187+
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey("configcat-sdk-1/TEST_KEY-0123456789012/1234567890123456789012").build();
186188
ConfigCatProvider tempConfigCatProvider = new ConfigCatProvider(configCatProviderConfig);
187189

188190
assertThrows(ProviderNotReadyError.class, ()-> tempConfigCatProvider.getBooleanEvaluation("fail_not_initialized", false, new ImmutableContext()));
@@ -205,7 +207,7 @@ void eventsTest() {
205207
configCatProvider.emitProviderReady(ProviderEventDetails.builder().build());
206208
configCatProvider.emitProviderError(ProviderEventDetails.builder().build());
207209
configCatProvider.emitProviderConfigurationChanged(ProviderEventDetails.builder().build());
208-
assertDoesNotThrow(() -> {configCatProvider.getState();});
210+
assertDoesNotThrow(() -> log.debug("provider state: {}", configCatProvider.getState()));
209211
}
210212

211213
@SneakyThrows
@@ -223,7 +225,7 @@ void contextTransformTest() {
223225
evaluationContext.add("Email", email);
224226
evaluationContext.add(customPropertyKey, customPropertyValue);
225227

226-
HashMap<String, String > customMap = new HashMap<>();
228+
HashMap<String, Object > customMap = new HashMap<>();
227229
customMap.put(customPropertyKey, customPropertyValue);
228230
User expectedUser = User.newBuilder().email(email).country(country).custom(customMap).build(userId);
229231
User transformedUser = ContextTransformer.transform(evaluationContext);
Lines changed: 157 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,199 @@
11
{
2+
"p": {
3+
"s": "80xCU/SlDz1lCiWFaxIBjyJeJecWjq46T4eu6GtozkM="
4+
},
25
"f": {
36
"enabledFeature": {
4-
"v": true
7+
"t": 0,
8+
"v": {
9+
"b": true
10+
}
511
},
612
"intSetting": {
7-
"v": 5
13+
"t": 2,
14+
"v": {
15+
"i": 5
16+
}
817
},
918
"doubleSetting": {
10-
"v": 3.14
19+
"t": 3,
20+
"v": {
21+
"d": 3.14
22+
}
1123
},
1224
"stringSetting": {
13-
"v": "test"
25+
"t": 1,
26+
"v": {
27+
"s": "test"
28+
}
1429
},
1530
"userIdMatching": {
16-
"v": false,
31+
"t": 0,
1732
"r": [
1833
{
19-
"o": 0,
20-
"a": "Identifier",
21-
"t": 2,
22-
"c": "@matching.com",
23-
"v": true
34+
"c": [
35+
{
36+
"u": {
37+
"a": "Identifier",
38+
"c": 2,
39+
"l": [
40+
"@matching.com"
41+
]
42+
}
43+
}
44+
],
45+
"s": {
46+
"v": {
47+
"b": true
48+
},
49+
"i": "bcfb84a7"
50+
}
2451
}
25-
]
52+
],
53+
"v": {
54+
"b": false
55+
},
56+
"i": "430bded3"
2657
},
2758
"emailMatching": {
28-
"v": false,
59+
"t": 0,
2960
"r": [
3061
{
31-
"o": 0,
32-
"a": "Email",
33-
"t": 2,
34-
"c": "@matching.com",
35-
"v": true
62+
"c": [
63+
{
64+
"u": {
65+
"a": "Email",
66+
"c": 2,
67+
"l": [
68+
"@matching.com"
69+
]
70+
}
71+
}
72+
],
73+
"s": {
74+
"v": {
75+
"b": true
76+
},
77+
"i": "bcfb84a7"
78+
}
3679
}
37-
]
80+
],
81+
"v": {
82+
"b": false
83+
},
84+
"i": "430bded3"
3885
},
3986
"countryMatching": {
40-
"v": false,
87+
"t": 0,
4188
"r": [
4289
{
43-
"o": 0,
44-
"a": "Country",
45-
"t": 2,
46-
"c": "country1",
47-
"v": true
90+
"c": [
91+
{
92+
"u": {
93+
"a": "Country",
94+
"c": 2,
95+
"l": [
96+
"country1"
97+
]
98+
}
99+
}
100+
],
101+
"s": {
102+
"v": {
103+
"b": true
104+
},
105+
"i": "bcfb84a7"
106+
}
48107
}
49-
]
108+
],
109+
"v": {
110+
"b": false
111+
},
112+
"i": "430bded3"
50113
},
51114
"userIdMatchingInt": {
52-
"v": 111,
115+
"t": 2,
53116
"r": [
54117
{
55-
"o": 0,
56-
"a": "Identifier",
57-
"t": 2,
58-
"c": "@matching.com",
59-
"v": 123
118+
"c": [
119+
{
120+
"u": {
121+
"a": "Identifier",
122+
"c": 2,
123+
"l": [
124+
"@matching.com"
125+
]
126+
}
127+
}
128+
],
129+
"s": {
130+
"v": {
131+
"i": 123
132+
},
133+
"i": "bcfb84a7"
134+
}
60135
}
61-
]
136+
],
137+
"v": {
138+
"i": 111
139+
},
140+
"i": "430bded3"
62141
},
63142
"userIdMatchingDouble": {
64-
"v": 0.1,
143+
"t": 3,
65144
"r": [
66145
{
67-
"o": 0,
68-
"a": "Identifier",
69-
"t": 2,
70-
"c": "@matching.com",
71-
"v": 1.23
146+
"c": [
147+
{
148+
"u": {
149+
"a": "Identifier",
150+
"c": 2,
151+
"l": [
152+
"@matching.com"
153+
]
154+
}
155+
}
156+
],
157+
"s": {
158+
"v": {
159+
"d": 1.23
160+
},
161+
"i": "bcfb84a7"
162+
}
72163
}
73-
]
164+
],
165+
"v": {
166+
"d": 0.1
167+
},
168+
"i": "430bded3"
74169
},
75170
"userIdMatchingStr": {
76-
"v": "fallback",
171+
"t": 1,
77172
"r": [
78173
{
79-
"o": 0,
80-
"a": "Identifier",
81-
"t": 2,
82-
"c": "@matching.com",
83-
"v": "expected"
174+
"c": [
175+
{
176+
"u": {
177+
"a": "Identifier",
178+
"c": 2,
179+
"l": [
180+
"@matching.com"
181+
]
182+
}
183+
}
184+
],
185+
"s": {
186+
"v": {
187+
"s": "expected"
188+
},
189+
"i": "bcfb84a7"
190+
}
84191
}
85-
]
192+
],
193+
"v": {
194+
"s": "fallback"
195+
},
196+
"i": "430bded3"
86197
}
87198
}
88199
}

0 commit comments

Comments
 (0)