@Test public void shouldThrowsBadRequest() { try { String responseAsString = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<errors>" + "<error>" + "<code>0001</code>" + "<message>Code is required.</message>" + "</error>" + "</errors>"; HttpResponse response = new HttpResponse(400, responseAsString); when(httpClient.execute(any(HttpMethod.class), anyString(), anyMap(), any(HttpRequestBody.class))).thenReturn(response); authorizationSearchByCode.execute(pagSeguro, httpClient); } catch (PagSeguroBadRequestException e) { ServerErrors errors = e.getErrors(); ServerError error = errors.getErrors().iterator().next(); assertEquals(new Integer(0001), error.getCode()); assertEquals("Code is required.", error.getMessage()); } catch (Exception e) { } }
@Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: authorizationCode:%s", code)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_CODE, pagseguro.getHost(), code), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo"); 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 finalizada"); return authorizationDetail; }
AuthorizationSearchByCode implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: authorizationCode:%s", code)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_CODE, pagseguro.getHost(), code), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo"); 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 finalizada"); return authorizationDetail; } }
AuthorizationSearchByCode implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: authorizationCode:%s", code)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_CODE, pagseguro.getHost(), code), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo"); 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 finalizada"); return authorizationDetail; } AuthorizationSearchByCode(String code); }
AuthorizationSearchByCode implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: authorizationCode:%s", code)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_CODE, pagseguro.getHost(), code), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo"); 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 finalizada"); return authorizationDetail; } AuthorizationSearchByCode(String code); @Override AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient); }
AuthorizationSearchByCode implements PagSeguroCommand<AuthorizationDetail> { @Override public AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient) { LOGGER.info("Iniciando busca de autorizacao por codigo"); final HttpResponse response; try { LOGGER.debug(String.format("Parametros: authorizationCode:%s", code)); response = httpClient.execute(HttpMethod.GET, String.format(Endpoints.AUTHORIZATION_SEARCH_BY_CODE, pagseguro.getHost(), code), null, null); LOGGER.debug(String.format("Resposta: %s", response.toString())); } catch (IOException e) { LOGGER.error("Erro ao executar busca de autorizacao por codigo"); 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 finalizada"); return authorizationDetail; } AuthorizationSearchByCode(String code); @Override AuthorizationDetail execute(PagSeguro pagseguro, HttpClient httpClient);  }