5 Replies Latest reply on Jul 19, 2012 11:27 PM by murray.hughes

    NullPointerException on unit test advice due to wrong blueprint context.




      Have a unit test using CamelBlueprintTestSupport, attempting to advise amq endpoints with mock/direct endpoints.


           public void setUp() throws Exception {


                System.err.println("context=" + context.getRouteDefinitions());


                new AdviceWithRouteBuilder() {


                     public void configure() throws Exception {





      I found that context.getRouteDefinition(route) was returning null.

      Further investigation showed that CamelBlueprintTestSupport.context refered to the wrong context.


      I had used this in the unit test.

          protected String getBlueprintDescriptor() {

              return "/OSGI-INF/blueprint/blueprint.xml";


      Changing the xml file name didn't avoid the problem.


      It appears that the root cause is that CamelBluePrintHelper.getOsgiService is getting called without a filter.

      I attempted to add this to my unit test:


           protected String getBundleFilter() {

                return "(Bundle-SymbolicName = MyTest)";


      I tried the Unit test class name (MyTest) because that appeared in the debug log.

      but obvously that's not right because when I tried this it found no context.


      The only workaround I found that worked was to move the maven dependency of the offending context to the end of the dependencies.


      A possible enhancement is to CamelBlueprintTestSupport is to pass CamelBluePrintHelper.getOsgiService a filter by default to ensure the correct context is selected.


      It would be good to know what to return from getBundleFilter() to ensure my unit test's context is selected?