Search in sources :

Example 1 with NoSuchCustomerException

use of com.example.customerservice.NoSuchCustomerException 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 NoSuchCustomerException

use of com.example.customerservice.NoSuchCustomerException 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 NoSuchCustomerException

use of com.example.customerservice.NoSuchCustomerException 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 4 with NoSuchCustomerException

use of com.example.customerservice.NoSuchCustomerException 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)

Example 5 with NoSuchCustomerException

use of com.example.customerservice.NoSuchCustomerException in project camel by apache.

the class SoapCxfServerTest method testFault.

@Test
public void testFault() {
    GetCustomersByName request = new GetCustomersByName();
    request.setName("none");
    try {
        customerServiceProxy.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)

Aggregations

NoSuchCustomer (com.example.customerservice.NoSuchCustomer)5 NoSuchCustomerException (com.example.customerservice.NoSuchCustomerException)5 Test (org.junit.Test)4 GetCustomersByName (com.example.customerservice.GetCustomersByName)2 Customer (com.example.customerservice.Customer)1 GetCustomersByNameResponse (com.example.customerservice.GetCustomersByNameResponse)1 SaveCustomer (com.example.customerservice.SaveCustomer)1 InputStream (java.io.InputStream)1