8 Replies Latest reply on Jun 6, 2013 10:41 AM by Luis del Toro

    Registering a MockHandler for a Camel Service

    Luis del Toro Newbie

      I'm trying to test a the rest biding of promoted Camel Service using Switchyard 0.8.0.Final

       

      Because I'm just interested in the binding, I would like to register a MockHandler instead of the actual Camel Implementation.

       

      I've tried to do this by unregistering (SwitchYardTestKit.removeService) the original service (SwitchYardTestKit.registerInOutService) and registering the MockHandler instead.

       

      I can see that in the service registry the camel service is removed and the new service that makes use of the MockHandler is added. The strange thing is that when I run the test the message is still going into the Camel Route.

       

      Is this behaviour normal?

       

      Thanks in advance!

       

      Luis

        • 2. Re: Registering a MockHandler for a Camel Service
          Luis del Toro Newbie

          Hi Keith!

           

          I've tried with the replaceService method and I'm still bumping into the same issue...

          • 3. Re: Registering a MockHandler for a Camel Service
            Keith Babo Master

            Hmm ... works fine for me.   To test, I took the camel-service quickstart and added a test method which replaces the JavaDSL service with a MockHandler:

             

            @Test

            public void testCamelRoute2() {

               MockHandler handler = testKit.replaceService("JavaDSL");

                // write file here so file binding picks it up after service provider is replaced

               Assert.assertEquals(1, handler.waitForOKMessage().getMessages().size());

            }

             

            Can you provide the source for the test class and your switchyard.xml?

            • 4. Re: Registering a MockHandler for a Camel Service
              Luis del Toro Newbie

              Hi Keith,

               

              after some investigation I was able to pinpoint the problem and reproduce it in the quickstart. Basically in seem to be due to the promoted service that holds the rest binding having a different name than the actual service:

               

              This does not work:

               

              <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
                  xmlns:file="urn:switchyard-component-camel-file:config:1.0"
                  xmlns:swyd="urn:switchyard-config:switchyard:1.0">

               

                  <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="camel-service"
                      targetNamespace="urn:switchyard-quickstart:camel-service:0.1.0">
                      <service name="JavaDSLRest" promote="JavaDSLBuilder/JavaDSL">
                          <rest:binding.rest xmlns:rest="urn:switchyard-component-resteasy:config:1.0">
                              <rest:interfaces>org.switchyard.quickstarts.camel.service.JavaDSL</rest:interfaces>
                              <rest:contextPath>rest-binding</rest:contextPath>
                          </rest:binding.rest>
                      </service>
                      <component name="JavaDSLBuilder">
                          <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                              <java class="org.switchyard.quickstarts.camel.service.JavaDSLBuilder"/>
                          </implementation.camel>
                          <service name="JavaDSL">
                              <interface.java interface="org.switchyard.quickstarts.camel.service.JavaDSL"/>
                          </service>
                          <reference name="XMLService">
                              <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                          </reference>
                      </component>
                      <component name="XMLComponent">
                          <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                              <xml path="META-INF/route.xml"/>
                          </implementation.camel>
                          <service name="XMLService">
                              <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                          </service>
                      </component>
                  </composite>
              </switchyard>

               

              Although this does work:

               

              <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
                  xmlns:file="urn:switchyard-component-camel-file:config:1.0"
                  xmlns:swyd="urn:switchyard-config:switchyard:1.0">

               

                  <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="camel-service"
                      targetNamespace="urn:switchyard-quickstart:camel-service:0.1.0">
                      <service name="JavaDSL" promote="JavaDSLBuilder/JavaDSL">
                          <rest:binding.rest xmlns:rest="urn:switchyard-component-resteasy:config:1.0">
                              <rest:interfaces>org.switchyard.quickstarts.camel.service.JavaDSL</rest:interfaces>
                              <rest:contextPath>rest-binding</rest:contextPath>
                          </rest:binding.rest>
                      </service>
                      <component name="JavaDSLBuilder">
                          <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                              <java class="org.switchyard.quickstarts.camel.service.JavaDSLBuilder"/>
                          </implementation.camel>
                          <service name="JavaDSL">
                              <interface.java interface="org.switchyard.quickstarts.camel.service.JavaDSL"/>
                          </service>
                          <reference name="XMLService">
                              <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                          </reference>
                      </component>
                      <component name="XMLComponent">
                          <implementation.camel xmlns="urn:switchyard-component-camel:config:1.0">
                              <xml path="META-INF/route.xml"/>
                          </implementation.camel>
                          <service name="XMLService">
                              <swyd:interface.esb xmlns:swyd="urn:switchyard-config:switchyard:1.0" inputType="java:java.lang.String"/>
                          </service>
                      </component>
                  </composite>
              </switchyard>

               

              I noticed that when the promoted service and the service have the same name there is just one service in the service registry. When they have different names, there are two.

               

              I still newbie in sca and switchyard matters so I would like to know if my approach is wrong and the promoted service should always have the same name as the service being promoted or if this is a bug.

               

              PS: Please find attached a modified version of the camel service quickstart that reproduces this behaviour.

              • 5. Re: Registering a MockHandler for a Camel Service
                Keith Babo Master

                I think this might be a skeleton in the deployment closet.  Can you try to replace *both* names like this:

                 

                MockHandler handler = testKit.replaceService("JavaDSL");
                MockHandler handler = testKit.replaceService("JavaDSLRest");
                

                 

                If that works, then just try this:

                 

                MockHandler handler = testKit.replaceService("JavaDSLRest");
                

                 

                thanks,

                keith

                • 6. Re: Registering a MockHandler for a Camel Service
                  Luis del Toro Newbie

                  Hi Keith,

                   

                  replacing the promoted service did trick!

                   

                  It still not clear to me if this is the normal behaviour or we are using just a workaround here...

                  • 8. Re: Registering a MockHandler for a Camel Service
                    Luis del Toro Newbie

                    I understand.

                     

                    Thanks for the explanation Keith!

                     

                    Regards,

                     

                    Luis