Skip navigation

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...


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")); 


// wait, since this is async

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);

Magesh recently wrote some SwitchYard components to enable SOAP bindings on a SwitchYard Service, while at the same time, I did some work to allow SwitchYard expose POJOs as Services.  Keith mentioned this in his last blog post.


As part of my work, I looked at approaches to making these components work more smoothly together.  I recorded a VERY rough screencast of some of this work.  It was recorded in one pass, so I talked too much about some things and forgot to menton others, but still... it gives an idea of what we've been doing.  Take a look:


Also see docs on creating CDI based bean services: