Skip to content

feat: Adopt ConfigCat v9 #644

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 2 commits into from
Jan 22, 2024
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 providers/configcat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>configcat</artifactId>
<version>0.0.2</version> <!--x-release-please-version -->
<version>0.1.0</version> <!--x-release-please-version -->

<name>configcat</name>
<description>configcat provider for Java</description>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.configcat</groupId>
<artifactId>configcat-java-client</artifactId>
<version>8.4.0</version>
<version>9.0.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ContextTransformer {

protected static User transform(EvaluationContext ctx) {
User.Builder userBuilder = User.newBuilder();
Map<String, String> customMap = new HashMap<>();
Map<String, Object> customMap = new HashMap<>();
ctx.asObjectMap().forEach((k, v) -> {
switch (k) {
case CONTEXT_COUNTRY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.openfeature.sdk.exceptions.GeneralError;
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -26,6 +27,7 @@
* ConfigCatProvider test, based on local config file evaluation.
* Configuration file test by ConfigCat tests.
*/
@Slf4j
class ConfigCatProviderTest {

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

@BeforeAll
static void setUp() {
String sdkKey = "test";
String sdkKey = "configcat-sdk-1/TEST_KEY-0123456789012/1234567890123456789012";
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey(sdkKey)
.options(options ->
options.flagOverrides(
Expand Down Expand Up @@ -182,7 +184,7 @@ void getStringEvaluationByUser() {
@SneakyThrows
@Test
void shouldThrowIfNotInitialized() {
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey("test").build();
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder().sdkKey("configcat-sdk-1/TEST_KEY-0123456789012/1234567890123456789012").build();
ConfigCatProvider tempConfigCatProvider = new ConfigCatProvider(configCatProviderConfig);

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

@SneakyThrows
Expand All @@ -223,7 +225,7 @@ void contextTransformTest() {
evaluationContext.add("Email", email);
evaluationContext.add(customPropertyKey, customPropertyValue);

HashMap<String, String > customMap = new HashMap<>();
HashMap<String, Object > customMap = new HashMap<>();
customMap.put(customPropertyKey, customPropertyValue);
User expectedUser = User.newBuilder().email(email).country(country).custom(customMap).build(userId);
User transformedUser = ContextTransformer.transform(evaluationContext);
Expand Down
203 changes: 157 additions & 46 deletions providers/configcat/src/test/resources/features.json
Original file line number Diff line number Diff line change
@@ -1,88 +1,199 @@
{
"p": {
"s": "80xCU/SlDz1lCiWFaxIBjyJeJecWjq46T4eu6GtozkM="
},
"f": {
"enabledFeature": {
"v": true
"t": 0,
"v": {
"b": true
}
},
"intSetting": {
"v": 5
"t": 2,
"v": {
"i": 5
}
},
"doubleSetting": {
"v": 3.14
"t": 3,
"v": {
"d": 3.14
}
},
"stringSetting": {
"v": "test"
"t": 1,
"v": {
"s": "test"
}
},
"userIdMatching": {
"v": false,
"t": 0,
"r": [
{
"o": 0,
"a": "Identifier",
"t": 2,
"c": "@matching.com",
"v": true
"c": [
{
"u": {
"a": "Identifier",
"c": 2,
"l": [
"@matching.com"
]
}
}
],
"s": {
"v": {
"b": true
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"b": false
},
"i": "430bded3"
},
"emailMatching": {
"v": false,
"t": 0,
"r": [
{
"o": 0,
"a": "Email",
"t": 2,
"c": "@matching.com",
"v": true
"c": [
{
"u": {
"a": "Email",
"c": 2,
"l": [
"@matching.com"
]
}
}
],
"s": {
"v": {
"b": true
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"b": false
},
"i": "430bded3"
},
"countryMatching": {
"v": false,
"t": 0,
"r": [
{
"o": 0,
"a": "Country",
"t": 2,
"c": "country1",
"v": true
"c": [
{
"u": {
"a": "Country",
"c": 2,
"l": [
"country1"
]
}
}
],
"s": {
"v": {
"b": true
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"b": false
},
"i": "430bded3"
},
"userIdMatchingInt": {
"v": 111,
"t": 2,
"r": [
{
"o": 0,
"a": "Identifier",
"t": 2,
"c": "@matching.com",
"v": 123
"c": [
{
"u": {
"a": "Identifier",
"c": 2,
"l": [
"@matching.com"
]
}
}
],
"s": {
"v": {
"i": 123
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"i": 111
},
"i": "430bded3"
},
"userIdMatchingDouble": {
"v": 0.1,
"t": 3,
"r": [
{
"o": 0,
"a": "Identifier",
"t": 2,
"c": "@matching.com",
"v": 1.23
"c": [
{
"u": {
"a": "Identifier",
"c": 2,
"l": [
"@matching.com"
]
}
}
],
"s": {
"v": {
"d": 1.23
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"d": 0.1
},
"i": "430bded3"
},
"userIdMatchingStr": {
"v": "fallback",
"t": 1,
"r": [
{
"o": 0,
"a": "Identifier",
"t": 2,
"c": "@matching.com",
"v": "expected"
"c": [
{
"u": {
"a": "Identifier",
"c": 2,
"l": [
"@matching.com"
]
}
}
],
"s": {
"v": {
"s": "expected"
},
"i": "bcfb84a7"
}
}
]
],
"v": {
"s": "fallback"
},
"i": "430bded3"
}
}
}