unit testing sca binding
mlybarger Mar 17, 2015 9:37 AMi 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
@Service(Foo.class)
public class FooBean implements Foo {
Logger LOG = Logger.getLogger(FooBean.class);
@Inject
@Reference
private Bar bar;
@Override
public void service(String message) {
LOG.info("message:"+ message);
ComplexMessage c = new ComplexMessage();
c.setMessage(message);
bar.complexMessage(c);
}
}
And the test:
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(config = SwitchYardTestCaseConfig.SWITCHYARD_XML, mixins = {
CDIMixIn.class, NamingMixIn.class })
public class FooBeanTest {
private SwitchYardTestKit testKit;
@ServiceOperation("Foo")
private Invoker service;
@Before
public void before() {
testKit.registerInOutService("urn:com.example.switchyard:bar:1.0");
testKit.getServiceDomain().registerService(new QName("urn:com.example.switchyard:bar:1.0"), new InOutService(),
new MockHandler());
}
@Test
public void testOne() {
service.sendInOut("message");
}
}
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:service>
<sca:reference name="Bar">
<sca:interface.java interface="com.example.switchyard.bar.Bar"/>
</sca:reference>
</sca:component>
<sca:service name="Foo" promote="FooBean/Foo">
<sca:interface.java interface="com.example.switchyard.foo.Foo"/>
<file:binding.file name="file1">
<file:directory>/tmp</file:directory>
<file:fileName>foo</file:fileName>
<file:consume/>
</file:binding.file>
</sca:service>
<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"/>
</sca:reference>
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.