Search in sources :

Example 41 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class OrganizationEntityTest method shouldGetOrgRolesWithPaging.

@Test
public void shouldGetOrgRolesWithPaging() throws Exception {
    Request<RolesPage> request = api.organizations().getRoles("org_abc", "user_123", new PageFilter().withPage(0, 20));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(ORGANIZATION_MEMBER_ROLES_LIST, 200);
    RolesPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/organizations/org_abc/members/user_123/roles"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("page", "0"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "20"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(1));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PageFilter(com.auth0.client.mgmt.filter.PageFilter) RolesPage(com.auth0.json.mgmt.RolesPage) Test(org.junit.Test)

Example 42 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class OrganizationEntityTest method shouldGetOrgRolesWithIncludeTotals.

@Test
public void shouldGetOrgRolesWithIncludeTotals() throws Exception {
    Request<RolesPage> request = api.organizations().getRoles("org_abc", "user_123", new PageFilter().withTotals(true));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(ORGANIZATION_MEMBER_ROLES_PAGED_LIST, 200);
    RolesPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/organizations/org_abc/members/user_123/roles"));
    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(1));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PageFilter(com.auth0.client.mgmt.filter.PageFilter) RolesPage(com.auth0.json.mgmt.RolesPage) Test(org.junit.Test)

Example 43 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class OrganizationEntityTest method shouldGetInvitationWithFilter.

@Test
public void shouldGetInvitationWithFilter() throws Exception {
    Request<Invitation> request = api.organizations().getInvitation("org_123", "invitation_id", new FieldsFilter().withFields("id,invitation_url,invitee", true));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(INVITATION, 200);
    Invitation response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/organizations/org_123/invitations/invitation_id"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("fields", "id,invitation_url,invitee"));
    assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) FieldsFilter(com.auth0.client.mgmt.filter.FieldsFilter) Test(org.junit.Test)

Example 44 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class OrganizationEntityTest method shouldGetOrgRolesWithoutPaging.

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

Example 45 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class ActionsEntityTest method shouldGetActionVersionsWithFilter.

@Test
public void shouldGetActionVersionsWithFilter() throws Exception {
    PageFilter filter = new PageFilter().withPage(1, 10);
    Request<VersionsPage> request = api.actions().getVersions("action-id", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MockServer.ACTION_VERSIONS_LIST, 200);
    VersionsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/actions/actions/action-id/versions"));
    assertThat(recordedRequest, hasQueryParameter("page", "1"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "10"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) PageFilter(com.auth0.client.mgmt.filter.PageFilter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)193 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)185 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)77 IOException (java.io.IOException)76 List (java.util.List)63 Algorithm (com.auth0.jwt.algorithms.Algorithm)35 VoidRequest (com.auth0.net.VoidRequest)33 Auth0Exception (com.auth0.exception.Auth0Exception)30 APIException (com.auth0.exception.APIException)27 RateLimitException (com.auth0.exception.RateLimitException)25 HashMap (java.util.HashMap)24 PageFilter (com.auth0.client.mgmt.filter.PageFilter)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 ServletException (javax.servlet.ServletException)23 TokenHolder (com.auth0.json.auth.TokenHolder)22 JWTVerifier (com.auth0.jwt.JWTVerifier)22 ArrayList (java.util.ArrayList)22 Test (org.junit.jupiter.api.Test)22 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)20 Date (java.util.Date)20