Search in sources :

Example 86 with Client

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

the class MultipartRequestTest method shouldParseJSONErrorResponseWithMessage.

@Test
public void shouldParseJSONErrorResponseWithMessage() throws Exception {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    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));
}
Also used : APIException(com.auth0.exception.APIException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 87 with Client

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

the class MultipartRequestTest method shouldThrowOnBodyCreationFailure.

@Test
public void shouldThrowOnBodyCreationFailure() {
    Exception exception = null;
    try {
        MultipartRequest<Void> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", voidType);
        request.execute();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(Auth0Exception.class)));
    assertThat(exception.getMessage(), is("Couldn't create the request body."));
    assertThat(exception.getCause(), is(instanceOf(IOException.class)));
    assertThat(exception.getCause().getMessage(), is("Cannot create multipart/form-data request body with zero parts."));
}
Also used : RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 88 with Client

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

the class MultipartRequestTest method shouldParseJSONErrorResponseWithDescriptionAndExtraProperties.

@Test
public void shouldParseJSONErrorResponseWithDescriptionAndExtraProperties() throws Exception {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.jsonResponse(AUTH_ERROR_WITH_DESCRIPTION_AND_EXTRA_PROPERTIES, 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: Multifactor authentication required"));
    APIException authException = (APIException) exception;
    assertThat(authException.getDescription(), is("Multifactor authentication required"));
    assertThat(authException.getError(), is("mfa_required"));
    assertThat(authException.getValue("mfa_token"), is("Fe26...Ha"));
    assertThat(authException.getValue("non_existing_key"), is(nullValue()));
    assertThat(authException.getStatusCode(), is(400));
}
Also used : APIException(com.auth0.exception.APIException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 89 with Client

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

the class VoidRequestTest method setUp.

@Before
public void setUp() throws Exception {
    client = new OkHttpClient();
    server = new MockServer();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) MockServer(com.auth0.client.MockServer) Before(org.junit.Before)

Example 90 with Client

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

the class BaseRequestTest method alwaysCloseResponseOnSuccessfulRequest.

@Test
public void alwaysCloseResponseOnSuccessfulRequest() {
    Exception exception = null;
    try {
        new MockBaseRequest<String>(client) {

            @Override
            protected String parseResponse(Response response) {
                return "";
            }
        }.execute();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(nullValue()));
    verify(response, times(1)).close();
}
Also used : Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)36 APIException (com.auth0.exception.APIException)27 Auth0Exception (com.auth0.exception.Auth0Exception)27 RateLimitException (com.auth0.exception.RateLimitException)27 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)26 List (java.util.List)25 Test (org.junit.Test)25 VoidRequest (com.auth0.net.VoidRequest)24 TokenHolder (com.auth0.json.auth.TokenHolder)22 JsonParseException (com.fasterxml.jackson.core.JsonParseException)19 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)19 ExpectedException (org.junit.rules.ExpectedException)19 RecordedMultipartRequest (com.auth0.net.multipart.RecordedMultipartRequest)16 Test (org.junit.jupiter.api.Test)14 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 AuthAPI (com.auth0.client.auth.AuthAPI)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 OkHttpClient (okhttp3.OkHttpClient)7