You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2007/07/06 20:55:54 UTC
svn commit: r553996 - in /velocity/tools/branches/2.x:
src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
test/conf/tools.test.properties test/conf/tools.test.xml
Author: nbubna
Date: Fri Jul 6 11:55:53 2007
New Revision: 553996
URL: http://svn.apache.org/viewvc?view=rev&rev=553996
Log:
add some configuration tests
Added:
velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java (with props)
velocity/tools/branches/2.x/test/conf/tools.test.properties (with props)
velocity/tools/branches/2.x/test/conf/tools.test.xml (with props)
Added: 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=auto&rev=553996
==============================================================================
--- velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java (added)
+++ velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java Fri Jul 6 11:55:53 2007
@@ -0,0 +1,129 @@
+package org.apache.velocity.tools.test.whitebox;
+
+/*
+ * 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.util.Locale;
+import java.util.Map;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.junit.*;
+import static org.junit.Assert.*;
+
+import org.apache.velocity.tools.generic.Alternator;
+import org.apache.velocity.tools.generic.AlternatorTool;
+import org.apache.velocity.tools.generic.ComparisonDateTool;
+import org.apache.velocity.tools.generic.DateTool;
+import org.apache.velocity.tools.generic.EscapeTool;
+import org.apache.velocity.tools.generic.MathTool;
+import org.apache.velocity.tools.generic.NumberTool;
+import org.apache.velocity.tools.generic.ResourceTool;
+import org.apache.velocity.tools.ToolManager;
+import org.apache.velocity.tools.config.*;
+
+/**
+ * <p>Configuration tests.</p>
+ *
+ * @author Nathan Bubna
+ * @since Velocity Tools 2.0
+ * @version $Id$
+ */
+public class ConfigTests {
+
+ private static final String XML_PATH = "@test.conf.dir@/tools.test.xml";
+ private static final String PROPS_PATH = "@test.conf.dir@/tools.test.properties";
+
+ private static final FactoryConfiguration baseline;
+ static
+ {
+ 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);
+
+ 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.setProperty("locale", Locale.FRENCH);
+ toolbox.addTool(tool);
+ baseline.addToolbox(toolbox);
+System.out.println("baseline: \n"+baseline.toString()+"\n\n");
+ }
+
+ /*public static @BeforeClass void initConfigTests() throws Exception {
+ ToolManager manager = new ToolManager(false);
+ manager.configure(TOOLBOX_PATH);
+ toolbox = manager.createContext();
+ }*/
+
+ public @Test void testXmlConfig()
+ {
+ XmlFactoryConfiguration xml = new XmlFactoryConfiguration();
+ xml.read(XML_PATH);
+System.out.println("xml: \n"+xml.toString()+"\n\n");
+
+ assertConfigEquals(baseline, xml);
+ }
+
+ public @Test void testPropsConfig()
+ {
+ PropertiesFactoryConfiguration props =
+ new PropertiesFactoryConfiguration();
+ props.read(PROPS_PATH);
+System.out.println("props: \n"+props.toString()+"\n\n");
+
+ assertConfigEquals(baseline, props);
+ }
+
+ public @Test void testEasyConfig()
+ {
+ EasyFactoryConfiguration easy = new EasyFactoryConfiguration();
+ easy.toolbox("request")
+ .property("locale", Locale.US)
+ .tool(DateTool.class)
+ .tool("calc", MathTool.class);
+ easy.toolbox("application")
+ .tool(NumberTool.class).property("locale", Locale.FRENCH);
+System.out.println("easy: \n"+easy.toString()+"\n\n");
+
+ assertConfigEquals(baseline, easy);
+ }
+
+ protected void assertConfigEquals(Configuration one, Configuration two)
+ {
+ assertNotNull(one);
+ assertNotNull(two);
+
+ // for now, just compare the toString() output
+ assertEquals(one.toString(), two.toString());
+ }
+
+}
Propchange: velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/tools/branches/2.x/src/test/java/org/apache/velocity/tools/test/whitebox/ConfigTests.java
------------------------------------------------------------------------------
svn:keywords = Revision
Added: 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=auto&rev=553996
==============================================================================
--- velocity/tools/branches/2.x/test/conf/tools.test.properties (added)
+++ velocity/tools/branches/2.x/test/conf/tools.test.properties Fri Jul 6 11:55:53 2007
@@ -0,0 +1,23 @@
+## 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.
+
+tools.toolbox = request,application
+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.application.number = org.apache.velocity.tools.generic.NumberTool
+tools.application.number.locale = fr
\ No newline at end of file
Propchange: velocity/tools/branches/2.x/test/conf/tools.test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=auto&rev=553996
==============================================================================
--- velocity/tools/branches/2.x/test/conf/tools.test.xml (added)
+++ velocity/tools/branches/2.x/test/conf/tools.test.xml Fri Jul 6 11:55:53 2007
@@ -0,0 +1,29 @@
+<?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.
+-->
+<tools>
+ <toolbox scope="request" locale="en_US">
+ <tool class="org.apache.velocity.tools.generic.DateTool"/>
+ <tool key="calc" class="org.apache.velocity.tools.generic.MathTool"/>
+ </toolbox>
+ <toolbox scope="application">
+ <tool class="org.apache.velocity.tools.generic.NumberTool" locale="fr"/>
+ </toolbox>
+</tools>
Propchange: velocity/tools/branches/2.x/test/conf/tools.test.xml
------------------------------------------------------------------------------
svn:eol-style = native