@Test public void testRetrieveCharge() throws BaseException { Charge expectedCharge = new Charge.Builder() .amount(new BigDecimal(1234)) .currency("SomeCurrency") .card(new Card.Builder().name("SomeCardName").build()) .build(); final String serializedResponseString = JsonUtil.serialize(expectedCharge); final Response mockedResponse = new Response(200, serializedResponseString, "some_intuit_tid"); mockedResponse.setResponseObject(expectedCharge); new Expectations() {{ serviceBase.sendRequest((Request) any); result = mockedResponse; }}; RequestContext requestContext = new RequestContext(); requestContext.setBaseUrl("SomeBaseUrl"); ChargeService chargeService = new ChargeService(requestContext); Charge actualCharge = chargeService.retrieve("SomeChargeId"); Assert.assertEquals(expectedCharge.getAmount(), actualCharge.getAmount()); Assert.assertEquals(expectedCharge.getCurrency(), actualCharge.getCurrency()); Assert.assertEquals(expectedCharge.getCard().getName(), actualCharge.getCard().getName()); }
public Charge retrieve(String chargeId) throws BaseException { logger.debug("Enter ChargeService::retrieve"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", chargeId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; }
ChargeService extends ServiceBase { public Charge retrieve(String chargeId) throws BaseException { logger.debug("Enter ChargeService::retrieve"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", chargeId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } }
ChargeService extends ServiceBase { public Charge retrieve(String chargeId) throws BaseException { logger.debug("Enter ChargeService::retrieve"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", chargeId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); }
ChargeService extends ServiceBase { public Charge retrieve(String chargeId) throws BaseException { logger.debug("Enter ChargeService::retrieve"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", chargeId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId); }
ChargeService extends ServiceBase { public Charge retrieve(String chargeId) throws BaseException { logger.debug("Enter ChargeService::retrieve"); if (StringUtils.isBlank(chargeId)) { logger.error("IllegalArgumentException {}", chargeId); throw new IllegalArgumentException("chargeId cannot be empty or null"); } String apiUrl = requestContext.getBaseUrl() + "charges/{id}".replaceAll("\\{format\\}", "json") .replaceAll("\\{" + "id" + "\\}", chargeId.toString()); logger.info("apiUrl - " + apiUrl); TypeReference<Charge> typeReference = new TypeReference<Charge>() { }; Request request = new Request.RequestBuilder(MethodType.GET, apiUrl).typeReference(typeReference) .context(requestContext).build(); Response response = sendRequest(request); Charge chargeResponse = (Charge) response.getResponseObject(); prepareResponse(request, response, chargeResponse); return chargeResponse; } ChargeService(RequestContext requestContext); protected  ChargeService(); RequestContext getRequestContext(); void setRequestContext(RequestContext requestContext); Charge create(Charge charge); Charge retrieve(String chargeId); Charge capture(String chargeId, Capture capture); Refund refund(String chargeId, Refund refund); Refund getRefund(String chargeId, String refundId); Refund voidTransaction(String chargeRequestId);  }