3 Replies Latest reply on Apr 9, 2015 12:26 PM by Mark Lybarger

    unit testing sca binding

    Mark Lybarger Apprentice

      i have the following setup.  i have two composites. and one references a component on the other via an sca binding.  Foo(foo.jar) ,  Foo  has sca reference to Bar. 


      Bar (bar.jar), BarBean exposed by SCA as Bar.


      I want to unit test Foo and have been looking at how to mock Bar, but I'm just not getting there.


        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.switchyard.component.bean.ServiceProxyHandler.handle(ServiceProxyHandler.java:163)

        ... 95 more

      Caused by: org.switchyard.HandlerException: SWITCHYARD039604: Service reference {urn:com.example.switchyard:bar:1.0}Bar not found in domain org.switchyard.domains.root

        at org.switchyard.component.sca.SCAInvoker.invokeLocal(SCAInvoker.java:114)


      Here's the FooBean


      public class FooBean implements Foo {



        Logger LOG = Logger.getLogger(FooBean.class);





        private Bar bar;



        public void service(String message) {

        LOG.info("message:"+ message);

        ComplexMessage c = new ComplexMessage();







      And the test:



      @SwitchYardTestCaseConfig(config = SwitchYardTestCaseConfig.SWITCHYARD_XML, mixins = {

        CDIMixIn.class, NamingMixIn.class })

      public class FooBeanTest {



        private SwitchYardTestKit testKit;


        private Invoker service;



        public void before() {


        testKit.getServiceDomain().registerService(new QName("urn:com.example.switchyard:bar:1.0"), new InOutService(),

        new MockHandler());




        public void testOne() {







      here's some perhaps relevant sy.xml stuff.

          <sca:component name="FooBean">

            <bean:implementation.bean class="com.example.switchyard.foo.FooBean"/>

            <sca:service name="Foo">

              <sca:interface.java interface="com.example.switchyard.foo.Foo"/>


            <sca:reference name="Bar">

              <sca:interface.java interface="com.example.switchyard.bar.Bar"/>



          <sca:service name="Foo" promote="FooBean/Foo">

            <sca:interface.java interface="com.example.switchyard.foo.Foo"/>

            <file:binding.file name="file1">






          <sca:reference name="Bar" multiplicity="0..1" promote="FooBean/Bar">

            <sca:interface.java interface="com.example.switchyard.bar.Bar"/>

            <sca:binding.sca sy:targetNamespace="urn:com.example.switchyard:bar:1.0" name="sca1"/>


      Any insights into how I should mock Bar when testing Foo?  It works fine when all the components are deployed inside FSW, but I want to unit test of course.