private InputStream callRecurlySafeGetPdf(String url) { final Response response; final InputStream pdfInputStream; try { response = clientRequestBuilderCommon(client.prepareGet(url)) .addHeader("Accept", "application/pdf") .addHeader("Content-Type", "application/pdf") .execute() .get(); pdfInputStream = response.getResponseBodyAsStream(); } catch (InterruptedException e) { log.error("Interrupted while calling recurly", e); return null; } catch (ExecutionException e) { log.error("Execution error", e); return null; } catch (IOException e) { log.error("Error retrieving response body", e); return null; } if (response.getStatusCode() != 200) { final RecurlyAPIError recurlyAPIError = RecurlyAPIError.buildFromResponse(response); throw new RecurlyAPIException(recurlyAPIError); } return pdfInputStream; }
@Test(groups = "integration") public void testUnauthorizedException() throws Exception { final String subdomain = System.getProperty(KILLBILL_PAYMENT_RECURLY_SUBDOMAIN); RecurlyClient unauthorizedRecurlyClient = new RecurlyClient("invalid-api-key", subdomain); unauthorizedRecurlyClient.open(); try { unauthorizedRecurlyClient.getAccounts(); Assert.fail("getAccounts call should not succeed with invalid credentials."); } catch (RecurlyAPIException expected) { Assert.assertEquals(expected.getRecurlyError().getSymbol(), "unauthorized"); } }
@Test(groups = "integration") public void testUnauthorizedException() throws Exception { final String subdomain = System.getProperty(KILLBILL_PAYMENT_RECURLY_SUBDOMAIN); RecurlyClient unauthorizedRecurlyClient = new RecurlyClient("invalid-api-key", subdomain); unauthorizedRecurlyClient.open(); try { unauthorizedRecurlyClient.getAccounts(); Assert.fail("getAccounts call should not succeed with invalid credentials."); } catch (RecurlyAPIException expected) { Assert.assertEquals(expected.getRecurlyError().getSymbol(), "unauthorized"); } }
recurlyError.setDescription("We could not authenticate your request. Either your subdomain and private key are not set or incorrect"); throw new RecurlyAPIException(recurlyError); } else { try { throw new RecurlyAPIException(recurlyError);
Assert.fail("Should not have been able to fetch shipping address we just deleted"); } catch (RecurlyAPIException ex) { final RecurlyAPIError err = ex.getRecurlyError(); Assert.assertEquals(err.getSymbol(), "not_found"); } catch (Exception ex) {
Assert.fail("Should not have been able to fetch shipping address we just deleted"); } catch (RecurlyAPIException ex) { final RecurlyAPIError err = ex.getRecurlyError(); Assert.assertEquals(err.getSymbol(), "not_found"); } catch (Exception ex) {
Assert.fail("Failed to delete the Adjustment"); } catch (final RecurlyAPIException e) { Assert.assertEquals(e.getRecurlyError().getHttpStatusCode(), 404);
Assert.fail("Failed to delete the Adjustment"); } catch (final RecurlyAPIException e) { Assert.assertEquals(e.getRecurlyError().getHttpStatusCode(), 404);