use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldThrowOnParseInvalidSuccessfulResponse.
@Test
public void shouldThrowOnParseInvalidSuccessfulResponse() throws Exception {
MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
request.addPart("non_empty", "body");
server.jsonResponse(AUTH_TOKENS, 200);
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(instanceOf(JsonMappingException.class)));
assertThat(exception.getMessage(), is("Request failed with status code 200: Failed to parse the response body."));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("Failed to parse the response body."));
assertThat(authException.getError(), is(nullValue()));
assertThat(authException.getStatusCode(), is(200));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldThrowOnExecuteFailure.
@Test
public void shouldThrowOnExecuteFailure() throws Exception {
exception.expect(Auth0Exception.class);
exception.expectCause(Matchers.<Throwable>instanceOf(IOException.class));
exception.expectMessage("Failed to execute request");
OkHttpClient client = mock(OkHttpClient.class);
Call call = mock(Call.class);
when(client.newCall(any(okhttp3.Request.class))).thenReturn(call);
when(call.execute()).thenThrow(IOException.class);
MultipartRequest<Void> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", voidType);
request.addPart("non_empty", "body");
request.execute();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldAddHeaders.
@Test
public void shouldAddHeaders() throws Exception {
MultipartRequest<TokenHolder> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
request.addPart("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 MultipartRequestTest method shouldParseSuccessfulResponse.
@Test
public void shouldParseSuccessfulResponse() throws Exception {
MultipartRequest<TokenHolder> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
request.addPart("non_empty", "body");
server.jsonResponse(AUTH_TOKENS, 200);
TokenHolder response = request.execute();
server.takeRequest();
assertThat(response, is(notNullValue()));
assertThat(response.getAccessToken(), not(emptyOrNullString()));
assertThat(response.getIdToken(), not(emptyOrNullString()));
assertThat(response.getRefreshToken(), not(emptyOrNullString()));
assertThat(response.getTokenType(), not(emptyOrNullString()));
assertThat(response.getExpiresIn(), is(notNullValue()));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldParseJSONErrorResponseWithError.
@Test
public void shouldParseJSONErrorResponseWithError() throws Exception {
MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
request.addPart("non_empty", "body");
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));
}
Aggregations