You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dh...@apache.org on 2014/06/10 21:51:58 UTC

[30/35] git commit: Updated generated tests to get api name for test routes from ApiCollection, added java.awt.headless=true to Javadoc mojo

Updated generated tests to get api name for test routes from ApiCollection, added java.awt.headless=true to Javadoc mojo


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

Branch: refs/heads/master
Commit: 4e1254a7e2df28b2c659fc9028ee8d15cdbe5c30
Parents: 911e541
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Wed Jun 4 18:41:37 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 10 12:48:34 2014 -0700

----------------------------------------------------------------------
 .../java/org/apache/camel/util/component/ApiCollection.java   | 5 +++++
 .../apache/camel/maven/AbstractApiMethodGeneratorMojo.java    | 2 ++
 .../org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java | 5 +++++
 .../src/main/resources/api-collection.vm                      | 7 +++++--
 .../src/main/resources/api-route-test.vm                      | 7 +++++--
 5 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4e1254a7/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
index a1fd2b7..3d0fce8 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
@@ -29,6 +29,7 @@ import java.util.Set;
 public abstract class ApiCollection<T extends Enum & ApiName, C> {
 
     protected final Map<T, ApiMethodHelper> apis = new HashMap<T, ApiMethodHelper>();
+    protected final Map<Class<? extends ApiMethod>, T> apiMethods = new HashMap<Class<? extends ApiMethod>, T>();
 
     /**
      * Returns a {@link ApiMethodHelper} for a particular API.
@@ -51,6 +52,10 @@ public abstract class ApiCollection<T extends Enum & ApiName, C> {
         return Collections.unmodifiableSet(result);
     }
 
+    public final T getApiName(Class<? extends ApiMethod> apiMethod) {
+        return apiMethods.get(apiMethod);
+    }
+
     /**
      * Creates an endpoint configuration for a particular API
      * @param apiName name of the API.

http://git-wip-us.apache.org/repos/asf/camel/blob/4e1254a7/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
index de70464..445ceda 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java
@@ -111,6 +111,8 @@ public abstract class AbstractApiMethodGeneratorMojo extends AbstractGeneratorMo
         VelocityContext context = getCommonContext(models);
         context.put("testName", getUnitTestName());
         context.put("scheme", scheme);
+        context.put("componentName", componentName);
+        context.put("enumName", getEnumName());
         return context;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4e1254a7/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
index 7eea008..28bd958 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/java/org/apache/camel/maven/JavadocApiMethodGeneratorMojo.java
@@ -49,6 +49,11 @@ import org.codehaus.plexus.util.IOUtil;
         defaultPhase = LifecyclePhase.GENERATE_SOURCES)
 public class JavadocApiMethodGeneratorMojo extends AbstractApiMethodGeneratorMojo {
 
+    static {
+        // set Java AWT to headless before using Swing HTML parser
+        System.setProperty("java.awt.headless", "true");
+    }
+
     protected static final String DEFAULT_EXCLUDE_PACKAGES = "javax?\\.lang.*";
 
     @Parameter(property = "camel.component.util.excludePackages", defaultValue = DEFAULT_EXCLUDE_PACKAGES)

http://git-wip-us.apache.org/repos/asf/camel/blob/4e1254a7/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
index e2c7eb4..868b958 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
@@ -43,12 +43,15 @@ public final class $collectionName extends ApiCollection<${apiNameEnum}, ${compo
     private ${collectionName}() {
         final Map<String, String> aliases = new HashMap<String, String>();
 #foreach( $api in $apis )
+
         aliases.clear();
 #foreach( $alias in $api.Aliases )
         aliases.put("$alias.MethodPattern", "$alias.MethodAlias");
 #end
-#set( $apiMethod = $helper.getApiMethod($api.ProxyClass) )
-        apis.put(${apiNameEnum}.${helper.getEnumConstant($api.ApiName)}, new ApiMethodHelper<$apiMethod>(${apiMethod}.class, aliases));
+#set( $apiMethod = "${helper.getApiMethod($api.ProxyClass)}.class" )
+#set( $apiName = "${apiNameEnum}.${helper.getEnumConstant($api.ApiName)}" )
+        apis.put($apiName, new ApiMethodHelper<$apiMethod>(${apiMethod}, aliases));
+        apiMethods.put(${apiMethod}, ${apiName});
 #end
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/4e1254a7/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-route-test.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-route-test.vm b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-route-test.vm
index f61ecc5..e53331f 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-route-test.vm
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-route-test.vm
@@ -32,11 +32,13 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Test class for $proxyType.Name APIs.
- * TODO Copy the file to src/test/java, populate parameter values, and remove @Ignore annotations.
+ * 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 {
 
     private static final Logger LOG = LoggerFactory.getLogger(${testName}.class);
+    private static final String PATH_PREFIX = ${componentName}ApiCollection.getCollection().getApiName(${enumName}.class).getName();
 
 #foreach ( $model in $models )
 #set ( $testName = $helper.getTestName($model) )
@@ -89,9 +91,10 @@ template().requestBodyAndHeader("direct://${model.UniqueName}", null, headers);
         return new RouteBuilder() {
             public void configure() {
 #foreach ( $model in $models )
+#set ( $args = $model.Arguments )
                 // test route for $model.Name
                 from("direct://${model.UniqueName}")
-                  .to("${scheme}://${model.Name}");
+                  .to("${scheme}://" + PATH_PREFIX + "${model.Name}#if ( $args.size() == 1 )?inBody=${args.get(0).Name}#end");
 
 #end
             }