use of com.example.customerservice.NoSuchCustomer in project camel by apache.
the class SoapCxfClientTest method testFault.
@Test
public void testFault() {
GetCustomersByName request = new GetCustomersByName();
request.setName("none");
try {
customerService.getCustomersByName(request);
Assert.fail("NoSuchCustomerException expected");
} catch (NoSuchCustomerException e) {
NoSuchCustomer info = e.getFaultInfo();
Assert.assertEquals("none", info.getCustomerId());
}
}
use of com.example.customerservice.NoSuchCustomer in project camel by apache.
the class SoapMarshalTest method testMarshalException.
/**
* Test Soap marshalling by sending a NoSuchCustomerException object and
* checking against a xml file. We expect to receive a SOAP fault here that
* contains a NoSuchCustomer object as detail.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testMarshalException() throws IOException, InterruptedException {
InputStream in = this.getClass().getResourceAsStream("SoapMarshalTestExpectedFault.xml");
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedBodiesReceived(TestUtil.readStream(in));
NoSuchCustomer noSuchCustomer = new NoSuchCustomer();
noSuchCustomer.setCustomerId("None");
NoSuchCustomerException exception = new NoSuchCustomerException("No customer found", noSuchCustomer);
producer.sendBodyAndHeader(null, Exchange.EXCEPTION_CAUGHT, exception);
resultEndpoint.assertIsSatisfied();
}
use of com.example.customerservice.NoSuchCustomer in project cxf by apache.
the class CustomerServiceImpl method getCustomersByName.
public List<Customer> getCustomersByName(String name) throws NoSuchCustomerException {
if ("None".equals(name)) {
NoSuchCustomer noSuchCustomer = new NoSuchCustomer();
noSuchCustomer.setCustomerName(name);
throw new NoSuchCustomerException("Did not find any matching customer for name=" + name, noSuchCustomer);
}
List<Customer> customers = new ArrayList<>();
for (int c = 0; c < 2; c++) {
Customer cust = new Customer();
cust.setName(name);
cust.getAddress().add("Pine Street 200");
Date bDate = new GregorianCalendar(2009, 01, 01).getTime();
cust.setBirthDate(bDate);
cust.setNumOrders(1);
cust.setRevenue(10000);
cust.setTest(new BigDecimal(1.5));
cust.setType(CustomerType.BUSINESS);
customers.add(cust);
}
return customers;
}
use of com.example.customerservice.NoSuchCustomer in project camel by apache.
the class Soap12MarshalTest method testMarshalException.
/**
* Test Soap marshalling by sending a NoSuchCustomerException object and
* checking against a xml file. We expect to receive a SOAP fault here that
* contains a NoSuchCustomer object as detail.
*
* @throws java.io.IOException
* @throws InterruptedException
*/
@Test
public void testMarshalException() throws IOException, InterruptedException {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.message(0).body(String.class).contains("<ns2:Envelope xmlns:ns2=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns3=\"http://customerservice.example.com/\">");
resultEndpoint.message(0).body(String.class).contains("<ns2:Fault>");
resultEndpoint.message(0).body(String.class).contains("<ns2:Value>ns2:Receiver</ns2:Value>");
resultEndpoint.message(0).body(String.class).contains("<ns2:Text xml:lang=\"en\">No customer found</ns2:Text>");
resultEndpoint.message(0).body(String.class).contains("<customerId>None</customerId>");
resultEndpoint.message(0).body(String.class).contains("</ns2:Fault>");
NoSuchCustomer noSuchCustomer = new NoSuchCustomer();
noSuchCustomer.setCustomerId("None");
NoSuchCustomerException exception = new NoSuchCustomerException("No customer found", noSuchCustomer);
producer.sendBodyAndHeader(null, Exchange.EXCEPTION_CAUGHT, exception);
resultEndpoint.assertIsSatisfied();
}
use of com.example.customerservice.NoSuchCustomer in project camel by apache.
the class CustomerServiceImpl method getCustomersByName.
/**
* If the request.name is "none" a NoSuchCustomerException is thrown in any
* other case a dummy customer is returned that has the same name as the
* request
*/
public GetCustomersByNameResponse getCustomersByName(GetCustomersByName request) throws NoSuchCustomerException {
if ("none".equals(request.getName())) {
NoSuchCustomer noSuchCustomer = new NoSuchCustomer();
noSuchCustomer.setCustomerId(request.getName());
throw new NoSuchCustomerException("Customer not found", noSuchCustomer);
}
GetCustomersByNameResponse response = new GetCustomersByNameResponse();
Customer customer = new Customer();
customer.setName(request.getName());
customer.setRevenue(100000);
response.getReturn().add(customer);
return response;
}
Aggregations