Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-15401

Improve website documentation on testing with SpringBoot & JUnit5

    XMLWordPrintableJSON

Details

    • Task
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.4.2
    • None
    • None
    • Spring Boot 2.3.2, JUnit5 that comes with the former, Java 11, Maven 3.6

       

    • Unknown

    Description

      When searching online for strategies to test a fragment of a Camel route with JUnit5 in the context of a Spring Boot application, the returned documentation seems somewhat outdated (favouring xml instead of java config for both Spring and Camel related aspects) and missing a major point.

      Some top google hits for "apache camel test spring boot" are:

      • https://camel.apache.org/manual/latest/testing.html 
        One (at least me) gets drawn to the "Spring Test With Java Config" example. When rebuilding from that example in a SpringBoot app, it won't ever work because the ProducerTemplate and MockEndpoint instances remain null.
        I happened to have an old working example of a project built with Camel v2.20 which had the annotation @ContextConfiguration(loader = CamelSpringDelegatingTestContextLoader.class). Adding that (and a dependency on camel-test-spring on top of camel-test-spring-junit5) made the injections work but caused an NPE at org.apache.camel.test.spring.CamelAnnotationsHandler.handleDisableJmx(CamelAnnotationsHandler.java:90) which gets fixed by adding a static method that sets a dummy test class in CamelSpringTestHelper.
        After asking for assistance on gitter it was suggested to try to annotate the test class with @CamelSpring*Boot*Test instead of @CamelSpringTest as the example showed. As always with annotations: that "magically" solved all issues. There was no way I could have known it existed.
      • https://camel.apache.org/manual/latest/spring-testing.html
        Using CamelSpringTestSupport and rolling your own implementation of an AbstractApplicationContext does not sound very attractive.
        The list of examples goes further with "Plain Spring tests" but only supported by JUnit4. It is uncertain whether this has any chance to work with JUnit5.
      • https://camel.apache.org/components/latest/others/test-spring.html 
        As already stated on the page: old and needs updating. Won't comment further. This looks like the original example I built my Camel v2.20 project with, using the  CamelSpringDelegatingTestContextLoader
      • https://camel.apache.org/components/latest/others/test-spring-junit5.html 
        It first suggests to extend CamelSpringTestSupport, but writing only my test config in xml does not sound appealing.
        Next comes an example again using @CamelSpringTest which has identical issues as brought up in my first bullet.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bertkoor Bert Koorengevel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: