apache-camelcitrus-framework

How do I use camel endpoints to manage files?


I have an application that reads files in a folder, changes its content and writes it back in another folder. I'm trying to add integration tests with Citrus to write a file in the first folder with some content and check the altered content in the second folder once the application modified it.

My question is very similar to this one where the reply says to use a Camel route but I'm fairly new with those concepts and do not know where to really start...

I don't really understand the <camelContext> tag and how it works. I wrote what is following so far, which is where I just try to write in a file:

<citrus-camel:endpoint id="inputCamelEndpoint" camel-contxt="inputCamelContext" endpoint-uri="file://C:/HL7/source/?fileName=test.hl7"/>

<camelContext id="inputCamelContext" xmlns="http://camel.apache.org/schema/spring">
    <route id="inputRoute">
        <to uri="file://C:/HL7/source/?fileName=test.hl7"/>
    </route>
</camelContext>

<send endpoint="inputCamelEndpoint">
    <message type="plaintext">
        <data>Hello!</data>
    </message>
</send>

What should I write for <from uri="">? And also, is the xmlns attribut of camelContext broken? I have this error.

I really hope someone can give me some details about all of this, I'm quite lost.


Solution

  • Welcome to Stackoverflow! I haven't heard of Citrus framework before encountering this question but I know a wee bit of Camel and shall try to help you here with a personalized Camel 101, to get you going.

    First things first

    In your case, as far as I understand, you need a Route that can receive a message from Citrus framework and store it to disk, so that your System Under Test can process this file. To interpret this use case as a route definition, in Camel's XML DSL.

    
    <camelContext id="inputCamelContext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://camel.apache.org/schema/spring"
            xsi:schemaLocation="
                http://camel.apache.org/schema/spring
                http://camel.apache.org/schema/spring/camel-spring.xsd">
      <route id="inputRoute">
        <from uri="direct:citrusConsumer" />
        <to uri="file://C:/HL7/source/?fileName=test.hl7" />
      </route>
    <camelContext/>
    

    direct: URI represents a synchronous Consumer endpoint [Docs on direct component]. What this example route does is, take whatever input message arriving at the consumer(direct:direct:citrusConsumer) and write it to a file, with name test.hl7 in the directory C:/HL7/source/. If you want to get fancy here, please read additional options for the File component. Citrus-Camel integration docs also show usage of a direct: component named direct:news. Once the Route in the example code above Route is ready, Citrus can send a message to direct:citrusConsumer to talk to Camel.

    Reusing your sample code, the integration would be like the snippet below (Note the change to endpoint-uri)

    <citrus-camel:endpoint id="inputCamelEndpoint" camel-contxt="inputCamelContext" endpoint-uri="direct:citrusConsumer"/>
    

    I hope this helps you to get ahead.