You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cf...@apache.org on 2012/05/29 17:35:15 UTC
svn commit: r1343781 [12/17] - in /incubator/flex/trunk/modules: ./
thirdparty/velocity/ thirdparty/velocity/build/
thirdparty/velocity/build/lib/ thirdparty/velocity/build/xsl/
thirdparty/velocity/src/java/org/apache/velocity/anakia/ thirdparty/veloci...
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java Tue May 29 15:35:01 2012
@@ -0,0 +1,121 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeServices;
+
+import org.apache.velocity.runtime.log.LogSystem;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests if we can hand Velocity an arbitrary class for logging.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: ExternalLoggerTest.java,v 1.4.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class ExternalLoggerTest extends TestCase implements LogSystem
+{
+
+ private String logString = null;
+ private VelocityEngine ve = null;
+
+ /**
+ * Default constructor.
+ */
+ public ExternalLoggerTest()
+ {
+ super("LoggerTest");
+
+ try
+ {
+ /*
+ * use an alternative logger. Set it up here and pass it in.
+ */
+
+ ve = new VelocityEngine();
+ ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this );
+ ve.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup LoggerTest : " + e);
+ System.exit(1);
+ }
+ }
+
+ public void init( RuntimeServices rs )
+ {
+ // do nothing with it
+ }
+
+ public static junit.framework.Test suite ()
+ {
+ return new ExternalLoggerTest();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ /*
+ * simply log something and see if we get it.
+ */
+
+ logString = null;
+
+ String testString = "This is a test.";
+
+ ve.warn( testString );
+
+ if (logString == null || !logString.equals( VelocityEngine.WARN_PREFIX + testString ) )
+ {
+ fail("Didn't recieve log message.");
+ }
+ }
+
+ public void logVelocityMessage(int level, String message)
+ {
+ String out = "";
+
+ /*
+ * Start with the appropriate prefix
+ */
+ switch( level )
+ {
+ case LogSystem.DEBUG_ID :
+ out = VelocityEngine.DEBUG_PREFIX;
+ break;
+ case LogSystem.INFO_ID :
+ out = VelocityEngine.INFO_PREFIX;
+ break;
+ case LogSystem.WARN_ID :
+ out = VelocityEngine.WARN_PREFIX;
+ break;
+ case LogSystem.ERROR_ID :
+ out = VelocityEngine.ERROR_PREFIX;
+ break;
+ default :
+ out = VelocityEngine.UNKNOWN_PREFIX;
+ break;
+ }
+
+ logString = out + message;
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,143 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import java.util.Properties;
+
+import org.apache.velocity.VelocityContext;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.util.StringUtils;
+import org.apache.velocity.runtime.VelocimacroFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests if the VM template-locality is working.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
+ * @version $Id: InlineScopeVMTestCase.java,v 1.11.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class InlineScopeVMTestCase extends BaseTestCase implements TemplateTestBase
+{
+ /**
+ * The name of this test case.
+ */
+ private static final String TEST_CASE_NAME = "InlineScopeVMTestCase";
+
+ InlineScopeVMTestCase()
+ {
+ super(TEST_CASE_NAME);
+
+ try
+ {
+ /*
+ * do our properties locally, and just override the ones we want
+ * changed
+ */
+
+ Velocity.setProperty(
+ Velocity.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true");
+
+ Velocity.setProperty(
+ Velocity.VM_PERM_INLINE_LOCAL, "true");
+
+ Velocity.setProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
+
+ Velocity.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup " + TEST_CASE_NAME);
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite ()
+ {
+ return new InlineScopeVMTestCase();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ assureResultsDirectoryExists(RESULT_DIR);
+
+ /*
+ * Get the template and the output. Do them backwards.
+ * vm_test2 uses a local VM and vm_test1 doesn't
+ */
+
+ Template template2 = RuntimeSingleton.getTemplate(
+ getFileName(null, "vm_test2", TMPL_FILE_EXT));
+
+ Template template1 = RuntimeSingleton.getTemplate(
+ getFileName(null, "vm_test1", TMPL_FILE_EXT));
+
+ FileOutputStream fos1 =
+ new FileOutputStream (
+ getFileName(RESULT_DIR, "vm_test1", RESULT_FILE_EXT));
+
+ FileOutputStream fos2 =
+ new FileOutputStream (
+ getFileName(RESULT_DIR, "vm_test2", RESULT_FILE_EXT));
+
+ Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
+ Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
+
+ /*
+ * put the Vector into the context, and merge both
+ */
+
+ VelocityContext context = new VelocityContext();
+
+ template1.merge(context, writer1);
+ writer1.flush();
+ writer1.close();
+
+ template2.merge(context, writer2);
+ writer2.flush();
+ writer2.close();
+
+ if (!isMatch(RESULT_DIR,COMPARE_DIR,"vm_test1",
+ RESULT_FILE_EXT,CMP_FILE_EXT) ||
+ !isMatch(RESULT_DIR,COMPARE_DIR,"vm_test2",
+ RESULT_FILE_EXT,CMP_FILE_EXT))
+ {
+ fail("Output incorrect.");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,211 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.util.ArrayList;
+
+import java.lang.reflect.Method;
+
+import org.apache.velocity.runtime.RuntimeSingleton;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the Velocity Introspector which uses
+ * the Java Reflection API to determine the correct
+ * signature of the methods used in VTL templates.
+ *
+ * This should be split into separate tests for each
+ * of the methods searched for but this is a start
+ * for now.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: IntrospectorTestCase.java,v 1.10.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class IntrospectorTestCase extends BaseTestCase
+{
+ private Method method;
+ private String result;
+ private String type;
+ private ArrayList failures = new ArrayList();
+
+ IntrospectorTestCase()
+ {
+ super("IntrospectorTestCase");
+ }
+
+ /**
+ * Creates a new instance.
+ */
+ public IntrospectorTestCase (String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Get the containing <code>TestSuite</code>. This is always
+ * <code>VelocityTestSuite</code>.
+ *
+ * @return The <code>TestSuite</code> to run.
+ */
+ public static junit.framework.Test suite ()
+ {
+ return new IntrospectorTestCase();
+ }
+
+ public void runTest()
+ {
+ MethodProvider mp = new MethodProvider();
+
+ try
+ {
+ // Test boolean primitive.
+ Object[] booleanParams = { new Boolean(true) };
+ type = "boolean";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", booleanParams);
+ result = (String) method.invoke(mp, booleanParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test byte primitive.
+ Object[] byteParams = { new Byte("1") };
+ type = "byte";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", byteParams);
+ result = (String) method.invoke(mp, byteParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test char primitive.
+ Object[] characterParams = { new Character('a') };
+ type = "character";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", characterParams);
+ result = (String) method.invoke(mp, characterParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test double primitive.
+ Object[] doubleParams = { new Double((double)1) };
+ type = "double";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", doubleParams);
+ result = (String) method.invoke(mp, doubleParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test float primitive.
+ Object[] floatParams = { new Float((float)1) };
+ type = "float";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", floatParams);
+ result = (String) method.invoke(mp, floatParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test integer primitive.
+ Object[] integerParams = { new Integer((int)1) };
+ type = "integer";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", integerParams);
+ result = (String) method.invoke(mp, integerParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test long primitive.
+ Object[] longParams = { new Long((long)1) };
+ type = "long";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", longParams);
+ result = (String) method.invoke(mp, longParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test short primitive.
+ Object[] shortParams = { new Short((short)1) };
+ type = "short";
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, type + "Method", shortParams);
+ result = (String) method.invoke(mp, shortParams);
+
+ if (!result.equals(type))
+ failures.add(type + "Method could not be found!");
+
+ // Test untouchable
+
+ Object[] params = {};
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "untouchable", params);
+
+ if (method != null)
+ failures.add(type + "able to access a private-access method.");
+
+ // Test really untouchable
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "reallyuntouchable", params);
+
+ if (method != null)
+ failures.add(type + "able to access a default-access method.");
+
+ // There were any failures then show all the
+ // errors that occured.
+
+ int totalFailures = failures.size();
+ if (totalFailures > 0)
+ {
+ StringBuffer sb = new StringBuffer("\nIntrospection Errors:\n");
+ for (int i = 0; i < totalFailures; i++)
+ sb.append((String) failures.get(i)).append("\n");
+
+ fail(sb.toString());
+ }
+ }
+ catch (Exception e)
+ {
+ fail( e.toString() );
+ }
+ }
+
+ public static class MethodProvider
+ {
+ /*
+ * Methods with native parameter types.
+ */
+ public String booleanMethod (boolean p) { return "boolean"; }
+ public String byteMethod (byte p) { return "byte"; }
+ public String characterMethod (char p) { return "character"; }
+ public String doubleMethod (double p) { return "double"; }
+ public String floatMethod (float p) { return "float"; }
+ public String integerMethod (int p) { return "integer"; }
+ public String longMethod (long p) { return "long"; }
+ public String shortMethod (short p) { return "short"; }
+
+ String untouchable() { return "yech";}
+ private String reallyuntouchable() { return "yech!"; }
+
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase2.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase2.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase2.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase2.java Tue May 29 15:35:01 2012
@@ -0,0 +1,173 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.util.ArrayList;
+
+import java.lang.reflect.Method;
+
+import org.apache.velocity.app.Velocity;
+
+import org.apache.velocity.runtime.RuntimeSingleton;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the Velocity Introspector which
+ * tests the ability to find a 'best match'
+ *
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id: IntrospectorTestCase2.java,v 1.1.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class IntrospectorTestCase2 extends BaseTestCase
+{
+
+ IntrospectorTestCase2()
+ {
+ super("IntrospectorTestCase2");
+ }
+
+ /**
+ * Creates a new instance.
+ */
+ public IntrospectorTestCase2(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Get the containing <code>TestSuite</code>.
+ *
+ * @return The <code>TestSuite</code> to run.
+ */
+ public static junit.framework.Test suite ()
+ {
+ return new IntrospectorTestCase2();
+ }
+
+ public void runTest()
+ {
+ try
+ {
+ Velocity.init();
+
+ Method method;
+ String result;
+ Tester t = new Tester();
+
+ Object[] params = { new Foo(), new Foo() };
+
+ method = RuntimeSingleton.getIntrospector()
+ .getMethod( Tester.class, "find", params );
+
+ if ( method == null)
+ fail("Returned method was null");
+
+ result = (String) method.invoke( t, params);
+
+ if ( !result.equals( "Bar-Bar" ) )
+ {
+ fail("Should have gotten 'Bar-Bar' : recieved '" + result + "'");
+ }
+
+ /*
+ * now test for failure due to ambiguity
+ */
+
+ method = RuntimeSingleton.getIntrospector()
+ .getMethod( Tester2.class, "find", params );
+
+ if ( method != null)
+ fail("Introspector shouldn't have found a method as it's ambiguous.");
+ }
+ catch (Exception e)
+ {
+ fail( e.toString() );
+ }
+ }
+
+ public interface Woogie
+ {
+ }
+
+ public static class Bar implements Woogie
+ {
+ int i;
+ }
+
+ public static class Foo extends Bar
+ {
+ int j;
+ }
+
+ public static class Tester
+ {
+ public static String find(Woogie w, Object o )
+ {
+ return "Woogie-Object";
+ }
+
+ public static String find(Object w, Bar o )
+ {
+ return "Object-Bar";
+ }
+
+ public static String find(Bar w, Bar o )
+ {
+ return "Bar-Bar";
+ }
+
+ public static String find( Object o )
+ {
+ return "Object";
+ }
+
+ public static String find( Woogie o )
+ {
+ return "Woogie";
+ }
+ }
+
+ public static class Tester2
+ {
+ public static String find(Woogie w, Object o )
+ {
+ return "Woogie-Object";
+ }
+
+ public static String find(Object w, Bar o )
+ {
+ return "Object-Bar";
+ }
+
+ public static String find(Bar w, Object o )
+ {
+ return "Bar-Object";
+ }
+
+ public static String find( Object o )
+ {
+ return "Object";
+ }
+
+ public static String find( Woogie o )
+ {
+ return "Woogie";
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase3.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase3.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase3.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase3.java Tue May 29 15:35:01 2012
@@ -0,0 +1,152 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import java.lang.reflect.Method;
+
+import org.apache.velocity.runtime.RuntimeSingleton;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Simple introspector test case for primitive problem found in 1.3
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id: IntrospectorTestCase3.java,v 1.2.4.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class IntrospectorTestCase3 extends BaseTestCase
+{
+ /**
+ * Creates a new instance.
+ */
+ public IntrospectorTestCase3(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(IntrospectorTestCase3.class);
+ }
+
+ public void testSimple()
+ throws Exception
+ {
+ Method method;
+ String result;
+ String type;
+
+ MethodProvider mp = new MethodProvider();
+
+ /*
+ * string integer
+ */
+
+ Object[] listIntInt = { new ArrayList(), new Integer(1), new Integer(2) };
+ Object[] listLongList = { new ArrayList(), new Long(1), new ArrayList() };
+ Object[] listLongInt = { new ArrayList(), new Long(1), new Integer(2) };
+ Object[] intInt = { new Integer(1), new Integer(2) };
+ Object[] longInt = { new Long(1), new Integer(2) };
+ Object[] longLong = { new Long(1), new Long(2) };
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "lii", listIntInt);
+ result = (String) method.invoke(mp, listIntInt);
+
+ assertTrue(result.equals("lii"));
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "ii", intInt);
+ result = (String) method.invoke(mp, intInt);
+
+ assertTrue(result.equals("ii"));
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "ll", longInt);
+ result = (String) method.invoke(mp, longInt);
+
+ assertTrue(result.equals("ll"));
+
+ /*
+ * test overloading with primitives
+ */
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "ll", longLong);
+ result = (String) method.invoke(mp, longLong);
+
+ assertTrue(result.equals("ll"));
+
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "lll", listLongList);
+ result = (String) method.invoke(mp, listLongList);
+
+ assertTrue(result.equals("lll"));
+
+ /*
+ * test invocation with nulls
+ */
+
+ Object [] oa = {null, new Integer(0)};
+ method = RuntimeSingleton.getIntrospector().getMethod(
+ MethodProvider.class, "lll", oa );
+ result = (String) method.invoke(mp, oa);
+
+ assertTrue(result.equals("Listl"));
+
+ }
+
+ public static class MethodProvider
+ {
+ public String ii(int p, int d)
+ {
+ return "ii";
+ }
+
+ public String lii(List s, int p, int d)
+ {
+ return "lii";
+ }
+
+ public String lll(List s, long p, List d)
+ {
+ return "lll";
+ }
+
+
+ public String lll(List s, long p, int d)
+ {
+ return "lli";
+ }
+
+ public String lll(List s, long p)
+ {
+ return "Listl";
+ }
+
+ public String ll(long p, long d)
+ {
+ return "ll";
+ }
+
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/IntrospectorTestCase3.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java Tue May 29 15:35:01 2012
@@ -0,0 +1,207 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.StringWriter;
+
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.runtime.log.LogSystem;
+
+import org.apache.velocity.exception.MethodInvocationException;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests if we can hand Velocity an arbitrary class for logging.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: MethodInvocationExceptionTest.java,v 1.6.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class MethodInvocationExceptionTest extends TestCase
+{
+ /**
+ * Default constructor.
+ */
+ public MethodInvocationExceptionTest()
+ {
+ super("MethodInvocationExceptionTest");
+
+ try
+ {
+ /*
+ * init() Runtime with defaults
+ */
+ Velocity.init();
+
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup MethodInvocationExceptionTest : " + e);
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite ()
+ {
+ return new MethodInvocationExceptionTest();
+ }
+
+ /**
+ * Runs the test :
+ *
+ * uses the Velocity class to eval a string
+ * which accesses a method that throws an
+ * exception.
+ */
+ public void runTest ()
+ {
+ String template = "$woogie.doException() boing!";
+
+ VelocityContext vc = new VelocityContext();
+
+ vc.put("woogie", this );
+
+ StringWriter w = new StringWriter();
+
+ try
+ {
+ Velocity.evaluate( vc, w, "test", template );
+ fail("No exception thrown");
+ }
+ catch( MethodInvocationException mie )
+ {
+ System.out.println("Caught MIE (good!) :" );
+ System.out.println(" reference = " + mie.getReferenceName() );
+ System.out.println(" method = " + mie.getMethodName() );
+
+ Throwable t = mie.getWrappedThrowable();
+ System.out.println(" throwable = " + t );
+
+ if( t instanceof Exception)
+ {
+ System.out.println(" exception = " + ( (Exception) t).getMessage() );
+ }
+ }
+ catch( Exception e)
+ {
+ fail("Wrong exception thrown, first test." + e);
+ e.printStackTrace();
+ }
+
+ /*
+ * second test - to ensure that methods accessed via get+ construction
+ * also work
+ */
+
+ template = "$woogie.foo boing!";
+
+ try
+ {
+ Velocity. evaluate( vc, w, "test", template );
+ fail("No exception thrown, second test.");
+ }
+ catch( MethodInvocationException mie )
+ {
+ System.out.println("Caught MIE (good!) :" );
+ System.out.println(" reference = " + mie.getReferenceName() );
+ System.out.println(" method = " + mie.getMethodName() );
+
+ Throwable t = mie.getWrappedThrowable();
+ System.out.println(" throwable = " + t );
+
+ if( t instanceof Exception)
+ {
+ System.out.println(" exception = " + ( (Exception) t).getMessage() );
+ }
+ }
+ catch( Exception e)
+ {
+ fail("Wrong exception thrown, second test");
+ }
+
+ template = "$woogie.Foo boing!";
+
+ try
+ {
+ Velocity. evaluate( vc, w, "test", template );
+ fail("No exception thrown, third test.");
+ }
+ catch( MethodInvocationException mie )
+ {
+ System.out.println("Caught MIE (good!) :" );
+ System.out.println(" reference = " + mie.getReferenceName() );
+ System.out.println(" method = " + mie.getMethodName() );
+
+ Throwable t = mie.getWrappedThrowable();
+ System.out.println(" throwable = " + t );
+
+ if( t instanceof Exception)
+ {
+ System.out.println(" exception = " + ( (Exception) t).getMessage() );
+ }
+ }
+ catch( Exception e)
+ {
+ fail("Wrong exception thrown, third test");
+ }
+
+ template = "#set($woogie.foo = 'lala') boing!";
+
+ try
+ {
+ Velocity. evaluate( vc, w, "test", template );
+ fail("No exception thrown, set test.");
+ }
+ catch( MethodInvocationException mie )
+ {
+ System.out.println("Caught MIE (good!) :" );
+ System.out.println(" reference = " + mie.getReferenceName() );
+ System.out.println(" method = " + mie.getMethodName() );
+
+ Throwable t = mie.getWrappedThrowable();
+ System.out.println(" throwable = " + t );
+
+ if( t instanceof Exception)
+ {
+ System.out.println(" exception = " + ( (Exception) t).getMessage() );
+ }
+ }
+ catch( Exception e)
+ {
+ fail("Wrong exception thrown, set test");
+ }
+ }
+
+ public void doException()
+ throws Exception
+ {
+ throw new NullPointerException();
+ }
+
+ public void getFoo()
+ throws Exception
+ {
+ throw new Exception("Hello from getFoo()" );
+ }
+
+ public void setFoo( String foo )
+ throws Exception
+ {
+ throw new Exception("Hello from setFoo()");
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MiscTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MiscTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MiscTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MiscTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,75 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+
+import org.apache.velocity.util.StringUtils;
+
+/**
+ * Test case for any miscellaneous stuff. If it isn't big, and doesn't fit
+ * anywhere else, it goes here
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id: MiscTestCase.java,v 1.1.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class MiscTestCase extends BaseTestCase
+{
+ public MiscTestCase()
+ {
+ super("MiscTestCase");
+ }
+
+ public MiscTestCase (String name)
+ {
+ super(name);
+ }
+
+ public static Test suite ()
+ {
+ return new MiscTestCase();
+ }
+
+ public void runTest()
+ {
+ /*
+ * some StringUtils tests
+ */
+
+ String eol = "XY";
+
+ String arg = "XY";
+ String res = StringUtils.chop(arg, 1, eol );
+ assertTrue( "Test 1", res.equals("") );
+
+ arg = "X";
+ res = StringUtils.chop( arg, 1, eol );
+ assertTrue( "Test 2", res.equals("") );
+
+ arg = "ZXY";
+ res = StringUtils.chop( arg, 1, eol );
+ assertTrue( "Test 3", res.equals("Z") );
+
+
+ arg = "Hello!";
+ res = StringUtils.chop( arg, 2, eol );
+ assertTrue( "Test 4", res.equals("Hell"));
+
+ }
+
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MiscTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultiLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultiLoaderTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultiLoaderTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultiLoaderTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,229 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.File;
+
+import java.util.Properties;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.util.StringUtils;
+import org.apache.velocity.runtime.VelocimacroFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Load templates from the Classpath.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
+ * @version $Id: MultiLoaderTestCase.java,v 1.4.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class MultiLoaderTestCase extends BaseTestCase
+{
+ /**
+ * VTL file extension.
+ */
+ private static final String TMPL_FILE_EXT = "vm";
+
+ /**
+ * Comparison file extension.
+ */
+ private static final String CMP_FILE_EXT = "cmp";
+
+ /**
+ * Comparison file extension.
+ */
+ private static final String RESULT_FILE_EXT = "res";
+
+ /**
+ * Results relative to the build directory.
+ */
+ private static final String RESULTS_DIR = "../test/multiloader/results";
+
+ /**
+ * Path for templates. This property will override the
+ * value in the default velocity properties file.
+ */
+ private final static String FILE_RESOURCE_LOADER_PATH = "../test/multiloader";
+
+ /**
+ * Results relative to the build directory.
+ */
+ private static final String COMPARE_DIR = "../test/multiloader/compare";
+
+ /**
+ * Default constructor.
+ */
+ public MultiLoaderTestCase()
+ {
+ super("MultiLoaderTestCase");
+
+ try
+ {
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ /*
+ * Set up the file loader.
+ */
+
+ Velocity.setProperty(Velocity.RESOURCE_LOADER, "file");
+
+ Velocity.setProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
+
+ Velocity.addProperty(Velocity.RESOURCE_LOADER, "classpath");
+
+ Velocity.addProperty(Velocity.RESOURCE_LOADER, "jar");
+
+ /*
+ * Set up the classpath loader.
+ */
+
+ Velocity.setProperty(
+ "classpath." + Velocity.RESOURCE_LOADER + ".class",
+ "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+
+ Velocity.setProperty(
+ "classpath." + Velocity.RESOURCE_LOADER + ".cache", "false");
+
+ Velocity.setProperty(
+ "classpath." + Velocity.RESOURCE_LOADER + ".modificationCheckInterval",
+ "2");
+
+ /*
+ * setup the Jar loader
+ */
+
+ Velocity.setProperty(
+ "jar." + Velocity.RESOURCE_LOADER + ".class",
+ "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
+
+ Velocity.setProperty( "jar." + Velocity.RESOURCE_LOADER + ".path",
+ "jar:file:" + FILE_RESOURCE_LOADER_PATH + "/test2.jar" );
+
+ Velocity.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup MultiLoaderTestCase!");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite ()
+ {
+ return new MultiLoaderTestCase();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ /*
+ * lets ensure the results directory exists
+ */
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ /*
+ * Template to find with the file loader.
+ */
+ Template template1 = Velocity.getTemplate(
+ getFileName(null, "path1", TMPL_FILE_EXT));
+
+ /*
+ * Template to find with the classpath loader.
+ */
+ Template template2 = Velocity.getTemplate(
+ getFileName(null, "template/test1", TMPL_FILE_EXT));
+
+ /*
+ * Template to find with the jar loader
+ */
+ Template template3 = Velocity.getTemplate(
+ getFileName(null, "template/test2", TMPL_FILE_EXT));
+
+ /*
+ * and the results files
+ */
+
+ FileOutputStream fos1 =
+ new FileOutputStream (
+ getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));
+
+ FileOutputStream fos2 =
+ new FileOutputStream (
+ getFileName(RESULTS_DIR, "test2", RESULT_FILE_EXT));
+
+ FileOutputStream fos3 =
+ new FileOutputStream (
+ getFileName(RESULTS_DIR, "test3", RESULT_FILE_EXT));
+
+ Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
+ Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
+ Writer writer3 = new BufferedWriter(new OutputStreamWriter(fos3));
+
+ /*
+ * put the Vector into the context, and merge both
+ */
+
+ VelocityContext context = new VelocityContext();
+
+ template1.merge(context, writer1);
+ writer1.flush();
+ writer1.close();
+
+ template2.merge(context, writer2);
+ writer2.flush();
+ writer2.close();
+
+ template3.merge(context, writer3);
+ writer3.flush();
+ writer3.close();
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"path1",RESULT_FILE_EXT,CMP_FILE_EXT))
+ {
+ fail("Output incorrect for FileResourceLoader test.");
+ }
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"test2",RESULT_FILE_EXT,CMP_FILE_EXT) )
+ {
+ fail("Output incorrect for ClasspathResourceLoader test.");
+ }
+
+ if( !isMatch(RESULTS_DIR,COMPARE_DIR,"test3",RESULT_FILE_EXT,CMP_FILE_EXT))
+ {
+ fail("Output incorrect for JarResourceLoader test.");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultiLoaderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java Tue May 29 15:35:01 2012
@@ -0,0 +1,166 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.io.File;
+
+import java.util.Properties;
+
+import org.apache.velocity.VelocityContext;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.util.StringUtils;
+import org.apache.velocity.runtime.VelocimacroFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Multiple paths in the file resource loader.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: MultipleFileResourcePathTest.java,v 1.8.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class MultipleFileResourcePathTest extends BaseTestCase
+{
+ /**
+ * VTL file extension.
+ */
+ private static final String TMPL_FILE_EXT = "vm";
+
+ /**
+ * Comparison file extension.
+ */
+ private static final String CMP_FILE_EXT = "cmp";
+
+ /**
+ * Comparison file extension.
+ */
+ private static final String RESULT_FILE_EXT = "res";
+
+ /**
+ * Path for templates. This property will override the
+ * value in the default velocity properties file.
+ */
+ private final static String FILE_RESOURCE_LOADER_PATH1 = "../test/multi/path1";
+
+ /**
+ * Path for templates. This property will override the
+ * value in the default velocity properties file.
+ */
+ private final static String FILE_RESOURCE_LOADER_PATH2 = "../test/multi/path2";
+
+ /**
+ * Results relative to the build directory.
+ */
+ private static final String RESULTS_DIR = "../test/multi/results";
+
+ /**
+ * Results relative to the build directory.
+ */
+ private static final String COMPARE_DIR = "../test/multi/compare";
+
+ /**
+ * Default constructor.
+ */
+ MultipleFileResourcePathTest()
+ {
+ super("MultipleFileResourcePathTest");
+
+ try
+ {
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ Velocity.addProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);
+
+ Velocity.addProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH2);
+
+ Velocity.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup MultipleFileResourcePathTest!");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite ()
+ {
+ return new MultipleFileResourcePathTest();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ Template template1 = RuntimeSingleton.getTemplate(
+ getFileName(null, "path1", TMPL_FILE_EXT));
+
+ Template template2 = RuntimeSingleton.getTemplate(
+ getFileName(null, "path2", TMPL_FILE_EXT));
+
+ FileOutputStream fos1 =
+ new FileOutputStream (
+ getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));
+
+ FileOutputStream fos2 =
+ new FileOutputStream (
+ getFileName(RESULTS_DIR, "path2", RESULT_FILE_EXT));
+
+ Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
+ Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
+
+ /*
+ * put the Vector into the context, and merge both
+ */
+
+ VelocityContext context = new VelocityContext();
+
+ template1.merge(context, writer1);
+ writer1.flush();
+ writer1.close();
+
+ template2.merge(context, writer2);
+ writer2.flush();
+ writer2.close();
+
+ if (!isMatch(RESULTS_DIR, COMPARE_DIR, "path1",
+ RESULT_FILE_EXT, CMP_FILE_EXT) ||
+ !isMatch(RESULTS_DIR, COMPARE_DIR, "path2",
+ RESULT_FILE_EXT, CMP_FILE_EXT))
+ {
+ fail("Output incorrect.");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ParserTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ParserTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ParserTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ParserTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,158 @@
+package org.apache.velocity.test;
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.exception.ParseErrorException;
+
+import java.io.StringWriter;
+
+/**
+ * More specific parser tests where just templating
+ * isn't enough.
+ *
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id: ParserTestCase.java,v 1.1.4.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class ParserTestCase extends TestCase
+{
+ public ParserTestCase(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(ParserTestCase.class);
+ }
+
+ /**
+ * Test to make sure that using '=' in #if() throws a PEE
+ */
+ public void testEquals()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+
+ ve.init();
+
+ /*
+ * this should parse fine -> uses ==
+ */
+
+ String template = "#if($a == $b) foo #end";
+
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+
+ /*
+ * this should throw an exception
+ */
+
+ template = "#if($a = $b) foo #end";
+
+ try
+ {
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+ assertTrue(false);
+ }
+ catch(ParseErrorException pe)
+ {
+ }
+ }
+
+ /**
+ * Test to see if we force the first arg to #macro() to be a word
+ */
+ public void testMacro()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+
+ ve.init();
+
+ /*
+ * this should work
+ */
+
+ String template = "#macro(foo) foo #end";
+
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+
+ /*
+ * this should throw an exception
+ */
+
+ template = "#macro($x) foo #end";
+
+ try
+ {
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+ assertTrue(false);
+ }
+ catch(ParseErrorException pe)
+ {
+ }
+ }
+
+ /**
+ * Test to see if don't tolerage passing word tokens in anything but the
+ * 0th arg to #macro() and the 1th arg to foreach()
+ */
+ public void testArgs()
+ throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+
+ ve.init();
+
+ /*
+ * this should work
+ */
+
+ String template = "#macro(foo) foo #end";
+
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+
+ /*
+ * this should work - spaces intentional
+ */
+
+ template = "#foreach( $i in $woogie ) end #end";
+
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+
+ /*
+ * this should bomb
+ */
+
+ template = "#macro( foo $a) $a #end #foo(woogie)";
+
+ try
+ {
+ ve.evaluate(new VelocityContext(), new StringWriter(), "foo", template);
+ assertTrue(false);
+ }
+ catch(ParseErrorException pe)
+ {
+ System.out.println("Caught pee!");
+ }
+ }
+
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/ParserTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestBase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestBase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestBase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestBase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,68 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+/**
+ * This is a base interface that contains a bunch of static final
+ * strings that are of use when testing templates.
+ *
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @version $Id: TemplateTestBase.java,v 1.2.14.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public interface TemplateTestBase
+{
+ /**
+ * VTL file extension.
+ */
+ public final static String TMPL_FILE_EXT = "vm";
+
+ /**
+ * Comparison file extension.
+ */
+ public final static String CMP_FILE_EXT = "cmp";
+
+ /**
+ * Comparison file extension.
+ */
+ public final static String RESULT_FILE_EXT = "res";
+
+ /**
+ * Path for templates. This property will override the
+ * value in the default velocity properties file.
+ */
+ public final static String FILE_RESOURCE_LOADER_PATH =
+ "../test/templates";
+
+ /**
+ * Properties file that lists which template tests to run.
+ */
+ public final static String TEST_CASE_PROPERTIES =
+ FILE_RESOURCE_LOADER_PATH + "/templates.properties";
+
+ /**
+ * Results relative to the build directory.
+ */
+ public final static String RESULT_DIR =
+ FILE_RESOURCE_LOADER_PATH + "/results";
+
+ /**
+ * Results relative to the build directory.
+ */
+ public final static String COMPARE_DIR =
+ FILE_RESOURCE_LOADER_PATH + "/compare";
+
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,202 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Vector;
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.Template;
+import org.apache.velocity.runtime.RuntimeSingleton;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.test.provider.BoolObj;
+import org.apache.velocity.util.StringUtils;
+
+import org.apache.velocity.app.FieldMethodizer;
+
+import junit.framework.TestCase;
+
+/**
+ * Easily add test cases which evaluate templates and check their output.
+ *
+ * NOTE:
+ * This class DOES NOT extend RuntimeTestCase because the TemplateTestSuite
+ * already initializes the Velocity runtime and adds the template
+ * test cases. Having this class extend RuntimeTestCase causes the
+ * Runtime to be initialized twice which is not good. I only discovered
+ * this after a couple hours of wondering why all the properties
+ * being setup were ending up as Vectors. At first I thought it
+ * was a problem with the Configuration class, but the Runtime
+ * was being initialized twice: so the first time the property
+ * is seen it's stored as a String, the second time it's seen
+ * the Configuration class makes a Vector with both Strings.
+ * As a result all the getBoolean(property) calls were failing because
+ * the Configurations class was trying to create a Boolean from
+ * a Vector which doesn't really work that well. I have learned
+ * my lesson and now have to add some code to make sure the
+ * Runtime isn't initialized more then once :-)
+ *
+ * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @version $Id: TemplateTestCase.java,v 1.34.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class TemplateTestCase extends BaseTestCase implements TemplateTestBase
+{
+ /**
+ * The base file name of the template and comparison file (i.e. array for
+ * array.vm and array.cmp).
+ */
+ protected String baseFileName;
+
+ private TestProvider provider;
+ private ArrayList al;
+ private Hashtable h;
+ private VelocityContext context;
+ private VelocityContext context1;
+ private VelocityContext context2;
+ private Vector vec;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param baseFileName The base name of the template and comparison file to
+ * use (i.e. array for array.vm and array.cmp).
+ */
+ public TemplateTestCase (String baseFileName)
+ {
+ super(getTestCaseName(baseFileName));
+ this.baseFileName = baseFileName;
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new TemplateTestSuite();
+ }
+
+ /**
+ * Sets up the test.
+ */
+ protected void setUp ()
+ {
+ provider = new TestProvider();
+ al = provider.getCustomers();
+ h = new Hashtable();
+
+ h.put("Bar", "this is from a hashtable!");
+ h.put("Foo", "this is from a hashtable too!");
+
+ /*
+ * lets set up a vector of objects to test late introspection. See ASTMethod.java
+ */
+
+ vec = new Vector();
+
+ vec.addElement(new String("string1"));
+ vec.addElement(new String("string2"));
+
+ /*
+ * set up 3 chained contexts, and add our data
+ * throught the 3 of them.
+ */
+
+ context2 = new VelocityContext();
+ context1 = new VelocityContext( context2 );
+ context = new VelocityContext( context1 );
+
+ context.put("provider", provider);
+ context1.put("name", "jason");
+ context2.put("providers", provider.getCustomers2());
+ context.put("list", al);
+ context1.put("hashtable", h);
+ context2.put("hashmap", new HashMap());
+ context2.put("search", provider.getSearch());
+ context.put("relatedSearches", provider.getRelSearches());
+ context1.put("searchResults", provider.getRelSearches());
+ context2.put("stringarray", provider.getArray());
+ context.put("vector", vec );
+ context.put("mystring", new String());
+ context.put("runtime", new FieldMethodizer( "org.apache.velocity.runtime.RuntimeSingleton" ));
+ context.put("fmprov", new FieldMethodizer( provider ));
+ context.put("Floog", "floogie woogie");
+ context.put("boolobj", new BoolObj() );
+
+ /*
+ * we want to make sure we test all types of iterative objects
+ * in #foreach()
+ */
+
+ Object[] oarr = { "a","b","c","d" } ;
+ int intarr[] = { 10, 20, 30, 40, 50 };
+
+ context.put( "collection", vec );
+ context2.put("iterator", vec.iterator());
+ context1.put("map", h );
+ context.put("obarr", oarr );
+ context.put("enumerator", vec.elements());
+ context.put("intarr", intarr );
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ Template template = RuntimeSingleton.getTemplate
+ (getFileName(null, baseFileName, TMPL_FILE_EXT));
+
+ assureResultsDirectoryExists(RESULT_DIR);
+
+ /* get the file to write to */
+ FileOutputStream fos =
+ new FileOutputStream (getFileName(
+ RESULT_DIR, baseFileName, RESULT_FILE_EXT));
+
+ Writer writer = new BufferedWriter(new OutputStreamWriter(fos));
+
+ /* process the template */
+ template.merge( context, writer);
+
+ /* close the file */
+ writer.flush();
+ writer.close();
+
+ if (!isMatch(RESULT_DIR,COMPARE_DIR,baseFileName,
+ RESULT_FILE_EXT,CMP_FILE_EXT))
+ {
+ fail("Processed template did not match expected output");
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println("EXCEPTION : " + e );
+
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java Tue May 29 15:35:01 2012
@@ -0,0 +1,107 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.FileInputStream;
+
+import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.velocity.app.Velocity;
+
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for Templates.
+ *
+ * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @version $Id: TemplateTestSuite.java,v 1.6.8.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class TemplateTestSuite extends TestSuite implements TemplateTestBase
+{
+ private Properties testProperties;
+
+ /**
+ * Creates an instace of the Apache Velocity test suite.
+ */
+ public TemplateTestSuite()
+ {
+ try
+ {
+ Velocity.setProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
+
+ Velocity.setProperty(Velocity.RUNTIME_LOG_ERROR_STACKTRACE, "true");
+ Velocity.setProperty(Velocity.RUNTIME_LOG_WARN_STACKTRACE, "true");
+ Velocity.setProperty(Velocity.RUNTIME_LOG_INFO_STACKTRACE, "true");
+
+ Velocity.init();
+
+ testProperties = new Properties();
+ testProperties.load(new FileInputStream(TEST_CASE_PROPERTIES));
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup TemplateTestSuite!");
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ addTemplateTestCases();
+ }
+
+ /**
+ * Adds the template test cases to run to this test suite. Template test
+ * cases are listed in the <code>TEST_CASE_PROPERTIES</code> file.
+ */
+ private void addTemplateTestCases()
+ {
+ String template;
+ for (int i = 1 ;; i++)
+ {
+ template = testProperties.getProperty(getTemplateTestKey(i));
+
+ if (template != null)
+ {
+ System.out.println("Adding TemplateTestCase : " + template);
+ addTest(new TemplateTestCase(template));
+ }
+ else
+ {
+ // Assume we're done adding template test cases.
+ break;
+ }
+ }
+ }
+
+ /**
+ * Macro which returns the properties file key for the specified template
+ * test number.
+ *
+ * @param nbr The template test number to return a property key for.
+ * @return The property key.
+ */
+ private static final String getTemplateTestKey(int nbr)
+ {
+ return ("test.template." + nbr);
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenClasspathTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenClasspathTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenClasspathTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenClasspathTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,90 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.File;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.util.StringUtils;
+import junit.framework.TestCase;
+
+/**
+ * This is a test case for Texen. Simply executes a simple
+ * generative task and compares the output.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: TexenClasspathTestCase.java,v 1.3.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class TexenClasspathTestCase
+ extends BaseTestCase
+{
+ /**
+ * Directory where results are generated.
+ */
+ private static final String RESULTS_DIR = "../test/texen-classpath/results";
+
+ /**
+ * Directory where comparison output is stored.
+ */
+ private static final String COMPARE_DIR = "../test/texen-classpath/compare";
+
+ /**
+ * Creates a new instance.
+ *
+ */
+ public TexenClasspathTestCase()
+ {
+ super("TexenClasspathTestCase");
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new TexenClasspathTestCase();
+ }
+
+ /**
+ * Sets up the test.
+ */
+ protected void setUp ()
+ {
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeather","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeatherService","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"WeatherService","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"book","txt","txt") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"Test","txt","txt"))
+ {
+ fail("Output is incorrect!");
+ }
+ }
+ catch(Exception e)
+ {
+ /*
+ * do nothing.
+ */
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenClasspathTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,89 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.File;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.util.StringUtils;
+import junit.framework.TestCase;
+
+/**
+ * This is a test case for Texen. Simply executes a simple
+ * generative task and compares the output.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id: TexenTestCase.java,v 1.6.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class TexenTestCase extends BaseTestCase
+{
+ /**
+ * Directory where results are generated.
+ */
+ private static final String RESULTS_DIR = "../test/texen/results";
+
+ /**
+ * Directory where comparison output is stored.
+ */
+ private static final String COMPARE_DIR = "../test/texen/compare";
+
+ /**
+ * Creates a new instance.
+ *
+ */
+ public TexenTestCase()
+ {
+ super("TexenTestCase");
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new TexenTestCase();
+ }
+
+ /**
+ * Sets up the test.
+ */
+ protected void setUp ()
+ {
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeather","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeatherService","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"WeatherService","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"book","txt","txt") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"Test","txt","txt"))
+ {
+ fail("Output is incorrect!");
+ }
+ }
+ catch(Exception e)
+ {
+ /*
+ * do nothing.
+ */
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/TexenTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocimacroTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocimacroTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocimacroTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocimacroTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,96 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+
+import java.util.Vector;
+
+import org.apache.velocity.VelocityContext;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.util.StringUtils;
+
+import org.apache.velocity.app.Velocity;
+
+import junit.framework.TestCase;
+
+/**
+ * This class tests strange Velocimacro issues.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @version $Id: VelocimacroTestCase.java,v 1.1.10.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class VelocimacroTestCase extends TestCase
+{
+ private String template1 = "#macro(foo $a)$a#end #macro(bar $b)#foo($b)#end #foreach($i in [1..3])#bar($i)#end";
+ private String result1 = " 123";
+
+ public VelocimacroTestCase()
+ {
+ super("VelocimacroTestCase");
+
+ try
+ {
+ /*
+ * setup local scope for templates
+ */
+ Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE);
+ Velocity.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup VelocimacroTestCase!");
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new VelocimacroTestCase();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ VelocityContext context = new VelocityContext();
+
+ try
+ {
+ StringWriter writer = new StringWriter();
+ Velocity.evaluate(context, writer, "vm_chain1", template1);
+
+ String out = writer.toString();
+
+ if( !result1.equals( out ) )
+ {
+ fail("output incorrect.");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocimacroTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java
URL: http://svn.apache.org/viewvc/incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java?rev=1343781&view=auto
==============================================================================
--- incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java (added)
+++ incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java Tue May 29 15:35:01 2012
@@ -0,0 +1,107 @@
+package org.apache.velocity.test;
+
+/*
+ * Copyright 2001,2004 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+
+import java.util.Vector;
+
+import org.apache.velocity.VelocityContext;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.test.provider.TestProvider;
+import org.apache.velocity.util.StringUtils;
+
+import org.apache.velocity.app.Velocity;
+
+import junit.framework.TestCase;
+
+/**
+ * This class is intended to test the app.Velocity.java class.
+ *
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
+ * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @version $Id: VelocityAppTestCase.java,v 1.3.14.1 2004/03/03 23:23:04 geirm Exp $
+ */
+public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase
+{
+ private StringWriter compare1 = new StringWriter();
+ private String input1 = "My name is $name -> $Floog";
+ private String result1 = "My name is jason -> floogie woogie";
+
+ public VelocityAppTestCase()
+ {
+ super("VelocityAppTestCase");
+
+ try
+ {
+ Velocity.setProperty(
+ Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
+
+ Velocity.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup VelocityAppTestCase!");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new VelocityAppTestCase();
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ VelocityContext context = new VelocityContext();
+ context.put("name", "jason");
+ context.put("Floog", "floogie woogie");
+
+ try
+ {
+ Velocity.evaluate(context, compare1, "evaltest", input1);
+
+/*
+ FIXME: Not tested right now.
+
+ StringWriter result2 = new StringWriter();
+ Velocity.mergeTemplate("mergethis.vm", context, result2);
+
+ StringWriter result3 = new StringWriter();
+ Velocity.invokeVelocimacro("floog", "test", new String[2],
+ context, result3);
+*/
+ if (!result1.equals(compare1.toString()))
+ {
+ fail("Output incorrect.");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+}
Propchange: incubator/flex/trunk/modules/thirdparty/velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native