Search in sources :

Example 66 with Request

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

the class EmailProviderEntityTest method shouldGetEmailProvider.

@Test
public void shouldGetEmailProvider() throws Exception {
    Request<EmailProvider> request = api.emailProvider().get(null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_EMAIL_PROVIDER, 200);
    EmailProvider response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/emails/provider"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) EmailProvider(com.auth0.json.mgmt.emailproviders.EmailProvider) Test(org.junit.Test)

Example 67 with Request

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

the class EmailTemplatesEntityTest method shouldGetEmailTemplate.

@Test
public void shouldGetEmailTemplate() throws Exception {
    Request<EmailTemplate> request = api.emailTemplates().get("welcome_email");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_EMAIL_TEMPLATE, 200);
    EmailTemplate response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/email-templates/welcome_email"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) EmailTemplate(com.auth0.json.mgmt.EmailTemplate) Test(org.junit.Test)

Example 68 with Request

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

the class GrantsEntityTest method shouldListGrantsWithPage.

@Test
public void shouldListGrantsWithPage() throws Exception {
    GrantsFilter filter = new GrantsFilter().withPage(23, 5);
    Request<GrantsPage> request = api.grants().list("userId", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_GRANTS_LIST, 200);
    GrantsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("user_id", "userId"));
    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) GrantsFilter(com.auth0.client.mgmt.filter.GrantsFilter) GrantsPage(com.auth0.json.mgmt.GrantsPage) Test(org.junit.Test)

Example 69 with Request

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

the class GrantsEntityTest method shouldListGrants.

@Test
public void shouldListGrants() throws Exception {
    @SuppressWarnings("deprecation") Request<List<Grant>> request = api.grants().list("userId");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_GRANTS_LIST, 200);
    List<Grant> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/grants"));
    assertThat(recordedRequest, hasQueryParameter("user_id", "userId"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
    for (Grant grant : response) {
        assertThat(grant.getAudience(), notNullValue());
        assertThat(grant.getClientId(), notNullValue());
        assertThat(grant.getId(), notNullValue());
        assertThat(grant.getScope(), notNullValue());
        assertThat(grant.getScope(), hasSize(2));
        assertThat(grant.getUserId(), equalTo("userId"));
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Grant(com.auth0.json.mgmt.Grant) List(java.util.List) Test(org.junit.Test)

Example 70 with Request

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

the class GrantsEntityTest method shouldListGrantsWithTotals.

@Test
public void shouldListGrantsWithTotals() throws Exception {
    GrantsFilter filter = new GrantsFilter().withTotals(true);
    Request<GrantsPage> request = api.grants().list("userId", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_GRANTS_PAGED_LIST, 200);
    GrantsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("user_id", "userId"));
    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) GrantsFilter(com.auth0.client.mgmt.filter.GrantsFilter) GrantsPage(com.auth0.json.mgmt.GrantsPage) 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