You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2022/09/02 15:52:00 UTC
[jira] [Commented] (CAMEL-15401) Improve website documentation on testing with SpringBoot & JUnit5
[ https://issues.apache.org/jira/browse/CAMEL-15401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17599579#comment-17599579 ]
Claus Ibsen commented on CAMEL-15401:
-------------------------------------
Community users is welcome to help with this
> Improve website documentation on testing with SpringBoot & JUnit5
> -----------------------------------------------------------------
>
> Key: CAMEL-15401
> URL: https://issues.apache.org/jira/browse/CAMEL-15401
> Project: Camel
> Issue Type: Task
> Components: camel-spring-boot, camel-test
> Affects Versions: 3.4.2
> Environment: Spring Boot 2.3.2, JUnit5 that comes with the former, Java 11, Maven 3.6
>
> Reporter: Bert Koorengevel
> Priority: Minor
>
> 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)