use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testUnknownError.
@Test
public void testUnknownError() throws IOException {
final Call mCall = mock(Call.class);
Answer answer = (i) -> {
return mCall;
};
final Response response = MockClient.buildResponse(999, "Unknown", getErrorJson("unknown"));
when(mCall.execute()).thenReturn(response);
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
// asserts that generic api exception is thrown for unknown error
assertThrows(ApiException.class, () -> {
client.getResource("code-aaron");
});
final RecurlyException exception = ExceptionFactory.getExceptionClass(response);
assertTrue(exception.toString().contains("ApiException"));
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testCantSetApiUrlWithoutRecurlyInsecure.
@Test
public void testCantSetApiUrlWithoutRecurlyInsecure() throws Exception {
final HashMap<String, String> environmentVariables = new HashMap<String, String>();
environmentVariables.put("RECURLY_INSECURE", "false");
setEnv(environmentVariables);
final MockClient client = new MockClient("apiKey");
final String originalUrl = client.getApiUrl();
final String newApiUrl = "https://my.base.url/";
client._setApiUrl(newApiUrl);
assertEquals(originalUrl, client.getApiUrl());
environmentVariables.clear();
environmentVariables.put("RECURLY_INSECURE", "true");
setEnv(environmentVariables);
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testInterpolatePathMatching.
@Test
public void testInterpolatePathMatching() {
final MockClient client = new MockClient("apiKey");
final String path = "/url_path/{url_path}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("url_path", "replacement");
final String interpolatedPath = client.interpolatePath(path, urlParams);
assertEquals("/url_path/replacement", interpolatedPath);
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testNetworkErrorWithoutResource.
@Test
public void testNetworkErrorWithoutResource() throws IOException {
final Call mCall = mock(Call.class);
Answer answer = (i) -> {
return mCall;
};
when(mCall.execute()).thenThrow(new IOException());
OkHttpClient mockOkHttpClient = MockClient.getMockOkHttpClient(answer);
final MockClient client = new MockClient("apiKey", mockOkHttpClient);
assertThrows(NetworkException.class, () -> {
client.removeResource("code-aaron");
});
}
use of com.recurly.v3.fixtures.MockClient in project recurly-client-java by recurly.
the class BaseClientTest method testSetApiUrl.
@Test
public void testSetApiUrl() {
final MockClient client = new MockClient("apiKey");
final String newApiUrl = "https://my.base.url/";
client._setApiUrl(newApiUrl);
assertEquals(newApiUrl, client.getApiUrl());
}
Aggregations