@Test public void shouldSearch() throws Exception { String responseAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<authorization>\n" + "<code>code</code>\n" + "<authorizerEmail>" + "teste@sandbox.pagseguro.com.br" + "</authorizerEmail>\n" + "<creationDate>2016-11-09T00:00:00.000-02:00</creationDate>\n" + "<reference>AUTH_LIB_JAVA_0001</reference>\n" + "<account>\n" + "<publicKey>publicKey</publicKey>\n" + "</account>\n" + "<permissions>\n" + "<permission>\n" + "<code>CREATE_CHECKOUTS</code>\n" + "<status>APPROVED</status>\n" + "<lastUpdate>2016-11-09T23:59:59.000-02:00</lastUpdate>\n" + "</permission>\n" + "</permissions>\n" + "</authorization>"; HttpResponse response = new HttpResponse(200, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); AuthorizationDetail authorizationDetail = authorizationSearchByNotification.execute(pagSeguro, httpClient); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); assertEquals("code", authorizationDetail.getCode()); assertEquals("teste@sandbox.pagseguro.com.br", authorizationDetail.getAuthorizerEmail()); assertEquals(dateFormat.parse("2016-11-09 00:00:00"), authorizationDetail.getCreationDate()); assertEquals("AUTH_LIB_JAVA_0001", authorizationDetail.getReference()); assertEquals("publicKey", authorizationDetail.getAccount().getPublicKey()); Permission permission = authorizationDetail.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 AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); AuthorizationDetail authorizationDetail = response.parseXMLContent(pagseguro, AuthorizationDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por codigo de notificacao finalizada"); return authorizationDetail; }
AuthorizationSearchByNotification implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); AuthorizationDetail authorizationDetail = response.parseXMLContent(pagseguro, AuthorizationDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por codigo de notificacao finalizada"); return authorizationDetail; } }
AuthorizationSearchByNotification implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); AuthorizationDetail authorizationDetail = response.parseXMLContent(pagseguro, AuthorizationDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por codigo de notificacao finalizada"); return authorizationDetail; } AuthorizationSearchByNotification(String notificationCode); }
AuthorizationSearchByNotification implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); AuthorizationDetail authorizationDetail = response.parseXMLContent(pagseguro, AuthorizationDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por codigo de notificacao finalizada"); return authorizationDetail; } AuthorizationSearchByNotification(String notificationCode); @Override AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient); }
AuthorizationSearchByNotification implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo de notificacao"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: notificationCode:%s", notificationCode)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_NOTIFICATION_CODE, pagseguro.getHost(), notificationCode), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo de notificacao"); throw new PagSeguroLibException(e); } LOGGER.info("Parseando XML de resposta"); AuthorizationDetail authorizationDetail = response.parseXMLContent(pagseguro, AuthorizationDetailXML.class); LOGGER.info("Parseamento finalizado"); LOGGER.info("Busca de autorizacao por codigo de notificacao finalizada"); return authorizationDetail; } AuthorizationSearchByNotification(String notificationCode); @Override AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient);  }