@Test public void testRetrieveAllBankAccount() throws BaseException { List<BankAccount> bankAccounts = new ArrayList<>(); BankAccount bankAccount1 = new BankAccount(); bankAccount1.setAccountNumber("accountNumber1"); bankAccounts.add(bankAccount1); BankAccount bankAccount2 = new BankAccount(); bankAccount2.setAccountNumber("accountNumber2"); bankAccounts.add(bankAccount2); QueryResponse expectedQueryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); final String bankAccountString = JsonUtil.serialize(expectedQueryResponse); final Response mockedResponse = new Response(200, bankAccountString, "fjkdlsfd"); mockedResponse.setResponseObject(bankAccounts); new Expectations() {{ serviceBase.sendRequest((Request) any); result = mockedResponse; }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("fakeBaseUrl"); BankAccountService bankAccountService = new BankAccountService(requestContext); try { QueryResponse queryResponse = bankAccountService.getAllBankAccounts("customerId"); Assert.assertEquals(expectedQueryResponse.getBankAccounts(), bankAccounts); } catch (BaseException e) { Assert.fail("Unexpected BaseException thrown " + e.getMessage()); } }
@SuppressWarnings("unchecked") public QueryResponse getAllBankAccounts(String customerId) throws BaseException { logger.debug("Enter BankAccountService::getAllBankAccounts"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", customerId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<List<BankAccount>> typeReference = new TypeReference<List<BankAccount>>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); List<BankAccount> bankAccounts = (List<BankAccount>) response.getResponseObject(); QueryResponse queryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); prepareResponse(request, response, queryResponse); return queryResponse; }
BankAccountService extends ServiceBase { @SuppressWarnings("unchecked") public QueryResponse getAllBankAccounts(String customerId) throws BaseException { logger.debug("Enter BankAccountService::getAllBankAccounts"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", customerId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<List<BankAccount>> typeReference = new TypeReference<List<BankAccount>>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); List<BankAccount> bankAccounts = (List<BankAccount>) response.getResponseObject(); QueryResponse queryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); prepareResponse(request, response, queryResponse); return queryResponse; } }
BankAccountService extends ServiceBase { @SuppressWarnings("unchecked") public QueryResponse getAllBankAccounts(String customerId) throws BaseException { logger.debug("Enter BankAccountService::getAllBankAccounts"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", customerId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<List<BankAccount>> typeReference = new TypeReference<List<BankAccount>>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); List<BankAccount> bankAccounts = (List<BankAccount>) response.getResponseObject(); QueryResponse queryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); prepareResponse(request, response, queryResponse); return queryResponse; } BankAccountService(RequestContext requestContext); protected  BankAccountService(); }
BankAccountService extends ServiceBase { @SuppressWarnings("unchecked") public QueryResponse getAllBankAccounts(String customerId) throws BaseException { logger.debug("Enter BankAccountService::getAllBankAccounts"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", customerId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<List<BankAccount>> typeReference = new TypeReference<List<BankAccount>>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); List<BankAccount> bankAccounts = (List<BankAccount>) response.getResponseObject(); QueryResponse queryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); prepareResponse(request, response, queryResponse); return queryResponse; } 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 { @SuppressWarnings("unchecked") public QueryResponse getAllBankAccounts(String customerId) throws BaseException { logger.debug("Enter BankAccountService::getAllBankAccounts"); if (StringUtils.isBlank(customerId)) { logger.error("IllegalArgumentException {}", customerId); throw new IllegalArgumentException("customerId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl().replaceAll("payments", "customers") + "{id}/bank-accounts" .replaceAll("\\{format\\}", "json").replaceAll("\\{" + "id" + "\\}", customerId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<List<BankAccount>> typeReference = new TypeReference<List<BankAccount>>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); List<BankAccount> bankAccounts = (List<BankAccount>) response.getResponseObject(); QueryResponse queryResponse = new QueryResponse.Builder().bankAccounts(bankAccounts).build(); prepareResponse(request, response, queryResponse); return queryResponse; } 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);  }