use of com.auth0.json.mgmt.client.Client 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()));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class UsersEntity method delete.
/**
* Delete an existing User.
* A token with scope delete:users is needed.
* See https://auth0.com/docs/api/management/v2#!/Users/delete_users_by_id
*
* @param userId the user id
* @return a Request to execute.
*/
public Request<Void> delete(String userId) {
Asserts.assertNotNull(userId, "user id");
String url = baseUrl.newBuilder().addPathSegments("api/v2/users").addPathSegment(userId).build().toString();
VoidRequest request = new VoidRequest(client, url, "DELETE");
request.addHeader("Authorization", "Bearer " + apiToken);
return request;
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class BaseRequestTest method alwaysCloseResponseOnAuth0Exception.
@Test
public void alwaysCloseResponseOnAuth0Exception() {
Exception exception = null;
try {
new MockBaseRequest<String>(client) {
@Override
protected String parseResponse(Response response) throws Auth0Exception {
throw new Auth0Exception("Auth0Exception");
}
}.execute();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(Auth0Exception.class)));
assertThat(exception.getMessage(), is("Auth0Exception"));
verify(response, times(1)).close();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class BaseRequestTest method alwaysCloseResponseOnRateLimitException.
@Test
public void alwaysCloseResponseOnRateLimitException() {
Exception exception = null;
try {
new MockBaseRequest<String>(client) {
@Override
protected String parseResponse(Response response) throws Auth0Exception {
throw new RateLimitException(-1, -1, -1);
}
}.execute();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(RateLimitException.class)));
assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
verify(response, times(1)).close();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class BaseRequestTest method asyncCompletesWithExceptionWhenResponseParsingFails.
@Test
public void asyncCompletesWithExceptionWhenResponseParsingFails() throws Exception {
doReturn(call).when(client).newCall(any());
doAnswer(invocation -> {
((Callback) invocation.getArgument(0)).onResponse(call, response);
return null;
}).when(call).enqueue(any());
CompletableFuture<?> request = new MockBaseRequest<String>(client) {
@Override
protected String parseResponse(Response response) throws Auth0Exception {
throw new Auth0Exception("Response Parsing Error");
}
}.executeAsync();
Exception exception = null;
Object result = null;
try {
result = request.get();
} catch (Exception e) {
exception = e;
}
assertThat(result, is(nullValue()));
assertThat(exception, is(notNullValue()));
assertThat(exception.getCause(), is(instanceOf(Auth0Exception.class)));
assertThat(exception.getCause().getMessage(), is("Response Parsing Error"));
}
Aggregations