diff --git a/build.gradle b/build.gradle index 27d72ca38..1942dedde 100644 --- a/build.gradle +++ b/build.gradle @@ -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" } } @@ -114,7 +115,7 @@ test { } ext { - okhttpVersion = '4.11.0' + okhttpVersion = '4.12.0' hamcrestVersion = '2.2' jupiterVersion = '5.9.3' @@ -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" diff --git a/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java b/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java index 375fe13d7..d1a160f8f 100644 --- a/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java +++ b/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java @@ -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; + } } diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index 211d13cb3..4e1149334 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -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 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 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,