Clean up Apache Camel example
This commit is contained in:
parent
9d6f56c40a
commit
54a1235d17
|
@ -23,6 +23,6 @@ To build this application execute following maven command in ApacheCamelFileProc
|
||||||
|
|
||||||
<code>mvn clean install</code>
|
<code>mvn clean install</code>
|
||||||
|
|
||||||
To run this application you can either run our main class org.apache.camel.main.App from your IDE or you can execute following maven command:
|
To run this application you can either run our main class App from your IDE or you can execute following maven command:
|
||||||
|
|
||||||
<code>mvn exec:java -Dexec.mainClass="org.apache.camel.main.App"</code>
|
<code>mvn exec:java -Dexec.mainClass="App"</code>
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.camel.main;
|
package com.baeldung.camel.main;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.baeldung.camel.processor;
|
||||||
|
|
||||||
|
import org.apache.camel.Exchange;
|
||||||
|
import org.apache.camel.Processor;
|
||||||
|
|
||||||
|
public class FileProcessor implements Processor {
|
||||||
|
|
||||||
|
public void process(Exchange exchange) throws Exception {
|
||||||
|
String originalFileContent = exchange.getIn().getBody(String.class);
|
||||||
|
String upperCaseFileContent = originalFileContent.toUpperCase();
|
||||||
|
exchange.getIn().setBody(upperCaseFileContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
package org.apache.camel.processor;
|
|
||||||
|
|
||||||
import org.apache.camel.Exchange;
|
|
||||||
import org.apache.camel.Processor;
|
|
||||||
|
|
||||||
public class FileProcessor implements Processor {
|
|
||||||
|
|
||||||
public void process(Exchange exchange) throws Exception {
|
|
||||||
String originalFileContent = exchange.getIn().getBody(String.class);
|
|
||||||
String upperCaseFileContent = originalFileContent.toUpperCase();
|
|
||||||
exchange.getIn().setBody(upperCaseFileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -9,13 +9,13 @@
|
||||||
<route customId="true" id="route1">
|
<route customId="true" id="route1">
|
||||||
|
|
||||||
<!-- Read files from input directory -->
|
<!-- Read files from input directory -->
|
||||||
<from uri="file://src/test/data/input" />
|
<from uri="file://src/test/data/input"/>
|
||||||
|
|
||||||
<!-- Transform content to UpperCase -->
|
<!-- Transform content to UpperCase -->
|
||||||
<process ref="myFileProcessor" />
|
<process ref="myFileProcessor"/>
|
||||||
|
|
||||||
<!-- Write converted file content -->
|
<!-- Write converted file content -->
|
||||||
<to uri="file://src/test/data/outputUpperCase" />
|
<to uri="file://src/test/data/outputUpperCase"/>
|
||||||
|
|
||||||
<!-- Transform content to LowerCase -->
|
<!-- Transform content to LowerCase -->
|
||||||
<transform>
|
<transform>
|
||||||
|
@ -23,18 +23,17 @@
|
||||||
</transform>
|
</transform>
|
||||||
|
|
||||||
<!-- Write converted file content -->
|
<!-- Write converted file content -->
|
||||||
<to uri="file://src/test/data/outputLowerCase" />
|
<to uri="file://src/test/data/outputLowerCase"/>
|
||||||
|
|
||||||
<!-- Display process completion message on console -->
|
<!-- Display process completion message on console -->
|
||||||
<transform>
|
<transform>
|
||||||
<simple> .......... File content conversion completed ..........
|
<simple>.......... File content conversion completed ..........</simple>
|
||||||
</simple>
|
|
||||||
</transform>
|
</transform>
|
||||||
<to uri="stream:out" />
|
<to uri="stream:out"/>
|
||||||
|
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
</camelContext>
|
</camelContext>
|
||||||
|
|
||||||
<bean id="myFileProcessor" class="org.apache.camel.processor.FileProcessor" />
|
<bean id="myFileProcessor" class="com.baeldung.camel.processor.FileProcessor"/>
|
||||||
</beans>
|
</beans>
|
|
@ -1 +1 @@
|
||||||
THIS IS UPPERCASE CONTENT. this is lowercase content.
|
This is data that will be processed by a Camel route!
|
|
@ -1,5 +1,12 @@
|
||||||
package org.apache.camel.main;
|
package org.apache.camel.main;
|
||||||
|
|
||||||
|
import com.baeldung.camel.main.App;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.camel.util.FileUtil;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -8,19 +15,12 @@ import java.nio.channels.FileChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.camel.util.FileUtil;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class AppTest extends TestCase {
|
public class AppTest extends TestCase {
|
||||||
|
|
||||||
private static final String FILE_NAME = "file.txt";
|
private static final String FILE_NAME = "file.txt";
|
||||||
private static final String SAMPLE_INPUT_DIR = "src/test/data/sampleInputFile/";
|
private static final String SAMPLE_INPUT_DIR = "src/test/data/sampleInputFile/";
|
||||||
private static final String TEST_INPUT_DIR = "src/test/data/input/";
|
private static final String TEST_INPUT_DIR = "src/test/data/input/";
|
||||||
private static final String UPPERCARE_OUTPUT_DIR = "src/test/data/outputUpperCase/";
|
private static final String UPPERCASE_OUTPUT_DIR = "src/test/data/outputUpperCase/";
|
||||||
private static final String LOWERCASE_OUTPUT_DIR = "src/test/data/outputLowerCase/";
|
private static final String LOWERCASE_OUTPUT_DIR = "src/test/data/outputLowerCase/";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -34,20 +34,20 @@ public class AppTest extends TestCase {
|
||||||
System.out.println("Deleting the test input and output files...");
|
System.out.println("Deleting the test input and output files...");
|
||||||
deleteFile(TEST_INPUT_DIR);
|
deleteFile(TEST_INPUT_DIR);
|
||||||
deleteFile(LOWERCASE_OUTPUT_DIR);
|
deleteFile(LOWERCASE_OUTPUT_DIR);
|
||||||
deleteFile(UPPERCARE_OUTPUT_DIR);
|
deleteFile(UPPERCASE_OUTPUT_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void testMain() throws Exception {
|
public final void testMain() throws Exception {
|
||||||
App.main(null);
|
App.main(null);
|
||||||
|
|
||||||
String inputFileContent = readFileContent(SAMPLE_INPUT_DIR+FILE_NAME);
|
String inputFileContent = readFileContent(SAMPLE_INPUT_DIR + FILE_NAME);
|
||||||
String outputUpperCase = readFileContent(UPPERCARE_OUTPUT_DIR+FILE_NAME);
|
String outputUpperCase = readFileContent(UPPERCASE_OUTPUT_DIR + FILE_NAME);
|
||||||
String outputLowerCase = readFileContent(LOWERCASE_OUTPUT_DIR+FILE_NAME);
|
String outputLowerCase = readFileContent(LOWERCASE_OUTPUT_DIR + FILE_NAME);
|
||||||
|
|
||||||
System.out.println("Input File content = ["+inputFileContent+"]");
|
System.out.println("Input File content = [" + inputFileContent + "]");
|
||||||
System.out.println("UpperCaseOutput file content = ["+outputUpperCase+"]");
|
System.out.println("UpperCaseOutput file content = [" + outputUpperCase + "]");
|
||||||
System.out.println("LowerCaseOtput file content = ["+outputLowerCase+"]");
|
System.out.println("LowerCaseOtput file content = [" + outputLowerCase + "]");
|
||||||
|
|
||||||
assertEquals(inputFileContent.toUpperCase(), outputUpperCase);
|
assertEquals(inputFileContent.toUpperCase(), outputUpperCase);
|
||||||
assertEquals(inputFileContent.toLowerCase(), outputLowerCase);
|
assertEquals(inputFileContent.toLowerCase(), outputLowerCase);
|
||||||
|
@ -82,7 +82,7 @@ public class AppTest extends TestCase {
|
||||||
System.out.println("Creating input file = [" + TEST_INPUT_DIR + FILE_NAME + "]");
|
System.out.println("Creating input file = [" + TEST_INPUT_DIR + FILE_NAME + "]");
|
||||||
|
|
||||||
File destDir = new File(TEST_INPUT_DIR);
|
File destDir = new File(TEST_INPUT_DIR);
|
||||||
if(!destDir.exists()) {
|
if (!destDir.exists()) {
|
||||||
destDir.mkdir();
|
destDir.mkdir();
|
||||||
}
|
}
|
||||||
destFile.createNewFile();
|
destFile.createNewFile();
|
||||||
|
|
Loading…
Reference in New Issue