This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/master by this push:
     new a29ee8f  Updated archetype to unclude JUnit 5 test example
a29ee8f is described below

commit a29ee8f4a79af834b85ee2ae3841f28b0f65e618
Author: Farid Guliyev <fg7...@gmail.com>
AuthorDate: Mon Nov 2 08:29:20 2020 -0500

    Updated archetype to unclude JUnit 5 test example
---
 .../src/main/resources/archetype-resources/pom.xml |  8 ++-
 .../main/resources/archetype-resources/readme.adoc |  9 +++-
 .../src/test/java/MySpringBootApplicationTest.java | 63 ++++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git 
a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/pom.xml
 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/pom.xml
index f5a4327..70087fa 100644
--- 
a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/pom.xml
+++ 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/pom.xml
@@ -31,6 +31,7 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <spring.boot-version>${spring-boot-version}</spring.boot-version>
+    <surefire.plugin.version>3.0.0-M4</surefire.plugin.version>
   </properties>
 
   <dependencyManagement>
@@ -94,7 +95,7 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test-spring</artifactId>
+      <artifactId>camel-test-spring-junit5</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
@@ -122,6 +123,11 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.plugin.version}</version>
+      </plugin>
     </plugins>
   </build>
 
diff --git 
a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
index 73d6e18..fa027df 100644
--- 
a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
+++ 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/readme.adoc
@@ -9,10 +9,11 @@ The example generates messages using timer trigger, writes 
them to standard outp
 The Camel route is located in the `MyCamelRouter` class. In this class the 
route
 starts from a timer, that triggers every 2nd second and calls a Spring Bean 
`MyBean`
 which returns a message, that is routed to a stream endpoint which writes to 
standard output.
+The example contains test class demonstrating how to intercept and mock 
endpoints in unit tests using JUnit 5 and Camel Test Support.
 
 == Using Camel components
 
-Apache Camel provides 200+ components which you can use to integrate and route 
messages between many systems
+Apache Camel provides 300+ components which you can use to integrate and route 
messages between many systems
 and data formats. To use any of these Camel components, add the component as a 
dependency to your project.
 
 == How to run
@@ -21,6 +22,12 @@ You can run this example using
 
     mvn spring-boot:run
 
+== How to run test
+
+You can run unit test of this example using
+
+    mvn clean test
+
 == To get info about the routes
 
 To show a summary of all the routes
diff --git 
a/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/test/java/MySpringBootApplicationTest.java
 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/test/java/MySpringBootApplicationTest.java
new file mode 100644
index 0000000..a25b802
--- /dev/null
+++ 
b/archetypes/camel-archetype-spring-boot/src/main/resources/archetype-resources/src/test/java/MySpringBootApplicationTest.java
@@ -0,0 +1,63 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+package ${package};
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.AdviceWith;
+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;
+
+@SpringBootTest
+@CamelSpringBootTest
+public class MySpringBootApplicationTest {
+
+       @Autowired
+       private CamelContext camelContext;
+
+       @Autowired
+       private ProducerTemplate producerTemplate;
+
+       @Test
+       public void test() throws Exception {
+               MockEndpoint mock = camelContext.getEndpoint("mock:stream:out", 
MockEndpoint.class);
+
+               AdviceWith.adviceWith(camelContext, "hello",
+                               // intercepting an exchange on route
+                               r -> {
+                                       // replacing consumer with direct 
component
+                                       r.replaceFromWith("direct:start");
+                                       // mocking producer
+                                       r.mockEndpoints("stream*");
+                               }
+               );
+
+               // setting expectations
+               mock.expectedMessageCount(1);
+               mock.expectedBodiesReceived("Hello World");
+
+               // invoking consumer
+               producerTemplate.sendBody("direct:start", null);
+
+               // asserting mock is satisfied
+               mock.assertIsSatisfied();
+       }
+}

Reply via email to