Skip to content

Commit

Permalink
Add missing User-less method overloads (#38)
Browse files Browse the repository at this point in the history
* Add missing User-less method overloads

* Add tests
  • Loading branch information
z4kn4fein authored Sep 28, 2023
1 parent 108705d commit cf4ff05
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=8.2.2
version=8.3.0
20 changes: 20 additions & 0 deletions src/main/java/com/configcat/ConfigCatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public <T> CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync(Class<T>
});
}

@Override
public Map<String, Object> getAllValues() {
return this.getAllValues(null);
}

@Override
public Map<String, Object> getAllValues(User user) {
try {
Expand All @@ -198,6 +203,11 @@ public Map<String, Object> getAllValues(User user) {
}
}

@Override
public CompletableFuture<Map<String, Object>> getAllValuesAsync() {
return this.getAllValuesAsync(null);
}

@Override
public CompletableFuture<Map<String, Object>> getAllValuesAsync(User user) {
return this.getSettingsAsync()
Expand Down Expand Up @@ -227,6 +237,11 @@ public CompletableFuture<Map<String, Object>> getAllValuesAsync(User user) {
});
}

@Override
public List<EvaluationDetails<Object>> getAllValueDetails() {
return this.getAllValueDetails(null);
}

@Override
public List<EvaluationDetails<Object>> getAllValueDetails(User user) {
try {
Expand All @@ -241,6 +256,11 @@ public List<EvaluationDetails<Object>> getAllValueDetails(User user) {
}
}

@Override
public CompletableFuture<List<EvaluationDetails<Object>>> getAllValueDetailsAsync() {
return this.getAllValueDetailsAsync(null);
}

@Override
public CompletableFuture<List<EvaluationDetails<Object>>> getAllValueDetailsAsync(User user) {
return this.getSettingsAsync()
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/configcat/ConfigurationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ public interface ConfigurationProvider extends Closeable {
*/
<T> CompletableFuture<EvaluationDetails<T>> getValueDetailsAsync(Class<T> classOfT, String key, User user, T defaultValue);

/**
* Gets the values of all feature flags or settings synchronously.
*
* @return a collection of all values.
*/
Map<String, Object> getAllValues();

/**
* Gets the values of all feature flags or settings synchronously.
*
Expand All @@ -110,6 +117,13 @@ public interface ConfigurationProvider extends Closeable {
*/
Map<String, Object> getAllValues(User user);

/**
* Gets the values of all feature flags or settings asynchronously.
*
* @return a future which computes the collection of all values.
*/
CompletableFuture<Map<String, Object>> getAllValuesAsync();

/**
* Gets the values of all feature flags or settings asynchronously.
*
Expand All @@ -118,6 +132,13 @@ public interface ConfigurationProvider extends Closeable {
*/
CompletableFuture<Map<String, Object>> getAllValuesAsync(User user);

/**
* Gets the detailed values of all feature flags or settings synchronously.
*
* @return a collection of all the evaluation results with details
*/
List<EvaluationDetails<Object>> getAllValueDetails();

/**
* Gets the detailed values of all feature flags or settings synchronously.
*
Expand All @@ -126,6 +147,13 @@ public interface ConfigurationProvider extends Closeable {
*/
List<EvaluationDetails<Object>> getAllValueDetails(User user);

/**
* Gets the detailed values of all feature flags or settings asynchronously.
*
* @return a future which computes the collection of all detailed values.
*/
CompletableFuture<List<EvaluationDetails<Object>>> getAllValueDetailsAsync();

/**
* Gets the detailed values of all feature flags or settings asynchronously.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/configcat/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ private Constants() { /* prevent from instantiation*/ }
static final String CONFIG_JSON_NAME = "config_v5.json";
static final String SERIALIZATION_FORMAT_VERSION = "v2";

static final String VERSION = "8.2.2";
static final String VERSION = "8.3.0";
}
63 changes: 61 additions & 2 deletions src/test/java/com/configcat/ConfigCatClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,29 @@ public void getAllValues() throws IOException {
server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_MULTIPLE));
cl.forceRefresh();

Map<String, Object> allValues = cl.getAllValues(null);
Map<String, Object> allValues = cl.getAllValues();

assertEquals(true, allValues.get("key1"));
assertEquals(false, allValues.get("key2"));

server.shutdown();
cl.close();
}

@Test
public void getAllValuesAsync() throws IOException, ExecutionException, InterruptedException {
MockWebServer server = new MockWebServer();
server.start();

ConfigCatClient cl = ConfigCatClient.get(APIKEY, options -> {
options.pollingMode(PollingModes.manualPoll());
options.baseUrl(server.url("/").toString());
});

server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_MULTIPLE));
cl.forceRefresh();

Map<String, Object> allValues = cl.getAllValuesAsync().get();

assertEquals(true, allValues.get("key1"));
assertEquals(false, allValues.get("key2"));
Expand All @@ -280,7 +302,44 @@ public void getAllValueDetails() throws IOException {
server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_MULTIPLE));
cl.forceRefresh();

List<EvaluationDetails<Object>> allValuesDetails = cl.getAllValueDetails(null);
List<EvaluationDetails<Object>> allValuesDetails = cl.getAllValueDetails();

//assert result list
assertEquals(2, allValuesDetails.size());

//assert result 1
EvaluationDetails<Object> element = allValuesDetails.get(0);
assertEquals("key1", element.getKey());
assertTrue((boolean) element.getValue());
assertFalse(element.isDefaultValue());
assertNull(element.getError());
assertEquals("fakeId1", element.getVariationId());

//assert result 2
element = allValuesDetails.get(1);
assertEquals("key2", element.getKey());
assertFalse((boolean) element.getValue());
assertFalse(element.isDefaultValue());
assertNull(element.getError());
assertEquals("fakeId2", element.getVariationId());
server.shutdown();
cl.close();
}

@Test
public void getAllValueDetailsAsync() throws IOException, ExecutionException, InterruptedException {
MockWebServer server = new MockWebServer();
server.start();

ConfigCatClient cl = ConfigCatClient.get(APIKEY, options -> {
options.pollingMode(PollingModes.manualPoll());
options.baseUrl(server.url("/").toString());
});

server.enqueue(new MockResponse().setResponseCode(200).setBody(TEST_JSON_MULTIPLE));
cl.forceRefresh();

List<EvaluationDetails<Object>> allValuesDetails = cl.getAllValueDetailsAsync().get();

//assert result list
assertEquals(2, allValuesDetails.size());
Expand Down

0 comments on commit cf4ff05

Please sign in to comment.