use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldParseJSONErrorResponseWithDescription.
@Test
public void shouldParseJSONErrorResponseWithDescription() throws Exception {
CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
server.jsonResponse(AUTH_ERROR_WITH_DESCRIPTION, 400);
Exception exception = null;
try {
request.execute();
server.takeRequest();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(APIException.class)));
assertThat(exception.getCause(), is(nullValue()));
assertThat(exception.getMessage(), is("Request failed with status code 400: The user already exists."));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("The user already exists."));
assertThat(authException.getError(), is("user_exists"));
assertThat(authException.getStatusCode(), is(400));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldAddHeaders.
@Test
public void shouldAddHeaders() throws Exception {
CustomRequest<TokenHolder> request = new CustomRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
request.addParameter("non_empty", "body");
request.addHeader("Extra-Info", "this is a test");
request.addHeader("Authorization", "Bearer my_access_token");
server.jsonResponse(AUTH_TOKENS, 200);
request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getHeader("Extra-Info"), is("this is a test"));
assertThat(recordedRequest.getHeader("Authorization"), is("Bearer my_access_token"));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldParseRateLimitsHeaders.
@Test
public void shouldParseRateLimitsHeaders() {
CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
server.rateLimitReachedResponse(100, 10, 5);
Exception exception = null;
try {
request.execute();
server.takeRequest();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(RateLimitException.class)));
assertThat(exception.getCause(), is(nullValue()));
assertThat(exception.getMessage(), is("Request failed with status code 429: Rate limit reached"));
RateLimitException rateLimitException = (RateLimitException) exception;
assertThat(rateLimitException.getDescription(), is("Rate limit reached"));
assertThat(rateLimitException.getError(), is(nullValue()));
assertThat(rateLimitException.getValue("non_existing_key"), is(nullValue()));
assertThat(rateLimitException.getStatusCode(), is(429));
assertThat(rateLimitException.getLimit(), is(100L));
assertThat(rateLimitException.getRemaining(), is(10L));
assertThat(rateLimitException.getReset(), is(5L));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldParseJSONErrorResponseWithMessage.
@Test
public void shouldParseJSONErrorResponseWithMessage() throws Exception {
CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
server.jsonResponse(MGMT_ERROR_WITH_MESSAGE, 400);
Exception exception = null;
try {
request.execute();
server.takeRequest();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(APIException.class)));
assertThat(exception.getCause(), is(nullValue()));
assertThat(exception.getMessage(), is("Request failed with status code 400: Query validation error: 'String 'invalid_field' does not match pattern. Must be a comma separated list of the following values: allowed_logout_urls,change_password."));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("Query validation error: 'String 'invalid_field' does not match pattern. Must be a comma separated list of the following values: allowed_logout_urls,change_password."));
assertThat(authException.getError(), is("invalid_query_string"));
assertThat(authException.getStatusCode(), is(400));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldCreateGETRequest.
@Test
public void shouldCreateGETRequest() throws Exception {
CustomRequest<TokenHolder> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", tokenHolderType);
assertThat(request, is(notNullValue()));
server.jsonResponse(AUTH_TOKENS, 200);
TokenHolder execute = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod(), is("GET"));
assertThat(execute, is(notNullValue()));
}
Aggregations