use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.
the class BaseClientTest method testMakeRequestWithBody.
@Test
public void testMakeRequestWithBody() throws IOException {
final Call mCall = mock(Call.class);
AtomicBoolean postCalled = new AtomicBoolean(false);
AtomicBoolean putCalled = new AtomicBoolean(false);
Answer answer = (i) -> {
Request request = i.getArgument(0);
HttpUrl url = request.url();
switch(request.method()) {
case "POST":
assertEquals("/resources", url.url().getPath());
postCalled.set(true);
break;
case "PUT":
assertEquals("/resources/someId", url.url().getPath());
putCalled.set(true);
break;
default:
// Any other request method is a failure
Assert.fail();
}
return mCall;
};
when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", getResponseJson())).thenReturn(MockClient.buildResponse(200, "OK", getResponseJson()));
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
final MyRequest newResource = new MyRequest();
newResource.setMyString("aaron");
final MyResource resource = client.createResource(newResource);
assertEquals(MyResource.class, resource.getClass());
assertEquals("aaron", resource.getMyString());
assertTrue(postCalled.get());
final MyResource anotherResource = client.updateResource("someId", newResource);
assertEquals(MyResource.class, anotherResource.getClass());
assertEquals("aaron", anotherResource.getMyString());
assertTrue(putCalled.get());
}
use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.
the class JsonSerializerTest method testDeserializeUnknownEnum.
@Test
public void testDeserializeUnknownEnum() {
final JsonSerializer jsonSerializer = new JsonSerializer();
final MyResource mockResource = jsonSerializer.deserialize("{\"my_constant\":\"not-defined\"}", MyResource.class);
assertEquals(FixtureConstants.ConstantType.UNDEFINED, mockResource.getMyConstant());
}
use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.
the class BaseClientTest method testMakeRequestWithQueryParams.
@Test
public void testMakeRequestWithQueryParams() throws IOException {
DateTime dateTime = new DateTime();
final Call mCall = mock(Call.class);
Answer answer = (i) -> {
Request request = i.getArgument(0);
HttpUrl url = request.url();
assertEquals("Aaron", url.queryParameter("my_string"));
assertEquals(dateTime.toString(), url.queryParameter("my_date_time"));
assertEquals("1", url.queryParameter("my_integer"));
assertEquals("2.3", url.queryParameter("my_float"));
assertEquals("4.5", url.queryParameter("my_double"));
assertEquals("6", url.queryParameter("my_long"));
assertEquals("twenty-three", url.queryParameter("my_enum"));
assertEquals(null, url.queryParameter("my_random"));
assertEquals("[]", url.queryParameter("unsupported"));
return mCall;
};
when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", getResponseListJson()));
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
final MockQueryParams qp = new MockQueryParams();
qp.setMyString("Aaron");
qp.setMyDateTime(dateTime);
qp.setMyInteger(1);
qp.setMyFloat(2.3f);
qp.setMyDouble(4.5);
qp.setMyLong(6L);
qp.setMyEnum(FixtureConstants.ConstantType.TWENTY_THREE);
qp.setMyRandom(null);
qp.setUnsupported(new ArrayList<>());
final Pager<MyResource> pager = client.listResources(qp);
pager.getNextPage();
}
use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.
the class JsonSerializerTest method testDeserialize.
@Test
public void testDeserialize() {
final JsonSerializer jsonSerializer = new JsonSerializer();
final MyResource mockResource = jsonSerializer.deserialize(getMockResourceJson(), MyResource.class);
assertEquals("My String", mockResource.getMyString());
assertEquals(FixtureConstants.ConstantType.TWENTY_THREE, mockResource.getMyConstant());
}
use of com.recurly.v3.fixtures.MyResource in project recurly-client-java by recurly.
the class PagerTest method testCount.
@Test
public void testCount() throws IOException {
final Call mCall = mock(Call.class);
Headers headers = new Headers.Builder().set("Recurly-Total-Records", "1337").build();
Answer answer = (i) -> {
Request request = i.getArgument(0);
assertEquals("HEAD", request.method());
return mCall;
};
when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", getResourceFirstItemJson(), headers));
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
Pager<MyResource> pager = client.listResources(null);
int count = pager.getCount();
assertEquals(1337, count);
}
Aggregations