camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject git commit: Updated API component framework to generate test classes in the component's package, added abstract base class for tests to create component, added assertNotNull for results
Date Thu, 26 Jun 2014 23:37:03 GMT
Repository: camel
Updated Branches:
  refs/heads/master 73f067e61 -> 18573971a


Updated API component framework to generate test classes in the component's package, added
abstract base class for tests to create component, added assertNotNull for results


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/18573971
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/18573971
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/18573971

Branch: refs/heads/master
Commit: 18573971a767350d86696367cbf48183de3ff221
Parents: 73f067e
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Thu Jun 26 16:36:14 2014 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Thu Jun 26 16:36:52 2014 -0700

----------------------------------------------------------------------
 .../META-INF/maven/archetype-metadata.xml       |  6 ++
 .../test/java/Abstract__name__TestSupport.java  | 71 ++++++++++++++++++++
 .../src/test/resources/test-options.properties  |  1 +
 .../src/it/all-it/pom.xml                       |  3 +-
 .../maven/AbstractApiMethodGeneratorMojo.java   |  3 +-
 .../src/main/resources/api-route-test.vm        | 19 +++---
 .../component/test/AbstractTestTestSupport.java | 31 +++++++++
 7 files changed, 121 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
b/tooling/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
index 935370b..134af47 100644
--- a/tooling/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources-filtered/META-INF/maven/archetype-metadata.xml
@@ -81,6 +81,12 @@
         <include>**/*</include>
       </includes>
     </fileSet>
+    <fileSet filtered="true" packaged="true" encoding="UTF-8">
+      <directory>__artifactId__-component/src/test/java</directory>
+      <includes>
+        <include>**/*.java</include>
+      </includes>
+    </fileSet>
     <fileSet filtered="true" encoding="UTF-8">
       <directory>__artifactId__-component/src/test/resources</directory>
       <includes>

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java
b/tooling/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..0ad30f9
--- /dev/null
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/java/Abstract__name__TestSupport.java
@@ -0,0 +1,71 @@
+## ------------------------------------------------------------------------
+## 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.test.junit4.CamelTestSupport;
+import org.apache.camel.util.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;
+    }
+
+    @Override
+    public boolean isCreateCamelContextPerClass() {
+        // only create the context once for this class
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
----------------------------------------------------------------------
diff --git a/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
new file mode 100644
index 0000000..b38298a
--- /dev/null
+++ b/tooling/archetypes/camel-archetype-api-component/src/main/resources/archetype-resources/__artifactId__-component/src/test/resources/test-options.properties
@@ -0,0 +1 @@
+## TODO provide test values for ${name} configuration properties
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml b/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
index 9295755..369f65b 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
+++ b/tooling/maven/camel-api-component-maven-plugin/src/it/all-it/pom.xml
@@ -57,7 +57,8 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-test</artifactId>
       <version>@project.version@</version>
-      <scope>test</scope>
+      <!-- compile scope to avoid having to move AbstractTestTestSupport to src/test/java
-->
+      <scope>compile</scope>
     </dependency>
   </dependencies>
 

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
index 3881d84..6ddb5b6 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
@@ -124,6 +124,7 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
         VelocityContext context = getCommonContext(models);
         context.put("testName", getUnitTestName());
         context.put("scheme", scheme);
+        context.put("componentPackage", componentPackage);
         context.put("componentName", componentName);
         context.put("enumName", getEnumName());
         return context;
@@ -131,7 +132,7 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractApiMethodBa
 
     private String getTestFilePath() throws MojoExecutionException {
         final StringBuilder fileName = new StringBuilder();
-        fileName.append(outPackage.replaceAll("\\.", File.separator)).append(File.separator);
+        fileName.append(componentPackage.replaceAll("\\.", File.separator)).append(File.separator);
         fileName.append(getUnitTestName()).append(".java");
         return fileName.toString();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
index bf71e7f..15f0cf9 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/resources/api-route-test.vm
@@ -19,24 +19,26 @@
  * Camel Api Route test generated by camel-component-util-maven-plugin
  * Generated on: $generatedDate
  */
-package $packageName;
+package $componentPackage;
 
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import ${packageName}.${componentName}ApiCollection;
+import ${packageName}.${enumName};
+
 /**
  * Test class for $proxyType.Name APIs.
  * TODO Move the file to src/test/java, populate parameter values, and remove @Ignore annotations.
  * The class source won't be generated again if the generator MOJO finds it under src/test/java.
  */
-public class ${testName} extends CamelTestSupport {
+public class ${testName} extends Abstract${componentName}TestSupport {
 
     private static final Logger LOG = LoggerFactory.getLogger(${testName}.class);
     private static final String PATH_PREFIX = ${componentName}ApiCollection.getCollection().getApiName(${enumName}.class).getName();
@@ -68,6 +70,7 @@ public class ${testName} extends CamelTestSupport {
         headers.put("${helper.getExchangePropertyPrefix()}${arg.Name}", $helper.getDefaultArgValue($arg.Type));
 #end
 #end
+
 #end
 ## method invocation result
         #if ( !$voidResult )#set ( $type = $helper.getResultDeclaration($resultType) )$type
result = (${type})#end
@@ -81,8 +84,8 @@ template().requestBody("direct://${model.UniqueName}", (${helper.getCanonicalNam
 template().requestBodyAndHeaders("direct://${model.UniqueName}", null, headers);
 #end
 #if ( !$voidResult )
-
-        LOG.debug("${model.Name} :" + result);
+        assertNotNull("${model.Name} result", result);
+        LOG.debug("${model.Name}: " + result);
 #end
     }
 
@@ -101,10 +104,4 @@ template().requestBodyAndHeaders("direct://${model.UniqueName}", null,
headers);
             }
         };
     }
-
-    @Override
-    public boolean isCreateCamelContextPerClass() {
-        // only create the context once for this class
-        return true;
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/18573971/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/AbstractTestTestSupport.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/AbstractTestTestSupport.java
b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/AbstractTestTestSupport.java
new file mode 100644
index 0000000..f4de882
--- /dev/null
+++ b/tooling/maven/camel-api-component-maven-plugin/src/test/java/org/apache/camel/component/test/AbstractTestTestSupport.java
@@ -0,0 +1,31 @@
+/**
+ * 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.camel.component.test;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+/**
+ * Dummy TestSupport class.
+ */
+public class AbstractTestTestSupport extends CamelTestSupport {
+
+    @Override
+    public boolean isCreateCamelContextPerClass() {
+        // only create the context once for this class
+        return true;
+    }
+}


Mime
View raw message