Search in sources :

Example 1 with NoSuchCustomer

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());
    }
}
Also used : GetCustomersByName(com.example.customerservice.GetCustomersByName) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException) Test(org.junit.Test)

Example 2 with NoSuchCustomer

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();
}
Also used : InputStream(java.io.InputStream) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException) Test(org.junit.Test)

Example 3 with NoSuchCustomer

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;
}
Also used : Customer(com.example.customerservice.Customer) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 4 with NoSuchCustomer

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();
}
Also used : NoSuchCustomer(com.example.customerservice.NoSuchCustomer) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException) Test(org.junit.Test)

Example 5 with NoSuchCustomer

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;
}
Also used : GetCustomersByNameResponse(com.example.customerservice.GetCustomersByNameResponse) Customer(com.example.customerservice.Customer) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) SaveCustomer(com.example.customerservice.SaveCustomer) NoSuchCustomer(com.example.customerservice.NoSuchCustomer) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException)

Aggregations

NoSuchCustomer (com.example.customerservice.NoSuchCustomer)6 NoSuchCustomerException (com.example.customerservice.NoSuchCustomerException)6 Test (org.junit.Test)4 Customer (com.example.customerservice.Customer)2 GetCustomersByName (com.example.customerservice.GetCustomersByName)2 GetCustomersByNameResponse (com.example.customerservice.GetCustomersByNameResponse)1 SaveCustomer (com.example.customerservice.SaveCustomer)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1