Search in sources :

Example 1 with TransactionException

use of com.recurly.v3.exception.TransactionException in project recurly-client-java by recurly.

the class BaseClientTest method testTransactionError.

@Test
public void testTransactionError() throws IOException {
    final Call mCall = mock(Call.class);
    Answer answer = (i) -> {
        return mCall;
    };
    when(mCall.execute()).thenReturn(MockClient.buildResponse(422, "Unprocessable Entity", getErrorResponse("transaction")));
    OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
    final MockClient client = new MockClient("apiKey", mockOkHttpClient);
    TransactionException t = assertThrows(TransactionException.class, () -> {
        client.removeResource("code-aaron");
    });
    assertEquals("mbca9aaao6xr", t.getError().getTransactionError().getTransactionId());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) NotFoundException(com.recurly.v3.exception.NotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FixtureConstants(com.recurly.v3.fixtures.FixtureConstants) HashMap(java.util.HashMap) Headers(okhttp3.Headers) MockQueryParams(com.recurly.v3.fixtures.MockQueryParams) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) MockClient(com.recurly.v3.fixtures.MockClient) ApiException(com.recurly.v3.ApiException) Map(java.util.Map) Response(okhttp3.Response) Call(okhttp3.Call) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MediaType(okhttp3.MediaType) Request(okhttp3.Request) TransactionException(com.recurly.v3.exception.TransactionException) InvalidApiKeyException(com.recurly.v3.exception.InvalidApiKeyException) MyResource(com.recurly.v3.fixtures.MyResource) DateTime(org.joda.time.DateTime) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) OkHttpClient(okhttp3.OkHttpClient) ValidationException(com.recurly.v3.exception.ValidationException) MyRequest(com.recurly.v3.fixtures.MyRequest) HttpUrl(okhttp3.HttpUrl) Assert(org.junit.Assert) InternalServerException(com.recurly.v3.exception.InternalServerException) Collections(java.util.Collections) ExceptionFactory(com.recurly.v3.exception.ExceptionFactory) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) Call(okhttp3.Call) Answer(org.mockito.stubbing.Answer) OkHttpClient(okhttp3.OkHttpClient) TransactionException(com.recurly.v3.exception.TransactionException) MockClient(com.recurly.v3.fixtures.MockClient) Test(org.junit.jupiter.api.Test)

Aggregations

ApiException (com.recurly.v3.ApiException)1 ExceptionFactory (com.recurly.v3.exception.ExceptionFactory)1 InternalServerException (com.recurly.v3.exception.InternalServerException)1 InvalidApiKeyException (com.recurly.v3.exception.InvalidApiKeyException)1 NotFoundException (com.recurly.v3.exception.NotFoundException)1 TransactionException (com.recurly.v3.exception.TransactionException)1 ValidationException (com.recurly.v3.exception.ValidationException)1 FixtureConstants (com.recurly.v3.fixtures.FixtureConstants)1 MockClient (com.recurly.v3.fixtures.MockClient)1 MockQueryParams (com.recurly.v3.fixtures.MockQueryParams)1 MyRequest (com.recurly.v3.fixtures.MyRequest)1 MyResource (com.recurly.v3.fixtures.MyResource)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1