use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class BaseRequestTest method alwaysCloseResponseOnAPIException.
@Test
public void alwaysCloseResponseOnAPIException() {
Exception exception = null;
try {
new MockBaseRequest<String>(client) {
@Override
protected String parseResponse(Response response) throws Auth0Exception {
throw new APIException("APIException", 500, null);
}
}.execute();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(APIException.class)));
assertThat(exception.getMessage(), is("Request failed with status code 500: APIException"));
verify(response, times(1)).close();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CreateUserRequestTest method setUp.
@Before
public void setUp() throws Exception {
client = new OkHttpClient();
server = new MockServer();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CreateUserRequestTest method shouldCreatePOSTRequest.
@Test
public void shouldCreatePOSTRequest() throws Exception {
CreateUserRequest request = new CreateUserRequest(client, server.getBaseUrl());
assertThat(request, is(notNullValue()));
request.addParameter("non_empty", "body");
server.jsonResponse(AUTH_SIGN_UP, 200);
CreatedUser execute = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod(), is("POST"));
assertThat(execute, is(notNullValue()));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldParseJSONErrorResponseWithError.
@Test
public void shouldParseJSONErrorResponseWithError() throws Exception {
CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
server.jsonResponse(AUTH_ERROR_WITH_ERROR, 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: missing username for Username-Password-Authentication connection with requires_username enabled"));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
assertThat(authException.getError(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
assertThat(authException.getStatusCode(), is(400));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class CustomRequestTest method shouldDefaultRateLimitsHeadersWhenMissing.
@Test
public void shouldDefaultRateLimitsHeadersWhenMissing() {
CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
server.rateLimitReachedResponse(-1, -1, -1);
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(-1L));
assertThat(rateLimitException.getRemaining(), is(-1L));
assertThat(rateLimitException.getReset(), is(-1L));
}
Aggregations