From e8c2e2cb9637daf75ec06660ec1999c332cb7c35 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:34:27 +0330 Subject: [PATCH 01/14] #BAEL-6916: remove xml context --- .../src/main/resources/camel-context-test.xml | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 messaging-modules/apache-camel/src/main/resources/camel-context-test.xml diff --git a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml deleted file mode 100644 index f306574868..0000000000 --- a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - \ No newline at end of file From a34c8794edc009b8fa9c46bd4da43726d566a243 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:41:47 +0330 Subject: [PATCH 02/14] #BAEL-6916: add Spring Boot main class --- .../java/com/baeldung/camel/apache/Application.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java new file mode 100755 index 0000000000..51b2540aa8 --- /dev/null +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java @@ -0,0 +1,11 @@ +package com.baeldung.camel.apache; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file From 85ac5582781c704284fb61b0d26dd8620c42a88c Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:53:35 +0330 Subject: [PATCH 03/14] #BAEL-6916: add Spring Bean Annotation --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 2 ++ .../main/java/com/baeldung/camel/apache/file/FileRouter.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index ce4d92e8ab..5ca8cc9d72 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -5,7 +5,9 @@ import java.util.Date; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.springframework.stereotype.Component; +@Component public class FileProcessor implements Processor { public void process(Exchange exchange) throws Exception { diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java index 760f37677b..b57232d41e 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java @@ -1,7 +1,9 @@ package com.baeldung.camel.apache.file; import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +@Component public class FileRouter extends RouteBuilder { private static final String SOURCE_FOLDER = "src/test/source-folder"; From 036531949f12f019c1902cfac2e32ed33227de10 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 17:58:00 +0330 Subject: [PATCH 04/14] #BAEL-6916: add dependencies --- messaging-modules/apache-camel/pom.xml | 60 +++++++++++++++++++++----- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index bb20f178aa..026983484b 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -17,30 +17,68 @@ - org.apache.camel - camel-core - ${env.camel.version} + org.springframework.boot + spring-boot-starter-web + + + org.apache.camel.springboot + camel-spring-boot-starter + ${camel.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + org.apache.camel - camel-spring-javaconfig - ${env.camel.version} + camel-test-spring-junit5 + ${camel.version} + test org.apache.camel - camel-jackson - ${env.camel.version} + camel-http + ${camel.version} - org.apache.camel - camel-test - ${env.camel.version} + org.apache.camel.springboot + camel-bindy-starter + ${camel.version} + + + org.apache.camel.springboot + camel-jackson-starter + ${camel.version} + + + org.junit.platform + junit-platform-launcher test - 3.14.7 + 3.21.0 + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + \ No newline at end of file From d48a45c15a23a5b2723aec06fe321ef5359cf4ad Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Wed, 20 Sep 2023 18:00:31 +0330 Subject: [PATCH 05/14] #BAEL-6916: update test cases --- .../FruitArrayJacksonUnmarshalUnitTest.java | 65 ++++++++++++------- .../FruitListJacksonUnmarshalUnitTest.java | 64 +++++++++++------- .../FileProcessorIntegrationTest.java | 11 ++-- 3 files changed, 90 insertions(+), 50 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index bc0025b263..a5981ccb1a 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -1,5 +1,21 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +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.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.test.annotation.DirtiesContext; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -7,25 +23,42 @@ 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 static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; +@CamelSpringBootTest +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@SpringBootTest(classes = {Application.class, FruitArrayJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitArrayJacksonUnmarshalUnitTest { -public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(List.class); String json = readJsonFromFile("/json/fruit-array.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); @SuppressWarnings("unchecked") List fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); @@ -41,18 +74,6 @@ public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { 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); diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index 2d15ebf46b..b5b0fee2f9 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -1,5 +1,21 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import com.baeldung.camel.apache.jackson.FruitList; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +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.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -7,26 +23,41 @@ 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 static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; -import com.baeldung.camel.apache.jackson.FruitList; +@CamelSpringBootTest +@SpringBootTest(classes = {Application.class, FruitListJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitListJacksonUnmarshalUnitTest { -public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(FruitList.class); String json = readJsonFromFile("/json/fruit-list.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class); assertNotNull("Fruit lists should not be null", fruitList); @@ -43,17 +74,6 @@ public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { 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()))); diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index e4390a95e5..5df7543c6f 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -1,16 +1,14 @@ package com.apache.camel.file.processor; -import java.io.File; - +import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import com.baeldung.camel.apache.file.FileProcessor; +import java.io.File; public class FileProcessorIntegrationTest { @@ -67,9 +65,10 @@ public class FileProcessorIntegrationTest { @Test public void moveFolderContentSpringDSLTest() throws InterruptedException { - ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); +// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); +// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext(); Thread.sleep(DURATION_MILIS); - applicationContext.close(); + //applicationContext.close(); } } \ No newline at end of file From b5c06059f031bad344d00259899499c5b0fe5a2a Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sat, 23 Sep 2023 17:30:40 +0330 Subject: [PATCH 06/14] #BAEL-6916: refactor dependencies --- messaging-modules/apache-camel/pom.xml | 54 +++++--------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index 026983484b..88c807a86a 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -16,69 +16,35 @@ - - org.springframework.boot - spring-boot-starter-web - org.apache.camel.springboot camel-spring-boot-starter ${camel.version} - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.apache.camel - camel-test-spring-junit5 - ${camel.version} - test - - - org.apache.camel - camel-http - ${camel.version} - - - org.apache.camel.springboot - camel-bindy-starter - ${camel.version} - org.apache.camel.springboot camel-jackson-starter ${camel.version} + + org.apache.camel + camel-test-spring-junit5 + ${camel.version} + test + org.junit.platform junit-platform-launcher test + + org.springframework.boot + spring-boot-starter-web + 3.21.0 - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - - - \ No newline at end of file From 083cf15f77b45d8aec79f2d2ea5557b48f751ca5 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:05:22 +0330 Subject: [PATCH 07/14] #BAEL-6916: add StandardCharsets --- .../camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java | 3 ++- .../camel/jackson/FruitListJacksonUnmarshalUnitTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index a5981ccb1a..df7a57a984 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -19,6 +19,7 @@ import org.springframework.test.annotation.DirtiesContext; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -77,7 +78,7 @@ public class FruitArrayJacksonUnmarshalUnitTest { private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index b5b0fee2f9..bb31884d11 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -19,6 +19,7 @@ import org.springframework.context.annotation.Bean; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -76,7 +77,7 @@ public class FruitListJacksonUnmarshalUnitTest { private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } From 2bd5ae21de62df694122a342988b39c89b57cd29 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:05:54 +0330 Subject: [PATCH 08/14] #BAEL-6916: add camel-context xml --- .../src/main/resources/camel-context-test.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 messaging-modules/apache-camel/src/main/resources/camel-context-test.xml diff --git a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml new file mode 100644 index 0000000000..f6177c69b5 --- /dev/null +++ b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file From 84efed044f77d8bee9e1f8020d25a6d52590e7ef Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:06:22 +0330 Subject: [PATCH 09/14] #BAEL-6916: add awaitility dependency --- messaging-modules/apache-camel/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index 88c807a86a..8b49ad4893 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -41,6 +41,11 @@ org.springframework.boot spring-boot-starter-web + + org.awaitility + awaitility + test + From d05f27429af683552dc6808413ce44886e5f9ed2 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:10:13 +0330 Subject: [PATCH 10/14] #BAEL-6916: change timestamp to date for test assertion --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index 5ca8cc9d72..c9537d48de 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -14,7 +14,7 @@ public class FileProcessor implements Processor { 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"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String changedFileName = dateFormat.format(date) + originalFileName; exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName); } From fa56411bd38477d3d5827c3a9bd3c17fa10a7e78 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:13:59 +0330 Subject: [PATCH 11/14] #BAEL-6916: add Awaitility instead of Thread.sleep and given when then --- .../FileProcessorIntegrationTest.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index 5df7543c6f..67273d8a87 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -4,11 +4,18 @@ import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class FileProcessorIntegrationTest { @@ -50,7 +57,7 @@ public class FileProcessorIntegrationTest { } @Test - public void moveFolderContentJavaDSLTest() throws Exception { + public void givenJavaDSLRoute_whenCamelStart_thenMoveFolderContent() throws Exception { final CamelContext camelContext = new DefaultCamelContext(); camelContext.addRoutes(new RouteBuilder() { @Override @@ -59,16 +66,27 @@ public class FileProcessorIntegrationTest { } }); camelContext.start(); - Thread.sleep(DURATION_MILIS); + verifyFolderContent(); camelContext.stop(); } @Test - public void moveFolderContentSpringDSLTest() throws InterruptedException { -// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); -// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext(); - Thread.sleep(DURATION_MILIS); - //applicationContext.close(); + public void givenSpringDSLRoute_whenCamelStart_thenMoveFolderContent() throws InterruptedException { + ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); + verifyFolderContent(); + applicationContext.close(); } + + private void verifyFolderContent() { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + File destinationFile1 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File1.txt"); + File destinationFile2 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File2.txt"); + + Awaitility.await().atMost(DURATION_MILIS, TimeUnit.MILLISECONDS).untilAsserted(() -> { + assertThat(destinationFile1.exists()).isTrue(); + assertThat(destinationFile2.exists()).isTrue(); + }); + } } \ No newline at end of file From 6a858656fd9a3e6262edd549f2e4585604067e34 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 13:53:34 +0330 Subject: [PATCH 12/14] #BAEL-6916: remove extra space --- .../camel/file/processor/FileProcessorIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index 67273d8a87..5003021d20 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -75,7 +75,6 @@ public class FileProcessorIntegrationTest { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); verifyFolderContent(); applicationContext.close(); - } private void verifyFolderContent() { From a086bb8bcc3734f54a4e5876350496b78c81c781 Mon Sep 17 00:00:00 2001 From: hmdrz Date: Thu, 28 Sep 2023 10:52:56 +0330 Subject: [PATCH 13/14] #bael-6916:add @Override --- .../main/java/com/baeldung/camel/apache/file/FileProcessor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index c9537d48de..a0571e7083 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; @Component public class FileProcessor implements Processor { + @Override public void process(Exchange exchange) throws Exception { String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); From 1775ac73f03b303a9cfa4e9fb1f5fc4e230e7d2e Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Sat, 30 Sep 2023 17:27:47 +0330 Subject: [PATCH 14/14] #BAEL-6916: add indentation and private access --- .../camel/jackson/FruitListJacksonUnmarshalUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index bb31884d11..8120eeffec 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -32,7 +32,7 @@ import static org.springframework.test.util.AssertionErrors.assertNotNull; public class FruitListJacksonUnmarshalUnitTest { @Autowired - ProducerTemplate template; + private ProducerTemplate template; @EndpointInject("mock:marshalledObject") private MockEndpoint mock; @@ -44,8 +44,8 @@ public class FruitListJacksonUnmarshalUnitTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) - .to("mock:marshalledObject"); + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); } }; }