Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Camel context customisation

You may need to customise your Camel contexts for testing purpose, for example disabling JMX management to avoid TCP port allocation conflict. You can do that by declaring a custom Camel context bean in your test class, e.g.:

Code Block
languagejava
@RunWith(CamelCdiRunner.class)
public class CamelCdiTest {
 
    @Default
    @ContextName("camel-test-cdi")
    @ApplicationScoped
    static class CustomCamelContext extends DefaultCamelContext {

        @PostConstruct
        void customize() {
            disableJMX();
        }
    }
}

In that example, the custom Camel context bean declared in the test class will be used during the test execution instead of the default Camel context bean provided by the Camel CDI component.

JUnit rules

Camel CDI test starts the CDI container after all the JUnit class rules have executed.

...

Another use case is to assert the behaviour of your application after it has shutdown. In that case, you can use the Verifier rule, e.g.:

Code Block
languagejava
import org.junit.rules.Verifier;
 
@RunWith(CamelCdiRunner.class)
public class CamelCdiTest {
 
    @ClassRule
    public static Verifier verifier = new Verifier() {
 
        @Override
        protected void verify() {
            // Executes after the CDI container has shutdown
        }
    };
}

...