6 Replies Latest reply on Dec 5, 2011 12:38 PM by Julian Cable

    unit testing camel-web projects

    Julian Cable Newbie

      Hi,

       

        I'm trying to add unit tests as described in the Book and the docs and I can't get anything working.

       

      My projects use the camel-archetype-webconsole artefact and are deployed in Tomcat6.

       

      To try to get my head round the testing I created a new project and added a test class. I've tried the test class skeletons from the spring-testing page and from the testing page. I can get them to compile and they get run when invoking the package goal but they always return errors.

       

      The first error is not being able to find the applicationContext.xml file. I can get past this. Then I get type converter not found or other errors.

       

      Is there a working example anywhere for the camel-archetype-web or camel-archetype-webconsole project layout, with the right dependencies in the pom and a running unit test of a route? A test of the sample routes created by the artefact would be fine to get me started.

       

      If the artefact could be updated to include a unit test, that would be ideal.

       

      Julian

        • 1. Re: unit testing camel-web projects
          Willem Jiang Master

          If you just want to test the camel route, you can use the support classes in camel-test module. It will be more easy to run and test.

          When you finished the test , you can put the camel route inside the camel-web.

           

          Willem

          • 2. Re: unit testing camel-web projects
            Julian Cable Newbie

            Hi Willem,

             

              thats a good idea to get me going. I'd like the tests to run as part of mvn package but I'm trying your idea first.

             

            I've done this:

             

            mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes   -DarchetypeArtifactId=camel-archetype-activemq  -DarchetypeVersion=2.9.0-RC1

             

            add

                 

            to the pom.xml

             

            add the attached java class to

             

            src/test/java/wsinteg/unittest/FirstTest.java

             

            run

             

            mvn camel:run and all is well

             

            run

             

            mvn test

             

            get the following error:

             

            main] BrokerService                  ERROR Failed to start ActiveMQ JMS Message Broker. Reason: javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker

            javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker

             

            Any ideas ?

             

            Julian

            • 3. Re: unit testing camel-web projects
              Willem Jiang Master

              Can you disable the JMX server in you spring configuration ?

              It looks like the JMS broker try to register to the JMX server before running the test.

              • 4. Re: unit testing camel-web projects
                Julian Cable Newbie

                Tried that, it wasn't the answer, but it helped me find it, thanks.

                 

                Now, if I have only one test it works. But the second test fails because it tried to create the broker again but the broker is still running from the first test.

                 

                Any ideas?

                 

                Julian

                • 5. Re: unit testing camel-web projects
                  Claus Ibsen Master

                  You should possible stop the broker in the tearDown method, so its properly shutdown between tests.

                  • 6. Re: unit testing camel-web projects
                    Julian Cable Newbie

                    Hi Claus,

                     

                      I've got everything working. The most recent problem is with testNG. The attached patch modifies an instance of the standard spring archetype to use a test class. I've also now got it working the way I wanted with a webconsole archetype.

                     

                    All the problems were detail ones. I do think it would be great to have sample tests in the sample archetypes.

                     

                    Thanks to Willem for really helpful ideas that got me going in the right direction

                     

                    Julian

                     

                    Edited by: julianc on Dec 5, 2011 5:36 PM