Skip to content

Check point pagination support for get connection #704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
dependencies {
// https://github.com/melix/japicmp-gradle-plugin/issues/36
classpath 'com.google.guava:guava:31.1-jre'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0"
}
}

Expand Down Expand Up @@ -114,7 +115,7 @@ test {
}

ext {
okhttpVersion = '4.11.0'
okhttpVersion = '4.12.0'
hamcrestVersion = '2.2'
jupiterVersion = '5.9.3'

Expand All @@ -126,9 +127,14 @@ dependencies {
// TODO remove direct dependency when OkHttp 4.12.0 is released
implementation ("com.squareup.okhttp3:okhttp:${okhttpVersion}") {
exclude group: 'com.squareup.okhttp3', module: 'okio'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
implementation "com.squareup.okio:okio:3.5.0"

implementation "org.jetbrains.kotlin:kotlin-stdlib:2.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.1.0"

implementation "com.squareup.okhttp3:logging-interceptor:${okhttpVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.0"
implementation "com.auth0:java-jwt:4.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,27 @@ public ConnectionFilter withFields(String fields, boolean includeFields) {
super.withFields(fields, includeFields);
return this;
}

/**
* Include the {@code from} parameter to specify where to start the page selection. Only applicable for endpoints that
* support checkpoint pagination.
* @param from the ID from which to start selection. This can be obtained from the {@code next} field returned from
* a checkpoint-paginated result.
* @return this filter instance.
*/
public ConnectionFilter withFrom(String from) {
parameters.put("from", from);
return this;
}

/**
* Include the {@code take} parameter to specify the amount of results to return per page. Only applicable for endpoints that
* support checkpoint pagination.
* @param take the amount of entries to retrieve per page.
* @return this filter instance.
*/
public ConnectionFilter withTake(int take) {
parameters.put("take", take);
return this;
}
}
46 changes: 46 additions & 0 deletions src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,52 @@ public void shouldListConnectionsWithTotals() throws Exception {
assertThat(response.getLimit(), is(50));
}

@Test
public void shouldListConnectionsWithFrom() throws Exception {
ConnectionFilter filter = new ConnectionFilter().withFrom("10");
Request<ConnectionsPage> request = api.connections().listAll(filter);
assertThat(request, is(notNullValue()));

server.jsonResponse(MGMT_CONNECTIONS_PAGED_LIST, 200);
ConnectionsPage response = request.execute().getBody();
RecordedRequest recordedRequest = server.takeRequest();

assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
assertThat(recordedRequest, hasQueryParameter("from", "10"));

assertThat(response, is(notNullValue()));
assertThat(response.getItems(), hasSize(2));
assertThat(response.getStart(), is(0));
assertThat(response.getLength(), is(14));
assertThat(response.getTotal(), is(14));
assertThat(response.getLimit(), is(50));
}

@Test
public void shouldListConnectionsWithTake() throws Exception {
ConnectionFilter filter = new ConnectionFilter().withTake(1);
Request<ConnectionsPage> request = api.connections().listAll(filter);
assertThat(request, is(notNullValue()));

server.jsonResponse(MGMT_CONNECTIONS_PAGED_LIST, 200);
ConnectionsPage response = request.execute().getBody();
RecordedRequest recordedRequest = server.takeRequest();

assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
assertThat(recordedRequest, hasQueryParameter("take", "1"));

assertThat(response, is(notNullValue()));
assertThat(response.getItems(), hasSize(2));
assertThat(response.getStart(), is(0));
assertThat(response.getLength(), is(14));
assertThat(response.getTotal(), is(14));
assertThat(response.getLimit(), is(50));
}

@Test
public void shouldThrowOnGetConnectionWithNullId() {
verifyThrows(IllegalArgumentException.class,
Expand Down
Loading