Search in sources :

Example 56 with Request

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

the class ClientsEntityTest method shouldUpdateClient.

@Test
public void shouldUpdateClient() throws Exception {
    Request<Client> request = api.clients().update("1", new Client("My Application"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT, 200);
    Client response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/clients/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(1));
    assertThat(body, hasEntry("name", "My Application"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Client(com.auth0.json.mgmt.client.Client) Test(org.junit.Test)

Example 57 with Request

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

the class ConnectionsEntityTest method shouldListConnectionsWithFields.

@Test
public void shouldListConnectionsWithFields() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withFields("some,random,fields", true);
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> 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("fields", "some,random,fields"));
    assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 58 with Request

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

the class ConnectionsEntityTest method shouldListConnectionsWithName.

@Test
public void shouldListConnectionsWithName() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withName("my-connection");
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> 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("name", "my-connection"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 59 with Request

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

the class ConnectionsEntityTest method shouldListConnectionsWithPage.

@Test
public void shouldListConnectionsWithPage() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withPage(23, 5);
    Request<ConnectionsPage> 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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) ConnectionsPage(com.auth0.json.mgmt.ConnectionsPage) Test(org.junit.Test)

Example 60 with Request

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

the class ConnectionsEntityTest method shouldNotListConnectionsWithTotals.

@Test
public void shouldNotListConnectionsWithTotals() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withTotals(true);
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> 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));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) 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