title: CamelTestSupport with routes using classes with @Autowired
body: <p>After help from experts over at question <em><a href="https://stackoverflow.com/questions/49118176/camel-unit-test-with-cametestsupport-template-is-always-null">Camel unit test with cametestsupport, template is always null</a></em>, I ended up with one more issue.</p>
  <p>Below is my test class - a simple test that tests a route which has only ValidationProcessor <a href="https://en.wikipedia.org/wiki/Plain_old_Java_object" rel="nofollow noreferrer">POJO</a>.</p>
  <pre class="lang-java prettyprint-override"><code>public class RouteTests extends CamelTestSupport {
  
      @Override
      protected RouteBuilder createRouteBuilder() {
          return new RouteBuilder() {
              @Override
              public void configure() {
                  from(&quot;direct:start&quot;)
                          .filter().method(ValidationProcessor.class, &quot;validate&quot;)
                          .to(&quot;mock:result&quot;);
              }
          };
      }
  
      @Test
      public void testSendMatchingMessage() throws Exception {
          ObjectMapper objectmapper = new ObjectMapper();
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
          InputStream stream = loader.getResourceAsStream(&quot;test.json&quot;);
          JSONObject testJson = new JSONObject(objectmapper.readValue(stream, Map.class));
  
          MockEndpoint resultEndpoint = getMockEndpoint(&quot;mock:result&quot;);
          resultEndpoint.expectedMessageCount(1);
          template.sendBody(&quot;direct:start&quot;, testJson);
          resultEndpoint.assertIsSatisfied();
      }
  }
  </code></pre>
  <p>The problem comes when this ValidationProcessor has an <code>@Autowired</code> component in it. My validation method needs data from Elasticsearch and hence I have an <code>@Autowired</code> for an elastic client.</p>
  <p>When I run <code>mvn clean test</code>, I am getting a <code>NullPointerException</code> stating that this elastic client is null. I think the issue is that this test is devoid of anything to do with Spring and hence the issue, but I do not know how to overcome this.</p>
  <p>My test needs to fetch data from Elasticsearch and hence the ValidationProcessor POJO does need <code>@Autowired</code>.</p>