@Test public void testRetrieveBankAccount() throws BaseException { BankAccount expectedBankAccount = new BankAccount.Builder().id("ijids").accountNumber("accountId").build(); final String bankAccountGeneratedString = JsonUtil.serialize(expectedBankAccount); final Response mockedResponse = new Response(200, bankAccountGeneratedString, "fjkdlsfd"); mockedResponse.setResponseObject(expectedBankAccount); new Expectations() {{ serviceBase.sendRequest((Request) any); result = mockedResponse; }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("fakeBaseUrl"); BankAccountService bankAccountService = new BankAccountService(requestContext); try { BankAccount bankAccount = bankAccountService.getBankAccount("customerId", "accountId"); Assert.assertEquals(expectedBankAccount, bankAccount); } catch (BaseException e) { Assert.fail("Unexpected BaseException thrown " + e.getMessage()); } }
public BankAccount getBankAccount(String customerId, String bankaccountId) throws BaseException { logger.debug("Enter BankAccountService::getBankAccount"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } if (StringUtils.isBlank(bankaccountId)) { logger.error("IllegalArgumentException {}", bankaccountId); throw new IllegalArgumentException("bankaccountId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts/{bankaccount_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", customerId.toString()) .replaceAll("\\{" + "bankaccount_id" + "\\}", bankaccountId); logger.info("apiUrl - " + apiUrl); TypeReference<BankAccount> typeReference = new TypeReference<BankAccount>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); BankAccount bankAccountResponse = (BankAccount) response.getResponseObject(); prepareResponse(request, response, bankAccountResponse); return bankAccountResponse; }
BankAccountService extends ServiceBase { public BankAccount getBankAccount(String customerId, String bankaccountId) throws BaseException { logger.debug("Enter BankAccountService::getBankAccount"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } if (StringUtils.isBlank(bankaccountId)) { logger.error("IllegalArgumentException {}", bankaccountId); throw new IllegalArgumentException("bankaccountId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts/{bankaccount_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", customerId.toString()) .replaceAll("\\{" + "bankaccount_id" + "\\}", bankaccountId); logger.info("apiUrl - " + apiUrl); TypeReference<BankAccount> typeReference = new TypeReference<BankAccount>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); BankAccount bankAccountResponse = (BankAccount) response.getResponseObject(); prepareResponse(request, response, bankAccountResponse); return bankAccountResponse; } }
BankAccountService extends ServiceBase { public BankAccount getBankAccount(String customerId, String bankaccountId) throws BaseException { logger.debug("Enter BankAccountService::getBankAccount"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } if (StringUtils.isBlank(bankaccountId)) { logger.error("IllegalArgumentException {}", bankaccountId); throw new IllegalArgumentException("bankaccountId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts/{bankaccount_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", customerId.toString()) .replaceAll("\\{" + "bankaccount_id" + "\\}", bankaccountId); logger.info("apiUrl - " + apiUrl); TypeReference<BankAccount> typeReference = new TypeReference<BankAccount>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); BankAccount bankAccountResponse = (BankAccount) response.getResponseObject(); prepareResponse(request, response, bankAccountResponse); return bankAccountResponse; } BankAccountService(RequestContext requestContext); protected  BankAccountService(); }
BankAccountService extends ServiceBase { public BankAccount getBankAccount(String customerId, String bankaccountId) throws BaseException { logger.debug("Enter BankAccountService::getBankAccount"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } if (StringUtils.isBlank(bankaccountId)) { logger.error("IllegalArgumentException {}", bankaccountId); throw new IllegalArgumentException("bankaccountId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts/{bankaccount_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", customerId.toString()) .replaceAll("\\{" + "bankaccount_id" + "\\}", bankaccountId); logger.info("apiUrl - " + apiUrl); TypeReference<BankAccount> typeReference = new TypeReference<BankAccount>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); BankAccount bankAccountResponse = (BankAccount) response.getResponseObject(); prepareResponse(request, response, bankAccountResponse); return bankAccountResponse; } BankAccountService(RequestContext requestContext); protected  BankAccountService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); BankAccount create(BankAccount bankAccount, String customerId); BankAccount createFromToken(Token token, String customerId); BankAccount delete(String customerId, String bankaccountId); BankAccount getBankAccount(String customerId, String bankaccountId); @SuppressWarnings("unchecked") QueryResponse getAllBankAccounts(String customerId); @SuppressWarnings("unchecked") QueryResponse getAllBankAccounts(String customerId, int count); }
BankAccountService extends ServiceBase { public BankAccount getBankAccount(String customerId, String bankaccountId) throws BaseException { logger.debug("Enter BankAccountService::getBankAccount"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } if (StringUtils.isBlank(bankaccountId)) { logger.error("IllegalArgumentException {}", bankaccountId); throw new IllegalArgumentException("bankaccountId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts/{bankaccount_id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", customerId.toString()) .replaceAll("\\{" + "bankaccount_id" + "\\}", bankaccountId); logger.info("apiUrl - " + apiUrl); TypeReference<BankAccount> typeReference = new TypeReference<BankAccount>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); BankAccount bankAccountResponse = (BankAccount) response.getResponseObject(); prepareResponse(request, response, bankAccountResponse); return bankAccountResponse; } BankAccountService(RequestContext requestContext); protected  BankAccountService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); BankAccount create(BankAccount bankAccount, String customerId); BankAccount createFromToken(Token token, String customerId); BankAccount delete(String customerId, String bankaccountId); BankAccount getBankAccount(String customerId, String bankaccountId); @SuppressWarnings("unchecked") QueryResponse getAllBankAccounts(String customerId); @SuppressWarnings("unchecked") QueryResponse getAllBankAccounts(String customerId, int count);  }