Search in sources :

Example 76 with Client

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

the class EmptyBodyRequestTest method shouldNotAddParameters.

@Test
public void shouldNotAddParameters() throws Exception {
    EmptyBodyRequest<TokenHolder> request = new EmptyBodyRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
    Map mapValue = mock(Map.class);
    request.addParameter("key", "value");
    request.addParameter("map", mapValue);
    server.jsonResponse(AUTH_TOKENS, 200);
    request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getMethod(), is("POST"));
    assertThat(recordedRequest.getBodySize(), is(0L));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TokenHolder(com.auth0.json.auth.TokenHolder) Map(java.util.Map) Test(org.junit.Test)

Example 77 with Client

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

the class EmptyBodyRequestTest method shouldCreateEmptyRequestBody.

@Test
public void shouldCreateEmptyRequestBody() throws Exception {
    EmptyBodyRequest<TokenHolder> request = new EmptyBodyRequest<>(client, server.getBaseUrl(), "POST", tokenHolderType);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(AUTH_TOKENS, 200);
    request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest.getMethod(), is("POST"));
    assertThat(recordedRequest.getBodySize(), is(0L));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TokenHolder(com.auth0.json.auth.TokenHolder) Test(org.junit.Test)

Example 78 with Client

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

the class MultipartRequestTest method shouldParsePlainTextErrorResponse.

@Test
public void shouldParsePlainTextErrorResponse() throws Exception {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.textResponse(AUTH_ERROR_PLAINTEXT, 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(instanceOf(JsonParseException.class)));
    assertThat(exception.getMessage(), is("Request failed with status code 400: A plain-text error response"));
    APIException authException = (APIException) exception;
    assertThat(authException.getDescription(), is("A plain-text error response"));
    assertThat(authException.getError(), is(nullValue()));
    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 79 with Client

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

the class MultipartRequestTest method shouldParseRateLimitsHeaders.

@Test
public void shouldParseRateLimitsHeaders() {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    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));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) 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 80 with Client

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

the class MultipartRequestTest method shouldDefaultRateLimitsHeadersWhenMissing.

@Test
public void shouldDefaultRateLimitsHeadersWhenMissing() {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    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));
}
Also used : RateLimitException(com.auth0.exception.RateLimitException) 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)

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