Author: apetrelli
Date: Sat Mar 20 12:46:21 2010
New Revision: 925591

URL: http://svn.apache.org/viewvc?rev=925591&view=rev
Log:
TILESSB-29
Created generators for velocity classes and properties.

Added:
    tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
   (with props)
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
   (with props)
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
    tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
   (with props)
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
   (with props)
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
    
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/velocity.properties.test
Modified:
    tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/pom.xml

Modified: tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/pom.xml
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/pom.xml?rev=925591&r1=925590&r2=925591&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/pom.xml (original)
+++ tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/pom.xml Sat Mar 20 
12:46:21 2010
@@ -10,4 +10,23 @@
   <version>1.0-SNAPSHOT</version>
   <name>Autotag - Velocity support</name>
   <description>Module to generate Velocity code to use tag 
models.</description>
+  <dependencies>
+       <dependency>
+               <groupId>org.apache.tiles</groupId>
+               <artifactId>tiles-autotag-core</artifactId>
+               <version>1.0-SNAPSHOT</version>
+       </dependency>
+       <dependency>
+               <groupId>junit</groupId>
+               <artifactId>junit</artifactId>
+               <version>4.8.1</version>
+               <scope>test</scope>
+       </dependency>
+       <dependency>
+               <groupId>commons-io</groupId>
+               <artifactId>commons-io</artifactId>
+               <version>1.4</version>
+               <scope>test</scope>
+       </dependency>
+  </dependencies>
 </project>
\ No newline at end of file

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,28 @@
+package org.apache.tiles.autotag.velocity;
+
+import java.io.File;
+
+import org.apache.tiles.autotag.generate.AbstractTemplateClassGenerator;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateSuite;
+
+public class VelocityDirectiveGenerator extends AbstractTemplateClassGenerator 
{
+
+    @Override
+    protected String getDirectoryName(File directory, String packageName,
+            TemplateSuite suite, TemplateClass clazz) {
+        return packageName.replaceAll("\\.", "/");
+    }
+
+    @Override
+    protected String getFilename(File directory, String packageName,
+            TemplateSuite suite, TemplateClass clazz) {
+        return clazz.getTagClassPrefix() + "Directive.java";
+    }
+
+    @Override
+    protected String getTemplatePath(File directory, String packageName,
+            TemplateSuite suite, TemplateClass clazz) {
+        return "/org/apache/tiles/autotag/velocity/velocityDirective.vm";
+    }
+}

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,22 @@
+package org.apache.tiles.autotag.velocity;
+
+import java.io.File;
+
+import org.apache.tiles.autotag.generate.AbstractTemplateSuiteGenerator;
+import org.apache.tiles.autotag.model.TemplateSuite;
+
+public class VelocityPropertiesGenerator extends 
AbstractTemplateSuiteGenerator {
+
+    protected String getTemplatePath(File directory, String packageName, 
TemplateSuite suite) {
+        return "/org/apache/tiles/autotag/velocity/velocityProperties.vm";
+    }
+
+    protected String getFilename(File directory, String packageName, 
TemplateSuite suite) {
+        return "velocity.properties";
+    }
+
+    protected String getDirectoryName(File directory, String packageName, 
TemplateSuite suite) {
+        return "META-INF/";
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityDirective.vm
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,63 @@
+package ${packageName};
+#*
+ * $Id: tiles-jsp.tld 836180 2009-11-14 14:00:02Z apetrelli $
+ *
+ * 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.
+ *#
+
+import java.io.IOException;
+import java.util.Map;
+
+#if(${clazz.hasBody()})
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+#end
+import org.apache.tiles.request.Request;
+import org.apache.tiles.velocity.context.VelocityUtil;
+import 
org.apache.tiles.velocity.template.Body#if(!${clazz.hasBody()})less#{end}Directive;
+import org.apache.tiles.velocity.context.VelocityUtil;
+
+/**
+#foreach($line in $stringTool.splitOnNewlines(${clazz.documentation}))
+ * ${line}
+#end
+ */
+public class ${clazz.tagClassPrefix}Directive extends 
Body#if(!${clazz.hasBody()})less#{end}Directive {
+
+    /**
+     * The template model.
+     */
+    private ${clazz.name} model = new ${clazz.name}();
+
+    /** {...@inheritdoc} */
+    @Override
+    public String getName() {
+        return "${suite.name}_${clazz.tagName}";
+    }
+
+    /** {...@inheritdoc} */
+    @Override
+    protected void execute(Map<String, Object> params, Request 
request#if(${clazz.hasBody()}), ModelBody modelBody#end) throws IOException {
+        model.execute(
+#foreach($parameter in ${clazz.parameters})
+            ($stringTool.getClassToCast(${parameter.type})) 
VelocityUtil.getObject(parms.get("${parameter.exportedName}"), 
$stringTool.getDefaultValue(${parameter.type}, ${parameter.defaultValue})),
+#end
+            request#if(${clazz.hasBody()}), modelBody#end
+
+        );
+    }
+}

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/main/resources/org/apache/tiles/autotag/velocity/velocityProperties.vm
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,22 @@
+#*
+ * $Id: tiles-jsp.tld 836180 2009-11-14 14:00:02Z apetrelli $
+ *
+ * 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.
+ *#
+userdirective=#foreach($clazz in 
${suite.getTemplateClasses()})#if($velocityCount > 1),\
+  #{end}${packageName}.${clazz.tagClassPrefix}Directive#end

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,119 @@
+/**
+ *
+ */
+package org.apache.tiles.autotag.velocity;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateMethod;
+import org.apache.tiles.autotag.model.TemplateParameter;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.tiles.request.Request;
+import org.apache.velocity.app.Velocity;
+import org.junit.Test;
+
+/**
+ * Tests {...@link VelocityDirectiveGenerator}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class VelocityDirectiveGeneratorTest {
+
+    /**
+     * Test method for {...@link VelocityDirectiveGenerator#generate(File, 
String, TemplateSuite, TemplateClass)}.
+     * @throws Exception If something goes wrong.
+     */
+    @Test
+    public void testGenerate() throws Exception {
+        VelocityDirectiveGenerator generator = new 
VelocityDirectiveGenerator();
+        File file = File.createTempFile("autotag", null);
+        file.delete();
+        file.mkdir();
+        file.deleteOnExit();
+        TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD 
docs.");
+
+        List<TemplateParameter> params = new ArrayList<TemplateParameter>();
+        TemplateParameter param = new TemplateParameter("one", "one", 
"java.lang.String", null, true);
+        param.setDocumentation("Parameter one.");
+        params.add(param);
+        param = new TemplateParameter("two", "two", "int", null, false);
+        param.setDocumentation("Parameter two.");
+        params.add(param);
+        param = new TemplateParameter("three", "three", "boolean", null, 
false);
+        param.setDocumentation("Parameter three.");
+        params.add(param);
+        param = new TemplateParameter("request", "request", 
Request.class.getName(), null, false);
+        param.setDocumentation("The request.");
+        params.add(param);
+        param = new TemplateParameter("modelBody", "modelBody", 
ModelBody.class.getName(), null, false);
+        param.setDocumentation("The body.");
+        params.add(param);
+        TemplateMethod executeMethod = new TemplateMethod("execute", params);
+
+        TemplateClass clazz = new 
TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate",
+                "doStuff", "DoStuff", executeMethod);
+        clazz.setDocumentation("Documentation of the DoStuff class.");
+
+        Properties props = new Properties();
+        InputStream propsStream = 
getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
+        props.load(propsStream);
+        propsStream.close();
+        Velocity.init(props);
+
+        generator.generate(file, "org.apache.tiles.autotag.velocity.test", 
suite, clazz);
+
+        InputStream expected = 
getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat");
+        File effectiveFile = new File(file, 
"/org/apache/tiles/autotag/velocity/test/DoStuffDirective.java");
+        assertTrue(effectiveFile.exists());
+        InputStream effective = new FileInputStream(effectiveFile);
+        assertTrue(IOUtils.contentEquals(effective, expected));
+        effective.close();
+        expected.close();
+
+        suite.addTemplateClass(clazz);
+        params = new ArrayList<TemplateParameter>();
+        param = new TemplateParameter("one", "one", "java.lang.Double", null, 
true);
+        param.setDocumentation("Parameter one.");
+        params.add(param);
+        param = new TemplateParameter("two", "two", "float", null, false);
+        param.setDocumentation("Parameter two.");
+        params.add(param);
+        param = new TemplateParameter("three", "three", "java.util.Date", 
null, false);
+        param.setDocumentation("Parameter three.");
+        params.add(param);
+        param = new TemplateParameter("request", "request", 
Request.class.getName(), null, false);
+        param.setDocumentation("The request.");
+        params.add(param);
+        executeMethod = new TemplateMethod("execute", params);
+
+        clazz = new 
TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate",
+                "doStuffNoBody", "DoStuffNoBody", executeMethod);
+        clazz.setDocumentation("Documentation of the DoStuffNoBody class.");
+
+        suite.addTemplateClass(clazz);
+
+        generator.generate(file, "org.apache.tiles.autotag.velocity.test", 
suite, clazz);
+
+        expected = 
getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat");
+        effectiveFile = new File(file, 
"/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.java");
+        assertTrue(effectiveFile.exists());
+        effective = new FileInputStream(effectiveFile);
+        assertTrue(IOUtils.contentEquals(effective, expected));
+        effective.close();
+        expected.close();
+
+        FileUtils.deleteDirectory(file);
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityDirectiveGeneratorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,110 @@
+/**
+ *
+ */
+package org.apache.tiles.autotag.velocity;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.autotag.model.TemplateClass;
+import org.apache.tiles.autotag.model.TemplateMethod;
+import org.apache.tiles.autotag.model.TemplateParameter;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.tiles.request.Request;
+import org.apache.velocity.app.Velocity;
+import org.junit.Test;
+
+/**
+ * Tests {...@link VelocityPropertiesGenerator}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class VelocityPropertiesGeneratorTest {
+
+    /**
+     * Test method for {...@link 
org.apache.tiles.autotag.velocity.VelocityPropertiesGenerator#generate(java.io.File,
 java.lang.String, org.apache.tiles.autotag.model.TemplateSuite)}.
+     * @throws Exception If something goes wrong.
+     */
+    @Test
+    public void testGenerate() throws Exception {
+        VelocityPropertiesGenerator generator = new 
VelocityPropertiesGenerator();
+        File file = File.createTempFile("autotag", null);
+        file.delete();
+        file.mkdir();
+        file.deleteOnExit();
+        TemplateSuite suite = new TemplateSuite("tldtest", "Test for TLD 
docs.");
+        suite.getCustomVariables().put("taglibURI", 
"http://www.initrode.net/tags/test";);
+
+        List<TemplateParameter> params = new ArrayList<TemplateParameter>();
+        TemplateParameter param = new TemplateParameter("one", "one", 
"java.lang.String", null, true);
+        param.setDocumentation("Parameter one.");
+        params.add(param);
+        param = new TemplateParameter("two", "two", "int", null, false);
+        param.setDocumentation("Parameter two.");
+        params.add(param);
+        param = new TemplateParameter("three", "three", "long", null, false);
+        param.setDocumentation("Parameter three.");
+        params.add(param);
+        param = new TemplateParameter("request", "request", 
Request.class.getName(), null, false);
+        param.setDocumentation("The request.");
+        params.add(param);
+        param = new TemplateParameter("modelBody", "modelBody", 
ModelBody.class.getName(), null, false);
+        param.setDocumentation("The body.");
+        params.add(param);
+        TemplateMethod executeMethod = new TemplateMethod("execute", params);
+
+        TemplateClass clazz = new 
TemplateClass("org.apache.tiles.autotag.template.DoStuffTemplate",
+                "doStuff", "DoStuff", executeMethod);
+        clazz.setDocumentation("Documentation of the DoStuff class");
+
+        suite.addTemplateClass(clazz);
+        params = new ArrayList<TemplateParameter>();
+        param = new TemplateParameter("one", "one", "java.lang.Double", null, 
true);
+        param.setDocumentation("Parameter one.");
+        params.add(param);
+        param = new TemplateParameter("two", "two", "float", null, false);
+        param.setDocumentation("Parameter two.");
+        params.add(param);
+        param = new TemplateParameter("three", "three", "java.util.Date", 
null, false);
+        param.setDocumentation("Parameter three.");
+        params.add(param);
+        param = new TemplateParameter("request", "request", 
Request.class.getName(), null, false);
+        param.setDocumentation("The request.");
+        params.add(param);
+        executeMethod = new TemplateMethod("execute", params);
+
+        clazz = new 
TemplateClass("org.apache.tiles.autotag.template.DoStuffNoBodyTemplate",
+                "doStuffNoBody", "DoStuffNoBody", executeMethod);
+        clazz.setDocumentation("Documentation of the DoStuffNoBody class");
+
+        suite.addTemplateClass(clazz);
+
+        Properties props = new Properties();
+        InputStream propsStream = 
getClass().getResourceAsStream("/org/apache/tiles/autotag/velocity.properties");
+        props.load(propsStream);
+        propsStream.close();
+        Velocity.init(props);
+
+        generator.generate(file, "org.apache.tiles.autotag.velocity.test", 
suite);
+
+        InputStream expected = 
getClass().getResourceAsStream("/velocity.properties.test");
+        File effectiveFile = new File(file, "META-INF/velocity.properties");
+        assertTrue(effectiveFile.exists());
+        InputStream effective = new FileInputStream(effectiveFile);
+        assertTrue(IOUtils.contentEquals(effective, expected));
+        effective.close();
+        expected.close();
+
+        FileUtils.deleteDirectory(file);
+    }
+
+}

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/java/org/apache/tiles/autotag/velocity/VelocityPropertiesGeneratorTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffDirective.javat
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,39 @@
+package org.apache.tiles.autotag.velocity.test;
+
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.tiles.autotag.core.runtime.ModelBody;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.velocity.context.VelocityUtil;
+import org.apache.tiles.velocity.template.BodyDirective;
+import org.apache.tiles.velocity.context.VelocityUtil;
+
+/**
+ * Documentation of the DoStuff class.
+ */
+public class DoStuffDirective extends BodyDirective {
+
+    /**
+     * The template model.
+     */
+    private org.apache.tiles.autotag.template.DoStuffTemplate model = new 
org.apache.tiles.autotag.template.DoStuffTemplate();
+
+    /** {...@inheritdoc} */
+    @Override
+    public String getName() {
+        return "tldtest_doStuff";
+    }
+
+    /** {...@inheritdoc} */
+    @Override
+    protected void execute(Map<String, Object> params, Request request, 
ModelBody modelBody) throws IOException {
+        model.execute(
+            (java.lang.String) VelocityUtil.getObject(parms.get("one"), null),
+            (java.lang.Integer) VelocityUtil.getObject(parms.get("two"), 0),
+            (java.lang.Boolean) VelocityUtil.getObject(parms.get("three"), 
false),
+            request, modelBody
+        );
+    }
+}

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/org/apache/tiles/autotag/velocity/test/DoStuffNoBodyDirective.javat
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,38 @@
+package org.apache.tiles.autotag.velocity.test;
+
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.tiles.request.Request;
+import org.apache.tiles.velocity.context.VelocityUtil;
+import org.apache.tiles.velocity.template.BodylessDirective;
+import org.apache.tiles.velocity.context.VelocityUtil;
+
+/**
+ * Documentation of the DoStuffNoBody class.
+ */
+public class DoStuffNoBodyDirective extends BodylessDirective {
+
+    /**
+     * The template model.
+     */
+    private org.apache.tiles.autotag.template.DoStuffNoBodyTemplate model = 
new org.apache.tiles.autotag.template.DoStuffNoBodyTemplate();
+
+    /** {...@inheritdoc} */
+    @Override
+    public String getName() {
+        return "tldtest_doStuffNoBody";
+    }
+
+    /** {...@inheritdoc} */
+    @Override
+    protected void execute(Map<String, Object> params, Request request) throws 
IOException {
+        model.execute(
+            (java.lang.Double) VelocityUtil.getObject(parms.get("one"), null),
+            (java.lang.Float) VelocityUtil.getObject(parms.get("two"), 0.0f),
+            (java.util.Date) VelocityUtil.getObject(parms.get("three"), null),
+            request
+        );
+    }
+}

Added: 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/velocity.properties.test
URL: 
http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/velocity.properties.test?rev=925591&view=auto
==============================================================================
--- 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/velocity.properties.test
 (added)
+++ 
tiles/sandbox/trunk/tiles-autotag/tiles-autotag-velocity/src/test/resources/velocity.properties.test
 Sat Mar 20 12:46:21 2010
@@ -0,0 +1,3 @@
+
+userdirective=org.apache.tiles.autotag.velocity.test.DoStuffDirective,\
+  org.apache.tiles.autotag.velocity.test.DoStuffNoBodyDirective
\ No newline at end of file


Reply via email to