Search in sources :

Example 1 with PermissionsPage

use of com.auth0.json.mgmt.PermissionsPage in project auth0-java by auth0.

the class RolesEntityTest method shouldListPermissionsWithPage.

@Test
public void shouldListPermissionsWithPage() throws Exception {
    PageFilter filter = new PageFilter().withPage(23, 5);
    Request<PermissionsPage> request = api.roles().listPermissions("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_ROLE_PERMISSIONS_PAGED_LIST, 200);
    PermissionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/roles/1/permissions"));
    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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PermissionsPage(com.auth0.json.mgmt.PermissionsPage) PageFilter(com.auth0.client.mgmt.filter.PageFilter) Test(org.junit.Test)

Example 2 with PermissionsPage

use of com.auth0.json.mgmt.PermissionsPage in project auth0-java by auth0.

the class UsersEntityTest method shouldListPermissionsWithPage.

@Test
public void shouldListPermissionsWithPage() throws Exception {
    PageFilter filter = new PageFilter().withPage(23, 5);
    Request<PermissionsPage> request = api.users().listPermissions("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USER_PERMISSIONS_PAGED_LIST, 200);
    PermissionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users/1/permissions"));
    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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PermissionsPage(com.auth0.json.mgmt.PermissionsPage) PageFilter(com.auth0.client.mgmt.filter.PageFilter) Test(org.junit.Test)

Example 3 with PermissionsPage

use of com.auth0.json.mgmt.PermissionsPage in project auth0-java by auth0.

the class UsersEntityTest method shouldListPermissionsWithTotal.

@Test
public void shouldListPermissionsWithTotal() throws Exception {
    PageFilter filter = new PageFilter().withTotals(true);
    Request<PermissionsPage> request = api.users().listPermissions("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USER_PERMISSIONS_PAGED_LIST, 200);
    PermissionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users/1/permissions"));
    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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PermissionsPage(com.auth0.json.mgmt.PermissionsPage) PageFilter(com.auth0.client.mgmt.filter.PageFilter) Test(org.junit.Test)

Example 4 with PermissionsPage

use of com.auth0.json.mgmt.PermissionsPage in project auth0-java by auth0.

the class PermissionsPageTest method shouldDeserializeWithoutTotals.

@Test
public void shouldDeserializeWithoutTotals() throws Exception {
    PermissionsPage page = fromJSON(jsonWithoutTotals, PermissionsPage.class);
    assertThat(page, is(notNullValue()));
    assertThat(page.getStart(), is(nullValue()));
    assertThat(page.getLength(), is(nullValue()));
    assertThat(page.getTotal(), is(nullValue()));
    assertThat(page.getLimit(), is(nullValue()));
    assertThat(page.getItems(), is(notNullValue()));
    assertThat(page.getItems().size(), is(1));
}
Also used : PermissionsPage(com.auth0.json.mgmt.PermissionsPage) JsonTest(com.auth0.json.JsonTest) Test(org.junit.Test)

Example 5 with PermissionsPage

use of com.auth0.json.mgmt.PermissionsPage in project auth0-java by auth0.

the class RolesEntityTest method shouldListPermissionsWithoutFilter.

@Test
public void shouldListPermissionsWithoutFilter() throws Exception {
    Request<PermissionsPage> request = api.roles().listPermissions("1", null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_ROLE_PERMISSIONS_PAGED_LIST, 200);
    PermissionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/roles/1/permissions"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PermissionsPage(com.auth0.json.mgmt.PermissionsPage) Test(org.junit.Test)

Aggregations

PermissionsPage (com.auth0.json.mgmt.PermissionsPage)8 Test (org.junit.Test)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 PageFilter (com.auth0.client.mgmt.filter.PageFilter)4 JsonTest (com.auth0.json.JsonTest)2