JAVA-15787 Created new messaging-modules and saas-modules
- Moved jgroups, rabbitmq, spring-amqp, spring-apache-camel, spring-jms to messaging-modules - Moved twilio, twitter4j, strip to saas-modules - Renamed existing saas to jira-rest-integration
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class ContentBasedFileRouter extends RouteBuilder {
|
||||
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER_TXT = "src/test/destination-folder-txt";
|
||||
private static final String DESTINATION_FOLDER_OTHER = "src/test/destination-folder-other";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").choice().when(simple("${file:ext} == 'txt'")).to("file://" + DESTINATION_FOLDER_TXT).otherwise().to("file://" + DESTINATION_FOLDER_OTHER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.LoggingLevel;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class DeadLetterChannelFileRouter extends RouteBuilder {
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
errorHandler(deadLetterChannel("log:dead?level=ERROR").maximumRedeliveries(3)
|
||||
.redeliveryDelay(1000).retryAttemptedLogLevel(LoggingLevel.ERROR));
|
||||
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").process((exchange) -> {
|
||||
throw new IllegalArgumentException("Exception thrown!");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class FileProcessor implements Processor {
|
||||
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
|
||||
|
||||
Date date = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
String changedFileName = dateFormat.format(date) + originalFileName;
|
||||
exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class FileRouter extends RouteBuilder {
|
||||
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class MessageTranslatorFileRouter extends RouteBuilder {
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").transform(body().append(header(Exchange.FILE_NAME))).to("file://" + DESTINATION_FOLDER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class MulticastFileRouter extends RouteBuilder {
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER_WORLD = "src/test/destination-folder-world";
|
||||
private static final String DESTINATION_FOLDER_HELLO = "src/test/destination-folder-hello";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").multicast().to("direct:append", "direct:prepend").end();
|
||||
|
||||
from("direct:append").transform(body().append("World")).to("file://" + DESTINATION_FOLDER_WORLD);
|
||||
|
||||
from("direct:prepend").transform(body().prepend("Hello")).to("file://" + DESTINATION_FOLDER_HELLO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.camel.file;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
||||
public class SplitterFileRouter extends RouteBuilder {
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER = "src/test/destination-folder";
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("file://" + SOURCE_FOLDER + "?delete=true").split(body().convertToString().tokenize("\n")).setHeader(Exchange.FILE_NAME, body()).to("file://" + DESTINATION_FOLDER);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
|
||||
public class Fruit {
|
||||
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FruitList {
|
||||
|
||||
private List<Fruit> fruits;
|
||||
|
||||
public List<Fruit> getFruits() {
|
||||
return fruits;
|
||||
}
|
||||
|
||||
public void setFruits(List<Fruit> fruits) {
|
||||
this.fruits = fruits;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.camel.main;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class App {
|
||||
public static void main(final String[] args) throws Exception {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context.xml");
|
||||
// Keep main thread alive for some time to let application finish processing the input files.
|
||||
Thread.sleep(5000);
|
||||
applicationContext.close();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="contentBasedFileRouter" class="com.baeldung.camel.file.ContentBasedFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="contentBasedFileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="deadLetterChannelFileRouter" class="com.baeldung.camel.file.DeadLetterChannelFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="deadLetterChannelFileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="messageTranslatorFileRouter" class="com.baeldung.camel.file.MessageTranslatorFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="messageTranslatorFileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="multicastFileRouter" class="com.baeldung.camel.file.MulticastFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="multicastFileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="splitterFileRouter" class="com.baeldung.camel.file.SplitterFileRouter" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="splitterFileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="fileRouter" class="com.baeldung.camel.file.FileRouter" />
|
||||
<bean id="fileProcessor" class="com.baeldung.camel.file.FileProcessor" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="fileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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-3.1.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 customId="true" id="route1">
|
||||
|
||||
<!-- Read files from input directory -->
|
||||
<from uri="file://src/test/data/input" />
|
||||
|
||||
<!-- Transform content to UpperCase -->
|
||||
<process ref="myFileProcessor" />
|
||||
|
||||
<!-- Write converted file content -->
|
||||
<to uri="file://src/test/data/outputUpperCase" />
|
||||
|
||||
<!-- Transform content to LowerCase -->
|
||||
<transform>
|
||||
<simple>${body.toLowerCase()}</simple>
|
||||
</transform>
|
||||
|
||||
<!-- Write converted file content -->
|
||||
<to uri="file://src/test/data/outputLowerCase" />
|
||||
|
||||
<!-- Display process completion message on console -->
|
||||
<transform>
|
||||
<simple>.......... File content conversion completed ..........</simple>
|
||||
</transform>
|
||||
<to uri="stream:out" />
|
||||
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
||||
<bean id="myFileProcessor" class="com.baeldung.camel.processor.FileProcessor" />
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1 @@
|
||||
This is data that will be processed by a Camel route!
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.apache.camel.file.processor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.baeldung.camel.file.cfg.ContentBasedFileRouterConfig;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ContentBasedFileRouterIntegrationTest {
|
||||
|
||||
private static final long DURATION_MILIS = 10000;
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER_TXT = "src/test/destination-folder-txt";
|
||||
private static final String DESTINATION_FOLDER_OTHER = "src/test/destination-folder-other";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
File sourceFolder = new File(SOURCE_FOLDER);
|
||||
File destinationFolderTxt = new File(DESTINATION_FOLDER_TXT);
|
||||
File destinationFolderOther = new File(DESTINATION_FOLDER_OTHER);
|
||||
|
||||
cleanFolder(sourceFolder);
|
||||
cleanFolder(destinationFolderTxt);
|
||||
cleanFolder(destinationFolderOther);
|
||||
|
||||
sourceFolder.mkdirs();
|
||||
File file1 = new File(SOURCE_FOLDER + "/File1.txt");
|
||||
File file2 = new File(SOURCE_FOLDER + "/File2.csv");
|
||||
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
|
||||
@Ignore
|
||||
public void routeWithXMLConfigTest() throws InterruptedException {
|
||||
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"camel-context-ContentBasedFileRouterTest.xml");
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void routeWithJavaConfigTest() throws InterruptedException {
|
||||
AbstractApplicationContext applicationContext = new AnnotationConfigApplicationContext(
|
||||
ContentBasedFileRouterConfig.class);
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.apache.camel.file.processor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class DeadLetterChannelFileRouterIntegrationTest {
|
||||
|
||||
private static final long DURATION_MILIS = 10000;
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
File sourceFolder = new File(SOURCE_FOLDER);
|
||||
|
||||
cleanFolder(sourceFolder);
|
||||
|
||||
sourceFolder.mkdirs();
|
||||
File file = new File(SOURCE_FOLDER + "/File.txt");
|
||||
file.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 routeTest() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-DeadLetterChannelFileRouter.xml");
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 FileProcessorIntegrationTest {
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.apache.camel.file.processor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class MessageTranslatorFileRouterIntegrationTest {
|
||||
|
||||
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
|
||||
@Ignore
|
||||
public void routeTest() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-MessageTranslatorFileRouterTest.xml");
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.apache.camel.file.processor;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class MulticastFileRouterIntegrationTest {
|
||||
|
||||
private static final long DURATION_MILIS = 10000;
|
||||
private static final String SOURCE_FOLDER = "src/test/source-folder";
|
||||
private static final String DESTINATION_FOLDER_WORLD = "src/test/destination-folder-world";
|
||||
private static final String DESTINATION_FOLDER_HELLO = "src/test/destination-folder-hello";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
File sourceFolder = new File(SOURCE_FOLDER);
|
||||
File destinationFolderWorld = new File(DESTINATION_FOLDER_WORLD);
|
||||
File destinationFolderHello = new File(DESTINATION_FOLDER_HELLO);
|
||||
|
||||
cleanFolder(sourceFolder);
|
||||
cleanFolder(destinationFolderWorld);
|
||||
cleanFolder(destinationFolderHello);
|
||||
|
||||
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
|
||||
@Ignore
|
||||
public void routeTest() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-MulticastFileRouterTest.xml");
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.apache.camel.file.processor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class SplitterFileRouterIntegrationTest {
|
||||
|
||||
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 file = new File(SOURCE_FOLDER + "/File.txt");
|
||||
FileWriter fileWriter = new FileWriter(file, false);
|
||||
fileWriter.write("Hello\nWorld");
|
||||
file.createNewFile();
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
private void cleanFolder(File folder) {
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void routeTests() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-SplitterFileRouter.xml");
|
||||
Thread.sleep(DURATION_MILIS);
|
||||
applicationContext.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.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.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class AppIntegrationTest extends TestCase {
|
||||
|
||||
private static final String FILE_NAME = "file.txt";
|
||||
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 UPPERCASE_OUTPUT_DIR = "src/test/data/outputUpperCase/";
|
||||
private static final String LOWERCASE_OUTPUT_DIR = "src/test/data/outputLowerCase/";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Prepare input file for test
|
||||
copySampleFileToInputDirectory();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.out.println("Deleting the test input and output files...");
|
||||
deleteFile(TEST_INPUT_DIR);
|
||||
deleteFile(LOWERCASE_OUTPUT_DIR);
|
||||
deleteFile(UPPERCASE_OUTPUT_DIR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testMain() throws Exception {
|
||||
App.main(null);
|
||||
|
||||
String inputFileContent = readFileContent(SAMPLE_INPUT_DIR + FILE_NAME);
|
||||
String outputUpperCase = readFileContent(UPPERCASE_OUTPUT_DIR + FILE_NAME);
|
||||
String outputLowerCase = readFileContent(LOWERCASE_OUTPUT_DIR + FILE_NAME);
|
||||
|
||||
System.out.println("Input File content = [" + inputFileContent + "]");
|
||||
System.out.println("UpperCaseOutput file content = [" + outputUpperCase + "]");
|
||||
System.out.println("LowerCaseOtput file content = [" + outputLowerCase + "]");
|
||||
|
||||
assertEquals(inputFileContent.toUpperCase(), outputUpperCase);
|
||||
assertEquals(inputFileContent.toLowerCase(), outputLowerCase);
|
||||
}
|
||||
|
||||
private String readFileContent(String path) throws IOException {
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded);
|
||||
}
|
||||
|
||||
private void deleteFile(String path) {
|
||||
try {
|
||||
FileUtil.removeDir(new File(path));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy sample input file to input directory.
|
||||
*/
|
||||
private void copySampleFileToInputDirectory() {
|
||||
File sourceFile = new File(SAMPLE_INPUT_DIR + FILE_NAME);
|
||||
File destFile = new File(TEST_INPUT_DIR + FILE_NAME);
|
||||
|
||||
if (!sourceFile.exists()) {
|
||||
System.out.println("Sample input file not found at location = [" + SAMPLE_INPUT_DIR + FILE_NAME + "]. Please provide this file.");
|
||||
}
|
||||
|
||||
if (!destFile.exists()) {
|
||||
try {
|
||||
System.out.println("Creating input file = [" + TEST_INPUT_DIR + FILE_NAME + "]");
|
||||
|
||||
File destDir = new File(TEST_INPUT_DIR);
|
||||
if (!destDir.exists()) {
|
||||
destDir.mkdir();
|
||||
}
|
||||
destFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileChannel source = null;
|
||||
FileChannel destination = null;
|
||||
|
||||
try {
|
||||
source = new FileInputStream(sourceFile).getChannel();
|
||||
destination = new FileOutputStream(destFile).getChannel();
|
||||
if (destination != null && source != null) {
|
||||
destination.transferFrom(source, 0, source.size());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
source.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
destination.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.camel.main.App;
|
||||
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public final void testMain() throws Exception {
|
||||
App.main(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.jackson.ListJacksonDataFormat;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||
|
||||
@Test
|
||||
public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception {
|
||||
MockEndpoint mock = getMockEndpoint("mock:marshalledObject");
|
||||
mock.expectedMessageCount(1);
|
||||
mock.message(0).body().isInstanceOf(List.class);
|
||||
|
||||
String json = readJsonFromFile("/json/fruit-array.json");
|
||||
template.sendBody("direct:jsonInput", json);
|
||||
assertMockEndpointsSatisfied();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Fruit> fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
|
||||
assertNotNull("Fruit lists should not be null", fruitList);
|
||||
|
||||
assertEquals("There should be two fruits", 2, fruitList.size());
|
||||
|
||||
Fruit fruit = fruitList.get(0);
|
||||
assertEquals("Fruit name", "Banana", fruit.getName());
|
||||
assertEquals("Fruit id", 100, fruit.getId());
|
||||
|
||||
fruit = fruitList.get(1);
|
||||
assertEquals("Fruit name", "Apple", fruit.getName());
|
||||
assertEquals("Fruit id", 101, fruit.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouteBuilder createRouteBuilder() throws Exception {
|
||||
return new RouteBuilder() {
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class))
|
||||
.to("mock:marshalledObject");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
||||
URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path);
|
||||
return new String(Files.readAllBytes(Paths.get(resource.toURI())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.camel.jackson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.jackson.JacksonDataFormat;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.junit4.CamelTestSupport;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport {
|
||||
|
||||
@Test
|
||||
public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception {
|
||||
MockEndpoint mock = getMockEndpoint("mock:marshalledObject");
|
||||
mock.expectedMessageCount(1);
|
||||
mock.message(0).body().isInstanceOf(FruitList.class);
|
||||
|
||||
String json = readJsonFromFile("/json/fruit-list.json");
|
||||
template.sendBody("direct:jsonInput", json);
|
||||
assertMockEndpointsSatisfied();
|
||||
|
||||
FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class);
|
||||
assertNotNull("Fruit lists should not be null", fruitList);
|
||||
|
||||
List<Fruit> fruits = fruitList.getFruits();
|
||||
assertEquals("There should be two fruits", 2, fruits.size());
|
||||
|
||||
Fruit fruit = fruits.get(0);
|
||||
assertEquals("Fruit name", "Banana", fruit.getName());
|
||||
assertEquals("Fruit id", 100, fruit.getId());
|
||||
|
||||
fruit = fruits.get(1);
|
||||
assertEquals("Fruit name", "Apple", fruit.getName());
|
||||
assertEquals("Fruit id", 101, fruit.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RouteBuilder createRouteBuilder() throws Exception {
|
||||
return new RouteBuilder() {
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class))
|
||||
.to("mock:marshalledObject");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String readJsonFromFile(String path) throws URISyntaxException, IOException {
|
||||
URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path);
|
||||
return new String(Files.readAllBytes(Paths.get(resource.toURI())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"id": 100,
|
||||
"name": "Banana"
|
||||
},
|
||||
{
|
||||
"id": 101,
|
||||
"name": "Apple"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"fruits": [
|
||||
{
|
||||
"id": 100,
|
||||
"name": "Banana"
|
||||
},
|
||||
{
|
||||
"id": 101,
|
||||
"name": "Apple"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user