title: Required: Definitive Annotations and pom dependencies to test Apache Camel with Spring Boot and Java Config
body: <p>I'm going round in circles with this one.</p>
  <p>Because it uses Spring Test and Java Config, I copied the simple <code>FilterTest</code> example from <a href="https://camel.apache.org/manual/latest/testing.html" rel="nofollow noreferrer">here</a>, which worked OK as was.</p>
  <p>But as soon as I added an <code>@Autowired</code> field, I got an <code>UnsatisfiedDependencyException</code> [Unsatisfied dependency expressed through field ... No qualifying bean of type ... available].</p>
  <p>After fixing that I now get a <code>NullPointerException</code> on <code>resultEndpoint.expectedBodiesReceived(expectedBody);</code> in the first <code>@Test</code> method. When this happens, there is absolutely no output in the console, so evidently Spring hasn't even started.</p>
  <p>Here's the slightly modified test class:</p>
  <pre><code>package org.apache.camel.spring.javaconfig.patterns;
  
  import org.apache.camel.EndpointInject;
  import org.apache.camel.Produce;
  import org.apache.camel.ProducerTemplate;
  import org.apache.camel.builder.RouteBuilder;
  import org.apache.camel.component.mock.MockEndpoint;
  import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
  import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
  import org.junit.Test;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.test.annotation.DirtiesContext;
  import org.springframework.test.annotation.DirtiesContext.ClassMode;
  import org.springframework.test.context.ContextConfiguration;
  
  import c10y.camel.converter.QbInvoiceConverter;
  
  /**
   * Tests filtering using Spring Test and Java Config
   * page: https://camel.apache.org/manual/latest/testing.html
   * code: https://github.com/apache/camel/blob/master/core/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java
   */
  @CamelSpringBootTest
  @ContextConfiguration
  @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
  public class FilterTest {
  
      @EndpointInject(&quot;mock:result&quot;)
      protected MockEndpoint resultEndpoint;
  
      @Produce(&quot;direct:start&quot;)
      protected ProducerTemplate template;
  
      @Autowired
      private QbInvoiceConverter converter;
  
      @Test
      public void testSendMatchingMessage() throws Exception {
          String expectedBody = &quot;&lt;matched/&gt;&quot;;
  
          resultEndpoint.expectedBodiesReceived(expectedBody);
  
          template.sendBodyAndHeader(expectedBody, &quot;foo&quot;, &quot;bar&quot;);
  
          resultEndpoint.assertIsSatisfied();
      }
  
      @Test
      public void testSendNotMatchingMessage() throws Exception {
          resultEndpoint.expectedMessageCount(0);
  
          template.sendBodyAndHeader(&quot;&lt;notMatched/&gt;&quot;, &quot;foo&quot;, &quot;notMatchedHeaderValue&quot;);
  
          resultEndpoint.assertIsSatisfied();
      }
  
      @Configuration
      public static class ContextConfig extends SingleRouteCamelConfiguration {
          @Bean
          public RouteBuilder route() {
              return new RouteBuilder() {
                  public void configure() {
                      from(&quot;direct:start&quot;)
                          .filter(header(&quot;foo&quot;)
                          .isEqualTo(&quot;bar&quot;))
                          .to(&quot;mock:result&quot;)
                      ;
                  }
              };
          }
      }
  }
  </code></pre>
  <p>I have tried to bring this up to date with the migration instructions <a href="https://camel.apache.org/components/3.4.x/others/test-spring-junit5.html#_using_the_camelspringtest_annotation" rel="nofollow noreferrer">here</a>. Briefly, this states:</p>
  <ul>
  <li>Migration steps linked to JUnit 5 support in Camel Test itself should have been applied first</li>
  <li>Imports of org.apache.camel.test.spring.* should be replaced with org.apache.camel.test.spring.junit5.*</li>
  <li>Usage of @RunWith(CamelSpringRunner.class) should be replaced with @CamelSpringTest</li>
  <li>Usage of @BootstrapWith(CamelTestContextBootstrapper.class) should be replaced with @CamelSpringTest</li>
  <li>Usage of @RunWith(CamelSpringBootRunner.class) should be replaced with @CamelSpringBootTest</li>
  </ul>
  <p>The other part of my question relates to having the correct dependencies in <code>pom.xml</code>. I'm learning Camel from <strong>Camel in Action E2</strong>, so my pom has test dependencies from the book as well as others I have picked up on the way; so there may be clashes or incompatibilities in there:</p>
  <pre><code>&lt;!-- from .../camel-in-action-2/chapter9/spring-boot-test-one-route/pom.xml --&gt;
  &lt;!-- test --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
      &lt;artifactId&gt;camel-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;!-- testing --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
      &lt;artifactId&gt;camel-test-spring&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  
  &lt;!-- from elsewhere --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
      &lt;artifactId&gt;camel-test-spring-junit5&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>I'm using Apache Camel 3.4.0 LTS and Spring Boot 2.3.0.RELEASE.</p>
  <p>As the title to this question states, I'd really like to have the definitive annotation and pom configuration to allow me to simply get on with creating test routes to unit test my Components, Converters, and so forth [without tearing my hair out!].</p>
  <p>PS: What's the difference between <code>org.junit.Test</code> and <code>org.junit.jupiter.api.Test</code> annotations, and when should you use one over the other?</p>