@Test public void shouldSearch() throws Exception { String responseAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<authorizationSearchResult>" + "<date>2016-09-02T00:00:00.000-03:00</date>" + "<authorizations>" + "<authorization>" + "<code>0F9DE39A0CF949538606EE7217620ADB</code>" + "<authorizerEmail>v82066140592075093489@sandbox.pagseguro.com.br</authorizerEmail>" + "<creationDate>2016-11-09T00:00:00.000-02:00</creationDate>" + "<reference>AUTH_LIB_JAVA_0001</reference>" + "<account>" + "<publicKey>PUBD53899901C224B07B8719FD9CB4473E7</publicKey>" + "</account>" + "<permissions>" + "<permission>" + "<code>CREATE_CHECKOUTS</code>" + "<status>APPROVED</status>" + "<lastUpdate>2016-11-09T23:59:59.000-02:00</lastUpdate>" + "</permission>" + "</permissions>" + "</authorization>" + "<authorization>" + "<code>code</code>" + "<authorizerEmail>teste@sandbox.pagseguro.com.br</authorizerEmail>" + "<creationDate>2016-11-09T00:00:00.000-02:00</creationDate>" + "<reference>AUTH_LIB_JAVA_0001</reference>" + "<account>" + "<publicKey>publicKey</publicKey>" + "</account>" + "<permissions>" + "<permission>" + "<code>CREATE_CHECKOUTS</code>" + "<status>APPROVED</status>" + "<lastUpdate>2016-11-09T23:59:59.000-02:00</lastUpdate>" + "</permission>" + "</permissions>" + "</authorization>" + "</authorizations>" + "<resultsInThisPage>1</resultsInThisPage>" + "<currentPage>1</currentPage>" + "<totalPages>1</totalPages>" + "</authorizationSearchResult>"; HttpResponse response = new HttpResponse(200, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); DataList<? extends AuthorizationSummary> data = authorizationSearchByDateRange.execute(pagSeguro, httpClient); assertEquals(new Integer(1), data.getTotalPages()); assertEquals(false, data.isEmpty()); Iterator<AuthorizationSummary> authorizationSummaryIterator = (Iterator<AuthorizationSummary>) data.getData().iterator(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); AuthorizationSummary authorization = authorizationSummaryIterator.next(); assertEquals("0F9DE39A0CF949538606EE7217620ADB", authorization.getCode()); assertEquals("v82066140592075093489@sandbox.pagseguro.com.br", authorization.getAuthorizerEmail()); assertEquals(dateFormat.parse("2016-11-09 00:00:00"), authorization.getCreationDate()); assertEquals("AUTH_LIB_JAVA_0001", authorization.getReference()); assertEquals("PUBD53899901C224B07B8719FD9CB4473E7", authorization.getAccount().getPublicKey()); Permission permission = authorization.getPermissions().iterator().next(); assertEquals("CREATE_CHECKOUTS", permission.getCode().getCodeId()); assertEquals("APPROVED", permission.getStatus()); assertEquals(dateFormat.parse("2016-11-09 23:59:59"), permission.getLastUpdate()); authorization = authorizationSummaryIterator.next(); assertEquals("code", authorization.getCode()); assertEquals("teste@sandbox.pagseguro.com.br", authorization.getAuthorizerEmail()); assertEquals(dateFormat.parse("2016-11-09 00:00:00"), authorization.getCreationDate()); assertEquals("AUTH_LIB_JAVA_0001", authorization.getReference()); assertEquals("publicKey", authorization.getAccount().getPublicKey()); permission = authorization.getPermissions().iterator().next(); assertEquals("CREATE_CHECKOUTS", permission.getCode().getCodeId()); assertEquals("APPROVED", permission.getStatus()); assertEquals(dateFormat.parse("2016-11-09 23:59:59"), permission.getLastUpdate()); }
@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);  }