JAVA-18750 Split or move spring-apache-camel module (#13710)
This commit is contained in:
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.camel.apache.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);
|
||||
}
|
||||
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.camel.apache.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);
|
||||
}
|
||||
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.camel.apache.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;
|
||||
}
|
||||
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.baeldung.camel.apache.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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?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.apache.file.FileRouter" />
|
||||
<bean id="fileProcessor" class="com.baeldung.camel.apache.file.FileProcessor" />
|
||||
|
||||
<camelContext xmlns="http://camel.apache.org/schema/spring">
|
||||
<routeBuilder ref="fileRouter" />
|
||||
</camelContext>
|
||||
|
||||
</beans>
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package com.apache.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;
|
||||
|
||||
import com.baeldung.camel.apache.jackson.Fruit;
|
||||
|
||||
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())));
|
||||
}
|
||||
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package com.apache.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;
|
||||
|
||||
import com.baeldung.camel.apache.jackson.Fruit;
|
||||
import com.baeldung.camel.apache.jackson.FruitList;
|
||||
|
||||
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())));
|
||||
}
|
||||
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
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.apache.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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": 100,
|
||||
"name": "Banana"
|
||||
},
|
||||
{
|
||||
"id": 101,
|
||||
"name": "Apple"
|
||||
}
|
||||
]
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"fruits": [
|
||||
{
|
||||
"id": 100,
|
||||
"name": "Banana"
|
||||
},
|
||||
{
|
||||
"id": 101,
|
||||
"name": "Apple"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user