You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/09/12 20:05:43 UTC

[camel] 01/01: CAMEL-15528: Fix camel-archetype-api-component

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

janbednar pushed a commit to branch CAMEL-15528
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 32b63b24ba487feb6837fb74ef82accf356280c2
Author: Jan Bednář <ma...@janbednar.eu>
AuthorDate: Sat Sep 12 21:44:48 2020 +0200

    CAMEL-15528: Fix camel-archetype-api-component
---
 .../META-INF/maven/archetype-metadata.xml          |  3 +
 .../__artifactId__-component/pom.xml               | 10 ++-
 .../src/main/java/__name__Component.java           |  2 +-
 .../src/test/java/Abstract__name__TestSupport.java | 77 ++++++++++++++++++++++
 .../src/test/resources/test-options.properties     | 18 +++++
 5 files changed, 103 insertions(+), 7 deletions(-)

diff --git a/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml b/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
index f5b3f51..c0e8e5d 100644
--- a/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
+++ b/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
@@ -39,6 +39,9 @@
     <requiredProperty key="build-helper-maven-plugin-version">
       <defaultValue>${build-helper-maven-plugin-version}</defaultValue>
     </requiredProperty>
+    <requiredProperty key="maven-surefire-plugin-version">
+      <defaultValue>${maven-surefire-plugin-version}</defaultValue>
+    </requiredProperty>
     <requiredProperty key="junit-jupiter-version">
       <defaultValue>${junit-jupiter-version}</defaultValue>
     </requiredProperty>
diff --git a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
index 8cb68f5..251e912 100644
--- a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
+++ b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/pom.xml
@@ -73,12 +73,6 @@
       <artifactId>camel-test-junit5</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.junit.jupiter</groupId>
-      <artifactId>junit-jupiter</artifactId>
-      <version>${junit-jupiter-version}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>
@@ -250,6 +244,10 @@
             <outPackage>${outPackage}</outPackage>
           </configuration>
         </plugin>
+        <plugin>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>${maven-surefire-plugin-version}</version>
+        </plugin>
       </plugins>
     </pluginManagement>
 
diff --git a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
index b4914fb..0427232 100644
--- a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
+++ b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/main/java/__name__Component.java
@@ -36,7 +36,7 @@ public class ${name}Component extends AbstractApiComponent<${name}ApiName, ${nam
 
     @Override
     protected ${name}ApiName getApiName(String apiNameStr) throws IllegalArgumentException {
-        return ${name}ApiName.fromValue(apiNameStr);
+        return getCamelContext().getTypeConverter().convertTo(${name}ApiName.class, apiNameStr);
     }
 
     @Override
diff --git a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java
new file mode 100644
index 0000000..2269bf1
--- /dev/null
+++ b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java
@@ -0,0 +1,77 @@
+## ------------------------------------------------------------------------
+## 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 java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.camel.support.IntrospectionSupport;
+
+/**
+ * Abstract base class for ${name} Integration tests generated by Camel API component maven plugin.
+ */
+public class Abstract${name}TestSupport extends CamelTestSupport {
+
+    private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties";
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+
+        final CamelContext context = super.createCamelContext();
+
+        // read ${name} component configuration from TEST_OPTIONS_PROPERTIES
+        final Properties properties = new Properties();
+        try {
+            properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES));
+        } catch (Exception e) {
+            throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()),
+                e);
+        }
+
+        Map<String, Object> options = new HashMap<String, Object>();
+        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+            options.put(entry.getKey().toString(), entry.getValue());
+        }
+
+        final ${name}Configuration configuration = new ${name}Configuration();
+        IntrospectionSupport.setProperties(configuration, options);
+
+        // add ${name}Component to Camel context
+        final ${name}Component component = new ${name}Component(context);
+        component.setConfiguration(configuration);
+        context.addComponent("${scheme}", component);
+
+        return context;
+    }
+
+    @SuppressWarnings("unchecked")
+    protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers)
+        throws CamelExecutionException {
+        return (T) template().requestBodyAndHeaders(endpointUri, body, headers);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected <T> T requestBody(String endpoint, Object body) throws CamelExecutionException {
+        return (T) template().requestBody(endpoint, body);
+    }
+}
diff --git a/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
new file mode 100644
index 0000000..3e13bd8
--- /dev/null
+++ b/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# TODO provide test values for ${name} configuration properties
\ No newline at end of file