forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* - changed test package name from org.baeldung to com.baeldung - streams are added where neccessary - format fixes * Adding Java config for Content Based File Router * Adding Java config for Content Based File Router
- Loading branch information
Showing
4 changed files
with
157 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...-apache-camel/src/main/java/com/baeldung/camel/file/cfg/ContentBasedFileRouterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.baeldung.camel.file.cfg; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.spring.javaconfig.CamelConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.baeldung.camel.file.ContentBasedFileRouter; | ||
|
||
@Configuration | ||
public class ContentBasedFileRouterConfig extends CamelConfiguration { | ||
|
||
@Bean | ||
ContentBasedFileRouter getContentBasedFileRouter() { | ||
return new ContentBasedFileRouter(); | ||
} | ||
|
||
@Override | ||
public List<RouteBuilder> routes() { | ||
return Arrays.asList(getContentBasedFileRouter()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
spring-apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.apache.camel.file.processor; | ||
|
||
import java.io.File; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
import com.baeldung.camel.file.FileProcessor; | ||
|
||
|
||
public class FileProcessorTest { | ||
|
||
private static final long DURATION_MILIS = 10000; | ||
private static final String SOURCE_FOLDER = "src/test/source-folder"; | ||
private static final String DESTINATION_FOLDER = "src/test/destination-folder"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
File sourceFolder = new File(SOURCE_FOLDER); | ||
File destinationFolder = new File(DESTINATION_FOLDER); | ||
|
||
cleanFolder(sourceFolder); | ||
cleanFolder(destinationFolder); | ||
|
||
sourceFolder.mkdirs(); | ||
File file1 = new File(SOURCE_FOLDER + "/File1.txt"); | ||
File file2 = new File(SOURCE_FOLDER + "/File2.txt"); | ||
file1.createNewFile(); | ||
file2.createNewFile(); | ||
} | ||
|
||
private void cleanFolder(File folder) { | ||
File[] files = folder.listFiles(); | ||
if (files != null) { | ||
for (File file : files) { | ||
if (file.isFile()) { | ||
file.delete(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void moveFolderContentJavaDSLTest() throws Exception { | ||
final CamelContext camelContext = new DefaultCamelContext(); | ||
camelContext.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER); | ||
} | ||
}); | ||
camelContext.start(); | ||
Thread.sleep(DURATION_MILIS); | ||
camelContext.stop(); | ||
} | ||
|
||
@Test | ||
public void moveFolderContentSpringDSLTest() throws InterruptedException { | ||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); | ||
Thread.sleep(DURATION_MILIS); | ||
applicationContext.close(); | ||
|
||
} | ||
} |