Search in sources :

Example 11 with MyResource

use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.

the class PagerTest method testFirst.

@Test
public void testFirst() throws IOException {
    final Call mCall = mock(Call.class);
    Answer answer = (i) -> {
        Request request = i.getArgument(0);
        HttpUrl url = request.url();
        assertEquals("1", url.queryParameter("limit"));
        return mCall;
    };
    when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", getResourceFirstItemJson()));
    OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
    final MockClient client = new MockClient("apiKey", mockOkHttpClient);
    Pager<MyResource> pager = client.listResources(null);
    MyResource resource = pager.getFirst();
    assertEquals("Resource First Item", resource.getMyString());
}
Also used : Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) MockClient(com.recurly.v3.fixtures.MockClient) Request(okhttp3.Request) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) okhttp3(okhttp3) Assertions(org.junit.jupiter.api.Assertions) MyResource(com.recurly.v3.fixtures.MyResource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) Answer(org.mockito.stubbing.Answer) Request(okhttp3.Request) MockClient(com.recurly.v3.fixtures.MockClient) MyResource(com.recurly.v3.fixtures.MyResource) Test(org.junit.jupiter.api.Test)

Example 12 with MyResource

use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.

the class MockClient method listResources.

public Pager<MyResource> listResources(QueryParams queryParams) {
    final String url = "/resources";
    final HashMap<String, String> urlParams = new HashMap<String, String>();
    if (queryParams == null)
        queryParams = new QueryParams();
    final HashMap<String, Object> paramsMap = queryParams.getParams();
    final String path = this.interpolatePath(url, urlParams);
    Type parameterizedType = TypeToken.getParameterized(Pager.class, MyResource.class).getType();
    return new Pager<>(path, paramsMap, this, parameterizedType);
}
Also used : Type(java.lang.reflect.Type) MediaType(okhttp3.MediaType) HashMap(java.util.HashMap) Pager(com.recurly.v3.Pager) QueryParams(com.recurly.v3.QueryParams)

Aggregations

MyResource (com.recurly.v3.fixtures.MyResource)11 Test (org.junit.jupiter.api.Test)11 MockClient (com.recurly.v3.fixtures.MockClient)9 IOException (java.io.IOException)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Request (okhttp3.Request)9 Answer (org.mockito.stubbing.Answer)9 NoSuchElementException (java.util.NoSuchElementException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 okhttp3 (okhttp3)6 Assertions (org.junit.jupiter.api.Assertions)6 Mockito (org.mockito.Mockito)6 HashMap (java.util.HashMap)4 MediaType (okhttp3.MediaType)4 ApiException (com.recurly.v3.ApiException)3 ExceptionFactory (com.recurly.v3.exception.ExceptionFactory)3 InternalServerException (com.recurly.v3.exception.InternalServerException)3 InvalidApiKeyException (com.recurly.v3.exception.InvalidApiKeyException)3 NotFoundException (com.recurly.v3.exception.NotFoundException)3 TransactionException (com.recurly.v3.exception.TransactionException)3