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

nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new d1c094d6 Ref #408: Add maven archetype for integration tests (#409)
d1c094d6 is described below

commit d1c094d6e932cf2c6dcedcd52d6fc38deee7f4cd
Author: François de Parscau <116000379+f2p...@users.noreply.github.com>
AuthorDate: Tue Jul 9 17:28:21 2024 +0200

    Ref #408: Add maven archetype for integration tests (#409)
---
 .../camel-karaf-test-feature-archetype/README.md   | 17 +++++++
 .../pom.xml                                        | 33 +++++++------
 .../META-INF/maven/archetype-metadata.xml          | 43 +++++++++++++++++
 .../main/resources/archetype-resources}/pom.xml    | 27 ++++-------
 .../test/Camel__featureName__RouteSupplier.java    | 54 ++++++++++++++++++++++
 .../test/java/itest/Camel__featureName__ITest.java | 46 ++++++++++++++++++
 tooling/pom.xml                                    |  1 +
 7 files changed, 189 insertions(+), 32 deletions(-)

diff --git a/tooling/camel-karaf-test-feature-archetype/README.md 
b/tooling/camel-karaf-test-feature-archetype/README.md
new file mode 100644
index 00000000..6a57aa05
--- /dev/null
+++ b/tooling/camel-karaf-test-feature-archetype/README.md
@@ -0,0 +1,17 @@
+# Apache Camel Karaf Integration Test Archetype
+
+### Introduction
+
+This archetype is to initialize a maven project to write an integration test 
for a Camel Karaf feature using the 
+framework provided by `org.apache.camel.karaf:camel-integration-test`.
+
+### Usage
+
+This tool is using maven archetype:generate plugin, for instance, to 
+initialize an integration test for the component camel-atom, go to 
`camel-karaf/tests/features/`, then run
+    
+```shell
+mvn archetype:generate -DfeatureName=Atom 
-DarchetypeGroupId=org.apache.camel.karaf 
-DarchetypeArtifactId=camel-karaf-test-feature-archetype 
-DarchetypeVersion=4.6.0-SNAPSHOT 
+```
+
+Then rename the directory `camel-atom-test` to `camel-atom`, adapt the file 
`pom.xml`, and finally fill in the supplier class and integration test.
diff --git a/tooling/pom.xml 
b/tooling/camel-karaf-test-feature-archetype/pom.xml
similarity index 54%
copy from tooling/pom.xml
copy to tooling/camel-karaf-test-feature-archetype/pom.xml
index 23fc96d6..4c88b111 100644
--- a/tooling/pom.xml
+++ b/tooling/camel-karaf-test-feature-archetype/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
     contributor license agreements.  See the NOTICE file distributed with
@@ -15,27 +16,31 @@
     limitations under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
-    
     <parent>
         <groupId>org.apache.camel.karaf</groupId>
-        <artifactId>camel-karaf</artifactId>
+        <artifactId>tooling</artifactId>
         <version>4.6.0-SNAPSHOT</version>
     </parent>
-    
-    <artifactId>tooling</artifactId>
-    <packaging>pom</packaging>
-    <name>Apache Camel :: Karaf :: Tooling</name>
+
+    <artifactId>camel-karaf-test-feature-archetype</artifactId>
+    <name>Apache Camel :: Karaf :: Tooling :: Integration Test Archetype</name>
 
     <properties>
-        <maven-version>3.9.8</maven-version>
+        <maven-archetype-version>3.2.1</maven-archetype-version>
     </properties>
 
-    <modules>
-        <module>camel-karaf-feature-maven-plugin</module>
-        <module>camel-karaf-maven-plugin-integration-test</module>
-        <module>camel-upgrade</module>
-    </modules>
-    
+    <build>
+        <extensions>
+            <extension>
+                <groupId>org.apache.maven.archetype</groupId>
+                <artifactId>archetype-packaging</artifactId>
+                <version>${maven-archetype-version}</version>
+            </extension>
+        </extensions>
+    </build>
+
 </project>
\ No newline at end of file
diff --git 
a/tooling/camel-karaf-test-feature-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 00000000..586b703b
--- /dev/null
+++ 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+
+-->
+<archetype-descriptor 
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0";>
+    <requiredProperties>
+        <requiredProperty key="featureName"/>
+        <requiredProperty key="featureNameLower">
+            <defaultValue>${featureName.toLowerCase()}</defaultValue>
+        </requiredProperty>
+        <requiredProperty key="groupId">
+            <defaultValue>org.apache.karaf.camel</defaultValue>
+        </requiredProperty>
+        <requiredProperty key="artifactId">
+            <defaultValue>camel-${featureNameLower}-test</defaultValue>
+        </requiredProperty>
+        <requiredProperty key="version">
+            <defaultValue>4.6.0-SNAPSHOT</defaultValue>
+        </requiredProperty>
+    </requiredProperties>
+    <fileSets>
+        <fileSet filtered="true" packaged="true">
+            <directory>src/main/java</directory>
+        </fileSet>
+        <fileSet filtered="true" packaged="true">
+            <directory>src/test/java</directory>
+        </fileSet>
+    </fileSets>
+</archetype-descriptor>
\ No newline at end of file
diff --git a/tooling/pom.xml 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/pom.xml
similarity index 56%
copy from tooling/pom.xml
copy to 
tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/pom.xml
index 23fc96d6..470dc6a2 100644
--- a/tooling/pom.xml
+++ 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/pom.xml
@@ -1,4 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
+
     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.
@@ -15,27 +17,16 @@
     limitations under the License.
 
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <modelVersion>4.0.0</modelVersion>
-    
     <parent>
         <groupId>org.apache.camel.karaf</groupId>
-        <artifactId>camel-karaf</artifactId>
-        <version>4.6.0-SNAPSHOT</version>
+        <artifactId>camel-karaf-features-test</artifactId>
+        <version>${version}</version>
     </parent>
-    
-    <artifactId>tooling</artifactId>
-    <packaging>pom</packaging>
-    <name>Apache Camel :: Karaf :: Tooling</name>
-
-    <properties>
-        <maven-version>3.9.8</maven-version>
-    </properties>
 
-    <modules>
-        <module>camel-karaf-feature-maven-plugin</module>
-        <module>camel-karaf-maven-plugin-integration-test</module>
-        <module>camel-upgrade</module>
-    </modules>
-    
+    <artifactId>camel-${featureNameLower}-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: ${featureName}</name>
 </project>
\ No newline at end of file
diff --git 
a/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/main/java/test/Camel__featureName__RouteSupplier.java
 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/main/java/test/Camel__featureName__RouteSupplier.java
new file mode 100644
index 00000000..5fc71eb1
--- /dev/null
+++ 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/main/java/test/Camel__featureName__RouteSupplier.java
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.karaf.camel.test;
+
+import static org.apache.camel.builder.Builder.constant;
+
+import java.util.function.Function;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-${featureNameLower}-test",
+        immediate = true,
+        service = Camel${featureName}RouteSupplier.class
+)
+public class Camel${featureName}RouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    /*
+    @Override
+    public void configure(CamelContext context) {
+
+    }
+    */
+
+    @Override
+    protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+        return builder ->
+                builder.from("${featureNameLower}://")
+                        .log("received message ${body}")
+                        .setBody(constant("OK"));
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+
+    }
+}
+
diff --git 
a/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/test/java/itest/Camel__featureName__ITest.java
 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/test/java/itest/Camel__featureName__ITest.java
new file mode 100644
index 00000000..abbd3679
--- /dev/null
+++ 
b/tooling/camel-karaf-test-feature-archetype/src/main/resources/archetype-resources/src/test/java/itest/Camel__featureName__ITest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed 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 org.apache.karaf.camel.itest;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@CamelKarafTestHint(externalResourceProvider = 
Camel${featureName}ITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class Camel${featureName}ITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedBodiesReceived("OK");
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+    }
+
+    public static final class ExternalResourceProviders {
+        /* TODO : add external resource
+        public static AvailablePortProvider createAvailablePortProvider() {
+            return new 
AvailablePortProvider(List.of("${featureNameLower}.port"));
+        }*/
+    }
+}
\ No newline at end of file
diff --git a/tooling/pom.xml b/tooling/pom.xml
index 23fc96d6..3f76a520 100644
--- a/tooling/pom.xml
+++ b/tooling/pom.xml
@@ -35,6 +35,7 @@
     <modules>
         <module>camel-karaf-feature-maven-plugin</module>
         <module>camel-karaf-maven-plugin-integration-test</module>
+        <module>camel-karaf-test-feature-archetype</module>
         <module>camel-upgrade</module>
     </modules>
     

Reply via email to