diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 4dd8587f..00000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -auth0 \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 26c7e48e..00000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf33..00000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 25273730..fd1b2ba9 100644 --- a/README.md +++ b/README.md @@ -270,22 +270,27 @@ Click [here](https://auth0.com/docs/api/management/v2/tokens) for more informati The Management API is divided into different entities. Each of them have the list, create, update, delete and update methods plus a few more if corresponds. The calls are authenticated using the API Token given in the `ManagementAPI` instance creation and must contain the `scope` required by each entity. See the javadoc for details on which `scope` is expected for each call. -* **Client Grants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Client_Grants/get_client_grants). Access the methods by calling `mgmt.clientGrants()`. -* **Clients:** See [Docs](https://auth0.com/docs/api/management/v2#!/Clients/get_clients). Access the methods by calling `mgmt.clients()`. -* **Connections:** See [Docs](https://auth0.com/docs/api/management/v2#!/Connections/get_connections). Access the methods by calling `mgmt.connections()`. -* **Device Credentials:** See [Docs](https://auth0.com/docs/api/management/v2#!/Device_Credentials/get_device_credentials). Access the methods by calling `mgmt.deviceCredentials()`. -* **Logs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Logs/get_logs). Access the methods by calling `mgmt.logEvents()`. -* **Rules:** See [Docs](https://auth0.com/docs/api/management/v2#!/Rules/get_rules). Access the methods by calling `mgmt.rules()`. -* **User Blocks:** See [Docs](https://auth0.com/docs/api/management/v2#!/User_Blocks/get_user_blocks). Access the methods by calling `mgmt.userBlocks()`. -* **Users:** See [this](https://auth0.com/docs/api/management/v2#!/Users/get_users) and [this](https://auth0.com/docs/api/management/v2#!/Users_By_Email) doc. Access the methods by calling `mgmt.users()`. * **Blacklists:** See [Docs](https://auth0.com/docs/api/management/v2#!/Blacklists/get_tokens). Access the methods by calling `mgmt.blacklists()`. +* **Client Grants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Client_Grants/get_client_grants). Access the methods by calling `mgmt.clientGrants()`. This endpoint supports pagination. +* **Clients:** See [Docs](https://auth0.com/docs/api/management/v2#!/Clients/get_clients). Access the methods by calling `mgmt.clients()`. This endpoint supports pagination. +* **Connections:** See [Docs](https://auth0.com/docs/api/management/v2#!/Connections/get_connections). Access the methods by calling `mgmt.connections()`. This endpoint supports pagination. +* **Device Credentials:** See [Docs](https://auth0.com/docs/api/management/v2#!/Device_Credentials/get_device_credentials). Access the methods by calling `mgmt.deviceCredentials()`. * **Email Providers:** See [Docs](https://auth0.com/docs/api/management/v2#!/Emails/get_provider). Access the methods by calling `mgmt.emailProvider()`. * **Email Templates:** See [Docs](https://auth0.com/docs/api/management/v2#!/Email_Templates/get_email_templates_by_templateName). Access the methods by calling `mgmt.emailTemplates()`. +* **Grants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Grants/get_grants). Access the methods by calling `mgmt.grants()`. This endpoint supports pagination. * **Guardian:** See [Docs](https://auth0.com/docs/api/management/v2#!/Guardian/get_factors). Access the methods by calling `mgmt.guardian()`. +* **Jobs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Jobs/get_jobs_by_id). Access the methods by calling `mgmt.jobs()`. +* **Logs:** See [Docs](https://auth0.com/docs/api/management/v2#!/Logs/get_logs). Access the methods by calling `mgmt.logEvents()`. This endpoint supports pagination. +* **Resource Servers:** See [Docs](https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers). Access the methods by calling `mgmt.resourceServers()`. This endpoint supports pagination. +* **Rules:** See [Docs](https://auth0.com/docs/api/management/v2#!/Rules/get_rules). Access the methods by calling `mgmt.rules()`. This endpoint supports pagination. * **Stats:** See [Docs](https://auth0.com/docs/api/management/v2#!/Stats/get_active_users). Access the methods by calling `mgmt.stats()`. * **Tenants:** See [Docs](https://auth0.com/docs/api/management/v2#!/Tenants/get_settings). Access the methods by calling `mgmt.tenants()`. * **Tickets:** See [Docs](https://auth0.com/docs/api/management/v2#!/Tickets/post_email_verification). Access the methods by calling `mgmt.tickets()`. -* **Resource Servers:** See [Docs](https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers). Access the methods by calling `mgmt.resourceServers()`. +* **User Blocks:** See [Docs](https://auth0.com/docs/api/management/v2#!/User_Blocks/get_user_blocks). Access the methods by calling `mgmt.userBlocks()`. +* **Users:** See [this](https://auth0.com/docs/api/management/v2#!/Users/get_users) and [this](https://auth0.com/docs/api/management/v2#!/Users_By_Email) doc. Access the methods by calling `mgmt.users()`. This endpoint supports pagination. + + +> Some of the endpoints above indicate they support paginated responses. You can request a page of items by passing in the filter instance the `page` and `per_page` parameters, and optionally `include_totals` to obtain a summary of the results. Refer to the "List Users" example below for details. ### Users @@ -299,7 +304,8 @@ You can pass an optional Filter to narrow the results in the response. Example: ```java -FieldsFilter filter = new FieldsFilter(...); +FieldsFilter filter = new FieldsFilter(); +//... Request> request = mgmt.users().listByEmail("johndoe@auth0.com", filter); try { List response = request.execute(); @@ -319,7 +325,9 @@ You can pass an optional Filter to narrow the results in the response. Example: ```java -UserFilter filter = new UserFilter(...); +UserFilter filter = new UserFilter() + .withPage(1, 20); +//... Request request = mgmt.users().list(filter); try { UsersPage response = request.execute(); @@ -339,7 +347,8 @@ You can pass an optional Filter to narrow the results in the response. Example: ```java -UserFilter filter = new UserFilter(...); +UserFilter filter = new UserFilter(); +//... Request request = mgmt.users().get("auth0|123", filter); try { User response = request.execute(); @@ -358,7 +367,8 @@ Creates a request to create a User. An API Token with scope `create:users` is ne Example: ```java -User data = new User(...); +User data = new User("my-connection"); +//... Request request = mgmt.users().create(data); try { User response = request.execute(); @@ -395,7 +405,8 @@ Creates a request to update a User. An API Token with scope `update:users` is ne Example: ```java -User data = new User(...); +User data = new User(); +//... Request request = mgmt.users().update("auth0|123", data); try { User response = request.execute(); @@ -433,7 +444,8 @@ You can pass an optional Filter to narrow the results in the response. Example: ```java -LogEventFilter filter = new LogEventFilter(...); +LogEventFilter filter = new LogEventFilter(); +//... Request request = mgmt.users().getLogEvents("auth0|123", filter); try { LogEventsPage response = request.execute(); diff --git a/gradlew.bat b/gradlew.bat index f6d5974e..832fdb60 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,90 +1,90 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java index 7d95baa7..fcf5b715 100644 --- a/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java +++ b/src/main/java/com/auth0/client/mgmt/ConnectionsEntity.java @@ -2,6 +2,7 @@ import com.auth0.client.mgmt.filter.ConnectionFilter; import com.auth0.json.mgmt.Connection; +import com.auth0.json.mgmt.ConnectionsPage; import com.auth0.net.CustomRequest; import com.auth0.net.Request; import com.auth0.net.VoidRequest; @@ -23,6 +24,7 @@ public class ConnectionsEntity extends BaseManagementEntity { super(client, baseUrl, apiToken); } + /** * Request all the ConnectionsEntity. A token with scope read:connections is needed. * See https://auth0.com/docs/api/management/v2#!/Connections/get_connections @@ -30,7 +32,7 @@ public class ConnectionsEntity extends BaseManagementEntity { * @param filter the filter to use. Can be null. * @return a Request to execute. */ - public Request> list(ConnectionFilter filter) { + public Request listAll(ConnectionFilter filter) { HttpUrl.Builder builder = baseUrl .newBuilder() .addPathSegments("api/v2/connections"); @@ -40,6 +42,34 @@ public Request> list(ConnectionFilter filter) { } } String url = builder.build().toString(); + CustomRequest request = new CustomRequest<>(client, url, "GET", new TypeReference() { + }); + request.addHeader("Authorization", "Bearer " + apiToken); + return request; + } + + + /** + * Request all the ConnectionsEntity. A token with scope read:connections is needed. + * See https://auth0.com/docs/api/management/v2#!/Connections/get_connections + * + * @param filter the filter to use. Can be null. + * @return a Request to execute. + */ + public Request> list(ConnectionFilter filter) { + //TODO: Deprecate + HttpUrl.Builder builder = baseUrl + .newBuilder() + .addPathSegments("api/v2/connections"); + if (filter != null) { + for (Map.Entry e : filter.getAsMap().entrySet()) { + //This check below is to prevent JSON parsing errors + if (!e.getKey().equalsIgnoreCase("include_totals")) { + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); + } + } + } + String url = builder.build().toString(); CustomRequest> request = new CustomRequest<>(client, url, "GET", new TypeReference>() { }); request.addHeader("Authorization", "Bearer " + apiToken); diff --git a/src/main/java/com/auth0/client/mgmt/RulesEntity.java b/src/main/java/com/auth0/client/mgmt/RulesEntity.java index c7e75b96..6bee86fc 100644 --- a/src/main/java/com/auth0/client/mgmt/RulesEntity.java +++ b/src/main/java/com/auth0/client/mgmt/RulesEntity.java @@ -61,7 +61,10 @@ public Request> list(RulesFilter filter) { .addPathSegments("api/v2/rules"); if (filter != null) { for (Map.Entry e : filter.getAsMap().entrySet()) { - builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); + //This check below is to prevent JSON parsing errors + if (!e.getKey().equalsIgnoreCase("include_totals")) { + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); + } } } String url = builder.build().toString(); 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 c3470bbd..9371455d 100644 --- a/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java +++ b/src/main/java/com/auth0/client/mgmt/filter/ConnectionFilter.java @@ -40,6 +40,18 @@ public ConnectionFilter withPage(int pageNumber, int amountPerPage) { return this; } + /** + * Include the query summary. + * Warning: Can only be used with {@link com.auth0.client.mgmt.ConnectionsEntity#listAll(ConnectionFilter)} + * + * @param includeTotals whether to include or not the query summary. + * @return this filter instance + */ + public ConnectionFilter withTotals(boolean includeTotals) { + parameters.put("include_totals", includeTotals); + return this; + } + @Override public ConnectionFilter withFields(String fields, boolean includeFields) { super.withFields(fields, includeFields); diff --git a/src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java b/src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java index 5eff2d54..c7c3a418 100644 --- a/src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java +++ b/src/main/java/com/auth0/client/mgmt/filter/RulesFilter.java @@ -24,6 +24,7 @@ public RulesFilter withFields(String fields, boolean includeFields) { /** * Include the query summary + * Warning: Can only be used with {@link com.auth0.client.mgmt.RulesEntity#listAll(RulesFilter)} * * @param includeTotals whether to include or not the query summary. * @return this filter instance diff --git a/src/main/java/com/auth0/json/mgmt/ConnectionsPage.java b/src/main/java/com/auth0/json/mgmt/ConnectionsPage.java new file mode 100644 index 00000000..caf913f7 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/ConnectionsPage.java @@ -0,0 +1,26 @@ +package com.auth0.json.mgmt; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; + +/** + * Class that represents a given page of Grants. Related to the {@link com.auth0.client.mgmt.ConnectionsEntity} entity. + */ +@SuppressWarnings({"unused", "WeakerAccess"}) +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonDeserialize(using = ConnectionsPageDeserializer.class) +public class ConnectionsPage extends Page { + + public ConnectionsPage(List items) { + super(items); + } + + public ConnectionsPage(Integer start, Integer length, Integer total, Integer limit, List items) { + super(start, length, total, limit, items); + } + +} \ No newline at end of file diff --git a/src/main/java/com/auth0/json/mgmt/ConnectionsPageDeserializer.java b/src/main/java/com/auth0/json/mgmt/ConnectionsPageDeserializer.java new file mode 100644 index 00000000..cc22fef9 --- /dev/null +++ b/src/main/java/com/auth0/json/mgmt/ConnectionsPageDeserializer.java @@ -0,0 +1,22 @@ +package com.auth0.json.mgmt; + +import java.util.List; + +@SuppressWarnings({"unused", "WeakerAccess"}) +class ConnectionsPageDeserializer extends PageDeserializer { + + ConnectionsPageDeserializer() { + super(Connection.class, "connections"); + } + + @Override + protected ConnectionsPage createPage(List items) { + return new ConnectionsPage(items); + } + + @Override + protected ConnectionsPage createPage(Integer start, Integer length, Integer total, Integer limit, List items) { + return new ConnectionsPage(start, length, total, limit, items); + } + +} diff --git a/src/test/java/com/auth0/client/MockServer.java b/src/test/java/com/auth0/client/MockServer.java index 444cb1cc..88bf1df9 100644 --- a/src/test/java/com/auth0/client/MockServer.java +++ b/src/test/java/com/auth0/client/MockServer.java @@ -33,6 +33,7 @@ public class MockServer { public static final String MGMT_CLIENTS_PAGED_LIST = "src/test/resources/mgmt/clients_paged_list.json"; public static final String MGMT_CLIENT = "src/test/resources/mgmt/client.json"; public static final String MGMT_CONNECTIONS_LIST = "src/test/resources/mgmt/connections_list.json"; + public static final String MGMT_CONNECTIONS_PAGED_LIST = "src/test/resources/mgmt/connections_paged_list.json"; public static final String MGMT_CONNECTION = "src/test/resources/mgmt/connection.json"; public static final String MGMT_DEVICE_CREDENTIALS_LIST = "src/test/resources/mgmt/device_credentials_list.json"; public static final String MGMT_DEVICE_CREDENTIALS = "src/test/resources/mgmt/device_credentials.json"; diff --git a/src/test/java/com/auth0/client/RecordedRequestMatcher.java b/src/test/java/com/auth0/client/RecordedRequestMatcher.java index d884f48f..e963d4fe 100644 --- a/src/test/java/com/auth0/client/RecordedRequestMatcher.java +++ b/src/test/java/com/auth0/client/RecordedRequestMatcher.java @@ -9,6 +9,7 @@ public class RecordedRequestMatcher extends TypeSafeDiagnosingMatcher 0; + if (!hasQuery) { + mismatchDescription.appendText(" query was empty"); + return false; + } + + String query = path.substring(path.indexOf("?") + 1, path.length()); + String[] parameters = query.split("&"); + for (String p : parameters) { + if (p.startsWith(String.format("%s=", first))) { + return true; + } + } + mismatchDescription.appendValueList("Query parameters were {", ", ", "}.", parameters); + return false; + } + @Override public void describeTo(Description description) { switch (checkingOption) { @@ -108,6 +130,10 @@ public void describeTo(Description description) { .appendText(" with value ") .appendValue(second); break; + case QUERY_PARAMETER_PRESENCE: + description.appendText("A request containing query parameter ") + .appendValue(first); + break; } } @@ -122,4 +148,8 @@ public static RecordedRequestMatcher hasHeader(String name, String value) { public static RecordedRequestMatcher hasQueryParameter(String name, String value) { return new RecordedRequestMatcher(name, value, QUERY_PARAMETER); } + + public static RecordedRequestMatcher hasQueryParameter(String name) { + return new RecordedRequestMatcher(name, null, QUERY_PARAMETER_PRESENCE); + } } diff --git a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java index 919e1d37..1031d1cc 100644 --- a/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/ConnectionsEntityTest.java @@ -2,6 +2,7 @@ import com.auth0.client.mgmt.filter.ConnectionFilter; import com.auth0.json.mgmt.Connection; +import com.auth0.json.mgmt.ConnectionsPage; import com.auth0.net.Request; import okhttp3.mockwebserver.RecordedRequest; import org.junit.Test; @@ -91,6 +92,86 @@ public void shouldListConnectionsWithFields() throws Exception { assertThat(response, hasSize(2)); } + @Test + public void shouldListConnectionsWithoutFilter() throws Exception { + Request request = api.connections().listAll(null); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTIONS_LIST, 200); + ConnectionsPage response = request.execute(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + + assertThat(response, is(notNullValue())); + assertThat(response.getItems(), hasSize(2)); + } + + @Test + public void shouldNotListConnectionsWithTotals() throws Exception { + ConnectionFilter filter = new ConnectionFilter().withTotals(true); + Request> request = api.connections().list(filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTIONS_LIST, 200); + List response = request.execute(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, not(hasQueryParameter("include_totals"))); + + assertThat(response, is(notNullValue())); + assertThat(response, hasSize(2)); + } + + @Test + public void shouldListConnectionsWithPage() throws Exception { + ConnectionFilter filter = new ConnectionFilter().withPage(23, 5); + Request request = api.connections().listAll(filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTIONS_LIST, 200); + ConnectionsPage response = request.execute(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("page", "23")); + assertThat(recordedRequest, hasQueryParameter("per_page", "5")); + + assertThat(response, is(notNullValue())); + assertThat(response.getItems(), hasSize(2)); + } + + @Test + public void shouldListConnectionsWithTotals() throws Exception { + ConnectionFilter filter = new ConnectionFilter().withTotals(true); + Request request = api.connections().listAll(filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_CONNECTIONS_PAGED_LIST, 200); + ConnectionsPage response = request.execute(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, hasQueryParameter("include_totals", "true")); + + 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 shouldReturnEmptyConnections() throws Exception { Request> request = api.connections().list(null); diff --git a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java index 2a117b95..018e1120 100644 --- a/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java +++ b/src/test/java/com/auth0/client/mgmt/ManagementAPITest.java @@ -145,6 +145,11 @@ public void shouldDisableLoggingInterceptor() throws Exception { //Entities + @Test + public void shouldGetBlacklists() throws Exception { + assertThat(api.blacklists(), notNullValue()); + } + @Test public void shouldGetClientGrants() throws Exception { assertThat(api.clientGrants(), notNullValue()); @@ -166,38 +171,43 @@ public void shouldGetDeviceCredentials() throws Exception { } @Test - public void shouldGetLogEvents() throws Exception { - assertThat(api.logEvents(), notNullValue()); + public void shouldGetEmailProvider() throws Exception { + assertThat(api.emailProvider(), notNullValue()); } @Test - public void shouldGetRules() throws Exception { - assertThat(api.rules(), notNullValue()); + public void shouldGetEmailTemplates() throws Exception { + assertThat(api.emailTemplates(), notNullValue()); } @Test - public void shouldGetUserBlocks() throws Exception { - assertThat(api.userBlocks(), notNullValue()); + public void shouldGetGrants() throws Exception { + assertThat(api.grants(), notNullValue()); } @Test - public void shouldGetUsers() throws Exception { - assertThat(api.users(), notNullValue()); + public void shouldGetGuardian() throws Exception { + assertThat(api.guardian(), notNullValue()); } @Test - public void shouldGetBlacklists() throws Exception { - assertThat(api.blacklists(), notNullValue()); + public void shouldGetJobs() throws Exception { + assertThat(api.jobs(), notNullValue()); } @Test - public void shouldGetEmailProvider() throws Exception { - assertThat(api.emailProvider(), notNullValue()); + public void shouldGetLogEvents() throws Exception { + assertThat(api.logEvents(), notNullValue()); } @Test - public void shouldGetGuardian() throws Exception { - assertThat(api.guardian(), notNullValue()); + public void shouldGetResourceServers() throws Exception { + assertThat(api.resourceServers(), notNullValue()); + } + + @Test + public void shouldGetRules() throws Exception { + assertThat(api.rules(), notNullValue()); } @Test @@ -214,4 +224,15 @@ public void shouldGetTenants() throws Exception { public void shouldGetTickets() throws Exception { assertThat(api.tickets(), notNullValue()); } + + @Test + public void shouldGetUserBlocks() throws Exception { + assertThat(api.userBlocks(), notNullValue()); + } + + @Test + public void shouldGetUsers() throws Exception { + assertThat(api.users(), notNullValue()); + } + } \ No newline at end of file diff --git a/src/test/java/com/auth0/client/mgmt/RulesEntityTest.java b/src/test/java/com/auth0/client/mgmt/RulesEntityTest.java index 3ac2bbed..1813e5e9 100644 --- a/src/test/java/com/auth0/client/mgmt/RulesEntityTest.java +++ b/src/test/java/com/auth0/client/mgmt/RulesEntityTest.java @@ -91,7 +91,26 @@ public void shouldListRulesWithFields() throws Exception { } @Test - public void shouldListClientsWithPage() throws Exception { + public void shouldNotListRulesWithTotals() throws Exception { + RulesFilter filter = new RulesFilter().withTotals(true); + Request> request = api.rules().list(filter); + assertThat(request, is(notNullValue())); + + server.jsonResponse(MGMT_RULES_LIST, 200); + List response = request.execute(); + RecordedRequest recordedRequest = server.takeRequest(); + + assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules")); + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); + assertThat(recordedRequest, not(hasQueryParameter("include_totals"))); + + assertThat(response, is(notNullValue())); + assertThat(response, hasSize(2)); + } + + @Test + public void shouldListRulesWithPage() throws Exception { RulesFilter filter = new RulesFilter().withPage(23, 5); Request request = api.rules().listAll(filter); assertThat(request, is(notNullValue())); @@ -111,7 +130,7 @@ public void shouldListClientsWithPage() throws Exception { } @Test - public void shouldListClientsWithTotals() throws Exception { + public void shouldListRulesWithTotals() throws Exception { RulesFilter filter = new RulesFilter().withTotals(true); Request request = api.rules().listAll(filter); assertThat(request, is(notNullValue())); diff --git a/src/test/java/com/auth0/client/mgmt/filter/ConnectionFilterTest.java b/src/test/java/com/auth0/client/mgmt/filter/ConnectionFilterTest.java index c5ed107c..8338eae1 100644 --- a/src/test/java/com/auth0/client/mgmt/filter/ConnectionFilterTest.java +++ b/src/test/java/com/auth0/client/mgmt/filter/ConnectionFilterTest.java @@ -55,6 +55,15 @@ public void shouldFilterWithFields() throws Exception { assertThat(filter.getAsMap(), Matchers.hasEntry("include_fields", (Object) true)); } + @Test + public void shouldIncludeTotals() throws Exception { + ConnectionFilter instance = filter.withTotals(true); + + assertThat(filter, is(instance)); + assertThat(filter.getAsMap(), is(notNullValue())); + assertThat(filter.getAsMap(), Matchers.hasEntry("include_totals", (Object) true)); + } + @Test public void shouldFilterWithoutFields() throws Exception { ConnectionFilter instance = filter.withFields("a,b,c", false); diff --git a/src/test/resources/mgmt/connections_paged_list.json b/src/test/resources/mgmt/connections_paged_list.json new file mode 100644 index 00000000..1c2b8cd3 --- /dev/null +++ b/src/test/resources/mgmt/connections_paged_list.json @@ -0,0 +1,28 @@ +{ + "start": 0, + "length": 14, + "total": 14, + "limit": 50, + "connections": [ + { + "name": "My connection1", + "options": {}, + "id": "con_0000000000000001", + "strategy": "auth0", + "enabled_clients": [ + "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", + "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" + ] + }, + { + "name": "My connection2", + "options": {}, + "id": "con_0000000000000002", + "strategy": "auth0", + "enabled_clients": [ + "avUAvH1pgnZGgAGlv8guZLPoaOnjVJsM", + "ScKKdrpyUwfkhOQP6KXItH32INgZf7Rb" + ] + } + ] +}