Author: nbubna
Date: Mon Jul 9 12:09:20 2007
New Revision: 554741
URL: http://svn.apache.org/viewvc?view=rev&rev=554741
Log:
add testing for old toolbox format and for data
Added:
velocity/tools/branches/2.x/test/conf/toolbox.test.xml (with props)
Modified:
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
velocity/tools/branches/2.x/test/conf/tools.test.properties
velocity/tools/branches/2.x/test/conf/tools.test.xml
Modified:
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java?view=diff&rev=554741&r1=554740&r2=554741
==============================================================================
---
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
(original)
+++
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
Mon Jul 9 12:09:20 2007
@@ -22,7 +22,7 @@
import java.util.Locale;
import org.junit.*;
import static org.junit.Assert.*;
-import org.apache.velocity.tools.generic.DateTool;
+import org.apache.velocity.tools.view.ViewRenderTool;
import org.apache.velocity.tools.generic.MathTool;
import org.apache.velocity.tools.generic.NumberTool;
import org.apache.velocity.tools.config.*;
@@ -37,40 +37,66 @@
public class ConfigTests {
private static final String XML_PATH = "@test.conf.dir@/tools.test.xml";
+ private static final String OLD_XML_PATH =
"@test.conf.dir@/toolbox.test.xml";
private static final String PROPS_PATH =
"@test.conf.dir@/tools.test.properties";
- private static final FactoryConfiguration baseline;
- static
+ protected FactoryConfiguration getBaseConfig()
{
- baseline = new FactoryConfiguration();
- ToolboxConfiguration toolbox = new ToolboxConfiguration();
- toolbox.setScope("request");
- toolbox.setProperty("locale", Locale.US);
- ToolConfiguration tool = new ToolConfiguration();
- tool.setClassname(DateTool.class.getName());
- toolbox.addTool(tool);
+ FactoryConfiguration base = new FactoryConfiguration();
- tool = new ToolConfiguration();
+ Data datum = new Data();
+ datum.setKey("version");
+ datum.setType("number");
+ datum.setValue("2.0");
+ base.addData(datum);
+
+ ToolboxConfiguration toolbox = new ToolboxConfiguration();
+ toolbox.setScope("request");
+ toolbox.setProperty("locale", Locale.US);
+ ToolConfiguration tool = new ToolConfiguration();
+ tool.setClass(ViewRenderTool.class);
+ toolbox.addTool(tool);
+ base.addToolbox(toolbox);
+
+ toolbox = new ToolboxConfiguration();
+ toolbox.setScope("application");
+ tool = new ToolConfiguration();
tool.setKey("calc");
- tool.setClassname(MathTool.class.getName());
- toolbox.addTool(tool);
- baseline.addToolbox(toolbox);
-
- toolbox = new ToolboxConfiguration();
- toolbox.setScope("application");
- tool = new ToolConfiguration();
- tool.setClassname(NumberTool.class.getName());
+ tool.setClass(MathTool.class);
+ toolbox.addTool(tool);
+
+ tool = new ToolConfiguration();
+ tool.setClass(NumberTool.class);
tool.setProperty("locale", Locale.FRENCH);
- toolbox.addTool(tool);
- baseline.addToolbox(toolbox);
+ toolbox.addTool(tool);
+ base.addToolbox(toolbox);
+
+ return base;
}
+
public @Test void testXmlConfig()
{
FileFactoryConfiguration xml = new XmlFactoryConfiguration();
xml.read(XML_PATH);
- assertConfigEquals(baseline, xml);
+ assertConfigEquals(getBaseConfig(), xml);
+ }
+
+ public @Test void testOldConfig()
+ {
+ FileFactoryConfiguration old = new XmlFactoryConfiguration(true);
+ old.read(OLD_XML_PATH);
+
+ FactoryConfiguration base = getBaseConfig();
+ // remove the request toolbox property locale=en_US manually,
+ // because the old format provide no means to set properties
+ // on a whole toolbox
+ base.getToolbox("request").removeProperty("locale");
+ // add the expected deprecationSupportMode property
+ base.setProperty("deprecationSupportMode", "true");
+
+ assertConfigEquals(base, old);
}
public @Test void testPropsConfig()
@@ -78,26 +104,30 @@
FileFactoryConfiguration props = new PropertiesFactoryConfiguration();
props.read(PROPS_PATH);
- assertConfigEquals(baseline, props);
+ assertConfigEquals(getBaseConfig(), props);
}
public @Test void testEasyConfig()
{
EasyFactoryConfiguration easy = new EasyFactoryConfiguration();
+ easy.number("version", 2.0);
easy.toolbox("request")
- .property("locale", Locale.US)
- .tool(DateTool.class)
- .tool("calc", MathTool.class);
+ .property("locale", Locale.US)
+ .tool(ViewRenderTool.class);
easy.toolbox("application")
- .tool(NumberTool.class).property("locale", Locale.FRENCH);
+ .tool("calc", MathTool.class)
+ .tool(NumberTool.class)
+ .property("locale", Locale.FRENCH);
- assertConfigEquals(baseline, easy);
+ assertConfigEquals(getBaseConfig(), easy);
}
protected void assertConfigEquals(Configuration one, Configuration two)
{
assertNotNull(one);
assertNotNull(two);
+if (!one.toString().equals(two.toString()))
+System.out.println("\n"+one.getClass().getName()+":\n"+one+"\n"+two.getClass().getName()+":\n"+two+"\n");
// for now, just compare the toString() output
assertEquals(one.toString(), two.toString());
Added: velocity/tools/branches/2.x/test/conf/toolbox.test.xml
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/test/conf/toolbox.test.xml?view=auto&rev=554741
==============================================================================
--- velocity/tools/branches/2.x/test/conf/toolbox.test.xml (added)
+++ velocity/tools/branches/2.x/test/conf/toolbox.test.xml Mon Jul 9 12:09:20
2007
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+
+<!--
+ 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.
+-->
+<toolbox>
+ <data type="number">
+ <key>version</key>
+ <value>2.0</value>
+ </data>
+ <tool>
+ <class>org.apache.velocity.tools.view.ViewRenderTool</class>
+ <key>render</key>
+ </tool>
+ <tool>
+ <class>org.apache.velocity.tools.generic.MathTool</class>
+ <key>calc</key>
+ <scope>application</scope>
+ </tool>
+ <tool>
+ <class>org.apache.velocity.tools.generic.NumberTool</class>
+ <key>number</key>
+ <scope>application</scope>
+ <parameter name="locale" value="fr"/>
+ </tool>
+</toolbox>
Propchange: velocity/tools/branches/2.x/test/conf/toolbox.test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: velocity/tools/branches/2.x/test/conf/tools.test.properties
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/test/conf/tools.test.properties?view=diff&rev=554741&r1=554740&r2=554741
==============================================================================
--- velocity/tools/branches/2.x/test/conf/tools.test.properties (original)
+++ velocity/tools/branches/2.x/test/conf/tools.test.properties Mon Jul 9
12:09:20 2007
@@ -16,8 +16,10 @@
## under the License.
tools.toolbox = request,application
+tools.data.version = 2.0
+tools.data.version.type = number
tools.request.property.locale = en_US
-tools.request.date = org.apache.velocity.tools.generic.DateTool
-tools.request.calc = org.apache.velocity.tools.generic.MathTool
+tools.request.render = org.apache.velocity.tools.view.ViewRenderTool
+tools.application.calc = org.apache.velocity.tools.generic.MathTool
tools.application.number = org.apache.velocity.tools.generic.NumberTool
-tools.application.number.locale = fr
\ No newline at end of file
+tools.application.number.locale = fr
Modified: velocity/tools/branches/2.x/test/conf/tools.test.xml
URL:
http://svn.apache.org/viewvc/velocity/tools/branches/2.x/test/conf/tools.test.xml?view=diff&rev=554741&r1=554740&r2=554741
==============================================================================
--- velocity/tools/branches/2.x/test/conf/tools.test.xml (original)
+++ velocity/tools/branches/2.x/test/conf/tools.test.xml Mon Jul 9 12:09:20
2007
@@ -19,11 +19,12 @@
under the License.
-->
<tools>
+ <data key="version" type="number" value="2.0"/>
<toolbox scope="request" locale="en_US">
- <tool class="org.apache.velocity.tools.generic.DateTool"/>
- <tool key="calc" class="org.apache.velocity.tools.generic.MathTool"/>
+ <tool class="org.apache.velocity.tools.view.ViewRenderTool"/>
</toolbox>
<toolbox scope="application">
+ <tool key="calc" class="org.apache.velocity.tools.generic.MathTool"/>
<tool class="org.apache.velocity.tools.generic.NumberTool"
locale="fr"/>
</toolbox>
</tools>