@Test(expected = TaxWebServiceFatalException.class) public void testProcess_ClientExceptionOccurs_TaxWebserviceFatalExceptionIsRethrown() throws Exception { whenCallingTheWebservice().thenThrow(aMethodNotAllowedException()); Employee employee = new EmployeeTestBuilder().build(); taxPaymentWebService.doWebserviceCallToTaxService(employee, Money.of(CurrencyUnit.EUR, 2000.0)); }
public void doWebserviceCallToTaxService(Employee employee, Money taxesToPay) throws TaxWebServiceException { TaxTo taxTo = createWebserviceInput(employee, taxesToPay); try { URI uri = URI.create(taxServiceUrl); ResponseEntity<TaxServiceResponseTo> webserviceResult = restTemplate.postForEntity(uri, taxTo, TaxServiceResponseTo.class); TaxServiceResponseTo taxServiceResponseTo = webserviceResult.getBody(); if (!"OK".equals(taxServiceResponseTo.getStatus())) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, webserviceResult.getStatusCode(), getJson(taxServiceResponseTo), "invalid response from server"); } } catch (HttpClientErrorException e) { throw new TaxWebServiceFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (HttpServerErrorException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (ResourceAccessException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); } }
TaxPaymentWebService { public void doWebserviceCallToTaxService(Employee employee, Money taxesToPay) throws TaxWebServiceException { TaxTo taxTo = createWebserviceInput(employee, taxesToPay); try { URI uri = URI.create(taxServiceUrl); ResponseEntity<TaxServiceResponseTo> webserviceResult = restTemplate.postForEntity(uri, taxTo, TaxServiceResponseTo.class); TaxServiceResponseTo taxServiceResponseTo = webserviceResult.getBody(); if (!"OK".equals(taxServiceResponseTo.getStatus())) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, webserviceResult.getStatusCode(), getJson(taxServiceResponseTo), "invalid response from server"); } } catch (HttpClientErrorException e) { throw new TaxWebServiceFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (HttpServerErrorException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (ResourceAccessException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); } } }
TaxPaymentWebService { public void doWebserviceCallToTaxService(Employee employee, Money taxesToPay) throws TaxWebServiceException { TaxTo taxTo = createWebserviceInput(employee, taxesToPay); try { URI uri = URI.create(taxServiceUrl); ResponseEntity<TaxServiceResponseTo> webserviceResult = restTemplate.postForEntity(uri, taxTo, TaxServiceResponseTo.class); TaxServiceResponseTo taxServiceResponseTo = webserviceResult.getBody(); if (!"OK".equals(taxServiceResponseTo.getStatus())) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, webserviceResult.getStatusCode(), getJson(taxServiceResponseTo), "invalid response from server"); } } catch (HttpClientErrorException e) { throw new TaxWebServiceFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (HttpServerErrorException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (ResourceAccessException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); } }  }
TaxPaymentWebService { public void doWebserviceCallToTaxService(Employee employee, Money taxesToPay) throws TaxWebServiceException { TaxTo taxTo = createWebserviceInput(employee, taxesToPay); try { URI uri = URI.create(taxServiceUrl); ResponseEntity<TaxServiceResponseTo> webserviceResult = restTemplate.postForEntity(uri, taxTo, TaxServiceResponseTo.class); TaxServiceResponseTo taxServiceResponseTo = webserviceResult.getBody(); if (!"OK".equals(taxServiceResponseTo.getStatus())) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, webserviceResult.getStatusCode(), getJson(taxServiceResponseTo), "invalid response from server"); } } catch (HttpClientErrorException e) { throw new TaxWebServiceFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (HttpServerErrorException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (ResourceAccessException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); } }  void doWebserviceCallToTaxService(Employee employee, Money taxesToPay); }
TaxPaymentWebService { public void doWebserviceCallToTaxService(Employee employee, Money taxesToPay) throws TaxWebServiceException { TaxTo taxTo = createWebserviceInput(employee, taxesToPay); try { URI uri = URI.create(taxServiceUrl); ResponseEntity<TaxServiceResponseTo> webserviceResult = restTemplate.postForEntity(uri, taxTo, TaxServiceResponseTo.class); TaxServiceResponseTo taxServiceResponseTo = webserviceResult.getBody(); if (!"OK".equals(taxServiceResponseTo.getStatus())) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, webserviceResult.getStatusCode(), getJson(taxServiceResponseTo), "invalid response from server"); } } catch (HttpClientErrorException e) { throw new TaxWebServiceFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (HttpServerErrorException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, e.getStatusCode(), e.getResponseBodyAsString(), e); } catch (ResourceAccessException e) { throw new TaxWebServiceNonFatalException(employee, taxesToPay, HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e); } }  void doWebserviceCallToTaxService(Employee employee, Money taxesToPay);  }