camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: How to get hold of the content of log:message
Date Fri, 11 Nov 2016 18:29:05 GMT
Maybe just test the mock endpoint gets a header with key EmailAddress
and the expected value.

The Camel log should work. You don't go around testing log4j or JDK
util classes etc.

Otherwise if you want to test log its a lot of pain to mock them with
mockito or powermock or something. Or you can configure logging to
save to a file, and then read the file and parse the log lines to find
that log line with the email header.

Frankly there are bigger fish to fry and test than a log message.

On Fri, Nov 11, 2016 at 6:17 PM, idioma <corda.ilaria@gmail.com> wrote:
> Hi,
> I have a route like this:
>
>        <camelContext xmlns="http://camel.apache.org/schema/spring">
>                 <route>
>                         <from uri="activemq:topic:inbox" />
>                         <log message="From: ${in.header.EmailAddress}" />
>                         <to uri="mock:result" />
>                 </route>
>         </camelContext>
>
> My initial test looks like this:
>
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @BootstrapWith(CamelTestContextBootstrapper.class)
> @ContextConfiguration(locations="file:src/main/resources/META-INF/spring/camel-context-activemq-embedded.xml")
> @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
> @MockEndpoints("log:*")
> @DisableJmx(false)
>
> public class MySpringXMLEmbeddedActiveMQTest{
>
>         private Logger LOG =
> LogManager.getLogger(MySpringXMLEmbeddedActiveMQTest.class.getName());
>
>         protected LogRecipientsProcessor processor = new LogRecipientsProcessor();
>         protected Exchange exchange;
>
>         @Produce(uri="activemq:topic:inbox")
>         protected ProducerTemplate template;
>
>         @EndpointInject(uri="mock:result")
>         protected MockEndpoint resultEndpoint;
>
>         @Test
>         public void testMockEndpoint() throws Exception {
>                 EmailAddress recipients = new EmailAddress("recipient@example.com");
>                 String header = "This is my header";
>                 template.sendBodyAndHeader("activemq:topic:inbox", recipients.toString(),
> header);
>                 assertNotNull(exchange.getIn().getBody());
>                 resultEndpoint.assertIsSatisfied();
>         }
> }
>
> I am using a mock as endpoint and sending the body and the header. (The body
> is my email address). I fail to see how I can test the logged message in
> <log message="From: ${in.header.EmailAddress}" />. Do I have to read the
> header from the exchange? Do I need to set the content of the log message
> beforehand? Any available example would be most welcomed.
>
> Thank you,
>
> I.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-get-hold-of-the-content-of-log-message-tp5790064.html
> Sent from the Camel Development mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Mime
View raw message