Skip to content

Commit

Permalink
Merge pull request #2 from markbrooks/master
Browse files Browse the repository at this point in the history
Updated for Camel 2.8 / Fuse IDE 2.1 + Added a Unit test using a Mock
  • Loading branch information
scranton committed Apr 24, 2012
2 parents dfa905e + 1ad5858 commit 197011e
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 214 deletions.
2 changes: 1 addition & 1 deletion NOTICE
@@ -1 +1 @@
Copyright 2011 FuseSource
Copyright 2012 FuseSource
21 changes: 21 additions & 0 deletions README.md
@@ -0,0 +1,21 @@
File Batch Splitter Camel Project
=================================

This project demonstrates how to consume files from the file system and split the content of the file into multiple messages using Apache Camel.

The sample implements the Splitter EIP (Enterprise Integration Pattern) which splits an incoming message into a series of outgoing messages. Each of the outgoing messages contains a piece of the original message.

A sample incoming message file 'batch1.xml' is located in src/data/inbox. When the route is run, the split result files will be located in target/data/outbox.

This project was created with FuseSource Camel IDE available at http://fusesource.com/products/fuse-ide-camel/ which gives you a nice visualization of your routes, the ability to drag and drop Apache Camel components to design and edit routes, and testing capabilities within the Eclipse IDE.

To build the project and execute the unit test, execute the following command:
> mvn clean install
To run the example project as a standalone Camel route, execute the following command:
> mvn camel:run
For more help see the Apache Camel documentation

http://camel.apache.org/splitter.html

22 changes: 0 additions & 22 deletions ReadMe.txt

This file was deleted.

29 changes: 20 additions & 9 deletions pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2011 FuseSource
~ Copyright 2012 FuseSource
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
<groupId>com.fusesource.byexample</groupId>
<artifactId>FileBatchSplitter</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.1</version>

<name>File Batch Splitter</name>

Expand All @@ -33,10 +33,8 @@
</organization>

<properties>
<camel-version>2.6.0-fuse-00-00</camel-version>
<log4j-version>1.2.16</log4j-version>
<jaxb-api-version>2.1</jaxb-api-version>
<jaxb-impl-version>2.1.13</jaxb-impl-version>
<camel-version>2.8.0-fuse-02-05</camel-version>
<slf4j-version>1.6.2</slf4j-version>
</properties>

<repositories>
Expand Down Expand Up @@ -79,9 +77,16 @@
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j-version}</version>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

Expand All @@ -98,6 +103,12 @@
<target>1.5</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</plugin>

<!-- allows the route to be ran via 'mvn camel:run' -->
<plugin>
Expand Down
36 changes: 23 additions & 13 deletions src/data/message1.xml → src/data/inbox/order1.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2011 FuseSource
~ Copyright 2012 FuseSource
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -14,15 +14,25 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<club>
<person user="marcelo">
<firstName>Marcelo</firstName>
<lastName>Jabali</lastName>
<city>San Diego</city>
</person>
<person user="scott">
<firstName>Scott</firstName>
<lastName>Cranton</lastName>
<city>Boston</city>
</person>
</club>
<order>
<item id="item1">
<name>Telecaster</name>
<mfg>Fender</mfg>
</item>
<item id="item2">
<name>Stratocaster</name>
<mfg>Fender</mfg>
</item>
<item id="item3">
<name>Jazzmaster</name>
<mfg>Gibson</mfg>
</item>
<item id="item4">
<name>Explorer</name>
<mfg>Gibson</mfg>
</item>
<item id="item5">
<name>Flying V</name>
<mfg>Gibson</mfg>
</item>
</order>
17 changes: 10 additions & 7 deletions src/main/resources/META-INF/spring/camel-context.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
~ Copyright 2011 FuseSource
~ Copyright 2012 FuseSource
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -12,14 +12,17 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--><!-- Configures the Camel Context--><beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
--><!-- Configures the Camel Context--><beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true"/>
<split timeout="0">
<language language="xpath">/club/person</language>
<to uri="file:target/output?fileName=${date:now:yyyyMMddHHmmssSSSSS}.xml"/>
<route id="FileBatchSplitterRoute">
<from uri="file:src/data/inbox?noop=true"/>
<split id="LineItemSplitter" parallelProcessing="true" timeout="0">
<xpath>/order/item</xpath>
<setHeader headerName="LineItemId" id="SetLineItemFileName">
<xpath>/item/@id</xpath>
</setHeader>
<to id="LineItemOutbox" uri="file:target/data/outbox?fileName=${in.header.LineItemId}-${date:now:yyyyMMddHHmmssSSSSS}.xml"/>
</split>
</route>
</camelContext>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.properties
@@ -1,5 +1,5 @@
#
# Copyright 2011 FuseSource
# Copyright 2012 FuseSource
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
@@ -0,0 +1,71 @@
/*
* Copyright 2012 FuseSource
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fusesource.byexample.filebatchsplitter;

import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public final class CamelContextXmlTest extends CamelSpringTestSupport {

private static final int EXPECTED_NUMBER_OF_LINE_ITEMS = 5;

private static final String OUTBOX_DIR = "target/data/outbox";

/**
* This test relies on the batch file 'order1.xml' in the src/data/inbox dir
* which includes five line items. The Camel route under test should create
* one file per line item in the target/data/outbox dir.
*/
@Test
public void testCamelRoute() throws Exception {

// Mock the file endpoints
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {

mockEndpoints("file*");

}
});

// make sure we get the right number of line items
getMockEndpoint("mock:file:" + OUTBOX_DIR).expectedMessageCount(EXPECTED_NUMBER_OF_LINE_ITEMS);

assertMockEndpointsSatisfied();
}

@Override
public void setUp() throws Exception {
super.setUp();
deleteDirectory(OUTBOX_DIR);
createDirectory(OUTBOX_DIR);
}

@Override
public void tearDown() throws Exception {
super.tearDown();
deleteDirectory(OUTBOX_DIR);
}

@Override
protected ClassPathXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
}
}
Binary file removed target/FileBatchSplitter-0.0.1-SNAPSHOT.jar
Binary file not shown.
28 changes: 0 additions & 28 deletions target/classes/META-INF/spring/camel-context.xml

This file was deleted.

38 changes: 0 additions & 38 deletions target/classes/log4j.properties

This file was deleted.

5 changes: 0 additions & 5 deletions target/maven-archiver/pom.properties

This file was deleted.

40 changes: 0 additions & 40 deletions target/surefire/surefire1627486410163278663tmp

This file was deleted.

0 comments on commit 197011e

Please sign in to comment.