<commit_before>---
layout: post
title: Apache Camel Integration Testing - Part 3
---

In this post I will continue with the Apache Camel integration testing scenario that we have built up in
<a href="http://christophd.github.io/camel-testing-part-1/" title="Part 1" target="_blank">part one</a> and
<a href="http://christophd.github.io/camel-testing-part-2/" title="Part 2" target="_blank">part two</a> of this series.
This time we focus on exception handling in Camel routes. First of all let's add exception handling to our Camel route.

{% highlight xml %}
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
  <route id="helloRoute">
    <from uri="direct:hello"/>
    <to uri="seda:sayHello" pattern="InOut"/>
    <onException>
      <exception>com.consol.citrus.exceptions.CitrusRuntimeException</exception>
      <to uri="seda:errors"/>
    </onException>
  </route>
</camelContext>
{% endhighlight %}

Camel supports exception handling on specific exception types. The _onException_ route logic is executed when the defined exception type was raised
during message processing. In the sample route we call a separate Seda endpoint _seda:errors_ for further exception handling. The challenge for our
test scenario is obvious. We need to force this error handling and we need to make sure that the Seda endpoint _seda:errors_ has been called accordingly.

Let's add the error handling endpoint to the Citrus Spring bean configuration.

{% highlight xml %}
<citrus-camel:sync-endpoint id="sedaErrorHandlingEndpoint"
                       camel-context="camelContext"
                       endpoint-uri="seda:errors"/>
{% endhighlight %}
<commit_msg>Improved wording in camel-testing-part-3<commit_after>---
layout: post
title: Apache Camel Integration Testing - Part 3
---

In this post I will continue with the Apache Camel integration testing scenario that we have worked on in
<a href="http://christophd.github.io/camel-testing-part-1/" title="Part 1" target="_blank">part one</a> and
<a href="http://christophd.github.io/camel-testing-part-2/" title="Part 2" target="_blank">part two</a> of this series.
This time we focus on exception handling in Camel routes. First of all let's add exception handling to our Camel route.

{% highlight xml %}
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
  <route id="helloRoute">
    <from uri="direct:hello"/>
    <to uri="seda:sayHello" pattern="InOut"/>
    <onException>
      <exception>com.consol.citrus.exceptions.CitrusRuntimeException</exception>
      <to uri="seda:errors"/>
    </onException>
  </route>
</camelContext>
{% endhighlight %}

Camel supports exception handling on specific exception types. The _onException_ route logic is executed when the defined exception type was raised
during message processing. In the sample route we call a separate Seda endpoint _seda:errors_ for further exception handling. The challenge for our
test scenario is obvious. We need to force this error handling and we need to make sure that the Seda endpoint _seda:errors_ has been called accordingly.

Let's add the error handling endpoint to the Citrus Spring bean configuration.

{% highlight xml %}
<citrus-camel:sync-endpoint id="sedaErrorHandlingEndpoint"
                       camel-context="camelContext"
                       endpoint-uri="seda:errors"/>
{% endhighlight %}

{'fraction_non_alphanumeric': 0.10170990566037735, 'fraction_numerical': 0.003242924528301887, 'mean_word_length': 4.164383561643835, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '811001', 'n_tokens_mistral': 964, 'n_tokens_neox': 912, 'n_words': 351}