use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testMakeRequestWithoutResource.
@Test
public void testMakeRequestWithoutResource() throws IOException {
final Call mCall = mock(Call.class);
Answer answer = (i) -> {
Request request = i.getArgument(0);
HttpUrl url = request.url();
assertEquals("DELETE", request.method());
assertEquals("/resources/resource-id", url.url().getPath());
return mCall;
};
when(mCall.execute()).thenReturn(MockClient.buildResponse(200, "OK", ""));
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
client.removeResource("resource-id");
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testInterpolatePathWithParams.
@Test
public void testInterpolatePathWithParams() {
final MockClient client = new MockClient("apiKey");
final String path = "/accounts/{account_id}/notes/{account_note_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("account_id", "accountId/");
urlParams.put("account_note_id", "noteId,");
final String interpolatedPath = client.interpolatePath(path, urlParams);
assertEquals("/accounts/accountId%2F/notes/noteId%2C", interpolatedPath);
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testInterpolatePathValidations.
@Test
public void testInterpolatePathValidations() {
final MockClient client = new MockClient("apiKey");
final String path = "/accounts/{account_id}/notes/{account_note_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("account_id", "");
urlParams.put("account_note_id", "");
assertThrows(RecurlyException.class, () -> {
client.interpolatePath(path, urlParams);
});
}
use of com.recurly.v3.fixtures.MockClient 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.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testValidationError.
@Test
public void testValidationError() throws IOException {
final Call mCall = mock(Call.class);
Answer answer = (i) -> {
return mCall;
};
when(mCall.execute()).thenReturn(MockClient.buildResponse(422, "Unprocessable Entity", getErrorResponse("validation")));
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
assertThrows(ValidationException.class, () -> {
client.removeResource("code-aaron");
});
}
Aggregations