io.split.client.testing.SplitClientForTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client-testing Show documentation
Show all versions of java-client-testing Show documentation
Testing suite for Java SDK for Split
package io.split.client.testing;
import io.split.client.SplitClient;
import io.split.client.api.Key;
import io.split.client.api.SplitResult;
import io.split.grammar.Treatments;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.concurrent.TimeoutException;
public class SplitClientForTest implements SplitClient {
private Map _tests;
public SplitClientForTest() {
_tests = new HashMap<>();
}
public Map tests() {
return _tests;
}
public void clearTreatments() {
_tests = new HashMap<>();
}
public void registerTreatments(Map treatments) {
_tests.putAll(treatments);
}
public void registerTreatment(String feature, String treatment) {
_tests.put(feature, treatment);
}
public String getTreatment(String key, String featureFlagName) {
return _tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL;
}
public String getTreatment(String key, String featureFlagName, Map attributes) {
return _tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL;
}
public String getTreatment(Key key, String featureFlagName, Map attributes) {
return _tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL;
}
@Override
public SplitResult getTreatmentWithConfig(String key, String featureFlagName) {
return new SplitResult(_tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL, null);
}
@Override
public SplitResult getTreatmentWithConfig(String key, String featureFlagName, Map attributes) {
return new SplitResult(_tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL, null);
}
@Override
public SplitResult getTreatmentWithConfig(Key key, String featureFlagName, Map attributes) {
return new SplitResult(_tests.containsKey(featureFlagName)
? _tests.get(featureFlagName)
: Treatments.CONTROL, null);
}
@Override
public Map getTreatments(String key, List featureFlagNames) {
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, _tests.containsKey(split) ? _tests.get(split) : Treatments.CONTROL);
}
return treatments;
}
@Override
public Map getTreatments(String key, List featureFlagNames, Map attributes){
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, _tests.containsKey(split) ? _tests.get(split) : Treatments.CONTROL);
}
return treatments;
}
@Override
public Map getTreatments(Key key, List featureFlagNames, Map attributes) {
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, _tests.containsKey(split) ? _tests.get(split) : Treatments.CONTROL);
}
return treatments;
}
@Override
public Map getTreatmentsWithConfig(String key, List featureFlagNames) {
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, new SplitResult(_tests.containsKey(split)
? _tests.get(split)
: Treatments.CONTROL, null));
}
return treatments;
}
@Override
public Map getTreatmentsWithConfig(String key, List featureFlagNames, Map attributes) {
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, new SplitResult(_tests.containsKey(split)
? _tests.get(split)
: Treatments.CONTROL, null));
}
return treatments;
}
@Override
public Map getTreatmentsWithConfig(Key key, List featureFlagNames, Map attributes) {
Map treatments = new HashMap<>();
for (String split : featureFlagNames) {
treatments.put(split, new SplitResult(_tests.containsKey(split)
? _tests.get(split)
: Treatments.CONTROL, null));
}
return treatments;
}
@Override
public Map getTreatmentsByFlagSet(String key, String flagSet) {
return null;
}
@Override
public Map getTreatmentsByFlagSet(String key, String flagSet, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsByFlagSet(Key key, String flagSet, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsByFlagSets(String key, List flagSets) {
return null;
}
@Override
public Map getTreatmentsByFlagSets(String key, List flagSets, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsByFlagSets(Key key, List flagSets, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsWithConfigByFlagSet(String key, String flagSet) {
return null;
}
@Override
public Map getTreatmentsWithConfigByFlagSet(String key, String flagSet, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsWithConfigByFlagSet(Key key, String flagSet, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsWithConfigByFlagSets(String key, List flagSets) {
return null;
}
@Override
public Map getTreatmentsWithConfigByFlagSets(String key, List flagSets, Map attributes) {
return new HashMap<>();
}
@Override
public Map getTreatmentsWithConfigByFlagSets(Key key, List flagSets, Map attributes) {
return new HashMap<>();
}
@Override
public void destroy() {
}
@Override
public boolean track(String key, String trafficType, String eventType) {
return false;
}
@Override
public boolean track(String key, String trafficType, String eventType, double value) {
return false;
}
@Override
public boolean track(String key, String trafficType, String eventType, Map properties) {
return false;
}
@Override
public boolean track(String key, String trafficType, String eventType, double value, Map properties) {
return false;
}
@Override
public void blockUntilReady() throws TimeoutException, InterruptedException {
}
}