I've been working on making improvements to the unit testing of SwitchYard Services.  See Dev Forum post.

 

Imagine I have a CDI bean service as follows...

 

@Service
public class BasicOrderManagementService {

    public OrderResponse createOrder(OrderRequest request) { 
        return new OrderResponse(request.orderId);
    }
}

 

Up to this point, invoking/testing the createOrder operation on that service in a test would have involved code like the following...

 

ServiceDomain domain = ServiceDomains.getDomain();

// Consume the OM model...
MockHandler responseConsumer = new MockHandler();
org.switchyard.Service service = domain.getService(new QName("BasicOrderManagementService"));
Exchange exchange = domain.createExchange(service, new BaseExchangeContract(new InOutOperation("createOrder")), responseConsumer);

Message inMessage = exchange.createMessage();
inMessage.setContent(new OrderRequest("D123", "ABCD")); 

exchange.send(inMessage); 

// wait, since this is async
responseConsumer.waitForOKMessage();

OrderResponse response = (OrderResponse) responseConsumer.getMessages().poll().getMessage().getContent();
Assert.assertEquals("D123", response.orderId);

 

By extending the new SwitchYardCDITestCase class, we can now express the same test as...

 

Message responseMsg = newInvoker("BasicOrderManagementService.createOrder").
                            sendInOut(new OrderRequest("D123", "ABCD"));

OrderResponse response = (OrderResponse) responseMsg.getContent(); 
Assert.assertEquals("D123", response.orderId);