Search in sources :

Example 1 with ClientGrant

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

the class ClientGrantsEntityTest method shouldCreateClientGrant.

@Test
public void shouldCreateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().create("clientId", "audience", new String[] { "openid" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/client-grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(3));
    assertThat(body, hasEntry("client_id", "clientId"));
    assertThat(body, hasEntry("audience", "audience"));
    assertThat(body, hasKey("scope"));
    assertThat((Iterable<?>) body.get("scope"), contains("openid"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 2 with ClientGrant

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

the class ClientGrantsEntityTest method shouldUpdateClientGrant.

@Test
public void shouldUpdateClientGrant() throws Exception {
    Request<ClientGrant> request = api.clientGrants().update("1", new String[] { "openid", "profile" });
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANT, 200);
    ClientGrant response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/client-grants/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((ArrayList<?>) body.get("scope"), contains("openid", "profile"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Example 3 with ClientGrant

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

the class ClientGrantsEntityTest method shouldListClientGrants.

@Test
public void shouldListClientGrants() throws Exception {
    @SuppressWarnings("deprecation") Request<List<ClientGrant>> request = api.clientGrants().list();
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CLIENT_GRANTS_LIST, 200);
    List<ClientGrant> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/client-grants"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ArrayList(java.util.ArrayList) List(java.util.List) ClientGrant(com.auth0.json.mgmt.ClientGrant) Test(org.junit.Test)

Aggregations

ClientGrant (com.auth0.json.mgmt.ClientGrant)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1