@Test public void shouldThrowsBadRequest() { try { String responseAsString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<errors>" + "<error>" + "<code>0002</code>" + "<message>Date range is required.</message>" + "</error>" + "</errors>"; HttpResponse response = new HttpResponse(400, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); authorizationSearchByDateRange.execute(pagSeguro, httpClient); } catch (PagSeguroBadRequestException e) { ServerErrors errors = e.getErrors(); ServerError error = errors.getErrors().iterator().next(); assertEquals(new Integer(0002), error.getCode()); assertEquals("Date range is required.", error.getMessage()); } catch (Exception e) { } }
@Override public DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = AUTHORIZATION_SEARCH_MP.convert(authorizationSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_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 autorizacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends AuthorizationSummary> authorizationsSummary = response.parseXMLContent(pagseguro, AuthorizationSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por intervalo de data finalizada"); return authorizationsSummary; }
AuthorizationSearchByDateRange implements PagSeguroCommand<DataList<? extends
    AuthorizationSummary>> { @Override public DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = AUTHORIZATION_SEARCH_MP.convert(authorizationSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_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 autorizacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends AuthorizationSummary> authorizationsSummary = response.parseXMLContent(pagseguro, AuthorizationSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por intervalo de data finalizada"); return authorizationsSummary; } }
AuthorizationSearchByDateRange implements PagSeguroCommand<DataList<? extends
    AuthorizationSummary>> { @Override public DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = AUTHORIZATION_SEARCH_MP.convert(authorizationSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_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 autorizacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends AuthorizationSummary> authorizationsSummary = response.parseXMLContent(pagseguro, AuthorizationSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por intervalo de data finalizada"); return authorizationsSummary; } AuthorizationSearchByDateRange(AuthorizationSearch authorizationSearch); }
AuthorizationSearchByDateRange implements PagSeguroCommand<DataList<? extends
    AuthorizationSummary>> { @Override public DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = AUTHORIZATION_SEARCH_MP.convert(authorizationSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_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 autorizacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends AuthorizationSummary> authorizationsSummary = response.parseXMLContent(pagseguro, AuthorizationSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por intervalo de data finalizada"); return authorizationsSummary; } AuthorizationSearchByDateRange(AuthorizationSearch authorizationSearch); @Override DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro,
                                                          HttpClient httpClient); }
AuthorizationSearchByDateRange implements PagSeguroCommand<DataList<? extends
    AuthorizationSummary>> { @Override public DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por intervalo de data"); LOGGER.info("Convertendo valores"); final RequestMap map = AUTHORIZATION_SEARCH_MP.convert(authorizationSearch); LOGGER.info("Valores convertidos"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: %s", map)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_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 autorizacao por intervalo de data"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); DataList<? extends AuthorizationSummary> authorizationsSummary = response.parseXMLContent(pagseguro, AuthorizationSearchResponseXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por intervalo de data finalizada"); return authorizationsSummary; } AuthorizationSearchByDateRange(AuthorizationSearch authorizationSearch); @Override DataList<? extends AuthorizationSummary> execute(PagSeguro pagseguro,
                                                          HttpClient httpClient);  }