@Test public void shouldSearch() throws Exception { String responseAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<transactionSearchResult>" + "<date>2016-09-11T00:00:00.000-02:00</date>" + "<currentPage>1</currentPage>" + "<resultsInThisPage>2</resultsInThisPage>" + "<totalPages>1</totalPages>" + "<transactions>" + "<transaction>" + "<date>2016-11-09T01:01:01.000-02:00</date>" + "<lastEventDate>2016-11-09T02:02:02.000-02:00</lastEventDate>" + "<code>code3</code>" + "<reference>reference</reference>" + "<type>1</type>" + "<status>2</status>" + "<paymentMethod>" + "<type>1</type>" + "</paymentMethod>" + "<grossAmount>9.99</grossAmount>" + "<discountAmount>0.00</discountAmount>" + "<feeAmount>3.33</feeAmount>" + "<netAmount>2.22</netAmount>" + "<extraAmount>1.11</extraAmount>" + "</transaction>" + "<transaction>" + "<date>2016-11-09T01:01:01.000-02:00</date>" + "<lastEventDate>2016-11-09T02:02:02.000-02:00</lastEventDate>" + "<code>code4</code>" + "<reference>reference</reference>" + "<type>1</type>" + "<status>2</status>" + "<paymentMethod>" + "<type>1</type>" + "</paymentMethod>" + "<grossAmount>9.99</grossAmount>" + "<discountAmount>0.00</discountAmount>" + "<feeAmount>3.33</feeAmount>" + "<netAmount>2.22</netAmount>" + "<extraAmount>1.11</extraAmount>" + "</transaction>" + "</transactions>" + "</transactionSearchResult>"; HttpResponse response = new HttpResponse(200, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); DataList<? extends TransactionSummary> data = transactionSearchByDateRange.execute(pagSeguro, httpClient); assertEquals(new Integer(1), data.getTotalPages()); assertEquals(false, data.isEmpty()); Iterator<TransactionSummary> authorizationSummaryIterator = (Iterator<TransactionSummary>) data.getData().iterator(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); TransactionSummary preApproval = authorizationSummaryIterator.next(); assertEquals(dateFormat.parse("2016-11-09 01:01:01"), preApproval.getDate()); assertEquals(dateFormat.parse("2016-11-09 02:02:02"), preApproval.getLastEvent()); assertEquals("code3", preApproval.getCode()); assertEquals("reference", preApproval.getReference()); assertEquals(TransactionType.Type.CHECKOUT, preApproval.getType().getType()); assertEquals(TransactionStatus.Status.IN_REVIEW, preApproval.getStatus().getStatus()); assertEquals(TransactionPaymentMethod.Type.CREDIT_CARD, preApproval.getPaymentMethod().getType()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), preApproval.getGrossAmount()); assertEquals(new BigDecimal(0.00).setScale(2, RoundingMode.HALF_EVEN), preApproval.getDiscountAmount()); assertEquals(new BigDecimal(3.33).setScale(2, RoundingMode.HALF_EVEN), preApproval.getFeeAmount()); assertEquals(new BigDecimal(2.22).setScale(2, RoundingMode.HALF_EVEN), preApproval.getNetAmount()); assertEquals(new BigDecimal(1.11).setScale(2, RoundingMode.HALF_EVEN), preApproval.getExtraAmount()); preApproval = authorizationSummaryIterator.next(); assertEquals(dateFormat.parse("2016-11-09 01:01:01"), preApproval.getDate()); assertEquals(dateFormat.parse("2016-11-09 02:02:02"), preApproval.getLastEvent()); assertEquals("code4", preApproval.getCode()); assertEquals("reference", preApproval.getReference()); assertEquals(TransactionType.Type.CHECKOUT, preApproval.getType().getType()); assertEquals(TransactionStatus.Status.IN_REVIEW, preApproval.getStatus().getStatus()); assertEquals(TransactionPaymentMethod.Type.CREDIT_CARD, preApproval.getPaymentMethod().getType()); assertEquals(new BigDecimal(9.99).setScale(2, RoundingMode.HALF_EVEN), preApproval.getGrossAmount()); assertEquals(new BigDecimal(0.00).setScale(2, RoundingMode.HALF_EVEN), preApproval.getDiscountAmount()); assertEquals(new BigDecimal(3.33).setScale(2, RoundingMode.HALF_EVEN), preApproval.getFeeAmount()); assertEquals(new BigDecimal(2.22).setScale(2, RoundingMode.HALF_EVEN), preApproval.getNetAmount()); assertEquals(new BigDecimal(1.11).setScale(2, RoundingMode.HALF_EVEN), preApproval.getExtraAmount()); }
@Override public DataList<? extends TransactionSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_SEARCH_MC.convert(transactionSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH, pagseguro.getHost(), map.toUrlEncode(CharSet.ENCODING_UTF)), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends TransactionSummary> transactionsSummary = response.parseXMLContent(pagseguro, TransactionSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por intervalo de data finalizada"); return transactionsSummary; }
TransactionSearchByDateRange implements PagSeguroCommand<DataList<? extends
    TransactionSummary>> { @Override public DataList<? extends TransactionSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_SEARCH_MC.convert(transactionSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH, pagseguro.getHost(), map.toUrlEncode(CharSet.ENCODING_UTF)), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends TransactionSummary> transactionsSummary = response.parseXMLContent(pagseguro, TransactionSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por intervalo de data finalizada"); return transactionsSummary; } }
TransactionSearchByDateRange implements PagSeguroCommand<DataList<? extends
    TransactionSummary>> { @Override public DataList<? extends TransactionSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_SEARCH_MC.convert(transactionSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH, pagseguro.getHost(), map.toUrlEncode(CharSet.ENCODING_UTF)), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends TransactionSummary> transactionsSummary = response.parseXMLContent(pagseguro, TransactionSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por intervalo de data finalizada"); return transactionsSummary; } TransactionSearchByDateRange(TransactionSearch transactionSearch); }
TransactionSearchByDateRange implements PagSeguroCommand<DataList<? extends
    TransactionSummary>> { @Override public DataList<? extends TransactionSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_SEARCH_MC.convert(transactionSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH, pagseguro.getHost(), map.toUrlEncode(CharSet.ENCODING_UTF)), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends TransactionSummary> transactionsSummary = response.parseXMLContent(pagseguro, TransactionSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por intervalo de data finalizada"); return transactionsSummary; } TransactionSearchByDateRange(TransactionSearch transactionSearch); @Override DataList<? extends TransactionSummary> execute(PagSeguro pagseguro,
                                                        HttpClient httpClient); }
TransactionSearchByDateRange implements PagSeguroCommand<DataList<? extends
    TransactionSummary>> { @Override public DataList<? extends TransactionSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de transacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = TRANSACTION_SEARCH_MC.convert(transactionSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.TRANSACTION_SEARCH, pagseguro.getHost(), map.toUrlEncode(CharSet.ENCODING_UTF)), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de transacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends TransactionSummary> transactionsSummary = response.parseXMLContent(pagseguro, TransactionSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de transacao por intervalo de data finalizada"); return transactionsSummary; } TransactionSearchByDateRange(TransactionSearch transactionSearch); @Override DataList<? extends TransactionSummary> execute(PagSeguro pagseguro,
                                                        HttpClient httpClient);  }