CamelTestSupport cannot be used with SwitchYard endpoints in FSW

Solution Verified - Updated -

Issue

  • In FSW 6, I deployed a service having a Camel interface and a Camel URI binding. In order to invoke the service I'm using a Camel unit test (CamelTestSupport) like the following:
  @Test
  public void testStartService() throws Exception {
    template.sendBody("switchyard://SampleService", "Test message");
  }
  • However, running this unit test using "mvn test" raises the following error:
java.lang.ClassCastException: org.apache.camel.impl.DefaultCamelContext cannot be cast to org.switchyard.common.camel.SwitchYardCamelContext
    at com.example.switchyard.SampleServiceTest.testStartService(SampleServiceTest.java:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    ...
  • The Camel's ProducerTemplate uses a CamelDefaultContext while producing message to SwitchYard endpoints obviously requires a SwitchYardCamelContext instance. And the SwitchYardCamelContext cannot be casted to a CamelDefaultContext instance.
  • How then is one supposed to use the Camel unit test framework with SwitchYard?

Environment

  • Red Hat JBoss Fuse Service Works (FSW)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.