├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── java-ci.yml │ └── stale.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── DEPLOY.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── media └── readme02-3.png ├── samples ├── console │ ├── README.md │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── resources │ │ └── simplelogger.properties └── web │ ├── README.md │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ └── main │ ├── java │ └── websample │ │ ├── AppConfiguration.java │ │ ├── Application.java │ │ └── ConfigController.java │ └── resources │ ├── logback.xml │ └── static │ ├── images │ └── mgmt_console_v2.png │ └── index.html ├── settings.gradle └── src ├── main └── java │ └── com │ └── configcat │ ├── AutoPollingMode.java │ ├── ClientCacheState.java │ ├── Condition.java │ ├── ConditionAccessor.java │ ├── Config.java │ ├── ConfigCache.java │ ├── ConfigCatClient.java │ ├── ConfigCatHooks.java │ ├── ConfigCatLogMessages.java │ ├── ConfigCatLogger.java │ ├── ConfigFetcher.java │ ├── ConfigService.java │ ├── ConfigurationProvider.java │ ├── Constants.java │ ├── DataGovernance.java │ ├── DateTimeUtils.java │ ├── Entry.java │ ├── EvaluateLogger.java │ ├── EvaluationContext.java │ ├── EvaluationDetails.java │ ├── EvaluationResult.java │ ├── FetchResponse.java │ ├── FormattableLogMessage.java │ ├── FormattableLogMessageWithKeySet.java │ ├── FormattableLogMessageWithUserCondition.java │ ├── LazyLoadingMode.java │ ├── LocalFileDataSource.java │ ├── LocalMapDataSource.java │ ├── LogFilterFunction.java │ ├── LogLevel.java │ ├── ManualPollingMode.java │ ├── NullConfigCache.java │ ├── OverrideBehaviour.java │ ├── OverrideDataSource.java │ ├── OverrideDataSourceBuilder.java │ ├── PercentageOption.java │ ├── PollingMode.java │ ├── PollingModes.java │ ├── Preferences.java │ ├── PrerequisiteComparator.java │ ├── PrerequisiteFlagCondition.java │ ├── RefreshResult.java │ ├── Result.java │ ├── RolloutEvaluator.java │ ├── Segment.java │ ├── SegmentComparator.java │ ├── SegmentCondition.java │ ├── Setting.java │ ├── SettingResult.java │ ├── SettingType.java │ ├── SettingValue.java │ ├── TargetingRule.java │ ├── User.java │ ├── UserAttributeConverter.java │ ├── UserComparator.java │ ├── UserCondition.java │ └── Utils.java └── test ├── java └── com │ └── configcat │ ├── AutoPollingTest.java │ ├── ConfigCatClientIntegrationTest.java │ ├── ConfigCatClientTest.java │ ├── ConfigFetcherTest.java │ ├── ConfigV2EvaluationTest.java │ ├── DataGovernanceTest.java │ ├── EntrySerializationTest.java │ ├── EvaluationLoggerTurnOffTest.java │ ├── EvaluationTest.java │ ├── EvaluatorTrimTest.java │ ├── FailingCache.java │ ├── FormattableLogMessageTests.java │ ├── Helpers.java │ ├── InMemoryCache.java │ ├── LazyLoadingTest.java │ ├── LocalTests.java │ ├── LoggerTests.java │ ├── ManualPollingTest.java │ ├── RolloutIntegrationTests.java │ ├── SingleValueCache.java │ ├── UserAttributeConvertTest.java │ ├── UserTests.java │ └── VariationIdTests.java └── resources ├── comparison_attribute_conversion.json ├── evaluation ├── 1_targeting_rule.json ├── 1_targeting_rule │ ├── 1_rule_matching_targeted_attribute.txt │ ├── 1_rule_no_targeted_attribute.txt │ ├── 1_rule_no_user.txt │ └── 1_rule_not_matching_targeted_attribute.txt ├── 2_targeting_rules.json ├── 2_targeting_rules │ ├── 2_rules_matching_targeted_attribute.txt │ ├── 2_rules_no_targeted_attribute.txt │ ├── 2_rules_no_user.txt │ └── 2_rules_not_matching_targeted_attribute.txt ├── and_rules.json ├── and_rules │ ├── and_rules_no_user.txt │ └── and_rules_user.txt ├── comparators.json ├── comparators │ └── allinone.txt ├── epoch_date_validation.json ├── epoch_date_validation │ └── date_error.txt ├── list_truncation.json ├── list_truncation │ ├── list_truncation.txt │ └── test_list_truncation.json ├── number_validation.json ├── number_validation │ └── number_error.txt ├── options_after_targeting_rule.json ├── options_after_targeting_rule │ ├── options_after_targeting_rule_matching_targeted_attribute.txt │ ├── options_after_targeting_rule_no_targeted_attribute.txt │ ├── options_after_targeting_rule_no_user.txt │ └── options_after_targeting_rule_not_matching_targeted_attribute.txt ├── options_based_on_custom_attr.json ├── options_based_on_custom_attr │ ├── matching_options_custom_attribute.txt │ ├── no_options_custom_attribute.txt │ └── options_custom_attribute_no_user.txt ├── options_based_on_user_id.json ├── options_based_on_user_id │ ├── options_user_attribute_no_user.txt │ └── options_user_attribute_user.txt ├── options_within_targeting_rule.json ├── options_within_targeting_rule │ ├── options_within_targeting_rule_matching_targeted_attribute_no_options_attribute.txt │ ├── options_within_targeting_rule_matching_targeted_attribute_options_attribute.txt │ ├── options_within_targeting_rule_no_targeted_attribute.txt │ ├── options_within_targeting_rule_no_user.txt │ └── options_within_targeting_rule_not_matching_targeted_attribute.txt ├── prerequisite_flag.json ├── prerequisite_flag │ ├── prerequisite_flag.txt │ ├── prerequisite_flag_multilevel.txt │ ├── prerequisite_flag_no_user_needed_by_both.txt │ ├── prerequisite_flag_no_user_needed_by_dep.txt │ └── prerequisite_flag_no_user_needed_by_prereq.txt ├── segment.json ├── segment │ ├── segment_matching.txt │ ├── segment_no_matching.txt │ ├── segment_no_targeted_attribute.txt │ ├── segment_no_user.txt │ └── segment_no_user_multi_conditions.txt ├── semver_validation.json ├── semver_validation │ ├── semver_error.txt │ └── semver_relations_error.txt ├── simple_value.json └── simple_value │ ├── double_setting.txt │ ├── int_setting.txt │ ├── off_flag.txt │ ├── on_flag.txt │ └── text_setting.txt ├── matirx ├── testmatrix.csv ├── testmatrix_and_or.csv ├── testmatrix_comparators_v6.csv ├── testmatrix_number.csv ├── testmatrix_prerequisite_flag.csv ├── testmatrix_segment.csv ├── testmatrix_segments_old.csv ├── testmatrix_semantic.csv ├── testmatrix_semantic_2.csv ├── testmatrix_sensitive.csv ├── testmatrix_unicode.csv └── testmatrix_variationId.csv ├── specialCharacters.txt ├── test-simple.json ├── test.json ├── test_circulardependency.json ├── test_override_flagdependency_v6.json ├── test_override_segments_v6.json ├── trim_comparator_values.json └── trim_user_values.json /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @configcat/developers 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | enable-beta-ecosystems: true 3 | updates: 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | -------------------------------------------------------------------------------- /.github/workflows/java-ci.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | push: 7 | branches: [ master ] 8 | tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test: 16 | runs-on: ubuntu-latest 17 | strategy: 18 | matrix: 19 | java-versions: [ 11, 17, 19 ] 20 | fail-fast: false 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Set up JDK 25 | uses: actions/setup-java@v4 26 | with: 27 | java-version: ${{ matrix.java-versions }} 28 | distribution: zulu 29 | cache: gradle 30 | 31 | - name: Grant execute permission for gradlew 32 | run: chmod +x gradlew 33 | 34 | - name: Test with Gradle 35 | run: ./gradlew test --stacktrace 36 | 37 | coverage-scan: 38 | runs-on: ubuntu-latest 39 | steps: 40 | - uses: actions/checkout@v4 41 | with: 42 | fetch-depth: 0 43 | 44 | - name: Set up JDK 45 | uses: actions/setup-java@v4 46 | with: 47 | java-version: 17 48 | distribution: zulu 49 | cache: gradle 50 | 51 | - name: Cache SonarCloud packages 52 | uses: actions/cache@v4 53 | with: 54 | path: ~/.sonar/cache 55 | key: ${{ runner.os }}-sonar 56 | restore-keys: ${{ runner.os }}-sonar 57 | 58 | - name: Grant execute permission for gradlew 59 | run: chmod +x gradlew 60 | 61 | - name: Check with Gradle 62 | run: ./gradlew check --stacktrace 63 | 64 | - name: Execute sonar scan 65 | run: ./gradlew sonar -Dbuild.number=$GITHUB_RUN_NUMBER 66 | env: 67 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 68 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 69 | 70 | deploy-snapshot: 71 | needs: [ coverage-scan, test ] 72 | if: ${{ github.ref == 'refs/heads/master' }} 73 | runs-on: ubuntu-latest 74 | steps: 75 | - uses: actions/checkout@v4 76 | 77 | - name: Set up JDK 78 | uses: actions/setup-java@v4 79 | with: 80 | java-version: 11 81 | distribution: zulu 82 | cache: gradle 83 | 84 | - name: Grant execute permission for gradlew 85 | run: chmod +x gradlew 86 | 87 | - name: Deploy snapshot with Gradle 88 | run: ./gradlew publishAllPublicationsToMavenCentralRepository -Dsnapshot=true 89 | env: 90 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }} 91 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} 92 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} 93 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.PASSPHRASE }} 94 | 95 | deploy-release: 96 | needs: [ coverage-scan, test ] 97 | if: startsWith(github.ref, 'refs/tags') 98 | runs-on: ubuntu-latest 99 | steps: 100 | - uses: actions/checkout@v4 101 | 102 | - name: Set up JDK 103 | uses: actions/setup-java@v4 104 | with: 105 | java-version: 11 106 | distribution: zulu 107 | cache: gradle 108 | 109 | - name: Grant execute permission for gradlew 110 | run: chmod +x gradlew 111 | 112 | - name: Deploy release with Gradle 113 | run: ./gradlew publishToMavenCentral --no-configuration-cache 114 | env: 115 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }} 116 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} 117 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} 118 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.PASSPHRASE }} 119 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Mark stale issues 2 | 3 | on: 4 | schedule: 5 | - cron: '0 1 * * *' 6 | 7 | workflow_dispatch: 8 | 9 | jobs: 10 | stale: 11 | uses: configcat/.github/.github/workflows/stale.yml@master 12 | secrets: inherit 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | .classpath 3 | .project 4 | .settings 5 | 6 | # Compiled class file 7 | *.class 8 | 9 | # Log file 10 | *.log 11 | 12 | # BlueJ files 13 | *.ctxt 14 | 15 | # Mobile Tools for Java (J2ME) 16 | .mtj.tmp/ 17 | 18 | # Package Files # 19 | *.jar 20 | *.war 21 | *.ear 22 | *.zip 23 | *.tar.gz 24 | *.rar 25 | 26 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 27 | hs_err_pid* 28 | 29 | **/.idea/* 30 | 31 | **/.gradle/* 32 | **/build/* 33 | out/ 34 | 35 | .DS_Store 36 | .vscode 37 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Please check the [Github Releases](https://github.com/configcat/java-sdk/releases) page for the changelog of the ConfigCat Java SDK. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the ConfigCat SDK for Java 2 | 3 | ConfigCat SDK is an open source project. Feedback and contribution are welcome. Contributions are made to this repo via Issues and Pull Requests. 4 | 5 | ## Submitting bug reports and feature requests 6 | 7 | The ConfigCat SDK team monitors the [issue tracker](https://github.com/configcat/java-sdk/issues) in the SDK repository. Bug reports and feature requests specific to this SDK should be filed in this issue tracker. The team will respond to all newly filed issues. 8 | 9 | ## Submitting pull requests 10 | 11 | We encourage pull requests and other contributions from the community. 12 | - Before submitting pull requests, ensure that all temporary or unintended code is removed. 13 | - Be accompanied by a complete Pull Request template (loaded automatically when a PR is created). 14 | - Add unit or integration tests for fixed or changed functionality. 15 | 16 | When you submit a pull request or otherwise seek to include your change in the repository, you waive all your intellectual property rights, including your copyright and patent claims for the submission. For more details please read the [contribution agreement](https://github.com/configcat/legal/blob/main/contribution-agreement.md). 17 | 18 | In general, we follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr) 19 | 20 | 1. Fork the repository to your own Github account 21 | 2. Clone the project to your machine 22 | 3. Create a branch locally with a succinct but descriptive name 23 | 4. Commit changes to the branch 24 | 5. Following any formatting and testing guidelines specific to this repo 25 | 6. Push changes to your fork 26 | 7. Open a PR in our repository and follow the PR template so that we can efficiently review the changes. 27 | 28 | ## Build instructions 29 | 30 | This ConfigCat SDK builds with [Gradle](https://gradle.org/) and should be built against Java 8. 31 | 32 | ## Running tests 33 | 34 | - On Windows: 35 | 36 | ```bash 37 | gradlew test 38 | ``` 39 | 40 | - On Mac or Linux: 41 | 42 | ```bash 43 | ./gradlew test 44 | ``` 45 | -------------------------------------------------------------------------------- /DEPLOY.md: -------------------------------------------------------------------------------- 1 | # Steps to deploy 2 | 3 | ## Preparation 4 | 5 | 1. Run tests 6 | 3. Increase the version in the `gradle.properties` `src/main/java/com.configcat/Constants.java` file. 7 | 4. Commit & Push 8 | 9 | ## Publish 10 | 11 | Use the **same version** for the git tag as in the properties file. 12 | 13 | - Via git tag 14 | 1. Create a new version tag. 15 | ```bash 16 | git tag v[MAJOR].[MINOR].[PATCH] 17 | ``` 18 | > Example: `git tag v2.5.5` 19 | 2. Push the tag. 20 | ```bash 21 | git push origin --tags 22 | ``` 23 | - Via Github release 24 | 25 | Create a new [Github release](https://github.com/configcat/java-sdk/releases) with a new version tag and release 26 | notes. 27 | 28 | ## Sync 29 | 30 | 1. Log in to [Maven Central Repository](https://central.sonatype.org/) and follow these steps: 31 | 1. Go to the `Publish` page and select the version you published. 32 | 2. Click `Publish`. The process might take some time, click `Refresh` to get the latest state. 33 | 2. Make sure the new version is available 34 | on [Maven Central](https://central.sonatype.com/artifact/com.configcat/configcat-java-client). 35 | 36 | ## Update import examples in local README.md 37 | 38 | ## Update code examples in ConfigCat Dashboard projects 39 | 40 | `Steps to connect your application` 41 | 42 | 1. Update Maven import examples. 43 | 2. Update Gradle import examples. 44 | 45 | ## Update import examples in Docs 46 | 47 | ## Update samples 48 | 49 | Update and test sample apps with the new SDK version. 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ConfigCat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ConfigCat SDK for Java 2 | [![Java CI](https://github.com/configcat/java-sdk/actions/workflows/java-ci.yml/badge.svg?branch=master)](https://github.com/configcat/java-sdk/actions/workflows/java-ci.yml) 3 | [![Maven Central](https://img.shields.io/maven-central/v/com.configcat/configcat-java-client)](https://central.sonatype.com/artifact/com.configcat/configcat-java-client) 4 | [![Javadocs](http://javadoc.io/badge/com.configcat/configcat-java-client.svg)](http://javadoc.io/doc/com.configcat/configcat-java-client) 5 | [![Coverage Status](https://img.shields.io/sonar/coverage/configcat_java-sdk?logo=SonarCloud&server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/project/overview?id=configcat_java-sdk) 6 | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=configcat_java-sdk&metric=alert_status)](https://sonarcloud.io/dashboard?id=configcat_java-sdk) 7 | ![License](https://img.shields.io/github/license/configcat/java-sdk.svg) 8 | 9 | ConfigCat SDK for Java provides easy integration for your application to [ConfigCat](https://configcat.com). 10 | 11 | ## Getting started 12 | 13 | ### 1. Install the ConfigCat SDK 14 | *Maven:* 15 | ```xml 16 | 17 | com.configcat 18 | configcat-java-client 19 | [8.0.0,) 20 | 21 | ``` 22 | *Gradle:* 23 | ```groovy 24 | implementation "com.configcat:configcat-java-client:8.+" 25 | ``` 26 | 27 | ### 2. Go to the ConfigCat Dashboard to get your *SDK Key*: 28 | ![SDK-KEY](https://raw.githubusercontent.com/ConfigCat/java-sdk/master/media/readme02-3.png "SDK-KEY") 29 | 30 | ### 3. Import *com.configcat.** in your application code 31 | ```java 32 | import com.configcat.*; 33 | ``` 34 | 35 | ### 4. Create a *ConfigCat* client instance 36 | ```java 37 | ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#"); 38 | ``` 39 | 40 | ### 5. Get your setting value 41 | ```java 42 | boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false); 43 | if(isMyAwesomeFeatureEnabled) { 44 | doTheNewThing(); 45 | } else{ 46 | doTheOldThing(); 47 | } 48 | ``` 49 | Or use the async APIs: 50 | ```java 51 | client.getValueAsync(Boolean.class, "isMyAwesomeFeatureEnabled", false) 52 | .thenAccept(isMyAwesomeFeatureEnabled -> { 53 | if(isMyAwesomeFeatureEnabled) { 54 | doTheNewThing(); 55 | } else{ 56 | doTheOldThing(); 57 | } 58 | }); 59 | ``` 60 | 61 | ### 6. Close the client on application exit 62 | ```java 63 | client.close(); 64 | ``` 65 | 66 | ## Getting user-specific setting values with Targeting 67 | Using this feature, you will be able to get different setting values for different users in your application by passing a `User Object` to the `getValue()` function. 68 | 69 | Read more about Targeting [here](https://configcat.com/docs/advanced/targeting/). 70 | 71 | 72 | ## User Object 73 | Percentage and targeted rollouts are calculated by the user object passed to the configuration requests. 74 | The user object must be created with a **mandatory** identifier parameter which uniquely identifies each user: 75 | ```java 76 | User user = User.newBuilder() 77 | .build("#USER-IDENTIFIER#"); // mandatory 78 | 79 | boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", user, false); 80 | if(isMyAwesomeFeatureEnabled) { 81 | doTheNewThing(); 82 | } else{ 83 | doTheOldThing(); 84 | } 85 | ``` 86 | 87 | ## Sample/Demo app 88 | * [Sample Console App](https://github.com/ConfigCat/java-sdk/tree/master/samples/console) 89 | * [Sample Web app](https://github.com/ConfigCat/java-sdk/tree/master/samples/web) 90 | 91 | ## Polling Modes 92 | The ConfigCat SDK supports three different polling mechanisms to acquire the setting values from ConfigCat. After the latest setting values are downloaded, they are stored in an internal cache . After that, all requests are served from the cache. Read more about Polling Modes and how to use them at [ConfigCat Java Docs](https://configcat.com/docs/sdk-reference/java/) or [ConfigCat Android Docs](https://configcat.com/docs/sdk-reference/android/). 93 | 94 | ## Support 95 | If you need help using this SDK, feel free to contact the ConfigCat Staff at [https://configcat.com](https://configcat.com). We're happy to help. 96 | 97 | ## Contributing 98 | Contributions are welcome. For more info please read the [Contribution Guideline](CONTRIBUTING.md). 99 | 100 | ## About ConfigCat 101 | ConfigCat is a feature flag and configuration management service that lets you separate feature releases from code deployments. You can turn features ON/OFF using the ConfigCat Dashboard even after they are deployed. ConfigCat lets you target specific groups of users based on region, email, or any other custom user attribute. 102 | 103 | ConfigCat is a hosted feature flag service that lets you manage feature toggles across frontend, backend, mobile, and desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs. 104 | 105 | - [Official ConfigCat SDKs for other platforms](https://github.com/configcat) 106 | - [Documentation](https://configcat.com/docs) 107 | - [Blog](https://configcat.com/blog) 108 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import com.vanniktech.maven.publish.JavaLibrary 2 | import com.vanniktech.maven.publish.JavadocJar 3 | import com.vanniktech.maven.publish.SonatypeHost 4 | 5 | buildscript { 6 | repositories { 7 | mavenCentral() 8 | } 9 | } 10 | 11 | plugins { 12 | alias(libs.plugins.sonarqube) 13 | id "java" 14 | id 'java-library' 15 | id "jacoco" 16 | alias(libs.plugins.mavenPublish) 17 | } 18 | 19 | sourceCompatibility = JavaVersion.VERSION_1_8 20 | targetCompatibility = JavaVersion.VERSION_1_8 21 | 22 | ext { 23 | buildNumber = System.getProperty("build.number") 24 | isSnapshot = Boolean.valueOf(System.getProperty("snapshot")) 25 | } 26 | 27 | group = "com.configcat" 28 | version = "${version}" + (isSnapshot ? "-SNAPSHOT" : "") 29 | 30 | repositories { 31 | mavenLocal() 32 | mavenCentral() 33 | } 34 | 35 | dependencies { 36 | api(libs.okhttp) 37 | api(libs.okio) 38 | api(libs.slf4j.api) 39 | api(libs.gson) 40 | api(libs.commons.codec) 41 | api(libs.semantic.version) 42 | testImplementation(libs.junit.jupiter.api) 43 | testImplementation(libs.logback.classic) 44 | testImplementation(libs.logback.core) 45 | testImplementation(libs.mockwebserver) 46 | testImplementation(libs.mockito.core) 47 | testImplementation(libs.junit.jupiter.params) 48 | testRuntimeOnly(libs.junit.jupiter.engine) 49 | testRuntimeOnly(libs.junit.vintage.engine) 50 | } 51 | 52 | jar { 53 | manifest { 54 | attributes("Implementation-Version": archiveVersion) 55 | } 56 | } 57 | 58 | sonarqube { 59 | properties { 60 | property "sonar.projectKey", "configcat_java-sdk" 61 | property "sonar.projectName", "java-sdk" 62 | property "sonar.projectVersion", "${version}-${buildNumber}" 63 | property "sonar.organization", "configcat" 64 | property "sonar.host.url", "https://sonarcloud.io" 65 | property "sonar.sources", "src/main/java/com/configcat" 66 | property "sonar.coverage.jacoco.xmlReportPaths", layout.buildDirectory.file("reports/jacoco/report.xml").get() 67 | } 68 | } 69 | 70 | jacoco { 71 | toolVersion = "0.8.8" 72 | } 73 | 74 | tasks.withType(Test).configureEach { 75 | useJUnitPlatform() 76 | } 77 | 78 | tasks.named("jacocoTestReport", JacocoReport) { 79 | dependsOn test 80 | executionData test 81 | sourceSets sourceSets.main 82 | reports { 83 | xml.required.set(true) 84 | xml.destination layout.buildDirectory.file("reports/jacoco/report.xml").get().asFile 85 | html.required.set(false) 86 | csv.required.set(false) 87 | } 88 | } 89 | 90 | tasks.named("check") { 91 | it.dependsOn(tasks.named("jacocoTestReport")) 92 | } 93 | 94 | mavenPublishing { 95 | publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 96 | 97 | def signingInMemoryKey = findProperty("signingInMemoryKey") 98 | def signingInMemoryKeyPassword = findProperty("signingInMemoryKeyPassword") 99 | if (signingInMemoryKey && signingInMemoryKeyPassword) { 100 | signAllPublications() 101 | } 102 | 103 | configure(new JavaLibrary(new JavadocJar.Javadoc(), true)) 104 | 105 | coordinates(project.group as String, project.name, project.version as String) 106 | 107 | pom { 108 | name.set("ConfigCat Java SDK") 109 | description.set("Java SDK for ConfigCat, a feature flag, feature toggle, and configuration management service. That lets you launch new features and change your software configuration remotely without actually (re)deploying code. ConfigCat even helps you do controlled roll-outs like canary releases and blue-green deployments.") 110 | url.set("https://github.com/configcat/java-sdk") 111 | licenses { 112 | license { 113 | name.set("MIT License") 114 | url.set("https://raw.githubusercontent.com/configcat/java-sdk/master/LICENSE") 115 | distribution.set("repo") 116 | } 117 | } 118 | scm { 119 | connection.set("scm:git:git://github.com/configcat/java-sdk.git") 120 | developerConnection.set("scm:git:ssh:git@github.com:configcat/java-sdk.git") 121 | url.set("https://github.com/configcat/java-sdk") 122 | } 123 | developers { 124 | developer { 125 | id.set("configcat") 126 | name.set("ConfigCat") 127 | email.set("developer@configcat.com") 128 | } 129 | } 130 | organization { 131 | url.set("https://configcat.com") 132 | name.set("ConfigCat") 133 | } 134 | } 135 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=9.4.3 2 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | sonarqube = "5.0.0.4638" 3 | mavenPublish = "0.32.0" 4 | okhttp = "4.12.0" 5 | okio = "3.4.0" # indirect dependency to solve security vulnerability in 3.2.0 6 | slf4j-api = "1.7.36" 7 | gson = "2.9.0" 8 | commons-codec = "1.15" 9 | semantic-version = "2.1.0" 10 | junit-jupiter = "5.10.0" 11 | logback = "1.5.13" 12 | mockwebserver = "4.12.0" 13 | mockito = "4.2.0" 14 | 15 | [libraries] 16 | okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } 17 | okio = { module = "com.squareup.okio:okio", version.ref = "okio" } 18 | slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-api" } 19 | gson = { module = "com.google.code.gson:gson", version.ref = "gson" } 20 | commons-codec = { module = "commons-codec:commons-codec", version.ref = "commons-codec" } 21 | semantic-version = { module = "de.skuzzle:semantic-version", version.ref = "semantic-version" } 22 | junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" } 23 | logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } 24 | logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" } 25 | mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "mockwebserver" } 26 | mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" } 27 | junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" } 28 | junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" } 29 | junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit-jupiter" } 30 | 31 | [plugins] 32 | sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" } 33 | mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } 34 | 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/configcat/java-sdk/ce5ca050758e02db6db01298017a32ac0f8b0e36/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /media/readme02-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/configcat/java-sdk/ce5ca050758e02db6db01298017a32ac0f8b0e36/media/readme02-3.png -------------------------------------------------------------------------------- /samples/console/README.md: -------------------------------------------------------------------------------- 1 | # ConfigCat sample console app in Java 2 | 3 | ## Run 4 | 5 | Build and run Main.class 6 | 7 | Feature flag values should be logged to the console. -------------------------------------------------------------------------------- /samples/console/build.gradle: -------------------------------------------------------------------------------- 1 | group 'com.configcat.sample' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | sourceCompatibility = 1.8 7 | 8 | repositories { 9 | jcenter() 10 | mavenCentral() 11 | mavenLocal() 12 | } 13 | 14 | dependencies { 15 | implementation "com.configcat:configcat-java-client:9.+" 16 | implementation "org.slf4j:slf4j-simple:1.7.25" 17 | testImplementation "junit:junit:4.12" 18 | } 19 | -------------------------------------------------------------------------------- /samples/console/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /samples/console/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/console/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'configcat-java-client-sample' 2 | 3 | -------------------------------------------------------------------------------- /samples/console/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import com.configcat.ConfigCatClient; 2 | import com.configcat.LogLevel; 3 | import com.configcat.User; 4 | 5 | import java.io.IOException; 6 | 7 | public class Main { 8 | public static void main(String[] args) throws IOException { 9 | 10 | ConfigCatClient client = ConfigCatClient.get("PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ", options -> { 11 | // Info level logging helps to inspect the feature flag evaluation process. 12 | // Use the default Warning level to avoid too detailed logging in your application. 13 | options.logLevel(LogLevel.DEBUG); 14 | }); 15 | 16 | // Get individual config values identified by a key for a user. 17 | System.out.println("isAwesomeFeatureEnabled: " + client.getValue(Boolean.class, "isAwesomeFeatureEnabled", false)); 18 | 19 | 20 | // Create a user object to identify the caller. 21 | User user = User.newBuilder() 22 | .email("configcat@example.com") 23 | .build("key"); 24 | 25 | System.out.println("isPOCFeatureEnabled: " + client.getValue(Boolean.class, "isPOCFeatureEnabled", user, false)); 26 | 27 | client.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /samples/console/src/main/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | # Default logging detail level for all instances of SimpleLogger. 2 | # Must be one of ("trace", "debug", "info", "warn", or "error"). 3 | # If not specified, defaults to "info". 4 | #org.slf4j.simpleLogger.defaultLogLevel=debug 5 | 6 | # Logging detail level for a SimpleLogger instance named "xxxxx". 7 | # Must be one of ("trace", "debug", "info", "warn", or "error"). 8 | # If not specified, the default logging detail level is used. 9 | org.slf4j.simpleLogger.log.com.configcat.ConfigCatClient=debug -------------------------------------------------------------------------------- /samples/web/README.md: -------------------------------------------------------------------------------- 1 | # ConfigCat Spring Boot Sample App 2 | 3 | ### Start sample: 4 | 1. Run sample app 5 | ``` 6 | ./gradlew bootRun 7 | ``` 8 | 2. Open browser at `http://localhost:8080/` -------------------------------------------------------------------------------- /samples/web/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE") 7 | } 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'org.springframework.boot' 12 | 13 | sourceCompatibility = 1.8 14 | 15 | repositories { 16 | jcenter() 17 | mavenCentral() 18 | mavenLocal() 19 | } 20 | 21 | dependencies { 22 | implementation "com.configcat:configcat-java-client:9.+" 23 | implementation "org.springframework.boot:spring-boot-starter-web:2.2+" 24 | testImplementation "junit:junit:4.12" 25 | } 26 | -------------------------------------------------------------------------------- /samples/web/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /samples/web/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/web/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'configcat-web-sample' 2 | 3 | -------------------------------------------------------------------------------- /samples/web/src/main/java/websample/AppConfiguration.java: -------------------------------------------------------------------------------- 1 | package websample; 2 | 3 | import com.configcat.ConfigCatClient; 4 | import com.configcat.LogLevel; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class AppConfiguration { 10 | 11 | @Bean 12 | public ConfigCatClient configCatClient() { 13 | return ConfigCatClient.get("configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/tiOvFw5gkky9LFu1Duuvzw", options -> { 14 | // Info level logging helps to inspect the feature flag evaluation process. 15 | // Use the default Warning level to avoid too detailed logging in your application. 16 | options.logLevel(LogLevel.DEBUG); 17 | }); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /samples/web/src/main/java/websample/Application.java: -------------------------------------------------------------------------------- 1 | package websample; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | @SpringBootApplication 8 | public class Application { 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/web/src/main/java/websample/ConfigController.java: -------------------------------------------------------------------------------- 1 | package websample; 2 | 3 | import com.configcat.ConfigCatClient; 4 | import com.configcat.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 13 | 14 | @Controller 15 | public class ConfigController { 16 | 17 | @Autowired 18 | ConfigCatClient client; 19 | 20 | @RequestMapping(value = "api/config/awesome", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) 21 | public @ResponseBody 22 | String awesome() { 23 | return this.client.getValue(Boolean.class, "isAwesomeFeatureEnabled", false).toString(); 24 | } 25 | 26 | @RequestMapping(value = "api/config/poc", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) 27 | public @ResponseBody 28 | String poc(@RequestParam String email) { 29 | User user = User.newBuilder().email(email).build("#SOME-USER-ID#"); 30 | return this.client.getValue(Boolean.class, "isPOCFeatureEnabled", user, false).toString(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /samples/web/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable 11 | 12 | 13 | 14 | 15 | 17 | ${LOGS}/spring-boot-logger.log 18 | 20 | %d %p %C{1.} [%t] %m%n 21 | 22 | 23 | 25 | 26 | ${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log 27 | 28 | 30 | 10MB 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /samples/web/src/main/resources/static/images/mgmt_console_v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/configcat/java-sdk/ce5ca050758e02db6db01298017a32ac0f8b0e36/samples/web/src/main/resources/static/images/mgmt_console_v2.png -------------------------------------------------------------------------------- /samples/web/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ConfigCat Spring Boot Sample 7 | 8 | 20 | 21 | 22 |
23 |

Simple feature flag

24 | 25 |

Value returned from ConfigCat:

26 |
27 |

Feature with Targeting

28 |

Set up to be enabled only for users with an e-mail address that contains "@example.com"

29 | 30 | 31 |

Value returned from ConfigCat:

32 |
33 |

ConfigCat Dashboard

34 |

A screen-shot to see how the ConfigCat Dashboard looks like for this Sample Project.

35 | 36 |
37 | 38 | 39 | 72 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'configcat-java-client' 2 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/AutoPollingMode.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class AutoPollingMode extends PollingMode { 4 | private final int autoPollRateInSeconds; 5 | private final int maxInitWaitTimeSeconds; 6 | 7 | AutoPollingMode(int autoPollRateInSeconds, int maxInitWaitTimeSeconds) { 8 | if (autoPollRateInSeconds < 1) 9 | throw new IllegalArgumentException("autoPollRateInSeconds cannot be less than 1 second"); 10 | 11 | this.autoPollRateInSeconds = autoPollRateInSeconds; 12 | this.maxInitWaitTimeSeconds = maxInitWaitTimeSeconds; 13 | } 14 | 15 | int getAutoPollRateInSeconds() { 16 | return autoPollRateInSeconds; 17 | } 18 | 19 | public int getMaxInitWaitTimeSeconds() { 20 | return maxInitWaitTimeSeconds; 21 | } 22 | 23 | @Override 24 | String getPollingIdentifier() { 25 | return "a"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/ClientCacheState.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Describes the Client state. 5 | */ 6 | public enum ClientCacheState { 7 | /** 8 | * The SDK has no feature flag data neither from the cache nor from the ConfigCat CDN. 9 | */ 10 | NO_FLAG_DATA, 11 | /** 12 | * The SDK runs with local only feature flag data. 13 | */ 14 | HAS_LOCAL_OVERRIDE_FLAG_DATA_ONLY, 15 | /** 16 | * The SDK has feature flag data to work with only from the cache. 17 | */ 18 | HAS_CACHED_FLAG_DATA_ONLY, 19 | /** 20 | * The SDK works with the latest feature flag data received from the ConfigCat CDN. 21 | */ 22 | HAS_UP_TO_DATE_FLAG_DATA, 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Condition.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents a condition. 7 | */ 8 | public class Condition implements ConditionAccessor { 9 | @SerializedName(value = "u") 10 | private UserCondition userCondition; 11 | @SerializedName(value = "s") 12 | private SegmentCondition segmentCondition; 13 | @SerializedName(value = "p") 14 | private PrerequisiteFlagCondition prerequisiteFlagCondition; 15 | 16 | @Override 17 | public UserCondition getUserCondition() { 18 | return userCondition; 19 | } 20 | 21 | @Override 22 | public SegmentCondition getSegmentCondition() { 23 | return segmentCondition; 24 | } 25 | 26 | @Override 27 | public PrerequisiteFlagCondition getPrerequisiteFlagCondition() { 28 | return prerequisiteFlagCondition; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/ConditionAccessor.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | interface ConditionAccessor { 4 | UserCondition getUserCondition(); 5 | 6 | SegmentCondition getSegmentCondition(); 7 | 8 | PrerequisiteFlagCondition getPrerequisiteFlagCondition(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Config.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * Details of a ConfigCat config. 10 | */ 11 | public class Config { 12 | 13 | @SerializedName(value = "p") 14 | private Preferences preferences; 15 | @SerializedName(value = "f") 16 | private final Map entries = new HashMap<>(); 17 | @SerializedName(value = "s") 18 | private Segment[] segments; 19 | 20 | /** 21 | * The config preferences. 22 | */ 23 | public Preferences getPreferences() { 24 | return preferences; 25 | } 26 | 27 | /** 28 | * The list of segments. 29 | */ 30 | public Segment[] getSegments() { 31 | return segments; 32 | } 33 | 34 | /** 35 | * The map of settings. 36 | */ 37 | public Map getEntries() { 38 | return entries; 39 | } 40 | 41 | boolean isEmpty() { 42 | return EMPTY.equals(this); 43 | } 44 | 45 | public static final Config EMPTY = new Config(); 46 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/ConfigCache.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * A cache API used to make custom cache implementations for {@link ConfigCatClient}. 5 | */ 6 | public abstract class ConfigCache { 7 | /** 8 | * Child classes has to implement this method, the {@link ConfigCatClient} 9 | * uses it to get the actual value from the cache. 10 | * 11 | * @param key the key of the cache entry. 12 | * @return the cached configuration. 13 | * @throws Exception if unable to read the cache. 14 | */ 15 | protected abstract String read(String key) throws Exception; 16 | 17 | /** 18 | * * Child classes has to implement this method, the {@link ConfigCatClient} 19 | * uses it to set the actual cached value. 20 | * 21 | * @param key the key of the cache entry. 22 | * @param value the new value to cache. 23 | * @throws Exception if unable to save the value. 24 | */ 25 | protected abstract void write(String key, String value) throws Exception; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/ConfigCatLogger.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import org.slf4j.Logger; 4 | 5 | class ConfigCatLogger { 6 | private final Logger logger; 7 | private final LogLevel logLevel; 8 | private final ConfigCatHooks configCatHooks; 9 | private final LogFilterFunction filterFunction ; 10 | 11 | public ConfigCatLogger(Logger logger, LogLevel logLevel, ConfigCatHooks configCatHooks, LogFilterFunction filterFunction ) { 12 | this.logger = logger; 13 | this.logLevel = logLevel; 14 | this.configCatHooks = configCatHooks; 15 | this.filterFunction = filterFunction ; 16 | } 17 | 18 | public ConfigCatLogger(Logger logger, LogLevel logLevel) { 19 | this(logger, logLevel, null, null); 20 | } 21 | 22 | public ConfigCatLogger(Logger logger) { 23 | this(logger, LogLevel.WARNING); 24 | } 25 | 26 | public void warn(int eventId, Object message) { 27 | if (filter(eventId, LogLevel.WARNING, message, null)) { 28 | this.logger.warn("[{}] {}", eventId, message); 29 | } 30 | } 31 | 32 | public void error(int eventId, Object message, Exception exception) { 33 | if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); 34 | if (filter(eventId, LogLevel.ERROR, message, exception)) { 35 | this.logger.error("[{}] {}", eventId, message, exception); 36 | } 37 | } 38 | 39 | public void error(int eventId, Object message) { 40 | if (this.configCatHooks != null) this.configCatHooks.invokeOnError(message); 41 | if (filter(eventId, LogLevel.ERROR, message, null)) { 42 | this.logger.error("[{}] {}", eventId, message); 43 | } 44 | } 45 | 46 | public void info(int eventId, Object message) { 47 | if (filter(eventId, LogLevel.INFO, message, null)) { 48 | this.logger.info("[{}] {}", eventId, message); 49 | } 50 | } 51 | 52 | public void debug(Object message) { 53 | if (filter(0, LogLevel.DEBUG, message, null)) { 54 | this.logger.debug("[{}] {}", 0, message); 55 | } 56 | } 57 | 58 | private boolean filter(int eventId, LogLevel logLevel, Object message, Exception exception) { 59 | return this.logLevel.ordinal() <= logLevel.ordinal() && (this.filterFunction == null || this.filterFunction.apply(logLevel, eventId, message, exception)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Constants.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | final class Constants { 4 | private Constants() { /* prevent from instantiation*/ } 5 | 6 | static final long DISTANT_FUTURE = Long.MAX_VALUE; 7 | static final long DISTANT_PAST = 0; 8 | static final String CONFIG_JSON_NAME = "config_v6.json"; 9 | static final String SERIALIZATION_FORMAT_VERSION = "v2"; 10 | static final String VERSION = "9.4.3"; 11 | 12 | static final String SDK_KEY_PROXY_PREFIX = "configcat-proxy/"; 13 | static final String SDK_KEY_PREFIX = "configcat-sdk-1"; 14 | 15 | static final int SDK_KEY_SECTION_LENGTH = 22; 16 | 17 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/DataGovernance.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Describes the location of your feature flag and setting data within the ConfigCat CDN. 5 | */ 6 | public enum DataGovernance { 7 | /** 8 | * Select this if your feature flags are published to all global CDN nodes. 9 | */ 10 | GLOBAL, 11 | /** 12 | * Select this if your feature flags are published to CDN nodes only in the EU. 13 | */ 14 | EU_ONLY 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/DateTimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.time.Instant; 5 | import java.util.Date; 6 | import java.util.TimeZone; 7 | 8 | public class DateTimeUtils { 9 | 10 | private DateTimeUtils() { /* prevent from instantiation*/ } 11 | 12 | public static boolean isValidDate(String date) { 13 | try { 14 | Long.parseLong(date); 15 | } catch (NumberFormatException e) { 16 | return false; 17 | } 18 | return true; 19 | } 20 | 21 | public static String doubleToFormattedUTC(double dateInDouble) { 22 | long dateInMillisecond = (long) dateInDouble * 1000; 23 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 24 | simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); 25 | return simpleDateFormat.format(new Date(dateInMillisecond)); 26 | } 27 | 28 | 29 | public static double getUnixSeconds(Date date) { 30 | return date.getTime() / 1000d; 31 | } 32 | 33 | public static double getUnixSeconds(Instant date) { 34 | return date.toEpochMilli() / 1000d; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Entry.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | public class Entry { 4 | private final Config config; 5 | private final String eTag; 6 | private final String cacheString; 7 | private final long fetchTime; 8 | 9 | public Config getConfig() { 10 | return config; 11 | } 12 | 13 | public String getETag() { 14 | return eTag; 15 | } 16 | 17 | public long getFetchTime() { 18 | return fetchTime; 19 | } 20 | 21 | public String getCacheString() { 22 | return cacheString; 23 | } 24 | 25 | public Entry withFetchTime(long fetchTime) { 26 | String cacheString = getCacheString(); 27 | int fetchTimeIndex = cacheString.indexOf("\n"); 28 | if (fetchTimeIndex == -1) { 29 | return this; 30 | } 31 | int eTagIndex = cacheString.indexOf("\n", fetchTimeIndex + 1); 32 | if (eTagIndex == -1) { 33 | return this; 34 | } 35 | String configJson = cacheString.substring(eTagIndex + 1); 36 | return new Entry(getConfig(), getETag(), configJson, fetchTime); 37 | } 38 | 39 | public boolean isExpired(long threshold) { 40 | return fetchTime <= threshold ; 41 | } 42 | public Entry(Config config, String eTag, String configJson, long fetchTime) { 43 | this.config = config; 44 | this.eTag = eTag; 45 | this.cacheString = serialize(fetchTime, eTag, configJson); 46 | this.fetchTime = fetchTime; 47 | } 48 | 49 | boolean isEmpty() { 50 | return EMPTY.equals(this); 51 | } 52 | 53 | public static final Entry EMPTY = new Entry(Config.EMPTY, "", "", Constants.DISTANT_PAST); 54 | 55 | private static String serialize(long fetchTime, String etag, String configJson) { 56 | return fetchTime + "\n" + etag + "\n" + configJson; 57 | } 58 | 59 | public static Entry fromString(String cacheValue) throws IllegalArgumentException { 60 | if (cacheValue == null || cacheValue.isEmpty()) { 61 | return Entry.EMPTY; 62 | } 63 | 64 | int fetchTimeIndex = cacheValue.indexOf("\n"); 65 | int eTagIndex = cacheValue.indexOf("\n", fetchTimeIndex + 1); 66 | if (fetchTimeIndex < 0 || eTagIndex < 0) { 67 | throw new IllegalArgumentException("Number of values is fewer than expected."); 68 | } 69 | String fetchTimeRaw = cacheValue.substring(0, fetchTimeIndex); 70 | if (!DateTimeUtils.isValidDate(fetchTimeRaw)) { 71 | throw new IllegalArgumentException("Invalid fetch time: " + fetchTimeRaw); 72 | } 73 | long fetchTimeUnixMillis = Long.parseLong(fetchTimeRaw); 74 | 75 | 76 | String eTag = cacheValue.substring(fetchTimeIndex + 1, eTagIndex); 77 | if (eTag.isEmpty()) { 78 | throw new IllegalArgumentException("Empty eTag value."); 79 | } 80 | String configJson = cacheValue.substring(eTagIndex + 1); 81 | if (configJson.isEmpty()) { 82 | throw new IllegalArgumentException("Empty config jsom value."); 83 | } 84 | try { 85 | Config config = Utils.deserializeConfig(configJson); 86 | return new Entry(config, eTag, configJson, fetchTimeUnixMillis); 87 | } catch (Exception e) { 88 | throw new IllegalArgumentException("Invalid config JSON content: " + configJson); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/EvaluationContext.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | class EvaluationContext { 7 | public EvaluationContext(String key, User user, List visitedKeys, Map settings) { 8 | this.key = key; 9 | this.user = user; 10 | this.visitedKeys = visitedKeys; 11 | this.settings = settings; 12 | } 13 | 14 | private String key; 15 | private User user; 16 | private final List visitedKeys; 17 | private final Map settings; 18 | private boolean isUserMissing = false; 19 | private boolean isUserAttributeMissing = false; 20 | 21 | public String getKey() { 22 | return key; 23 | } 24 | 25 | public void setKey(String key) { 26 | this.key = key; 27 | } 28 | 29 | public User getUser() { 30 | return user; 31 | } 32 | 33 | public void setUser(User user) { 34 | this.user = user; 35 | } 36 | 37 | public void setUserMissing(boolean userMissing) { 38 | isUserMissing = userMissing; 39 | } 40 | 41 | public void setUserAttributeMissing(boolean userAttributeMissing) { 42 | isUserAttributeMissing = userAttributeMissing; 43 | } 44 | 45 | public List getVisitedKeys() { 46 | return visitedKeys; 47 | } 48 | 49 | public Map getSettings() { 50 | return settings; 51 | } 52 | 53 | public boolean isUserMissing() { 54 | return isUserMissing; 55 | } 56 | 57 | public boolean isUserAttributeMissing() { 58 | return isUserAttributeMissing; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/EvaluationDetails.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Additional information about flag evaluation. 5 | */ 6 | public class EvaluationDetails { 7 | private final T value; 8 | private final String key; 9 | private final String variationId; 10 | private final User user; 11 | private final boolean isDefaultValue; 12 | private final Object error; 13 | private final long fetchTimeUnixMilliseconds; 14 | private final TargetingRule matchedTargetingRule; 15 | private final PercentageOption matchedPercentageOption; 16 | 17 | public EvaluationDetails(T value, 18 | String key, 19 | String variationId, 20 | User user, 21 | boolean isDefaultValue, 22 | Object error, 23 | long fetchTimeUnixMilliseconds, 24 | TargetingRule matchedTargetingRule, 25 | PercentageOption matchedPercentageOption) { 26 | this.value = value; 27 | this.key = key; 28 | this.variationId = variationId; 29 | this.user = user; 30 | this.isDefaultValue = isDefaultValue; 31 | this.error = error; 32 | this.fetchTimeUnixMilliseconds = fetchTimeUnixMilliseconds; 33 | this.matchedTargetingRule = matchedTargetingRule; 34 | this.matchedPercentageOption = matchedPercentageOption; 35 | } 36 | 37 | static EvaluationDetails fromError(String key, T defaultValue, Object error, User user) { 38 | return new EvaluationDetails<>(defaultValue, key, "", user, true, error, Constants.DISTANT_PAST, null, null); 39 | } 40 | 41 | EvaluationDetails asTypeSpecific() { 42 | return new EvaluationDetails<>((TR) value, key, variationId, user, isDefaultValue, error, fetchTimeUnixMilliseconds, matchedTargetingRule, matchedPercentageOption); 43 | } 44 | 45 | /** 46 | * The evaluated value of the feature flag or setting. 47 | */ 48 | public T getValue() { 49 | return value; 50 | } 51 | 52 | /** 53 | * The key of the evaluated feature flag or setting. 54 | */ 55 | public String getKey() { 56 | return key; 57 | } 58 | 59 | /** 60 | * The variationID is the identifier of the evaluated value. Usually used for analytics. 61 | */ 62 | public String getVariationId() { 63 | return variationId; 64 | } 65 | 66 | /** 67 | * The user object that was used for evaluation. 68 | */ 69 | public User getUser() { 70 | return user; 71 | } 72 | 73 | /** 74 | * True when the default value was returned, possibly due to an error. 75 | */ 76 | public boolean isDefaultValue() { 77 | return isDefaultValue; 78 | } 79 | 80 | /** 81 | * In case of an error, this field contains the error message. 82 | */ 83 | public String getError() { 84 | if(error != null) { 85 | return error.toString(); 86 | } 87 | return null; 88 | } 89 | 90 | /** 91 | * The last fetch time of the config.json in unix milliseconds format. 92 | */ 93 | public Long getFetchTimeUnixMilliseconds() { 94 | return fetchTimeUnixMilliseconds; 95 | } 96 | 97 | /** 98 | * If the evaluation was based on a targeting rule, this field contains that specific rule. 99 | */ 100 | public TargetingRule getMatchedTargetingRule() { 101 | return matchedTargetingRule; 102 | } 103 | 104 | /** 105 | * If the evaluation was based on a percentage rule, this field contains that specific rule. 106 | */ 107 | public PercentageOption getMatchedPercentageOption() { 108 | return matchedPercentageOption; 109 | } 110 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/EvaluationResult.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class EvaluationResult { 4 | public final SettingValue value; 5 | public final String variationId; 6 | public final TargetingRule matchedTargetingRule; 7 | public final PercentageOption matchedPercentageOption; 8 | 9 | EvaluationResult(SettingValue value, String variationId, TargetingRule matchedTargetingRule, PercentageOption matchedPercentageOption) { 10 | this.value = value; 11 | this.variationId = variationId; 12 | this.matchedTargetingRule = matchedTargetingRule; 13 | this.matchedPercentageOption = matchedPercentageOption; 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/FetchResponse.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class FetchResponse { 4 | public enum Status { 5 | FETCHED, 6 | NOT_MODIFIED, 7 | FAILED 8 | } 9 | 10 | private final Status status; 11 | private final Entry entry; 12 | private final Object error; 13 | private final boolean fetchTimeUpdatable; 14 | private final String cfRayId; 15 | 16 | public boolean isFetched() { 17 | return this.status == Status.FETCHED; 18 | } 19 | 20 | public boolean isNotModified() { 21 | return this.status == Status.NOT_MODIFIED; 22 | } 23 | 24 | public boolean isFailed() { 25 | return this.status == Status.FAILED; 26 | } 27 | 28 | public boolean isFetchTimeUpdatable() { 29 | return fetchTimeUpdatable; 30 | } 31 | 32 | public Entry entry() { 33 | return this.entry; 34 | } 35 | 36 | public Object error() { 37 | return error; 38 | } 39 | 40 | public String cfRayId() {return this.cfRayId;} 41 | 42 | FetchResponse(Status status, Entry entry, Object error, boolean fetchTimeUpdatable, String cfRayId) { 43 | this.status = status; 44 | this.entry = entry; 45 | this.error = error; 46 | this.fetchTimeUpdatable = fetchTimeUpdatable; 47 | this.cfRayId = cfRayId; 48 | } 49 | 50 | public static FetchResponse fetched(Entry entry, String cfRayId) { 51 | return new FetchResponse(Status.FETCHED, entry == null ? Entry.EMPTY : entry, null, false, cfRayId); 52 | } 53 | 54 | public static FetchResponse notModified(String cfRayId) { 55 | return new FetchResponse(Status.NOT_MODIFIED, Entry.EMPTY, null, true, cfRayId); 56 | } 57 | 58 | public static FetchResponse failed(Object error, boolean fetchTimeUpdatable, String cfRayId) { 59 | return new FetchResponse(Status.FAILED, Entry.EMPTY, error, fetchTimeUpdatable, cfRayId); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/FormattableLogMessage.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | 6 | class FormattableLogMessage { 7 | 8 | private String cachedMessage; 9 | protected final String message; 10 | protected final Object[] args; 11 | 12 | FormattableLogMessage(String message, Object... args) { 13 | this.message = message; 14 | this.args = args; 15 | } 16 | 17 | protected String formatLogMessage(){ 18 | return String.format(message, args); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | if(cachedMessage == null) { 24 | cachedMessage = formatLogMessage(); 25 | } 26 | return cachedMessage; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | if(obj instanceof FormattableLogMessage) { 32 | return toString().equals(obj.toString()); 33 | } 34 | return false; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(cachedMessage, message, Arrays.hashCode(args)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/FormattableLogMessageWithKeySet.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.Set; 4 | import java.util.stream.Collectors; 5 | 6 | class FormattableLogMessageWithKeySet extends FormattableLogMessage { 7 | 8 | FormattableLogMessageWithKeySet(String message, Object... args) { 9 | super(message,args); 10 | } 11 | 12 | @Override 13 | protected String formatLogMessage() { 14 | Object keySetObject = args[args.length - 1]; 15 | if(keySetObject instanceof Set) { 16 | Set keySet = (Set) keySetObject; 17 | args[args.length - 1] = keySet.stream().map(keyTo -> "'" + keyTo + "'").collect(Collectors.joining(", ")); 18 | } 19 | return String.format(message, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/FormattableLogMessageWithUserCondition.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class FormattableLogMessageWithUserCondition extends FormattableLogMessage { 4 | 5 | FormattableLogMessageWithUserCondition(String message, Object... args) { 6 | super(message,args); 7 | } 8 | 9 | @Override 10 | protected String formatLogMessage() { 11 | Object userConditionObject = args[0]; 12 | if(userConditionObject instanceof UserCondition) { 13 | UserCondition userCondition = (UserCondition) userConditionObject; 14 | args[0] = EvaluateLogger.formatUserCondition(userCondition); 15 | } 16 | return String.format(message, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/LazyLoadingMode.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class LazyLoadingMode extends PollingMode { 4 | private final int cacheRefreshIntervalInSeconds; 5 | 6 | LazyLoadingMode(int cacheRefreshIntervalInSeconds) { 7 | this.cacheRefreshIntervalInSeconds = cacheRefreshIntervalInSeconds; 8 | } 9 | 10 | int getCacheRefreshIntervalInSeconds() { 11 | return cacheRefreshIntervalInSeconds; 12 | } 13 | 14 | 15 | @Override 16 | String getPollingIdentifier() { 17 | return "l"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/LocalMapDataSource.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | class LocalMapDataSource extends OverrideDataSource { 7 | private final Map loadedSettings = new HashMap<>(); 8 | 9 | public LocalMapDataSource(Map source) { 10 | if (source == null) 11 | throw new IllegalArgumentException("'source' cannot be null."); 12 | 13 | for (Map.Entry entry : source.entrySet()) { 14 | Setting setting = convertToSetting(entry.getValue()); 15 | this.loadedSettings.put(entry.getKey(), setting); 16 | } 17 | } 18 | 19 | @Override 20 | public Map getLocalConfiguration() { 21 | return this.loadedSettings; 22 | } 23 | 24 | private Setting convertToSetting(Object object) { 25 | Setting setting = new Setting(); 26 | SettingValue settingValue = new SettingValue(); 27 | if (object instanceof String) { 28 | setting.setType(SettingType.STRING); 29 | settingValue.setStringValue((String) object); 30 | } else if (object instanceof Boolean) { 31 | setting.setType(SettingType.BOOLEAN); 32 | settingValue.setBooleanValue((Boolean) object); 33 | } else if (object instanceof Integer) { 34 | setting.setType(SettingType.INT); 35 | settingValue.setIntegerValue((Integer) object); 36 | } else if (object instanceof Double) { 37 | setting.setType(SettingType.DOUBLE); 38 | settingValue.setDoubleValue((Double) object); 39 | } else { 40 | throw new IllegalArgumentException("Only String, Integer, Double or Boolean types are supported."); 41 | } 42 | setting.setSettingsValue(settingValue); 43 | return setting; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/LogFilterFunction.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * The Log Filter Functional Interface provides a custom filter option for the ConfigCat Logger. 5 | */ 6 | @FunctionalInterface 7 | public interface LogFilterFunction { 8 | 9 | /** 10 | * Apply the custom filter option to the ConfigCatLogger. 11 | * 12 | * @param logLevel Event severity level. 13 | * @param eventId Event identifier. 14 | * @param message Message object. The formatted message String can be obtained by calling {@code toString}. (It is guaranteed that the message string is built only once even if {@code toString} called multiple times.) 15 | * @param exception The exception object related to the message (if any). 16 | * @return True to log the event, false will leave out the log. 17 | */ 18 | boolean apply(LogLevel logLevel, int eventId, Object message, Throwable exception); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/LogLevel.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Describes the log level. 5 | */ 6 | public enum LogLevel { 7 | DEBUG, 8 | INFO, 9 | WARNING, 10 | ERROR, 11 | NO_LOG, 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/ManualPollingMode.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * The manual polling mode configuration. 5 | */ 6 | class ManualPollingMode extends PollingMode { 7 | @Override 8 | String getPollingIdentifier() { 9 | return "m"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/NullConfigCache.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * A null cache implementation. 5 | */ 6 | class NullConfigCache extends ConfigCache { 7 | 8 | @Override 9 | protected String read(String key) { 10 | return null; 11 | } 12 | 13 | @Override 14 | protected void write(String key, String value) { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/OverrideBehaviour.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Describes how the overrides should behave. 5 | */ 6 | public enum OverrideBehaviour { 7 | /** 8 | * When evaluating values, the SDK will not use feature flags and settings from the ConfigCat CDN, but it will use 9 | * all feature flags and settings that are loaded from local-override sources. 10 | */ 11 | LOCAL_ONLY, 12 | /** 13 | * When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN, 14 | * plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is 15 | * defined both in the fetched and the local-override source then the local-override version will take precedence. 16 | */ 17 | LOCAL_OVER_REMOTE, 18 | /** 19 | * When evaluating values, the SDK will use all feature flags and settings that are downloaded from the ConfigCat CDN, 20 | * plus all feature flags and settings that are loaded from local-override sources. If a feature flag or a setting is 21 | * defined both in the fetched and the local-override source then the fetched version will take precedence. 22 | */ 23 | REMOTE_OVER_LOCAL, 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/OverrideDataSource.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.io.Closeable; 4 | import java.io.IOException; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | class OverrideDataSource implements Closeable { 9 | public Map getLocalConfiguration() { 10 | return new HashMap<>(); 11 | } 12 | 13 | @Override 14 | public void close() throws IOException { 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/OverrideDataSourceBuilder.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Describes a data source builder. 7 | */ 8 | public class OverrideDataSourceBuilder { 9 | private String filePath; 10 | private boolean isResource; 11 | private boolean autoReload; 12 | private Map map; 13 | 14 | private OverrideDataSourceBuilder(String filePath, boolean isResource, boolean autoReload) { 15 | this.filePath = filePath; 16 | this.isResource = isResource; 17 | this.autoReload = autoReload; 18 | } 19 | 20 | private OverrideDataSourceBuilder(Map map) { 21 | this.map = map; 22 | } 23 | 24 | OverrideDataSource build(ConfigCatLogger logger) { 25 | if (this.map != null) { 26 | return new LocalMapDataSource(this.map); 27 | } 28 | 29 | if (this.filePath != null && !this.filePath.isEmpty()) { 30 | return new LocalFileDataSource(this.filePath, this.isResource, logger, this.autoReload); 31 | } 32 | 33 | return new OverrideDataSource(); 34 | } 35 | 36 | /** 37 | * Creates an override data source builder that describes a local file data source. 38 | * 39 | * @param filePath path to the file. 40 | * @param autoReload when it's true, the file will be reloaded when it gets modified. 41 | * @return the builder. 42 | */ 43 | public static OverrideDataSourceBuilder localFile(String filePath, boolean autoReload) { 44 | return new OverrideDataSourceBuilder(filePath, false, autoReload); 45 | } 46 | 47 | /** 48 | * Creates an override data source builder that describes a classpath resource data source. 49 | * 50 | * @param resourceName name of the classpath resource. 51 | * @return the builder. 52 | */ 53 | public static OverrideDataSourceBuilder classPathResource(String resourceName) { 54 | return new OverrideDataSourceBuilder(resourceName, true, false); 55 | } 56 | 57 | /** 58 | * Creates an override data source builder that describes a map data source. 59 | * 60 | * @param map map that contains the overrides. 61 | * @return the builder. 62 | */ 63 | public static OverrideDataSourceBuilder map(Map map) { 64 | return new OverrideDataSourceBuilder(map); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/PercentageOption.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Represents a percentage option. 7 | */ 8 | public class PercentageOption { 9 | 10 | @SerializedName(value = "p") 11 | private int percentage; 12 | @SerializedName(value = "v") 13 | private SettingValue value; 14 | @SerializedName(value = "i") 15 | private String variationId; 16 | 17 | /** 18 | * A number between 0 and 100 that represents a randomly allocated fraction of the users. 19 | */ 20 | public int getPercentage() { 21 | return percentage; 22 | } 23 | 24 | /** 25 | * The value associated with the percentage option. 26 | * Can be a value of the following types: {@link Boolean}, {@link String}, {@link Integer} or {@link Double}. 27 | */ 28 | public SettingValue getValue() { 29 | return value; 30 | } 31 | 32 | /** 33 | * Variation ID. 34 | */ 35 | public String getVariationId() { 36 | return variationId; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/PollingMode.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * The base class of a polling mode configuration. 5 | */ 6 | public abstract class PollingMode { 7 | String getPollingIdentifier() { 8 | return "n/a"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/PollingModes.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Describes the polling modes. 5 | */ 6 | public final class PollingModes { 7 | 8 | private static final int DEFAULT_AUTO_POLL_INTERVAL_IN_SECONDS = 60; 9 | private static final int DEFAULT_MAX_INIT_WAIT_TIME_IN_SECONDS = 5; 10 | private static final int DEFAULT_CACHE_REFRESH_INTERVAL_IN_SECONDS = 60; 11 | 12 | 13 | /** 14 | * Set up the auto polling mode with default parameters. 15 | * 16 | * @return the auto polling mode. 17 | */ 18 | public static PollingMode autoPoll() { 19 | return new AutoPollingMode(DEFAULT_AUTO_POLL_INTERVAL_IN_SECONDS, DEFAULT_MAX_INIT_WAIT_TIME_IN_SECONDS); 20 | } 21 | 22 | /** 23 | * Set up the auto polling mode with custom parameters. 24 | * 25 | * @param autoPollIntervalInSeconds Sets how often the config.json should be fetched and cached. 26 | * @return the auto polling mode. 27 | */ 28 | public static PollingMode autoPoll(int autoPollIntervalInSeconds) { 29 | return new AutoPollingMode(autoPollIntervalInSeconds, DEFAULT_MAX_INIT_WAIT_TIME_IN_SECONDS); 30 | } 31 | 32 | /** 33 | * Set up the auto polling mode with custom parameters. 34 | * 35 | * @param autoPollIntervalInSeconds Sets how often the config.json should be fetched and cached. 36 | * @param maxInitWaitTimeSeconds Sets the time limit between the initialization of the client and the first config.json acquisition. 37 | * @return the auto polling mode. 38 | */ 39 | public static PollingMode autoPoll(int autoPollIntervalInSeconds, int maxInitWaitTimeSeconds) { 40 | return new AutoPollingMode(autoPollIntervalInSeconds, maxInitWaitTimeSeconds); 41 | } 42 | 43 | /** 44 | * Set up a lazy polling mode with default parameters. 45 | * 46 | * @return the lazy polling mode. 47 | */ 48 | public static PollingMode lazyLoad() { 49 | return new LazyLoadingMode(DEFAULT_CACHE_REFRESH_INTERVAL_IN_SECONDS); 50 | } 51 | 52 | /** 53 | * Set up a lazy polling mode with custom parameters. 54 | * 55 | * @param cacheRefreshIntervalInSeconds Sets how long the cache will store its value before fetching the latest from the network again. 56 | * @return the lazy polling mode. 57 | */ 58 | public static PollingMode lazyLoad(int cacheRefreshIntervalInSeconds) { 59 | return new LazyLoadingMode(cacheRefreshIntervalInSeconds); 60 | } 61 | 62 | /** 63 | * Set up the manual polling mode. 64 | * 65 | * @return the manual polling mode. 66 | */ 67 | public static PollingMode manualPoll() { 68 | return new ManualPollingMode(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Preferences.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | class Preferences { 6 | 7 | @SerializedName(value = "u") 8 | private String baseUrl; 9 | @SerializedName(value = "r") 10 | private int redirect; 11 | @SerializedName(value = "s") 12 | private String salt; 13 | 14 | public String getBaseUrl() { 15 | return baseUrl; 16 | } 17 | 18 | public int getRedirect() { 19 | return redirect; 20 | } 21 | 22 | public String getSalt() { 23 | return salt; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/PrerequisiteComparator.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Prerequisite flag comparison operator used during the evaluation process. 5 | */ 6 | public enum PrerequisiteComparator { 7 | /** 8 | * EQUALS - Checks whether the evaluated value of the specified prerequisite flag is equal to the comparison value. 9 | */ 10 | EQUALS(0, "EQUALS"), 11 | /** 12 | * NOT EQUALS - Checks whether the evaluated value of the specified prerequisite flag is not equal to the comparison value. 13 | */ 14 | NOT_EQUALS(1, "NOT EQUALS"); 15 | 16 | private final int id; 17 | private final String name; 18 | 19 | PrerequisiteComparator(int id, String name) { 20 | this.id = id; 21 | this.name = name; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public static PrerequisiteComparator fromId(int id) { 29 | for (PrerequisiteComparator comparator : PrerequisiteComparator.values()) { 30 | if (comparator.id == id) { 31 | return comparator; 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/PrerequisiteFlagCondition.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes a condition that is based on a prerequisite flag. 7 | */ 8 | public class PrerequisiteFlagCondition { 9 | 10 | @SerializedName(value = "f") 11 | private String prerequisiteFlagKey; 12 | @SerializedName(value = "c") 13 | private int prerequisiteComparator; 14 | @SerializedName(value = "v") 15 | private SettingValue value; 16 | 17 | /** 18 | * The key of the prerequisite flag that the condition is based on. 19 | */ 20 | public String getPrerequisiteFlagKey() { 21 | return prerequisiteFlagKey; 22 | } 23 | 24 | /** 25 | * The operator which defines the relation between the evaluated value of the prerequisite flag and the comparison value. 26 | */ 27 | public int getPrerequisiteComparator() { 28 | return prerequisiteComparator; 29 | } 30 | 31 | /** 32 | * The value that the evaluated value of the prerequisite flag is compared to. 33 | * Can be a value of the following types: {@link Boolean}, {@link String}, {@link Integer} or {@link Double}. 34 | */ 35 | public SettingValue getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/RefreshResult.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Represents the result of a forceRefresh() call. 5 | */ 6 | public class RefreshResult { 7 | private final boolean success; 8 | private final Object error; 9 | 10 | RefreshResult(boolean success, Object error) { 11 | this.success = success; 12 | this.error = error; 13 | } 14 | 15 | public boolean isSuccess() { 16 | return success; 17 | } 18 | 19 | public String error() { 20 | if(error != null) { 21 | return error.toString(); 22 | } 23 | return null; 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/Result.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | final class Result { 4 | private final T value; 5 | private final Object error; 6 | 7 | private Result(T value, Object error) { 8 | this.value = value; 9 | this.error = error; 10 | } 11 | 12 | T value() { 13 | return this.value; 14 | } 15 | 16 | Object error() { 17 | return this.error; 18 | } 19 | 20 | static Result error(Object error, T value) { 21 | return new Result<>(value, error); 22 | } 23 | 24 | static Result success(T value) { 25 | return new Result<>(value, null); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Segment.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * ConfigCat segment. 7 | */ 8 | public class Segment { 9 | 10 | @SerializedName(value = "n") 11 | private String name; 12 | @SerializedName(value = "r") 13 | private UserCondition[] segmentRules; 14 | 15 | /** 16 | * The name of the segment. 17 | */ 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | /** 23 | * The list of segment rule conditions (where there is a logical AND relation between the items). 24 | */ 25 | public UserCondition[] getSegmentRules() { 26 | return segmentRules; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/SegmentComparator.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | /** 4 | * Segment comparison operator used during the evaluation process. 5 | */ 6 | public enum SegmentComparator { 7 | /** 8 | * IS IN SEGMENT - Checks whether the conditions of the specified segment are evaluated to true. 9 | */ 10 | IS_IN_SEGMENT(0, "IS IN SEGMENT"), 11 | /** 12 | * IS NOT IN SEGMENT - Checks whether the conditions of the specified segment are evaluated to false. 13 | */ 14 | IS_NOT_IN_SEGMENT(1, "IS NOT IN SEGMENT"); 15 | 16 | private final int id; 17 | private final String name; 18 | 19 | SegmentComparator(int id, String name) { 20 | this.id = id; 21 | this.name = name; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public static SegmentComparator fromId(int id) { 29 | for (SegmentComparator comparator : SegmentComparator.values()) { 30 | if (comparator.id == id) { 31 | return comparator; 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/SegmentCondition.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes a condition that is based on a segment. 7 | */ 8 | public class SegmentCondition { 9 | 10 | @SerializedName(value = "s") 11 | private int segmentIndex; 12 | 13 | @SerializedName(value = "c") 14 | private int segmentComparator; 15 | 16 | /** 17 | * The index of the segment that the condition is based on. 18 | */ 19 | public int getSegmentIndex() { 20 | return segmentIndex; 21 | } 22 | 23 | /** 24 | * The operator which defines the expected result of the evaluation of the segment. 25 | */ 26 | public int getSegmentComparator() { 27 | return segmentComparator; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Setting.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Feature flag or setting. 7 | */ 8 | public class Setting { 9 | 10 | @SerializedName(value = "t") 11 | private SettingType type = SettingType.BOOLEAN; 12 | @SerializedName(value = "a") 13 | private String percentageAttribute; 14 | @SerializedName(value = "p") 15 | private PercentageOption[] percentageOptions; 16 | @SerializedName(value = "r") 17 | private TargetingRule[] targetingRules; 18 | @SerializedName(value = "v") 19 | private SettingValue settingValue; 20 | @SerializedName(value = "i") 21 | private String variationId; 22 | private String configSalt; 23 | private Segment[] segments; 24 | 25 | public void setSettingsValue(SettingValue settingValue) { 26 | this.settingValue = settingValue; 27 | } 28 | 29 | public void setType(SettingType type) { 30 | this.type = type; 31 | } 32 | 33 | public void setConfigSalt(String configSalt) { 34 | this.configSalt = configSalt; 35 | } 36 | 37 | public void setSegments(Segment[] segments) { 38 | this.segments = segments; 39 | } 40 | 41 | /** 42 | * Setting type. 43 | */ 44 | public SettingType getType() { 45 | return type; 46 | } 47 | 48 | /** 49 | * The User Object attribute which serves as the basis of percentage options evaluation. 50 | */ 51 | public String getPercentageAttribute() { 52 | return percentageAttribute; 53 | } 54 | 55 | /** 56 | * The list of percentage options. 57 | */ 58 | public PercentageOption[] getPercentageOptions() { 59 | return percentageOptions; 60 | } 61 | 62 | /** 63 | * The list of targeting rules (where there is a logical OR relation between the items). 64 | */ 65 | public TargetingRule[] getTargetingRules() { 66 | return targetingRules; 67 | } 68 | 69 | /** 70 | * Setting value. 71 | * Can be a value of the following types: {@link Boolean}, {@link String}, {@link Integer} or {@link Double}. 72 | */ 73 | public SettingValue getSettingsValue() { 74 | return settingValue; 75 | } 76 | 77 | /** 78 | * Variation ID. 79 | */ 80 | public String getVariationId() { 81 | return variationId; 82 | } 83 | 84 | public String getConfigSalt() { 85 | return configSalt; 86 | } 87 | 88 | public Segment[] getSegments() { 89 | return segments; 90 | } 91 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/SettingResult.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Represents the result of a getSettings() call. 8 | */ 9 | class SettingResult { 10 | private final Map settings; 11 | private final long fetchTime; 12 | 13 | public SettingResult(Map settings, long fetchTime) { 14 | this.settings = settings; 15 | this.fetchTime = fetchTime; 16 | } 17 | 18 | public Map settings() { 19 | return settings; 20 | } 21 | 22 | public long fetchTime() { 23 | return fetchTime; 24 | } 25 | 26 | boolean isEmpty() { 27 | return EMPTY.equals(this); 28 | } 29 | 30 | public static final SettingResult EMPTY = new SettingResult(new HashMap<>(), Constants.DISTANT_PAST); 31 | } -------------------------------------------------------------------------------- /src/main/java/com/configcat/SettingType.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Setting type. 7 | */ 8 | public enum SettingType { 9 | /** 10 | * On/off type (feature flag). 11 | */ 12 | @SerializedName("0") 13 | BOOLEAN, 14 | 15 | /** 16 | * Text type. 17 | */ 18 | @SerializedName("1") 19 | STRING, 20 | 21 | /** 22 | * Whole number type. 23 | */ 24 | @SerializedName("2") 25 | INT, 26 | 27 | /** 28 | * Decimal number type. 29 | */ 30 | @SerializedName("3") 31 | DOUBLE, 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/SettingValue.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * Describes the setting type-specific value of a setting or feature flag. 9 | */ 10 | public class SettingValue { 11 | @SerializedName("b") 12 | private Boolean booleanValue; 13 | 14 | @SerializedName("s") 15 | private String stringValue; 16 | 17 | @SerializedName("i") 18 | private Integer integerValue; 19 | 20 | @SerializedName("d") 21 | private Double doubleValue; 22 | 23 | public void setBooleanValue(Boolean booleanValue) { 24 | this.booleanValue = booleanValue; 25 | } 26 | 27 | public void setStringValue(String stringValue) { 28 | this.stringValue = stringValue; 29 | } 30 | 31 | public void setIntegerValue(Integer integerValue) { 32 | this.integerValue = integerValue; 33 | } 34 | 35 | public void setDoubleValue(Double doubleValue) { 36 | this.doubleValue = doubleValue; 37 | } 38 | 39 | public Boolean getBooleanValue() { 40 | return booleanValue; 41 | } 42 | 43 | public String getStringValue() { 44 | return stringValue; 45 | } 46 | 47 | public Integer getIntegerValue() { 48 | return integerValue; 49 | } 50 | 51 | public Double getDoubleValue() { 52 | return doubleValue; 53 | } 54 | 55 | public boolean equalsBasedOnSettingType(Object o, SettingType settingType) { 56 | if (this == o) return true; 57 | if (o == null || getClass() != o.getClass()) return false; 58 | SettingValue that = (SettingValue) o; 59 | switch (settingType){ 60 | case BOOLEAN: 61 | return Objects.equals(booleanValue, that.booleanValue); 62 | case STRING: 63 | return Objects.equals(stringValue, that.stringValue); 64 | case INT: 65 | return Objects.equals(integerValue, that.integerValue); 66 | case DOUBLE: 67 | return Objects.equals(doubleValue, that.doubleValue); 68 | default: 69 | throw new IllegalStateException("Setting is of an unsupported type (" + settingType.name() + ")."); 70 | } 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | if (booleanValue != null) { 76 | return booleanValue.toString(); 77 | } else if (integerValue != null) { 78 | return integerValue.toString(); 79 | } else if (doubleValue != null) { 80 | return doubleValue.toString(); 81 | } else { 82 | return stringValue; 83 | } 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/TargetingRule.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes a targeting rule. 7 | */ 8 | public class TargetingRule { 9 | 10 | @SerializedName(value = "c") 11 | private Condition[] conditions; 12 | @SerializedName(value = "p") 13 | private PercentageOption[] percentageOptions; 14 | @SerializedName(value = "s") 15 | private SimpleValue simpleValue; 16 | 17 | /** 18 | * The list of conditions that are combined with the AND logical operator. 19 | * Items can be one of the following types: {@link UserCondition}, {@link SegmentCondition} or {@link PrerequisiteFlagCondition}. 20 | */ 21 | public Condition[] getConditions() { 22 | return conditions != null ? conditions : new Condition[]{}; 23 | } 24 | 25 | /** 26 | * The list of percentage options associated with the targeting rule or {@code null} if the targeting rule has a simple value THEN part. 27 | */ 28 | public PercentageOption[] getPercentageOptions() { 29 | return percentageOptions; 30 | } 31 | 32 | /** 33 | * The simple value associated with the targeting rule or {@code null} if the targeting rule has percentage options THEN part. 34 | */ 35 | public SimpleValue getSimpleValue() { 36 | return simpleValue; 37 | } 38 | } 39 | 40 | class SimpleValue { 41 | @SerializedName(value = "v") 42 | private SettingValue value; 43 | @SerializedName(value = "i") 44 | private String variationId; 45 | 46 | public SettingValue getValue() { 47 | return value; 48 | } 49 | 50 | public String getVariationId() { 51 | return variationId; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/UserAttributeConverter.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.text.DecimalFormat; 4 | import java.text.DecimalFormatSymbols; 5 | import java.time.Instant; 6 | import java.util.Date; 7 | import java.util.List; 8 | import java.util.Locale; 9 | 10 | final class UserAttributeConverter { 11 | 12 | public static String userAttributeToString(Object userAttribute) { 13 | if (userAttribute == null) { 14 | return null; 15 | } 16 | if (userAttribute instanceof String) { 17 | return (String) userAttribute; 18 | } 19 | if (userAttribute instanceof String[]) { 20 | return Utils.gson.toJson(userAttribute); 21 | } 22 | if (userAttribute instanceof List) { 23 | return Utils.gson.toJson(userAttribute); 24 | } 25 | if (userAttribute instanceof Date) { 26 | Date userAttributeDate = (Date) userAttribute; 27 | return doubleToString(DateTimeUtils.getUnixSeconds(userAttributeDate)); 28 | } 29 | if (userAttribute instanceof Instant) { 30 | Instant userAttributeInstant = (Instant) userAttribute; 31 | return doubleToString(DateTimeUtils.getUnixSeconds(userAttributeInstant)); 32 | } 33 | if (userAttribute instanceof Float) { 34 | return doubleToString(((Float) userAttribute).doubleValue()); 35 | } 36 | if (userAttribute instanceof Double) { 37 | return doubleToString((Double) userAttribute); 38 | } 39 | return userAttribute.toString(); 40 | } 41 | 42 | private static String doubleToString(Double doubleToString) { 43 | 44 | // Handle Double.NaN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY 45 | if (doubleToString.isNaN() || doubleToString.isInfinite()) { 46 | return doubleToString.toString(); 47 | } 48 | 49 | // To get similar result between different SDKs the Double value format is modified. 50 | // Between 1e-6 and 1e21 we don't use scientific-notation. Over these limits scientific-notation used but the 51 | // ExponentSeparator replaced with "e" and "e+". 52 | // "." used as decimal separator in all cases. 53 | double abs = Math.abs(doubleToString); 54 | DecimalFormat fmt = 1e-6 <= abs && abs < 1e21 55 | ? new DecimalFormat("#.#################") 56 | : new DecimalFormat("#.#################E0"); 57 | DecimalFormatSymbols SYMBOLS = DecimalFormatSymbols.getInstance(Locale.UK); 58 | if (abs > 1) { 59 | SYMBOLS.setExponentSeparator("e+"); 60 | } else { 61 | SYMBOLS.setExponentSeparator("e"); 62 | } 63 | fmt.setDecimalFormatSymbols(SYMBOLS); 64 | return fmt.format(doubleToString); 65 | } 66 | 67 | public static Double userAttributeToDouble(Object userAttribute) { 68 | if (userAttribute == null) { 69 | return null; 70 | } 71 | if (userAttribute instanceof Double) { 72 | return (Double) userAttribute; 73 | } 74 | if (userAttribute instanceof String) { 75 | return Double.parseDouble(((String) userAttribute).trim().replace(",", ".")); 76 | } 77 | if (userAttribute instanceof Integer) { 78 | return ((Integer) userAttribute).doubleValue(); 79 | } 80 | if (userAttribute instanceof Float) { 81 | return ((Float) userAttribute).doubleValue(); 82 | } 83 | if (userAttribute instanceof Long) { 84 | return ((Long) userAttribute).doubleValue(); 85 | } 86 | if (userAttribute instanceof Byte) { 87 | return ((Byte) userAttribute).doubleValue(); 88 | } 89 | if (userAttribute instanceof Short) { 90 | return ((Short) userAttribute).doubleValue(); 91 | } 92 | 93 | throw new NumberFormatException(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/UserCondition.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | /** 6 | * Describes a condition that is based on a User Object attribute. 7 | */ 8 | public class UserCondition implements ConditionAccessor { 9 | 10 | @SerializedName(value = "a") 11 | private String comparisonAttribute; 12 | 13 | @SerializedName(value = "c") 14 | private int comparator; 15 | @SerializedName("s") 16 | private String stringValue; 17 | @SerializedName("d") 18 | private Double doubleValue; 19 | @SerializedName("l") 20 | private String[] stringArrayValue; 21 | 22 | /** 23 | * The User Object attribute that the condition is based on. Can be "Identifier", "Email", "Country" or any custom attribute. 24 | */ 25 | public String getComparisonAttribute() { 26 | return comparisonAttribute; 27 | } 28 | 29 | /** 30 | * The operator which defines the relation between the comparison attribute and the comparison value. 31 | */ 32 | public int getComparator() { 33 | return comparator; 34 | } 35 | 36 | /** 37 | * The String value that the User Object attribute is compared or {@code null} if the comparator use a different type of value. 38 | */ 39 | public String getStringValue() { 40 | return stringValue; 41 | } 42 | 43 | /** 44 | * The Double value that the User Object attribute is compared or {@code null} if the comparator use a different type of value. 45 | */ 46 | public Double getDoubleValue() { 47 | return doubleValue; 48 | } 49 | 50 | /** 51 | * The String Array value that the User Object attribute is compared or {@code null} if the comparator use a different type of value. 52 | */ 53 | public String[] getStringArrayValue() { 54 | return stringArrayValue; 55 | } 56 | 57 | @Override 58 | public UserCondition getUserCondition() { 59 | return this; 60 | } 61 | 62 | @Override 63 | public SegmentCondition getSegmentCondition() { 64 | return null; 65 | } 66 | 67 | @Override 68 | public PrerequisiteFlagCondition getPrerequisiteFlagCondition() { 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/configcat/Utils.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import org.apache.commons.codec.binary.Hex; 6 | import org.apache.commons.codec.digest.DigestUtils; 7 | 8 | import java.text.DecimalFormat; 9 | import java.text.DecimalFormatSymbols; 10 | import java.util.Locale; 11 | 12 | final class Utils { 13 | private Utils() { /* prevent from instantiation*/ } 14 | 15 | static final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); 16 | 17 | public static String sha256(byte[] byteArray) { 18 | return new String(Hex.encodeHex(DigestUtils.sha256(byteArray))); 19 | } 20 | 21 | public static String sha256(String text) { 22 | return new String(Hex.encodeHex(DigestUtils.sha256(text))); 23 | } 24 | 25 | public static String sha1(String text) { 26 | return new String(Hex.encodeHex(DigestUtils.sha1(text))); 27 | } 28 | 29 | public static String sha1(byte[] byteArray) { 30 | return new String(Hex.encodeHex(DigestUtils.sha1(byteArray))); 31 | } 32 | 33 | public static DecimalFormat getDecimalFormat() { 34 | DecimalFormat decimalFormat = new DecimalFormat("0.#####"); 35 | decimalFormat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.UK)); 36 | return decimalFormat; 37 | } 38 | 39 | public static Config deserializeConfig(String json) { 40 | Config config = Utils.gson.fromJson(json, Config.class); 41 | String salt = config.getPreferences().getSalt(); 42 | Segment[] segments = config.getSegments(); 43 | if (segments == null) { 44 | segments = new Segment[]{}; 45 | } 46 | for (Setting setting : config.getEntries().values()) { 47 | setting.setConfigSalt(salt); 48 | setting.setSegments(segments); 49 | } 50 | return config; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/EntrySerializationTest.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class EntrySerializationTest { 8 | 9 | private static final String TEST_JSON = "{ p: { s: 'test-salt'}, f: { fakeKey: { v: { s: %s }, t: %s, p: [], r: [] } } }"; 10 | 11 | private static final String SERIALIZED_DATA = "%s\n%s\n%s"; 12 | 13 | @Test 14 | void serialize() { 15 | String json = String.format(TEST_JSON, "test", "1"); 16 | Config config = Utils.gson.fromJson(json, Config.class); 17 | long fetchTime = System.currentTimeMillis(); 18 | Entry entry = new Entry(config, "fakeTag", json, fetchTime); 19 | 20 | String serializedString = entry.getCacheString(); 21 | 22 | assertEquals(String.format(SERIALIZED_DATA, fetchTime, "fakeTag", json), serializedString); 23 | } 24 | 25 | @Test 26 | void payloadSerializationPlatformIndependent() { 27 | String payloadTestConfigJson = "{\"p\":{\"u\":\"https://cdn-global.configcat.com\",\"r\":0,\"s\": \"test-salt\"},\"f\":{\"testKey\":{\"v\":{\"s\":\"testValue\"},\"t\":1,\"p\":[],\"r\":[]}}}"; 28 | 29 | Config config = Utils.gson.fromJson(payloadTestConfigJson, Config.class); 30 | Entry entry = new Entry(config, "test-etag", payloadTestConfigJson, 1686756435844L); 31 | String serializedString = entry.getCacheString(); 32 | 33 | assertEquals("1686756435844\ntest-etag\n" + payloadTestConfigJson, serializedString); 34 | } 35 | 36 | @Test 37 | void deserialize() { 38 | String json = String.format(TEST_JSON, "test", "1"); 39 | long currentTimeMillis = System.currentTimeMillis(); 40 | 41 | Entry entry = Entry.fromString(String.format(SERIALIZED_DATA, currentTimeMillis, "fakeTag", json)); 42 | 43 | assertNotNull(entry); 44 | assertEquals("fakeTag", entry.getETag()); 45 | assertEquals(currentTimeMillis + "\nfakeTag\n" + json, entry.getCacheString()); 46 | assertEquals(1, entry.getConfig().getEntries().size()); 47 | assertEquals(currentTimeMillis, entry.getFetchTime()); 48 | } 49 | 50 | @Test 51 | void withFetchTime() { 52 | String json = String.format(TEST_JSON, "test", "1"); 53 | long currentTimeMillis = System.currentTimeMillis(); 54 | 55 | Entry entry = Entry.fromString(String.format(SERIALIZED_DATA, currentTimeMillis, "fakeTag", json)); 56 | 57 | long updatedMillis = System.currentTimeMillis() + 1000; 58 | Entry updated = entry.withFetchTime(updatedMillis); 59 | 60 | assertEquals(updatedMillis + "\nfakeTag\n" + json, updated.getCacheString()); 61 | } 62 | 63 | @Test 64 | void deserializeMissingValue() { 65 | Entry deserializeNull = Entry.fromString(null); 66 | assertTrue(deserializeNull.isEmpty()); 67 | Entry deserializeEmpty = Entry.fromString(""); 68 | assertTrue(deserializeEmpty.isEmpty()); 69 | } 70 | 71 | @Test 72 | void deserializeWrongFormat() { 73 | Exception assertThrows = assertThrows(Exception.class, () -> Entry.fromString("value with no new line")); 74 | assertEquals("Number of values is fewer than expected.", assertThrows.getMessage()); 75 | 76 | assertThrows = assertThrows(Exception.class, () -> Entry.fromString("value with one \n new line")); 77 | assertEquals("Number of values is fewer than expected.", assertThrows.getMessage()); 78 | } 79 | 80 | @Test 81 | void deserializeInvalidDate() { 82 | Exception assertThrows = assertThrows(Exception.class, () -> Entry.fromString(String.format(SERIALIZED_DATA, "invalid", "fakeTag", "json"))); 83 | 84 | assertEquals("Invalid fetch time: invalid", assertThrows.getMessage()); 85 | } 86 | 87 | @Test 88 | void deserializeInvalidETag() { 89 | long currentTimeMillis = System.currentTimeMillis(); 90 | Exception assertThrows = assertThrows(Exception.class, () -> Entry.fromString(String.format(SERIALIZED_DATA, currentTimeMillis / 1000, "", "json"))); 91 | 92 | assertEquals("Empty eTag value.", assertThrows.getMessage()); 93 | } 94 | 95 | @Test 96 | void deserializeInvalidJson() { 97 | long currentTimeMillis = System.currentTimeMillis(); 98 | Exception assertThrows = assertThrows(Exception.class, () -> Entry.fromString(String.format(SERIALIZED_DATA, currentTimeMillis / 1000, "fakeTag", ""))); 99 | 100 | assertEquals("Empty config jsom value.", assertThrows.getMessage()); 101 | 102 | assertThrows = assertThrows(Exception.class, () -> Entry.fromString(String.format(SERIALIZED_DATA, currentTimeMillis / 1000, "fakeTag", "wrongjson"))); 103 | 104 | assertEquals("Invalid config JSON content: wrongjson", assertThrows.getMessage()); 105 | 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/EvaluationLoggerTurnOffTest.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import ch.qos.logback.classic.Level; 4 | import ch.qos.logback.classic.Logger; 5 | import ch.qos.logback.classic.spi.ILoggingEvent; 6 | import ch.qos.logback.core.read.ListAppender; 7 | import org.junit.Test; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | // Test cases based on EvaluationTest 1_rule_no_user test case. 16 | public class EvaluationLoggerTurnOffTest { 17 | @Test 18 | public void testEvaluationLogLevelInfo() throws IOException { 19 | 20 | ConfigCatClient client = ConfigCatClient.get("PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", options -> { 21 | options.pollingMode(PollingModes.manualPoll()); 22 | options.logLevel(LogLevel.INFO); 23 | }); 24 | 25 | client.forceRefresh(); 26 | 27 | Logger clientLogger = (Logger) LoggerFactory.getLogger(ConfigCatClient.class); 28 | // create and start a ListAppender 29 | clientLogger.setLevel(Level.INFO); 30 | ListAppender listAppender = new ListAppender<>(); 31 | listAppender.start(); 32 | 33 | clientLogger.addAppender(listAppender); 34 | 35 | String returnValue = client.getValue(String.class, "stringContainsDogDefaultCat", null, "default"); 36 | 37 | assertEquals("Return value not match.", "Cat", returnValue); 38 | 39 | List logsList = listAppender.list; 40 | assertEquals("Logged event size not match.", 2, logsList.size()); 41 | assertEquals("LogLevel mismatch.", Level.WARN, logsList.get(0).getLevel()); 42 | assertEquals("LogLevel mismatch.", Level.INFO, logsList.get(1).getLevel()); 43 | 44 | client.close(); 45 | } 46 | 47 | @Test 48 | public void testEvaluationLogLevelWarning() throws IOException { 49 | //based on 1_rule_no_user test case. 50 | ConfigCatClient client = ConfigCatClient.get("PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", options -> { 51 | options.pollingMode(PollingModes.manualPoll()); 52 | options.logLevel(LogLevel.WARNING); 53 | }); 54 | 55 | client.forceRefresh(); 56 | 57 | Logger clientLogger = (Logger) LoggerFactory.getLogger(ConfigCatClient.class); 58 | // create and start a ListAppender 59 | clientLogger.setLevel(Level.INFO); 60 | ListAppender listAppender = new ListAppender<>(); 61 | listAppender.start(); 62 | 63 | clientLogger.addAppender(listAppender); 64 | 65 | String returnValue = client.getValue(String.class, "stringContainsDogDefaultCat", null, "default"); 66 | 67 | assertEquals("Return value not match.", "Cat", returnValue); 68 | 69 | List logsList = listAppender.list; 70 | assertEquals("Logged event size not match.", 1, logsList.size()); 71 | assertEquals("LogLevel mismatch.", Level.WARN, logsList.get(0).getLevel()); 72 | 73 | client.close(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/FailingCache.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | public class FailingCache extends ConfigCache { 4 | 5 | @Override 6 | protected String read(String key) throws Exception { 7 | throw new Exception(); 8 | } 9 | 10 | @Override 11 | protected void write(String key, String value) throws Exception { 12 | throw new Exception(); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/FormattableLogMessageTests.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | class FormattableLogMessageTests { 13 | 14 | @Test 15 | void hashCodeTest() { 16 | FormattableLogMessage obj1 = new FormattableLogMessage("message %s", "formatted"); 17 | FormattableLogMessage obj2 = new FormattableLogMessage("message %s", "formatted"); 18 | 19 | //test hashcode consistency 20 | assertEquals(obj1.hashCode(), obj1.hashCode()); 21 | 22 | //test hashcode equality 23 | assertEquals(obj1.hashCode(), obj2.hashCode()); 24 | 25 | //test hashcode distribution 26 | List objects = new ArrayList<>(); 27 | for (int i = 0; i < 1000; i++) { 28 | objects.add(new FormattableLogMessage("message %s %d", "formatted", i)); 29 | } 30 | Set hashCodes = new HashSet<>(); 31 | for (FormattableLogMessage obj : objects) { 32 | hashCodes.add(obj.hashCode()); 33 | } 34 | assertEquals(objects.size(), hashCodes.size()); 35 | } 36 | 37 | @Test 38 | void equalsTest() { 39 | FormattableLogMessage obj1 = new FormattableLogMessage("message %s", "formatted"); 40 | FormattableLogMessage obj2 = new FormattableLogMessage("message %s", "formatted"); 41 | 42 | // assert equals 43 | boolean equalsResult = obj1.equals(obj2); 44 | assertTrue(equalsResult); 45 | 46 | // assert equals reverse 47 | equalsResult = obj2.equals(obj1); 48 | assertTrue(equalsResult); 49 | 50 | //assert not equals 51 | FormattableLogMessage obj3 = new FormattableLogMessage("message %s", "different"); 52 | equalsResult = obj1.equals(obj3); 53 | assertFalse(equalsResult); 54 | 55 | //assert null 56 | equalsResult = obj1.equals(null); 57 | assertFalse(equalsResult); 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/Helpers.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.function.Supplier; 4 | 5 | final class Helpers { 6 | public static final String SDK_KEY = "configcat-sdk-1/TEST_KEY-0123456789012/1234567890123456789012"; 7 | 8 | static String cacheValueFromConfigJson(String json) { 9 | Config config = Utils.gson.fromJson(json, Config.class); 10 | Entry entry = new Entry(config, "fakeTag", json, System.currentTimeMillis()); 11 | return entry.getCacheString(); 12 | } 13 | 14 | static String cacheValueFromConfigJsonWithTime(String json, long time) { 15 | Config config = Utils.gson.fromJson(json, Config.class); 16 | Entry entry = new Entry(config, "fakeTag", json, time); 17 | return entry.getCacheString(); 18 | } 19 | 20 | static String cacheValueFromConfigJsonWithEtag(String json, String etag) { 21 | Config config = Utils.gson.fromJson(json, Config.class); 22 | Entry entry = new Entry(config, etag, json, System.currentTimeMillis()); 23 | return entry.getCacheString(); 24 | } 25 | 26 | static void waitFor(Supplier predicate) throws InterruptedException { 27 | waitFor(3000, predicate); 28 | } 29 | 30 | static void waitFor(long timeout, Supplier predicate) throws InterruptedException { 31 | long end = System.currentTimeMillis() + timeout; 32 | while (!predicate.get()) { 33 | Thread.sleep(200); 34 | if (System.currentTimeMillis() > end) { 35 | throw new RuntimeException("Test timed out."); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/InMemoryCache.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import java.util.HashMap; 4 | 5 | class InMemoryCache extends ConfigCache { 6 | HashMap map = new HashMap<>(); 7 | 8 | @Override 9 | protected String read(String key) { 10 | return map.get(key); 11 | } 12 | 13 | @Override 14 | protected void write(String key, String value) { 15 | this.map.put(key, value); 16 | } 17 | 18 | public HashMap getMap() { 19 | return map; 20 | } 21 | } -------------------------------------------------------------------------------- /src/test/java/com/configcat/LoggerTests.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.slf4j.Logger; 5 | 6 | import static org.mockito.Mockito.*; 7 | 8 | public class LoggerTests { 9 | @Test 10 | public void debug() { 11 | Logger mockLogger = mock(Logger.class); 12 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.DEBUG); 13 | 14 | logger.debug("debug"); 15 | logger.info(5000, "info"); 16 | logger.warn(3000, "warn"); 17 | logger.error(1000, "error", new Exception()); 18 | 19 | verify(mockLogger, times(1)).debug(anyString(), eq(0), eq("debug")); 20 | verify(mockLogger, times(1)).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 21 | verify(mockLogger, times(1)).warn(anyString(), eq(3000), eq("warn")); 22 | verify(mockLogger, times(1)).info(anyString(), eq(5000), eq("info")); 23 | } 24 | 25 | @Test 26 | public void info() { 27 | Logger mockLogger = mock(Logger.class); 28 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO); 29 | 30 | logger.debug("debug"); 31 | logger.info(5000, "info"); 32 | logger.warn(3000, "warn"); 33 | logger.error(1000, "error", new Exception()); 34 | 35 | verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); 36 | verify(mockLogger, times(1)).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 37 | verify(mockLogger, times(1)).warn(anyString(), eq(3000), eq("warn")); 38 | verify(mockLogger, times(1)).info(anyString(), eq(5000), eq("info")); 39 | } 40 | 41 | @Test 42 | public void warn() { 43 | Logger mockLogger = mock(Logger.class); 44 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.WARNING); 45 | 46 | logger.debug("debug"); 47 | logger.info(5000, "info"); 48 | logger.warn(3000, "warn"); 49 | logger.error(1000, "error", new Exception()); 50 | 51 | verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); 52 | verify(mockLogger, never()).info(anyString(), eq(5000), eq("info")); 53 | verify(mockLogger, times(1)).warn(anyString(), eq(3000), eq("warn")); 54 | verify(mockLogger, times(1)).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 55 | } 56 | 57 | @Test 58 | public void error() { 59 | Logger mockLogger = mock(Logger.class); 60 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.ERROR); 61 | 62 | logger.debug("debug"); 63 | logger.info(5000, "info"); 64 | logger.warn(3000, "warn"); 65 | logger.error(1000, "error", new Exception()); 66 | 67 | verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); 68 | verify(mockLogger, never()).info(anyString(), eq(5000), eq("info")); 69 | verify(mockLogger, never()).warn(anyString(), eq(3000), eq("warn")); 70 | verify(mockLogger, times(1)).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 71 | 72 | 73 | } 74 | 75 | @Test 76 | public void noLog() { 77 | Logger mockLogger = mock(Logger.class); 78 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.NO_LOG); 79 | 80 | logger.debug("[0] debug"); 81 | logger.info(5000, "info"); 82 | logger.warn(3000, "warn"); 83 | logger.error(1000, "error", new Exception()); 84 | 85 | verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); 86 | verify(mockLogger, never()).info(anyString(), eq(5000), eq("info")); 87 | verify(mockLogger, never()).warn(anyString(), eq(3000), eq("warn")); 88 | verify(mockLogger, never()).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 89 | } 90 | 91 | @Test 92 | public void excludeLogEvents() { 93 | Logger mockLogger = mock(Logger.class); 94 | 95 | LogFilterFunction filterLogFunction = ( LogLevel logLevel, int eventId, Object message, Throwable exception) -> eventId != 1001 && eventId != 3001 && eventId != 5001 && !message.toString().contains("error"); 96 | 97 | ConfigCatLogger logger = new ConfigCatLogger(mockLogger, LogLevel.INFO, null, filterLogFunction); 98 | 99 | logger.debug("[0] debug"); 100 | logger.info(5000, "info"); 101 | logger.warn(3000, "warn"); 102 | logger.error(1000, "error", new Exception()); 103 | logger.info(5001, "info"); 104 | logger.warn(3001, "warn"); 105 | logger.error(1001, "error", new Exception()); 106 | 107 | verify(mockLogger, never()).debug(anyString(), eq(0), eq("debug")); 108 | verify(mockLogger, times(1)).info(anyString(), eq(5000), eq("info")); 109 | verify(mockLogger, times(1)).warn(anyString(), eq(3000), eq("warn")); 110 | verify(mockLogger, never()).error(anyString(), eq(1000), eq("error"), any(Exception.class)); 111 | verify(mockLogger, never()).info(anyString(), eq(5001), eq("info")); 112 | verify(mockLogger, never()).warn(anyString(), eq(3001), eq("warn")); 113 | verify(mockLogger, never()).error(anyString(), eq(1001), eq("error"), any(Exception.class)); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/test/java/com/configcat/SingleValueCache.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | class SingleValueCache extends ConfigCache { 4 | private String value; 5 | 6 | public SingleValueCache(String value) { 7 | this.value = value; 8 | } 9 | 10 | @Override 11 | protected String read(String key) { 12 | return this.value; 13 | } 14 | 15 | @Override 16 | protected void write(String key, String value) { 17 | this.value = value; 18 | } 19 | } -------------------------------------------------------------------------------- /src/test/java/com/configcat/UserTests.java: -------------------------------------------------------------------------------- 1 | package com.configcat; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.*; 6 | 7 | public class UserTests { 8 | 9 | @Test 10 | public void builderWorksWithEmptyOrNullId() { 11 | User u1 = User.newBuilder().build(null); 12 | assertEquals("", u1.getIdentifier()); 13 | User u2 = User.newBuilder().build(""); 14 | assertEquals("", u2.getIdentifier()); 15 | } 16 | 17 | @Test 18 | public void getAttributeThrowsWhenArgumentInvalid() { 19 | User user = User.newBuilder().build("a"); 20 | assertThrows(IllegalArgumentException.class, () -> user.getAttribute(null)); 21 | assertNull(user.getAttribute("")); 22 | } 23 | 24 | @Test 25 | public void getAttributeCaseSensitivityTest() { 26 | String email = "a@a.com"; 27 | String country = "b"; 28 | User user = User.newBuilder().email(email).country("b").build("a"); 29 | assertEquals(email, user.getAttribute("Email")); 30 | assertNotEquals(email, user.getAttribute("EMAIL")); 31 | assertNotEquals(email, user.getAttribute("email")); 32 | 33 | assertEquals(country, user.getAttribute("Country")); 34 | assertNotEquals(country, user.getAttribute("COUNTRY")); 35 | assertNotEquals(country, user.getAttribute("country")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/1_targeting_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", 3 | "tests": [ 4 | { 5 | "key": "stringContainsDogDefaultCat", 6 | "defaultValue": "default", 7 | "returnValue": "Cat", 8 | "expectedLog": "1_rule_no_user.txt" 9 | }, 10 | { 11 | "key": "stringContainsDogDefaultCat", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": "Cat", 17 | "expectedLog": "1_rule_no_targeted_attribute.txt" 18 | }, 19 | { 20 | "key": "stringContainsDogDefaultCat", 21 | "defaultValue": "default", 22 | "user": { 23 | "Identifier": "12345", 24 | "Email": "joe@example.com" 25 | }, 26 | "returnValue": "Cat", 27 | "expectedLog": "1_rule_not_matching_targeted_attribute.txt" 28 | }, 29 | { 30 | "key": "stringContainsDogDefaultCat", 31 | "defaultValue": "default", 32 | "user": { 33 | "Identifier": "12345", 34 | "Email": "joe@configcat.com" 35 | }, 36 | "returnValue": "Dog", 37 | "expectedLog": "1_rule_matching_targeted_attribute.txt" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/1_targeting_rule/1_rule_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'stringContainsDogDefaultCat' for User '{"Identifier":"12345","Email":"joe@configcat.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN 'Dog' => MATCH, applying rule 4 | Returning 'Dog'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/1_targeting_rule/1_rule_no_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email CONTAINS ANY OF ['@configcat.com']) for setting 'stringContainsDogDefaultCat' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringContainsDogDefaultCat' for User '{"Identifier":"12345"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN 'Dog' => cannot evaluate, the User.Email attribute is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'Cat'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/1_targeting_rule/1_rule_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'stringContainsDogDefaultCat' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringContainsDogDefaultCat' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN 'Dog' => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'Cat'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/1_targeting_rule/1_rule_not_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'stringContainsDogDefaultCat' for User '{"Identifier":"12345","Email":"joe@example.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN 'Dog' => no match 4 | Returning 'Cat'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/2_targeting_rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", 3 | "tests": [ 4 | { 5 | "key": "stringIsInDogDefaultCat", 6 | "defaultValue": "default", 7 | "returnValue": "Cat", 8 | "expectedLog": "2_rules_no_user.txt" 9 | }, 10 | { 11 | "key": "stringIsInDogDefaultCat", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": "Cat", 17 | "expectedLog": "2_rules_no_targeted_attribute.txt" 18 | }, 19 | { 20 | "key": "stringIsInDogDefaultCat", 21 | "defaultValue": "default", 22 | "user": { 23 | "Identifier": "12345", 24 | "Custom1": "user" 25 | }, 26 | "returnValue": "Cat", 27 | "expectedLog": "2_rules_not_matching_targeted_attribute.txt" 28 | }, 29 | { 30 | "key": "stringIsInDogDefaultCat", 31 | "defaultValue": "default", 32 | "user": { 33 | "Identifier": "12345", 34 | "Custom1": "admin" 35 | }, 36 | "returnValue": "Dog", 37 | "expectedLog": "2_rules_matching_targeted_attribute.txt" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/2_targeting_rules/2_rules_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com']) for setting 'stringIsInDogDefaultCat' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringIsInDogDefaultCat' for User '{"Identifier":"12345","Custom1":"admin"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com'] THEN 'Dog' => cannot evaluate, the User.Email attribute is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | - IF User.Custom1 IS ONE OF ['admin'] THEN 'Dog' => MATCH, applying rule 7 | Returning 'Dog'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/2_targeting_rules/2_rules_no_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com']) for setting 'stringIsInDogDefaultCat' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | WARNING [3003] Cannot evaluate condition (User.Custom1 IS ONE OF ['admin']) for setting 'stringIsInDogDefaultCat' (the User.Custom1 attribute is missing). You should set the User.Custom1 attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 3 | INFO [5000] Evaluating 'stringIsInDogDefaultCat' for User '{"Identifier":"12345"}' 4 | Evaluating targeting rules and applying the first match if any: 5 | - IF User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com'] THEN 'Dog' => cannot evaluate, the User.Email attribute is missing 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | - IF User.Custom1 IS ONE OF ['admin'] THEN 'Dog' => cannot evaluate, the User.Custom1 attribute is missing 8 | The current targeting rule is ignored and the evaluation continues with the next rule. 9 | Returning 'Cat'. 10 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/2_targeting_rules/2_rules_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'stringIsInDogDefaultCat' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringIsInDogDefaultCat' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com'] THEN 'Dog' => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | - IF User.Custom1 IS ONE OF ['admin'] THEN 'Dog' => cannot evaluate, User Object is missing 7 | The current targeting rule is ignored and the evaluation continues with the next rule. 8 | Returning 'Cat'. 9 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/2_targeting_rules/2_rules_not_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com']) for setting 'stringIsInDogDefaultCat' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringIsInDogDefaultCat' for User '{"Identifier":"12345","Custom1":"user"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email IS ONE OF ['a@configcat.com', 'b@configcat.com'] THEN 'Dog' => cannot evaluate, the User.Email attribute is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | - IF User.Custom1 IS ONE OF ['admin'] THEN 'Dog' => no match 7 | Returning 'Cat'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/and_rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A", 3 | "tests": [ 4 | { 5 | "key": "emailAnd", 6 | "defaultValue": "default", 7 | "returnValue": "Cat", 8 | "expectedLog": "and_rules_no_user.txt" 9 | }, 10 | { 11 | "key": "emailAnd", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345", 15 | "Email": "jane@configcat.com" 16 | }, 17 | "returnValue": "Cat", 18 | "expectedLog": "and_rules_user.txt" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/and_rules/and_rules_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'emailAnd' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'emailAnd' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email STARTS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 5 | THEN 'Dog' => cannot evaluate, User Object is missing 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | Returning 'Cat'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/and_rules/and_rules_user.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'emailAnd' for User '{"Identifier":"12345","Email":"jane@configcat.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email STARTS WITH ANY OF [<1 hashed value>] => true 4 | AND User.Email CONTAINS ANY OF ['@'] => true 5 | AND User.Email ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 6 | THEN 'Dog' => no match 7 | Returning 'Cat'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/comparators.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ", 3 | "tests": [ 4 | { 5 | "key": "allinone", 6 | "defaultValue": "", 7 | "user": { 8 | "Identifier": "12345", 9 | "Email": "joe@example.com", 10 | "Country": "[\"USA\"]", 11 | "Version": "1.0.0", 12 | "Number": "1.0", 13 | "Date": "1693497500" 14 | }, 15 | "returnValue": "default", 16 | "expectedLog": "allinone.txt" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/comparators/allinone.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'allinone' for User '{"Identifier":"12345","Email":"joe@example.com","Country":"[\"USA\"]","Date":"1693497500","Number":"1.0","Version":"1.0.0"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email EQUALS '' => true 4 | AND User.Email NOT EQUALS '' => false, skipping the remaining AND conditions 5 | THEN '1h' => no match 6 | - IF User.Email EQUALS 'joe@example.com' => true 7 | AND User.Email NOT EQUALS 'joe@example.com' => false, skipping the remaining AND conditions 8 | THEN '1c' => no match 9 | - IF User.Email IS ONE OF [<1 hashed value>] => true 10 | AND User.Email IS NOT ONE OF [<1 hashed value>] => false, skipping the remaining AND conditions 11 | THEN '2h' => no match 12 | - IF User.Email IS ONE OF ['joe@example.com'] => true 13 | AND User.Email IS NOT ONE OF ['joe@example.com'] => false, skipping the remaining AND conditions 14 | THEN '2c' => no match 15 | - IF User.Email STARTS WITH ANY OF [<1 hashed value>] => true 16 | AND User.Email NOT STARTS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 17 | THEN '3h' => no match 18 | - IF User.Email STARTS WITH ANY OF ['joe@'] => true 19 | AND User.Email NOT STARTS WITH ANY OF ['joe@'] => false, skipping the remaining AND conditions 20 | THEN '3c' => no match 21 | - IF User.Email ENDS WITH ANY OF [<1 hashed value>] => true 22 | AND User.Email NOT ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 23 | THEN '4h' => no match 24 | - IF User.Email ENDS WITH ANY OF ['@example.com'] => true 25 | AND User.Email NOT ENDS WITH ANY OF ['@example.com'] => false, skipping the remaining AND conditions 26 | THEN '4c' => no match 27 | - IF User.Email CONTAINS ANY OF ['e@e'] => true 28 | AND User.Email NOT CONTAINS ANY OF ['e@e'] => false, skipping the remaining AND conditions 29 | THEN '5' => no match 30 | - IF User.Version IS ONE OF ['1.0.0'] => true 31 | AND User.Version IS NOT ONE OF ['1.0.0'] => false, skipping the remaining AND conditions 32 | THEN '6' => no match 33 | - IF User.Version < '1.0.1' => true 34 | AND User.Version >= '1.0.1' => false, skipping the remaining AND conditions 35 | THEN '7' => no match 36 | - IF User.Version > '0.9.9' => true 37 | AND User.Version <= '0.9.9' => false, skipping the remaining AND conditions 38 | THEN '8' => no match 39 | - IF User.Number = '1' => true 40 | AND User.Number != '1' => false, skipping the remaining AND conditions 41 | THEN '9' => no match 42 | - IF User.Number < '1.1' => true 43 | AND User.Number >= '1.1' => false, skipping the remaining AND conditions 44 | THEN '10' => no match 45 | - IF User.Number > '0.9' => true 46 | AND User.Number <= '0.9' => false, skipping the remaining AND conditions 47 | THEN '11' => no match 48 | - IF User.Date BEFORE '1693497600' (2023-08-31T16:00:00.000Z UTC) => true 49 | AND User.Date AFTER '1693497600' (2023-08-31T16:00:00.000Z UTC) => false, skipping the remaining AND conditions 50 | THEN '12' => no match 51 | - IF User.Country ARRAY CONTAINS ANY OF [<1 hashed value>] => true 52 | AND User.Country ARRAY NOT CONTAINS ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 53 | THEN '13h' => no match 54 | - IF User.Country ARRAY CONTAINS ANY OF ['USA'] => true 55 | AND User.Country ARRAY NOT CONTAINS ANY OF ['USA'] => false, skipping the remaining AND conditions 56 | THEN '13c' => no match 57 | Returning 'default'. 58 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/epoch_date_validation.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/OfQqcTjfFUGBwMKqtyEOrQ", 3 | "tests": [ 4 | { 5 | "key": "boolTrueIn202304", 6 | "defaultValue": true, 7 | "returnValue": false, 8 | "expectedLog": "date_error.txt", 9 | "user": { 10 | "Identifier": "12345", 11 | "Custom1": "2023.04.10" 12 | } 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/epoch_date_validation/date_error.txt: -------------------------------------------------------------------------------- 1 | WARNING [3004] Cannot evaluate condition (User.Custom1 AFTER '1680307200' (2023-04-01T00:00:00.000Z UTC)) for setting 'boolTrueIn202304' ('2023.04.10' is not a valid Unix timestamp (number of seconds elapsed since Unix epoch)). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 2 | INFO [5000] Evaluating 'boolTrueIn202304' for User '{"Identifier":"12345","Custom1":"2023.04.10"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Custom1 AFTER '1680307200' (2023-04-01T00:00:00.000Z UTC) => false, skipping the remaining AND conditions 5 | THEN 'true' => cannot evaluate, the User.Custom1 attribute is invalid ('2023.04.10' is not a valid Unix timestamp (number of seconds elapsed since Unix epoch)) 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | Returning 'false'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/list_truncation.json: -------------------------------------------------------------------------------- 1 | { 2 | "jsonOverride": "test_list_truncation.json", 3 | "sdkKey": "configcat-sdk-test-key/0000000000000000000001", 4 | "tests": [ 5 | { 6 | "key": "booleanKey1", 7 | "defaultValue": false, 8 | "user": { 9 | "Identifier": "12" 10 | }, 11 | "returnValue": true, 12 | "expectedLog": "list_truncation.txt" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/list_truncation/list_truncation.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'booleanKey1' for User '{"Identifier":"12"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Identifier CONTAINS ANY OF ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] => true 4 | AND User.Identifier CONTAINS ANY OF ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', ... <1 more value>] => true 5 | AND User.Identifier CONTAINS ANY OF ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', ... <2 more values>] => true 6 | THEN 'true' => MATCH, applying rule 7 | Returning 'true'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/list_truncation/test_list_truncation.json: -------------------------------------------------------------------------------- 1 | { 2 | "p": { 3 | "u": "https://cdn-global.configcat.com", 4 | "r": 0, 5 | "s": "test-salt" 6 | }, 7 | "f": { 8 | "booleanKey1": { 9 | "t": 0, 10 | "v": { 11 | "b": false 12 | }, 13 | "r": [ 14 | { 15 | "c": [ 16 | { 17 | "u": { 18 | "a": "Identifier", 19 | "c": 2, 20 | "l": [ 21 | "1", 22 | "2", 23 | "3", 24 | "4", 25 | "5", 26 | "6", 27 | "7", 28 | "8", 29 | "9", 30 | "10" 31 | ] 32 | } 33 | }, 34 | { 35 | "u": { 36 | "a": "Identifier", 37 | "c": 2, 38 | "l": [ 39 | "1", 40 | "2", 41 | "3", 42 | "4", 43 | "5", 44 | "6", 45 | "7", 46 | "8", 47 | "9", 48 | "10", 49 | "11" 50 | ] 51 | } 52 | }, 53 | { 54 | "u": { 55 | "a": "Identifier", 56 | "c": 2, 57 | "l": [ 58 | "1", 59 | "2", 60 | "3", 61 | "4", 62 | "5", 63 | "6", 64 | "7", 65 | "8", 66 | "9", 67 | "10", 68 | "11", 69 | "12" 70 | ] 71 | } 72 | } 73 | ], 74 | "s": { 75 | "v": { 76 | "b": true 77 | }, 78 | "i": "test-variation-id" 79 | } 80 | } 81 | ], 82 | "i": "test-variation-id" 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/number_validation.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/uGyK3q9_ckmdxRyI7vjwCw", 3 | "tests": [ 4 | { 5 | "key": "number", 6 | "defaultValue": "default", 7 | "returnValue": "Default", 8 | "expectedLog": "number_error.txt", 9 | "user": { 10 | "Identifier": "12345", 11 | "Custom1": "not_a_number" 12 | } 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/number_validation/number_error.txt: -------------------------------------------------------------------------------- 1 | WARNING [3004] Cannot evaluate condition (User.Custom1 != '5') for setting 'number' ('not_a_number' is not a valid decimal number). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 2 | INFO [5000] Evaluating 'number' for User '{"Identifier":"12345","Custom1":"not_a_number"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Custom1 != '5' THEN '<>5' => cannot evaluate, the User.Custom1 attribute is invalid ('not_a_number' is not a valid decimal number) 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'Default'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_after_targeting_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", 3 | "tests": [ 4 | { 5 | "key": "integer25One25Two25Three25FourAdvancedRules", 6 | "defaultValue": 42, 7 | "returnValue": -1, 8 | "expectedLog": "options_after_targeting_rule_no_user.txt" 9 | }, 10 | { 11 | "key": "integer25One25Two25Three25FourAdvancedRules", 12 | "defaultValue": 42, 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": 2, 17 | "expectedLog": "options_after_targeting_rule_no_targeted_attribute.txt" 18 | }, 19 | { 20 | "key": "integer25One25Two25Three25FourAdvancedRules", 21 | "defaultValue": 42, 22 | "user": { 23 | "Identifier": "12345", 24 | "Email": "joe@example.com" 25 | }, 26 | "returnValue": 2, 27 | "expectedLog": "options_after_targeting_rule_not_matching_targeted_attribute.txt" 28 | }, 29 | { 30 | "key": "integer25One25Two25Three25FourAdvancedRules", 31 | "defaultValue": 42, 32 | "user": { 33 | "Identifier": "12345", 34 | "Email": "joe@configcat.com" 35 | }, 36 | "returnValue": 5, 37 | "expectedLog": "options_after_targeting_rule_matching_targeted_attribute.txt" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_after_targeting_rule/options_after_targeting_rule_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'integer25One25Two25Three25FourAdvancedRules' for User '{"Identifier":"12345","Email":"joe@configcat.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN '5' => MATCH, applying rule 4 | Returning '5'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_after_targeting_rule/options_after_targeting_rule_no_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email CONTAINS ANY OF ['@configcat.com']) for setting 'integer25One25Two25Three25FourAdvancedRules' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'integer25One25Two25Three25FourAdvancedRules' for User '{"Identifier":"12345"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN '5' => cannot evaluate, the User.Email attribute is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Evaluating % options based on the User.Identifier attribute: 7 | - Computing hash in the [0..99] range from User.Identifier => 25 (this value is sticky and consistent across all SDKs) 8 | - Hash value 25 selects % option 2 (25%), '2'. 9 | Returning '2'. 10 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_after_targeting_rule/options_after_targeting_rule_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'integer25One25Two25Three25FourAdvancedRules' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'integer25One25Two25Three25FourAdvancedRules' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN '5' => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Skipping % options because the User Object is missing. 7 | Returning '-1'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_after_targeting_rule/options_after_targeting_rule_not_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'integer25One25Two25Three25FourAdvancedRules' for User '{"Identifier":"12345","Email":"joe@example.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN '5' => no match 4 | Evaluating % options based on the User.Identifier attribute: 5 | - Computing hash in the [0..99] range from User.Identifier => 25 (this value is sticky and consistent across all SDKs) 6 | - Hash value 25 selects % option 2 (25%), '2'. 7 | Returning '2'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_custom_attr.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw", 3 | "tests": [ 4 | { 5 | "key": "string75Cat0Dog25Falcon0HorseCustomAttr", 6 | "defaultValue": "default", 7 | "returnValue": "Chicken", 8 | "expectedLog": "options_custom_attribute_no_user.txt" 9 | }, 10 | { 11 | "key": "string75Cat0Dog25Falcon0HorseCustomAttr", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": "Chicken", 17 | "expectedLog": "no_options_custom_attribute.txt" 18 | }, 19 | { 20 | "key": "string75Cat0Dog25Falcon0HorseCustomAttr", 21 | "defaultValue": "default", 22 | "user": { 23 | "Identifier": "12345", 24 | "Country": "US" 25 | }, 26 | "returnValue": "Cat", 27 | "expectedLog": "matching_options_custom_attribute.txt" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_custom_attr/matching_options_custom_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'string75Cat0Dog25Falcon0HorseCustomAttr' for User '{"Identifier":"12345","Country":"US"}' 2 | Evaluating % options based on the User.Country attribute: 3 | - Computing hash in the [0..99] range from User.Country => 70 (this value is sticky and consistent across all SDKs) 4 | - Hash value 70 selects % option 1 (75%), 'Cat'. 5 | Returning 'Cat'. 6 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_custom_attr/no_options_custom_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate % options for setting 'string75Cat0Dog25Falcon0HorseCustomAttr' (the User.Country attribute is missing). You should set the User.Country attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'string75Cat0Dog25Falcon0HorseCustomAttr' for User '{"Identifier":"12345"}' 3 | Skipping % options because the User.Country attribute is missing. 4 | Returning 'Chicken'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_custom_attr/options_custom_attribute_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'string75Cat0Dog25Falcon0HorseCustomAttr' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'string75Cat0Dog25Falcon0HorseCustomAttr' 3 | Skipping % options because the User Object is missing. 4 | Returning 'Chicken'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_user_id.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", 3 | "tests": [ 4 | { 5 | "key": "string75Cat0Dog25Falcon0Horse", 6 | "defaultValue": "default", 7 | "returnValue": "Chicken", 8 | "expectedLog": "options_user_attribute_no_user.txt" 9 | }, 10 | { 11 | "key": "string75Cat0Dog25Falcon0Horse", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": "Cat", 17 | "expectedLog": "options_user_attribute_user.txt" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_user_id/options_user_attribute_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'string75Cat0Dog25Falcon0Horse' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'string75Cat0Dog25Falcon0Horse' 3 | Skipping % options because the User Object is missing. 4 | Returning 'Chicken'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_based_on_user_id/options_user_attribute_user.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'string75Cat0Dog25Falcon0Horse' for User '{"Identifier":"12345"}' 2 | Evaluating % options based on the User.Identifier attribute: 3 | - Computing hash in the [0..99] range from User.Identifier => 21 (this value is sticky and consistent across all SDKs) 4 | - Hash value 21 selects % option 1 (75%), 'Cat'. 5 | Returning 'Cat'. 6 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw", 3 | "tests": [ 4 | { 5 | "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", 6 | "defaultValue": "default", 7 | "returnValue": "Cat", 8 | "expectedLog": "options_within_targeting_rule_no_user.txt" 9 | }, 10 | { 11 | "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", 12 | "defaultValue": "default", 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": "Cat", 17 | "expectedLog": "options_within_targeting_rule_no_targeted_attribute.txt" 18 | }, 19 | { 20 | "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", 21 | "defaultValue": "default", 22 | "user": { 23 | "Identifier": "12345", 24 | "Email": "joe@example.com" 25 | }, 26 | "returnValue": "Cat", 27 | "expectedLog": "options_within_targeting_rule_not_matching_targeted_attribute.txt" 28 | }, 29 | { 30 | "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", 31 | "defaultValue": "default", 32 | "user": { 33 | "Identifier": "12345", 34 | "Email": "joe@configcat.com" 35 | }, 36 | "returnValue": "Cat", 37 | "expectedLog": "options_within_targeting_rule_matching_targeted_attribute_no_options_attribute.txt" 38 | }, 39 | { 40 | "key": "stringContainsString75Cat0Dog25Falcon0HorseDefaultCat", 41 | "defaultValue": "default", 42 | "user": { 43 | "Identifier": "12345", 44 | "Email": "joe@configcat.com", 45 | "Country": "US" 46 | }, 47 | "returnValue": "Cat", 48 | "expectedLog": "options_within_targeting_rule_matching_targeted_attribute_options_attribute.txt" 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule/options_within_targeting_rule_matching_targeted_attribute_no_options_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate % options for setting 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' (the User.Country attribute is missing). You should set the User.Country attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' for User '{"Identifier":"12345","Email":"joe@configcat.com"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN % options => MATCH, applying rule 5 | Skipping % options because the User.Country attribute is missing. 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | Returning 'Cat'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule/options_within_targeting_rule_matching_targeted_attribute_options_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' for User '{"Identifier":"12345","Email":"joe@configcat.com","Country":"US"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN % options => MATCH, applying rule 4 | Evaluating % options based on the User.Country attribute: 5 | - Computing hash in the [0..99] range from User.Country => 63 (this value is sticky and consistent across all SDKs) 6 | - Hash value 63 selects % option 1 (75%), 'Cat'. 7 | Returning 'Cat'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule/options_within_targeting_rule_no_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email CONTAINS ANY OF ['@configcat.com']) for setting 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' for User '{"Identifier":"12345"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN % options => cannot evaluate, the User.Email attribute is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'Cat'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule/options_within_targeting_rule_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN % options => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'Cat'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/options_within_targeting_rule/options_within_targeting_rule_not_matching_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'stringContainsString75Cat0Dog25Falcon0HorseDefaultCat' for User '{"Identifier":"12345","Email":"joe@example.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User.Email CONTAINS ANY OF ['@configcat.com'] THEN % options => no match 4 | Returning 'Cat'. 5 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/ByMO9yZNn02kXcm72lnY1A", 3 | "tests": [ 4 | { 5 | "key": "dependentFeatureWithUserCondition", 6 | "defaultValue": "default", 7 | "returnValue": "Chicken", 8 | "expectedLog": "prerequisite_flag_no_user_needed_by_dep.txt" 9 | }, 10 | { 11 | "key": "dependentFeature", 12 | "defaultValue": "default", 13 | "returnValue": "Chicken", 14 | "expectedLog": "prerequisite_flag_no_user_needed_by_prereq.txt" 15 | }, 16 | { 17 | "key": "dependentFeatureWithUserCondition2", 18 | "defaultValue": "default", 19 | "returnValue": "Frog", 20 | "expectedLog": "prerequisite_flag_no_user_needed_by_both.txt" 21 | }, 22 | { 23 | "key": "dependentFeature", 24 | "defaultValue": "default", 25 | "user": { 26 | "Identifier": "12345", 27 | "Email": "kate@configcat.com", 28 | "Country": "USA" 29 | }, 30 | "returnValue": "Horse", 31 | "expectedLog": "prerequisite_flag.txt" 32 | }, 33 | { 34 | "key": "dependentFeatureMultipleLevels", 35 | "defaultValue": "default", 36 | "returnValue": "Dog", 37 | "expectedLog": "prerequisite_flag_multilevel.txt" 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag/prerequisite_flag.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'dependentFeature' for User '{"Identifier":"12345","Email":"kate@configcat.com","Country":"USA"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF Flag 'mainFeature' EQUALS 'target' 4 | ( 5 | Evaluating prerequisite flag 'mainFeature': 6 | Evaluating targeting rules and applying the first match if any: 7 | - IF User.Email ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 8 | THEN 'private' => no match 9 | - IF User.Country IS ONE OF [<1 hashed value>] => true 10 | AND User IS NOT IN SEGMENT 'Beta Users' 11 | ( 12 | Evaluating segment 'Beta Users': 13 | - IF User.Email IS ONE OF [<2 hashed values>] => false, skipping the remaining AND conditions 14 | Segment evaluation result: User IS NOT IN SEGMENT. 15 | Condition (User IS NOT IN SEGMENT 'Beta Users') evaluates to true. 16 | ) => true 17 | AND User IS NOT IN SEGMENT 'Developers' 18 | ( 19 | Evaluating segment 'Developers': 20 | - IF User.Email IS ONE OF [<2 hashed values>] => false, skipping the remaining AND conditions 21 | Segment evaluation result: User IS NOT IN SEGMENT. 22 | Condition (User IS NOT IN SEGMENT 'Developers') evaluates to true. 23 | ) => true 24 | THEN 'target' => MATCH, applying rule 25 | Prerequisite flag evaluation result: 'target'. 26 | Condition (Flag 'mainFeature' EQUALS 'target') evaluates to true. 27 | ) 28 | THEN % options => MATCH, applying rule 29 | Evaluating % options based on the User.Identifier attribute: 30 | - Computing hash in the [0..99] range from User.Identifier => 78 (this value is sticky and consistent across all SDKs) 31 | - Hash value 78 selects % option 4 (25%), 'Horse'. 32 | Returning 'Horse'. 33 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag/prerequisite_flag_multilevel.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'dependentFeatureMultipleLevels' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF Flag 'intermediateFeature' EQUALS 'true' 4 | ( 5 | Evaluating prerequisite flag 'intermediateFeature': 6 | Evaluating targeting rules and applying the first match if any: 7 | - IF Flag 'mainFeatureWithoutUserCondition' EQUALS 'true' 8 | ( 9 | Evaluating prerequisite flag 'mainFeatureWithoutUserCondition': 10 | Prerequisite flag evaluation result: 'true'. 11 | Condition (Flag 'mainFeatureWithoutUserCondition' EQUALS 'true') evaluates to true. 12 | ) => true 13 | AND Flag 'mainFeatureWithoutUserCondition' EQUALS 'true' 14 | ( 15 | Evaluating prerequisite flag 'mainFeatureWithoutUserCondition': 16 | Prerequisite flag evaluation result: 'true'. 17 | Condition (Flag 'mainFeatureWithoutUserCondition' EQUALS 'true') evaluates to true. 18 | ) => true 19 | THEN 'true' => MATCH, applying rule 20 | Prerequisite flag evaluation result: 'true'. 21 | Condition (Flag 'intermediateFeature' EQUALS 'true') evaluates to true. 22 | ) 23 | THEN 'Dog' => MATCH, applying rule 24 | Returning 'Dog'. 25 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag/prerequisite_flag_no_user_needed_by_both.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'dependentFeatureWithUserCondition2' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'mainFeature' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 3 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'mainFeature' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 4 | INFO [5000] Evaluating 'dependentFeatureWithUserCondition2' 5 | Evaluating targeting rules and applying the first match if any: 6 | - IF User.Email IS ONE OF [<2 hashed values>] THEN 'Dog' => cannot evaluate, User Object is missing 7 | The current targeting rule is ignored and the evaluation continues with the next rule. 8 | - IF Flag 'mainFeature' EQUALS 'public' 9 | ( 10 | Evaluating prerequisite flag 'mainFeature': 11 | Evaluating targeting rules and applying the first match if any: 12 | - IF User.Email ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 13 | THEN 'private' => cannot evaluate, User Object is missing 14 | The current targeting rule is ignored and the evaluation continues with the next rule. 15 | - IF User.Country IS ONE OF [<1 hashed value>] => false, skipping the remaining AND conditions 16 | THEN 'target' => cannot evaluate, User Object is missing 17 | The current targeting rule is ignored and the evaluation continues with the next rule. 18 | Prerequisite flag evaluation result: 'public'. 19 | Condition (Flag 'mainFeature' EQUALS 'public') evaluates to true. 20 | ) 21 | THEN % options => MATCH, applying rule 22 | Skipping % options because the User Object is missing. 23 | The current targeting rule is ignored and the evaluation continues with the next rule. 24 | - IF Flag 'mainFeature' EQUALS 'public' 25 | ( 26 | Evaluating prerequisite flag 'mainFeature': 27 | Evaluating targeting rules and applying the first match if any: 28 | - IF User.Email ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 29 | THEN 'private' => cannot evaluate, User Object is missing 30 | The current targeting rule is ignored and the evaluation continues with the next rule. 31 | - IF User.Country IS ONE OF [<1 hashed value>] => false, skipping the remaining AND conditions 32 | THEN 'target' => cannot evaluate, User Object is missing 33 | The current targeting rule is ignored and the evaluation continues with the next rule. 34 | Prerequisite flag evaluation result: 'public'. 35 | Condition (Flag 'mainFeature' EQUALS 'public') evaluates to true. 36 | ) 37 | THEN 'Frog' => MATCH, applying rule 38 | Returning 'Frog'. 39 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag/prerequisite_flag_no_user_needed_by_dep.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'dependentFeatureWithUserCondition' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'dependentFeatureWithUserCondition' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User.Email IS ONE OF [<2 hashed values>] THEN 'Dog' => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | - IF Flag 'mainFeatureWithoutUserCondition' EQUALS 'true' 7 | ( 8 | Evaluating prerequisite flag 'mainFeatureWithoutUserCondition': 9 | Prerequisite flag evaluation result: 'true'. 10 | Condition (Flag 'mainFeatureWithoutUserCondition' EQUALS 'true') evaluates to true. 11 | ) 12 | THEN % options => MATCH, applying rule 13 | Skipping % options because the User Object is missing. 14 | The current targeting rule is ignored and the evaluation continues with the next rule. 15 | Returning 'Chicken'. 16 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/prerequisite_flag/prerequisite_flag_no_user_needed_by_prereq.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'mainFeature' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'dependentFeature' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF Flag 'mainFeature' EQUALS 'target' 5 | ( 6 | Evaluating prerequisite flag 'mainFeature': 7 | Evaluating targeting rules and applying the first match if any: 8 | - IF User.Email ENDS WITH ANY OF [<1 hashed value>] => false, skipping the remaining AND conditions 9 | THEN 'private' => cannot evaluate, User Object is missing 10 | The current targeting rule is ignored and the evaluation continues with the next rule. 11 | - IF User.Country IS ONE OF [<1 hashed value>] => false, skipping the remaining AND conditions 12 | THEN 'target' => cannot evaluate, User Object is missing 13 | The current targeting rule is ignored and the evaluation continues with the next rule. 14 | Prerequisite flag evaluation result: 'public'. 15 | Condition (Flag 'mainFeature' EQUALS 'target') evaluates to false. 16 | ) 17 | THEN % options => no match 18 | Returning 'Chicken'. 19 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "configcat-sdk-1/PKDVCLf-Hq-h-kCzMp-L7Q/y_ZB7o-Xb0Swxth-ZlMSeA", 3 | "tests": [ 4 | { 5 | "key": "featureWithSegmentTargeting", 6 | "defaultValue": false, 7 | "returnValue": false, 8 | "expectedLog": "segment_no_user.txt" 9 | }, 10 | { 11 | "key": "featureWithNegatedSegmentTargetingCleartext", 12 | "defaultValue": false, 13 | "user": { 14 | "Identifier": "12345" 15 | }, 16 | "returnValue": false, 17 | "expectedLog": "segment_no_targeted_attribute.txt" 18 | }, 19 | { 20 | "key": "featureWithSegmentTargeting", 21 | "defaultValue": false, 22 | "user": { 23 | "Identifier": "12345", 24 | "Email": "jane@example.com" 25 | }, 26 | "returnValue": true, 27 | "expectedLog": "segment_matching.txt" 28 | }, 29 | { 30 | "key": "featureWithNegatedSegmentTargeting", 31 | "defaultValue": false, 32 | "user": { 33 | "Identifier": "12345", 34 | "Email": "jane@example.com" 35 | }, 36 | "returnValue": false, 37 | "expectedLog": "segment_no_matching.txt" 38 | }, 39 | { 40 | "key": "featureWithSegmentTargetingMultipleConditions", 41 | "defaultValue": false, 42 | "returnValue": false, 43 | "expectedLog": "segment_no_user_multi_conditions.txt" 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment/segment_matching.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'featureWithSegmentTargeting' for User '{"Identifier":"12345","Email":"jane@example.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User IS IN SEGMENT 'Beta users' 4 | ( 5 | Evaluating segment 'Beta users': 6 | - IF User.Email IS ONE OF [<2 hashed values>] => true 7 | Segment evaluation result: User IS IN SEGMENT. 8 | Condition (User IS IN SEGMENT 'Beta users') evaluates to true. 9 | ) 10 | THEN 'true' => MATCH, applying rule 11 | Returning 'true'. 12 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment/segment_no_matching.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'featureWithNegatedSegmentTargeting' for User '{"Identifier":"12345","Email":"jane@example.com"}' 2 | Evaluating targeting rules and applying the first match if any: 3 | - IF User IS NOT IN SEGMENT 'Beta users' 4 | ( 5 | Evaluating segment 'Beta users': 6 | - IF User.Email IS ONE OF [<2 hashed values>] => true 7 | Segment evaluation result: User IS IN SEGMENT. 8 | Condition (User IS NOT IN SEGMENT 'Beta users') evaluates to false. 9 | ) 10 | THEN 'true' => no match 11 | Returning 'false'. 12 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment/segment_no_targeted_attribute.txt: -------------------------------------------------------------------------------- 1 | WARNING [3003] Cannot evaluate condition (User.Email IS ONE OF ['jane@example.com', 'john@example.com']) for setting 'featureWithNegatedSegmentTargetingCleartext' (the User.Email attribute is missing). You should set the User.Email attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'featureWithNegatedSegmentTargetingCleartext' for User '{"Identifier":"12345"}' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User IS NOT IN SEGMENT 'Beta users (cleartext)' 5 | ( 6 | Evaluating segment 'Beta users (cleartext)': 7 | - IF User.Email IS ONE OF ['jane@example.com', 'john@example.com'] => false, skipping the remaining AND conditions 8 | Segment evaluation result: cannot evaluate, the User.Email attribute is missing. 9 | Condition (User IS NOT IN SEGMENT 'Beta users (cleartext)') failed to evaluate. 10 | ) 11 | THEN 'true' => cannot evaluate, the User.Email attribute is missing 12 | The current targeting rule is ignored and the evaluation continues with the next rule. 13 | Returning 'false'. 14 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment/segment_no_user.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'featureWithSegmentTargeting' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'featureWithSegmentTargeting' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User IS IN SEGMENT 'Beta users' THEN 'true' => cannot evaluate, User Object is missing 5 | The current targeting rule is ignored and the evaluation continues with the next rule. 6 | Returning 'false'. 7 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/segment/segment_no_user_multi_conditions.txt: -------------------------------------------------------------------------------- 1 | WARNING [3001] Cannot evaluate targeting rules and % options for setting 'featureWithSegmentTargetingMultipleConditions' (User Object is missing). You should pass a User Object to the evaluation methods like `getValue()`/`getValueAsync()` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/ 2 | INFO [5000] Evaluating 'featureWithSegmentTargetingMultipleConditions' 3 | Evaluating targeting rules and applying the first match if any: 4 | - IF User IS IN SEGMENT 'Beta users (cleartext)' => false, skipping the remaining AND conditions 5 | THEN 'true' => cannot evaluate, User Object is missing 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | Returning 'false'. 8 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/semver_validation.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/BAr3KgLTP0ObzKnBTo5nhA", 3 | "tests": [ 4 | { 5 | "key": "isNotOneOf", 6 | "defaultValue": "default", 7 | "returnValue": "Default", 8 | "expectedLog": "semver_error.txt", 9 | "user": { 10 | "Identifier": "12345", 11 | "Custom1": "wrong_semver" 12 | } 13 | }, 14 | { 15 | "key": "relations", 16 | "defaultValue": "default", 17 | "returnValue": "Default", 18 | "expectedLog": "semver_relations_error.txt", 19 | "user": { 20 | "Identifier": "12345", 21 | "Custom1": "wrong_semver" 22 | } 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/semver_validation/semver_error.txt: -------------------------------------------------------------------------------- 1 | WARNING [3004] Cannot evaluate condition (User.Custom1 IS NOT ONE OF ['1.0.0', '1.0.1', '2.0.0', '2.0.1', '2.0.2', '']) for setting 'isNotOneOf' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 2 | WARNING [3004] Cannot evaluate condition (User.Custom1 IS NOT ONE OF ['1.0.0', '3.0.1']) for setting 'isNotOneOf' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 3 | INFO [5000] Evaluating 'isNotOneOf' for User '{"Identifier":"12345","Custom1":"wrong_semver"}' 4 | Evaluating targeting rules and applying the first match if any: 5 | - IF User.Custom1 IS NOT ONE OF ['1.0.0', '1.0.1', '2.0.0', '2.0.1', '2.0.2', ''] THEN 'Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, )' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 6 | The current targeting rule is ignored and the evaluation continues with the next rule. 7 | - IF User.Custom1 IS NOT ONE OF ['1.0.0', '3.0.1'] THEN 'Is not one of (1.0.0, 3.0.1)' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 8 | The current targeting rule is ignored and the evaluation continues with the next rule. 9 | Returning 'Default'. 10 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/semver_validation/semver_relations_error.txt: -------------------------------------------------------------------------------- 1 | WARNING [3004] Cannot evaluate condition (User.Custom1 < '1.0.0,') for setting 'relations' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 2 | WARNING [3004] Cannot evaluate condition (User.Custom1 < '1.0.0') for setting 'relations' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 3 | WARNING [3004] Cannot evaluate condition (User.Custom1 <= '1.0.0') for setting 'relations' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 4 | WARNING [3004] Cannot evaluate condition (User.Custom1 > '2.0.0') for setting 'relations' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 5 | WARNING [3004] Cannot evaluate condition (User.Custom1 >= '2.0.0') for setting 'relations' ('wrong_semver' is not a valid semantic version). Please check the User.Custom1 attribute and make sure that its value corresponds to the comparison operator. 6 | INFO [5000] Evaluating 'relations' for User '{"Identifier":"12345","Custom1":"wrong_semver"}' 7 | Evaluating targeting rules and applying the first match if any: 8 | - IF User.Custom1 < '1.0.0,' THEN '<1.0.0,' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 9 | The current targeting rule is ignored and the evaluation continues with the next rule. 10 | - IF User.Custom1 < '1.0.0' THEN '< 1.0.0' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 11 | The current targeting rule is ignored and the evaluation continues with the next rule. 12 | - IF User.Custom1 <= '1.0.0' THEN '<=1.0.0' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 13 | The current targeting rule is ignored and the evaluation continues with the next rule. 14 | - IF User.Custom1 > '2.0.0' THEN '>2.0.0' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 15 | The current targeting rule is ignored and the evaluation continues with the next rule. 16 | - IF User.Custom1 >= '2.0.0' THEN '>=2.0.0' => cannot evaluate, the User.Custom1 attribute is invalid ('wrong_semver' is not a valid semantic version) 17 | The current targeting rule is ignored and the evaluation continues with the next rule. 18 | Returning 'Default'. 19 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdkKey": "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", 3 | "tests": [ 4 | { 5 | "key": "boolDefaultFalse", 6 | "defaultValue": true, 7 | "returnValue": false, 8 | "expectedLog": "off_flag.txt" 9 | }, 10 | { 11 | "key": "boolDefaultTrue", 12 | "defaultValue": false, 13 | "returnValue": true, 14 | "expectedLog": "on_flag.txt" 15 | }, 16 | { 17 | "key": "stringDefaultCat", 18 | "defaultValue": "Default", 19 | "returnValue": "Cat", 20 | "expectedLog": "text_setting.txt" 21 | }, 22 | { 23 | "key": "integerDefaultOne", 24 | "defaultValue": 0, 25 | "returnValue": 1, 26 | "expectedLog": "int_setting.txt" 27 | }, 28 | { 29 | "testName": "double_setting", 30 | "key": "doubleDefaultPi", 31 | "defaultValue": 0.0, 32 | "returnValue": 3.1415, 33 | "expectedLog": "double_setting.txt" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value/double_setting.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'doubleDefaultPi' 2 | Returning '3.1415'. 3 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value/int_setting.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'integerDefaultOne' 2 | Returning '1'. 3 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value/off_flag.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'boolDefaultFalse' 2 | Returning 'false'. 3 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value/on_flag.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'boolDefaultTrue' 2 | Returning 'true'. 3 | -------------------------------------------------------------------------------- /src/test/resources/evaluation/simple_value/text_setting.txt: -------------------------------------------------------------------------------- 1 | INFO [5000] Evaluating 'stringDefaultCat' 2 | Returning 'Cat'. 3 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_and_or.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;mainFeature;dependentFeature;emailAnd;emailOr 2 | ##null##;;;;public;Chicken;Cat;Cat 3 | ;;;;public;Chicken;Cat;Cat 4 | jane@example.com;jane@example.com;##null##;##null##;public;Chicken;Cat;Jane 5 | john@example.com;john@example.com;##null##;##null##;public;Chicken;Cat;John 6 | a@example.com;a@example.com;USA;##null##;target;Cat;Cat;Cat 7 | mark@example.com;mark@example.com;USA;##null##;target;Dog;Cat;Mark 8 | nora@example.com;nora@example.com;USA;##null##;target;Falcon;Cat;Cat 9 | stern@msn.com;stern@msn.com;USA;##null##;target;Horse;Cat;Cat 10 | jane@sensitivecompany.com;jane@sensitivecompany.com;England;##null##;private;Chicken;Dog;Jane 11 | anna@sensitivecompany.com;anna@sensitivecompany.com;France;##null##;private;Chicken;Cat;Cat 12 | jane@sensitivecompany.com;jane@sensitivecompany.com;england;##null##;public;Chicken;Dog;Jane 13 | jane;jane;##null##;##null##;public;Chicken;Cat;Cat 14 | @sensitivecompany.com;@sensitivecompany.com;##null##;##null##;public;Chicken;Cat;Cat 15 | jane.sensitivecompany.com;jane.sensitivecompany.com;##null##;##null##;public;Chicken;Cat;Cat 16 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_comparators_v6.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;boolTrueIn202304;stringEqualsDogDefaultCat;stringEqualsCleartextDogDefaultCat;stringDoseNotEqualDogDefaultCat;stringNotEqualsCleartextDogDefaultCat;stringStartsWithDogDefaultCat;stringNotStartsWithDogDefaultCat;stringEndsWithDogDefaultCat;stringNotEndsWithDogDefaultCat;arrayContainsDogDefaultCat;arrayDoesNotContainDogDefaultCat;arrayContainsCaseCheckDogDefaultCat;arrayDoesNotContainCaseCheckDogDefaultCat;customPercentageAttribute;missingPercentageAttribute;countryPercentageAttribute;stringContainsAnyOfDogDefaultCat;stringNotContainsAnyOfDogDefaultCat;stringStartsWithAnyOfDogDefaultCat;stringStartsWithAnyOfCleartextDogDefaultCat;stringNotStartsWithAnyOfDogDefaultCat;stringNotStartsWithAnyOfCleartextDogDefaultCat;stringEndsWithAnyOfDogDefaultCat;stringEndsWithAnyOfCleartextDogDefaultCat;stringNotEndsWithAnyOfDogDefaultCat;stringNotEndsWithAnyOfCleartextDogDefaultCat;stringArrayContainsAnyOfDogDefaultCat;stringArrayContainsAnyOfCleartextDogDefaultCat;stringArrayNotContainsAnyOfDogDefaultCat;stringArrayNotContainsAnyOfCleartextDogDefaultCat 2 | ##null##;;;;False;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Chicken;Chicken;Chicken;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat 3 | ;;;;False;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Chicken;Chicken;Chicken;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat;Cat 4 | a@configcat.com;a@configcat.com;##null##;##null##;False;Dog;Dog;Dog;Dog;Dog;Cat;Dog;Cat;Cat;Cat;Cat;Cat;Chicken;NotFound;Chicken;Cat;Dog;Dog;Dog;Cat;Cat;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 5 | b@configcat.com;b@configcat.com;Hungary;0;False;Cat;Cat;Cat;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Horse;NotFound;Falcon;Cat;Dog;Dog;Dog;Cat;Cat;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 6 | c@configcat.com;c@configcat.com;United Kingdom;1680307199.9;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Falcon;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 7 | anna@configcat.com;anna@configcat.com;Hungary;1681118000.56;True;Cat;Cat;Dog;Dog;Dog;Cat;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Falcon;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 8 | bogjobber@verizon.net;bogjobber@verizon.net;##null##;1682899200.1;False;Cat;Cat;Dog;Dog;Cat;Dog;Cat;Dog;Cat;Cat;Cat;Cat;Horse;Chicken;Chicken;Dog;Cat;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Cat 9 | cliffordj@aol.com;cliffordj@aol.com;Austria;1682999200;False;Cat;Cat;Dog;Dog;Cat;Dog;Cat;Dog;Cat;Cat;Cat;Cat;Falcon;Chicken;Falcon;Dog;Cat;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Cat 10 | reader@configcat.com;reader@configcat.com;Bahamas;read,execute;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Falcon;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 11 | writer@configcat.com;writer@configcat.com;Belgium;write, execute;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 12 | reader@configcat.com;reader@configcat.com;Canada;execute, Read;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 13 | writer@configcat.com;writer@configcat.com;China;Write;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 14 | admin@configcat.com;admin@configcat.com;France;read, write,execute;False;Cat;Cat;Dog;Dog;Dog;Cat;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 15 | user@configcat.com;user@configcat.com;Greece;,execute;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 16 | reader@configcat.com;reader@configcat.com;Bahamas;["read","execute"];False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Dog;Falcon;NotFound;Falcon;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 17 | writer@configcat.com;writer@configcat.com;Belgium;["write", "execute"];False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Dog;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 18 | reader@configcat.com;reader@configcat.com;Canada;["execute", "Read"];False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 19 | writer@configcat.com;writer@configcat.com;China;["Write"];False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Dog;Cat;Cat;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog 20 | admin@configcat.com;admin@configcat.com;France;["read", "write","execute"];False;Cat;Cat;Dog;Dog;Dog;Cat;Dog;Cat;Dog;Cat;Cat;Dog;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 21 | admin@configcat.com;admin@configcat.com;France;["Read", "Write", "execute"];False;Cat;Cat;Dog;Dog;Dog;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 22 | admin@configcat.com;admin@configcat.com;France;["Read", "Write", "eXecute"];False;Cat;Cat;Dog;Dog;Dog;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog 23 | user@configcat.com;user@configcat.com;Greece;["","execute"];False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Dog;Cat;Dog;Horse;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Dog;Dog;Cat;Cat 24 | user@configcat.com;user@configcat.com;Monaco;,null, ,,nil, None;False;Cat;Cat;Dog;Dog;Cat;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Falcon;NotFound;Horse;Cat;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Dog;Dog;Cat;Cat;Cat;Cat 25 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_number.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;numberWithPercentage;number 2 | ##null##;;;;Default;Default 3 | id1;;;0;<2.1;<>5 4 | id1;;;0.0;<2.1;<>5 5 | id1;;;0,0;<2.1;<>5 6 | id1;;;0.2;<2.1;<>5 7 | id2;;;0,2;<2.1;<>5 8 | id3;;;1;<2.1;<>5 9 | id4;;;1.0;<2.1;<>5 10 | id5;;;1,0;<2.1;<>5 11 | id6;;;1.5;<2.1;<>5 12 | id7;;;1,5;<2.1;<>5 13 | id8;;;2.1;<=2,1;<>5 14 | id9;;;2,1;<=2,1;<>5 15 | id10;;;3.50;=3.5;<>5 16 | id11;;;3,50;=3.5;<>5 17 | id12;;;5;>=5;Default 18 | id13;;;5.0;>=5;Default 19 | id14;;;5,0;>=5;Default 20 | id13;;;5.76;>5;<>5 21 | id14;;;5,76;>5;<>5 22 | id15;;;4;<>4.2;<>5 23 | id16;;;4.0;<>4.2;<>5 24 | id17;;;4,0;<>4.2;<>5 25 | id18;;;4.2;80%;<>5 26 | id19;;;4,2;20%;<>5 -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_prerequisite_flag.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;mainBoolFlag;mainStringFlag;mainIntFlag;mainDoubleFlag;stringDependsOnBool;stringDependsOnString;stringDependsOnStringCaseCheck;stringDependsOnInt;stringDependsOnDouble;stringDependsOnDoubleIntValue;boolDependsOnBool;intDependsOnBool;doubleDependsOnBool;boolDependsOnBoolDependsOnBool;mainBoolFlagEmpty;stringDependsOnEmptyBool;stringInverseDependsOnEmptyBool;mainBoolFlagInverse;boolDependsOnBoolInverse 2 | ##null##;;;;True;public;42;3.14;Dog;Cat;Cat;Cat;Cat;Cat;True;1;1.1;False;True;EmptyOn;EmptyOn;False;True 3 | ;;;;True;public;42;3.14;Dog;Cat;Cat;Cat;Cat;Cat;True;1;1.1;False;True;EmptyOn;EmptyOn;False;True 4 | john@sensitivecompany.com;john@sensitivecompany.com;##null##;##null##;False;private;2;0.1;Cat;Dog;Cat;Dog;Dog;Cat;False;42;3.14;True;True;EmptyOn;EmptyOn;True;False 5 | jane@example.com;jane@example.com;##null##;##null##;True;public;42;3.14;Dog;Cat;Cat;Cat;Cat;Cat;True;1;1.1;False;True;EmptyOn;EmptyOn;False;True 6 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_segment.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;developerAndBetaUserSegment;developerAndBetaUserCleartextSegment;notDeveloperAndNotBetaUserSegment;notDeveloperAndNotBetaUserCleartextSegment 2 | ##null##;;;;False;False;False;False 3 | ;;;;False;False;False;False 4 | john@example.com;john@example.com;##null##;##null##;False;False;False;False 5 | jane@example.com;jane@example.com;##null##;##null##;False;False;False;False 6 | kate@example.com;kate@example.com;##null##;##null##;True;True;True;True 7 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_segments_old.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;featureWithSegmentTargeting;featureWithSegmentTargetingCleartext;featureWithNegatedSegmentTargeting;featureWithNegatedSegmentTargetingCleartext;featureWithSegmentTargetingInverse;featureWithSegmentTargetingInverseCleartext;featureWithNegatedSegmentTargetingInverse;featureWithNegatedSegmentTargetingInverseCleartext 2 | ##null##;;;;False;False;False;False;False;False;False;False 3 | ;;;;False;False;False;False;False;False;False;False 4 | john@example.com;john@example.com;##null##;##null##;True;True;False;False;False;False;True;True 5 | jane@example.com;jane@example.com;##null##;##null##;True;True;False;False;False;False;True;True 6 | kate@example.com;kate@example.com;##null##;##null##;False;False;True;True;True;True;False;False 7 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_semantic.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;isOneOf;isOneOfWithPercentage;isNotOneOf;isNotOneOfWithPercentage;lessThanWithPercentage;relations 2 | ##null##;;;;Default;Default;Default;Default;Default;Default 3 | id1;;;0.0.0;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );< 1.0.0;< 1.0.0 4 | id1;;;0.1.0;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );< 1.0.0;< 1.0.0 5 | id1;;;0.2.1;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );< 1.0.0;< 1.0.0 6 | id1;;;1;Default;80%;Default;80%;20%;Default 7 | id2;;;1.0;Default;80%;Default;80%;80%;Default 8 | id3;;;1.0.0;Is one of (1.0.0);is one of (1.0.0);Default;80%;80%;<=1.0.0 9 | id4;;;1.0.0.0;Default;80%;Default;20%;20%;Default 10 | id5;;;1.0.0.0.0;Default;80%;Default;80%;80%;Default 11 | id6;;;1.0.1;Default;80%;Is not one of (1.0.0, 3.0.1);Is not one of (1.0.0, 3.0.1);80%;Default 12 | id7;;;1.0.11;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;Default 13 | id8;;;1.0.111;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 14 | id9;;;1.0.2;Default;20%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 15 | id10;;;1.0.3;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 16 | id11;;;1.0.4;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 17 | id12;;;1.0.5;Default;20%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 18 | id13;;;1.1.0;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 19 | id14;;;1.1.1;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 20 | id15;;;1.1.2;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 21 | id16;;;1.1.3;Default;20%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;Default 22 | id17;;;1.1.4;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;Default 23 | id18;;;1.1.5;Default;20%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 24 | id19;;;1.9.0;Default;20%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;Default 25 | id20;;;1.9.99;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;Default 26 | id21;;;2.0.0;Default;80%;Is not one of (1.0.0, 3.0.1);Is not one of (1.0.0, 3.0.1);20%;>=2.0.0 27 | id22;;;2.0.1;Is one of ( , 2.0.1, 2.0.2, );80%;Is not one of (1.0.0, 3.0.1);Is not one of (1.0.0, 3.0.1);80%;>2.0.0 28 | id23;;;2.0.11;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;>2.0.0 29 | id24;;;2.0.2;Is one of ( , 2.0.1, 2.0.2, );80%;Is not one of (1.0.0, 3.0.1);Is not one of (1.0.0, 3.0.1);80%;>2.0.0 30 | id25;;;2.0.3;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;>2.0.0 31 | id26;;;3.0.0;Is one of (3.0.0);80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;>2.0.0 32 | id27;;;3.0.1;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;>2.0.0 33 | id28;;;3.1.0;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;>2.0.0 34 | id28;;;3.1.1;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;>2.0.0 35 | id29;;;5.0.0;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );80%;>2.0.0 36 | id30;;;5.99.999;Default;80%;Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );Is not one of (1.0.0, 1.0.1, 2.0.0 , 2.0.1, 2.0.2, );20%;>2.0.0 -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_semantic_2.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;AppVersion;precedenceTests 2 | dontcare;;;1.9.1-1;< 1.9.1-2 3 | dontcare;;;1.9.1-2;< 1.9.1-10 4 | dontcare;;;1.9.1-10;< 1.9.1-10a 5 | dontcare;;;1.9.1-10a;< 1.9.1-1a 6 | dontcare;;;1.9.1-1a;< 1.9.1-alpha 7 | dontcare;;;1.9.1-alpha;< 1.9.99-alpha 8 | dontcare;;;1.9.99-alpha;= 1.9.99-alpha 9 | dontcare;;;1.9.99-alpha+build1;= 1.9.99-alpha 10 | dontcare;;;1.9.99-alpha+build2;= 1.9.99-alpha 11 | dontcare;;;1.9.99-alpha2;< 1.9.99-beta 12 | dontcare;;;1.9.99-beta;< 1.9.99-rc 13 | dontcare;;;1.9.99-rc;< 1.9.99-rc.1 14 | dontcare;;;1.9.99-rc.1;< 1.9.99-rc.2 15 | dontcare;;;1.9.99-rc.2;< 1.9.99-rc.20 16 | dontcare;;;1.9.99-rc.9;< 1.9.99-rc.20 17 | dontcare;;;1.9.99-rc.20;< 1.9.99-rc.20a 18 | dontcare;;;1.9.99-rc.20a;< 1.9.99-rc.2a 19 | dontcare;;;1.9.99-rc.2a;< 1.9.99 20 | dontcare;;;1.9.99;< 1.9.100 21 | dontcare;;;1.9.100;< 1.10.0-alpha 22 | dontcare;;;1.10.0-alpha;<= 1.10.0-alpha 23 | dontcare;;;1.10.0;<= 1.10.0 24 | dontcare;;;1.10.1;<= 1.10.1 25 | dontcare;;;1.10.2;<= 1.10.3 26 | dontcare;;;2.0.0;= 2.0.0 27 | dontcare;;;2.0.0+build3;= 2.0.0 28 | dontcare;;;2.0.0+001;= 2.0.0 29 | dontcare;;;2.0.0+20130313144700;= 2.0.0 30 | dontcare;;;2.0.0+exp.sha.5114f85;= 2.0.0 31 | dontcare;;;3.0.0;= 3.0.0+build3 32 | dontcare;;;4.0.0;= 4.0.0+001 33 | dontcare;;;5.0.0;= 5.0.0+20130313144700 34 | dontcare;;;6.0.0;= 6.0.0+exp.sha.5114f85 35 | dontcare;;;7.0.0-patch+metadata;= 7.0.0-patch 36 | dontcare;;;8.0.0-patch+metadata;= 8.0.0-patch+anothermetadata 37 | dontcare;;;9.0.0-patch;= 9.0.0-patch+metadata 38 | dontcare;;;10.0.0;DEFAULT-FROM-CC-APP 39 | dontcare;;;104.0.0;> 103.0.0 40 | dontcare;;;103.0.0;>= 103.0.0 41 | dontcare;;;102.0.0;>= 101.0.0 42 | dontcare;;;101.0.0;>= 101.0.0 43 | dontcare;;;90.104.0;> 90.103.0 44 | dontcare;;;90.103.0;>= 90.103.0 45 | dontcare;;;90.102.0;>= 90.101.0 46 | dontcare;;;90.101.0;>= 90.101.0 47 | dontcare;;;80.0.104;> 80.0.103 48 | dontcare;;;80.0.103;>= 80.0.103 49 | dontcare;;;80.0.102;>= 80.0.101 50 | dontcare;;;80.0.101;>= 80.0.101 51 | dontcare;;;73.0.0;>= 73.0.0-beta.2 52 | dontcare;;;72.0.0;> 72.0.0-beta.2 53 | dontcare;;;72.0.0-beta.2;> 72.0.0-beta.1 54 | dontcare;;;72.0.0-beta.1;> 72.0.0-beta 55 | dontcare;;;72.0.0-beta;> 72.0.0-alpha 56 | dontcare;;;72.0.0-alpha;> 72.0.0-1a 57 | dontcare;;;72.0.0-1a;> 72.0.0-10a 58 | dontcare;;;72.0.0-10aa;> 72.0.0-10a 59 | dontcare;;;72.0.0-10a;> 72.0.0-2 60 | dontcare;;;72.0.0-2;> 72.0.0-1 61 | dontcare;;;71.0.0+metadata;>= 71.0.0+anothermetadata 62 | dontcare;;;71.0.0-patch3+metadata;>= 71.0.0-patch3+anothermetadata 63 | dontcare;;;71.0.0-patch2+metadata;>= 71.0.0-patch2 64 | dontcare;;;71.0.0-patch1;>= 71.0.0-patch1+metadata 65 | dontcare;;;60.73.0;>= 60.73.0-beta.2 66 | dontcare;;;60.72.0;> 60.72.0-beta.2 67 | dontcare;;;60.72.0-beta.2;> 60.72.0-beta.1 68 | dontcare;;;60.72.0-beta.1;> 60.72.0-beta 69 | dontcare;;;60.72.0-beta;> 60.72.0-alpha 70 | dontcare;;;60.72.0-alpha;> 60.72.0-1a 71 | dontcare;;;60.72.0-1a;> 60.72.0-10a 72 | dontcare;;;60.72.0-10aa;> 60.72.0-10a 73 | dontcare;;;60.72.0-10a;> 60.72.0-2 74 | dontcare;;;60.72.0-2;> 60.72.0-1 75 | dontcare;;;60.71.0+metadata;>= 60.71.0+anothermetadata 76 | dontcare;;;60.71.0-patch3+metadata;>= 60.71.0-patch3+anothermetadata 77 | dontcare;;;60.71.0-patch2+metadata;>= 60.71.0-patch2 78 | dontcare;;;60.71.0-patch1;>= 60.71.0-patch1+metadata 79 | dontcare;;;50.60.73;>= 50.60.73-beta.2 80 | dontcare;;;50.60.72;> 50.60.72-beta.2 81 | dontcare;;;50.60.72-beta.2;> 50.60.72-beta.1 82 | dontcare;;;50.60.72-beta.1;> 50.60.72-beta 83 | dontcare;;;50.60.72-beta;> 50.60.72-alpha 84 | dontcare;;;50.60.72-alpha;> 50.60.72-1a 85 | dontcare;;;50.60.72-1a;> 50.60.72-10a 86 | dontcare;;;50.60.72-10aa;> 50.60.72-10a 87 | dontcare;;;50.60.72-10a;> 50.60.72-2 88 | dontcare;;;50.60.72-2;> 50.60.72-1 89 | dontcare;;;50.60.71+metadata;>= 50.60.71+anothermetadata 90 | dontcare;;;50.60.71-patch3+metadata;>= 50.60.71-patch3+anothermetadata 91 | dontcare;;;50.60.71-patch2+metadata;>= 50.60.71-patch2 92 | dontcare;;;50.60.71-patch1;>= 50.60.71-patch1+metadata 93 | dontcare;;;50.60.71-patch1+anothermetadata;>= 50.60.71-patch1+metadata 94 | dontcare;;;40.0.0-patch;>= 40.0.0-patch 95 | dontcare;;;30.0.0-beta;>= 30.0.0-alpha 96 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_sensitive.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;isOneOfSensitive;isNotOneOfSensitive 2 | ##null##;;;;ToAll;ToAll 3 | id1;macska@example.com;;;Macska;Kigyo 4 | Kutya;;;;Allat;ToAll 5 | Sas;;;;ToAll;Kigyo 6 | Kutya;macska@example.com;;;Macska;ToAll 7 | id1;;Scotland;;Britt;Kigyo 8 | Macska;;USA;;ToAll;Ireland -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_unicode.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;🆃🅴🆇🆃;boolTextEqualsHashed;boolTextEqualsCleartext;boolTextNotEqualsHashed;boolTextNotEqualsCleartext;boolIsOneOfHashed;boolIsOneOfCleartext;boolIsNotOneOfHashed;boolIsNotOneOfCleartext;boolStartsWithHashed;boolStartsWithCleartext;boolNotStartsWithHashed;boolNotStartsWithCleartext;boolEndsWithHashed;boolEndsWithCleartext;boolNotEndsWithHashed;boolNotEndsWithCleartext;boolContainsCleartext;boolNotContainsCleartext;boolArrayContainsHashed;boolArrayContainsCleartext;boolArrayNotContainsHashed;boolArrayNotContainsCleartext 2 | 1;;;ʄǟռƈʏ ȶɛӼȶ;True;True;False;False;False;False;True;True;False;False;True;True;False;False;True;True;False;True;False;False;False;False 3 | 1;;;ʄaռƈʏ ȶɛӼȶ;False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;False;True;False;False;False;False 4 | 1;;;ÁRVÍZTŰRŐ tükörfúrógép;False;False;True;True;True;True;False;False;True;True;False;False;True;True;False;False;True;False;False;False;False;False 5 | 1;;;árvíztűrő tükörfúrógép;False;False;True;True;False;False;True;True;False;False;True;True;True;True;False;False;True;False;False;False;False;False 6 | 1;;;ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP;False;False;True;True;False;False;True;True;True;True;False;False;False;False;True;True;True;False;False;False;False;False 7 | 1;;;árvíztűrő TÜKÖRFÚRÓGÉP;False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;False;True;False;False;False;False 8 | 1;;;u𝖓𝖎𝖈𝖔𝖉e;False;False;True;True;True;True;False;False;True;True;False;False;True;True;False;False;True;False;False;False;False;False 9 | ;;;𝖚𝖓𝖎𝖈𝖔𝖉e;False;False;True;True;False;False;True;True;False;False;True;True;True;True;False;False;True;False;False;False;False;False 10 | ;;;u𝖓𝖎𝖈𝖔𝖉𝖊;False;False;True;True;False;False;True;True;True;True;False;False;False;False;True;True;True;False;False;False;False;False 11 | ;;;𝖚𝖓𝖎𝖈𝖔𝖉𝖊;False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;False;True;False;False;False;False 12 | 1;;;["ÁRVÍZTŰRŐ tükörfúrógép", "unicode"];False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;True;False;True;True;False;False 13 | 1;;;["ÁRVÍZTŰRŐ", "tükörfúrógép", "u𝖓𝖎𝖈𝖔𝖉e"];False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;True;False;True;True;False;False 14 | 1;;;["ÁRVÍZTŰRŐ", "tükörfúrógép", "unicode"];False;False;True;True;False;False;True;True;False;False;True;True;False;False;True;True;True;False;False;False;True;True 15 | -------------------------------------------------------------------------------- /src/test/resources/matirx/testmatrix_variationId.csv: -------------------------------------------------------------------------------- 1 | Identifier;Email;Country;Custom1;boolean;decimal;text;whole 2 | ##null##;;;;a0e56eda;63612d39;3f05be89;cf2e9162; 3 | a@configcat.com;a@configcat.com;Hungary;admin;67787ae4;8f9559cf;9bdc6a1f;ab30533b; 4 | b@configcat.com;b@configcat.com;Hungary;admin;67787ae4;8f9559cf;9bdc6a1f;ab30533b; 5 | a@test.com;a@test.com;Hungary;admin;67787ae4;d66c5781;65310deb;ec14f6a9; 6 | b@test.com;b@test.com;Hungary;admin;a0e56eda;d66c5781;65310deb;ec14f6a9; 7 | cliffordj@aol.com;cliffordj@aol.com;Hungary;admin;67787ae4;8155ad7b;cf19e913;ec14f6a9; 8 | bryanw@verizon.net;bryanw@verizon.net;Hungary;;a0e56eda;d0dbc27f;30ba32b9;61a5a033; 9 | -------------------------------------------------------------------------------- /src/test/resources/specialCharacters.txt: -------------------------------------------------------------------------------- 1 | äöüÄÖÜçéèñışğ⢙✓😀 -------------------------------------------------------------------------------- /src/test/resources/test-simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "flags": { 3 | "disabledFeature": false, 4 | "enabledFeature": true, 5 | "intSetting": 5, 6 | "doubleSetting": 3.14, 7 | "stringSetting": "test" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/resources/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "p": { 3 | "s": "s449fLWNwiEFQ/AqfRj13pPHVdV9g3h0HAFzWtjpZgE=" 4 | }, 5 | "f": { 6 | "disabledFeature": { 7 | "t": 0, 8 | "v": { 9 | "b": false 10 | } 11 | }, 12 | "enabledFeature": { 13 | "t": 0, 14 | "v": { 15 | "b": true 16 | } 17 | }, 18 | "intSetting": { 19 | "t": 2, 20 | "v": { 21 | "i": 5 22 | } 23 | }, 24 | "doubleSetting": { 25 | "t": 3, 26 | "v": { 27 | "d": 3.14 28 | } 29 | }, 30 | "stringSetting": { 31 | "t": 1, 32 | "v": { 33 | "s": "test" 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resources/test_circulardependency.json: -------------------------------------------------------------------------------- 1 | { 2 | "p": { 3 | "u": "https://cdn-global.configcat.com", 4 | "r": 0, 5 | "s": "test-salt" 6 | }, 7 | "f": { 8 | "key1": { 9 | "t": 1, 10 | "v": { 11 | "s": "key1-value" 12 | }, 13 | "r": [ 14 | { 15 | "c": [ 16 | { 17 | "p": { 18 | "f": "key1", 19 | "c": 0, 20 | "v": { 21 | "s": "key1-prereq" 22 | } 23 | } 24 | } 25 | ], 26 | "s": { 27 | "v": { 28 | "s": "key1-prereq" 29 | } 30 | } 31 | } 32 | ] 33 | }, 34 | "key2": { 35 | "t": 1, 36 | "v": { 37 | "s": "key2-value" 38 | }, 39 | "r": [ 40 | { 41 | "c": [ 42 | { 43 | "p": { 44 | "f": "key3", 45 | "c": 0, 46 | "v": { 47 | "s": "key3-prereq" 48 | } 49 | } 50 | } 51 | ], 52 | "s": { 53 | "v": { 54 | "s": "key2-prereq" 55 | } 56 | } 57 | } 58 | ] 59 | }, 60 | "key3": { 61 | "t": 1, 62 | "v": { 63 | "s": "key3-value" 64 | }, 65 | "r": [ 66 | { 67 | "c": [ 68 | { 69 | "p": { 70 | "f": "key2", 71 | "c": 0, 72 | "v": { 73 | "s": "key2-prereq" 74 | } 75 | } 76 | } 77 | ], 78 | "s": { 79 | "v": { 80 | "s": "key3-prereq" 81 | } 82 | } 83 | } 84 | ] 85 | }, 86 | "key4": { 87 | "t": 1, 88 | "v": { 89 | "s": "key4-value" 90 | }, 91 | "r": [ 92 | { 93 | "c": [ 94 | { 95 | "p": { 96 | "f": "key3", 97 | "c": 0, 98 | "v": { 99 | "s": "key3-prereq" 100 | } 101 | } 102 | } 103 | ], 104 | "s": { 105 | "v": { 106 | "s": "key4-prereq" 107 | } 108 | } 109 | } 110 | ] 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/test/resources/test_override_flagdependency_v6.json: -------------------------------------------------------------------------------- 1 | { 2 | "p": { 3 | "u": "https://test-cdn-eu.configcat.com", 4 | "r": 0, 5 | "s": "TsTuRHo\u002BMHs8h8j16HQY83sooJsLg34Ir5KIVOletFU=" 6 | }, 7 | "f": { 8 | "mainStringFlag": { 9 | "t": 1, 10 | "v": { 11 | "s": "private" 12 | }, 13 | "i": "24c96275" 14 | }, 15 | "stringDependsOnInt": { 16 | "t": 1, 17 | "r": [ 18 | { 19 | "c": [ 20 | { 21 | "p": { 22 | "f": "mainIntFlag", 23 | "c": 0, 24 | "v": { 25 | "i": 42 26 | } 27 | } 28 | } 29 | ], 30 | "s": { 31 | "v": { 32 | "s": "Dog" 33 | }, 34 | "i": "12531eec" 35 | } 36 | } 37 | ], 38 | "v": { 39 | "s": "Cat" 40 | }, 41 | "i": "e227d926" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/resources/test_override_segments_v6.json: -------------------------------------------------------------------------------- 1 | { 2 | "p": { 3 | "u": "https://test-cdn-eu.configcat.com", 4 | "r": 0, 5 | "s": "80xCU/SlDz1lCiWFaxIBjyJeJecWjq46T4eu6GtozkM=" 6 | }, 7 | "s": [ 8 | { 9 | "n": "Beta Users", 10 | "r": [ 11 | { 12 | "a": "Email", 13 | "c": 16, 14 | "l": [ 15 | "9189c42f6035bd1d2df5eda347a4f62926d27c80540a7aa6cc72cc75bc6757ff" 16 | ] 17 | } 18 | ] 19 | }, 20 | { 21 | "n": "Developers", 22 | "r": [ 23 | { 24 | "a": "Email", 25 | "c": 16, 26 | "l": [ 27 | "a7cdf54e74b5527bd2617889ec47f6d29b825ccfc97ff00832886bcb735abded" 28 | ] 29 | } 30 | ] 31 | } 32 | ], 33 | "f": { 34 | "developerAndBetaUserSegment": { 35 | "t": 0, 36 | "r": [ 37 | { 38 | "c": [ 39 | { 40 | "s": { 41 | "s": 1, 42 | "c": 0 43 | } 44 | }, 45 | { 46 | "s": { 47 | "s": 0, 48 | "c": 1 49 | } 50 | } 51 | ], 52 | "s": { 53 | "v": { 54 | "b": true 55 | }, 56 | "i": "ddc50638" 57 | } 58 | } 59 | ], 60 | "v": { 61 | "b": false 62 | }, 63 | "i": "6427f4b8" 64 | } 65 | } 66 | } 67 | --------------------------------------------------------------------------------