You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2007/01/07 16:18:20 UTC
svn commit: r493738 - in /velocity/tools/trunk/src/test: ./ org/ org/apache/
org/apache/velocity/ org/apache/velocity/tools/
org/apache/velocity/tools/test/ org/apache/velocity/tools/test/blackbox/
org/apache/velocity/tools/test/whitebox/
Author: cbrisson
Date: Sun Jan 7 07:18:19 2007
New Revision: 493738
URL: http://svn.apache.org/viewvc?view=rev&rev=493738
Log:
testcases source files
Added:
velocity/tools/trunk/src/test/
velocity/tools/trunk/src/test/org/
velocity/tools/trunk/src/test/org/apache/
velocity/tools/trunk/src/test/org/apache/velocity/
velocity/tools/trunk/src/test/org/apache/velocity/tools/
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/FilteredLogSystemCommonsLog.java
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/JettyLogger.java
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/
velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
Added: velocity/tools/trunk/src/test/org/apache/velocity/tools/test/FilteredLogSystemCommonsLog.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/org/apache/velocity/tools/test/FilteredLogSystemCommonsLog.java?view=auto&rev=493738
==============================================================================
--- velocity/tools/trunk/src/test/org/apache/velocity/tools/test/FilteredLogSystemCommonsLog.java (added)
+++ velocity/tools/trunk/src/test/org/apache/velocity/tools/test/FilteredLogSystemCommonsLog.java Sun Jan 7 07:18:19 2007
@@ -0,0 +1,67 @@
+package org.apache.velocity.tools.test;
+
+/*
+ * 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 org.apache.velocity.tools.generic.log.LogSystemCommonsLog;
+
+/**
+ * This logging adapter filters out trace and debug messages that don't come from the velocity package
+ * (provided its given name contains a class name)
+ *
+ * @author <a href="mailto:cbrisson@apache.org">Claude Brisson</a>
+ * @version $Id:$
+ */
+
+public class FilteredLogSystemCommonsLog extends LogSystemCommonsLog {
+
+ private boolean filter = false;
+
+ public FilteredLogSystemCommonsLog(String name)
+ {
+ super(name);
+ filter = !name.startsWith("org.apache.velocity");
+ }
+
+
+ public FilteredLogSystemCommonsLog(boolean pst, String name)
+ {
+ super(pst,name);
+ filter = !name.startsWith("org.apache.velocity");
+ }
+
+ public void trace(Object message)
+ {
+ if(!filter) super.trace(message);
+ }
+
+ public void trace(Object message, Throwable t)
+ {
+ if(!filter) super.trace(message,t);
+ }
+
+ public void debug(Object message) {
+ if(!filter) super.debug(message);
+ }
+
+ public void debug(Object message, Throwable t) {
+ if(!filter) super.debug(message,t);
+ }
+
+}
Added: velocity/tools/trunk/src/test/org/apache/velocity/tools/test/JettyLogger.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/org/apache/velocity/tools/test/JettyLogger.java?view=auto&rev=493738
==============================================================================
--- velocity/tools/trunk/src/test/org/apache/velocity/tools/test/JettyLogger.java (added)
+++ velocity/tools/trunk/src/test/org/apache/velocity/tools/test/JettyLogger.java Sun Jan 7 07:18:19 2007
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2003 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.
+ */
+
+package org.apache.velocity.tools.test;
+
+import java.io.PrintWriter;
+import java.io.IOException;
+
+import org.mortbay.log.Logger;
+import org.mortbay.util.DateCache;
+
+/** Basic Jetty logger for our showcase webapp
+ *
+ * @author <a href=mailto:cbrisson@apache.org>Claude Brisson</a>
+ */
+
+public class JettyLogger implements Logger {
+
+ private boolean debug = false;
+ private String name = null;
+ private DateCache _dateCache=new DateCache("yyyy-MM-dd HH:mm:ss.SSS");
+
+ private static PrintWriter out = null;
+
+ static {
+ try {
+ String logfile = System.getProperty("jetty.log.file","/tmp/error.log");
+ out = new PrintWriter(logfile);
+ } catch(IOException ioe) {
+ System.out.println(ioe.getMessage());
+ }
+ }
+
+ public JettyLogger() {
+ this(null);
+ }
+
+ public JettyLogger(String name) {
+ this.name = name==null? "" : name;
+ }
+
+ /*
+ * org.mortbay.log.Logger interface
+ */
+
+ public boolean isDebugEnabled() {
+ return debug;
+ }
+
+ public void setDebugEnabled(boolean enabled) {
+ debug = enabled;
+ }
+
+ public void info(String msg,Object arg0, Object arg1)
+ {
+ if (out == null) return;
+ /* a bit of filtering in debug mode */
+ if (debug && (msg.startsWith("loaded class") || msg.startsWith("loaded interface"))) {
+ return;
+ }
+ logString(_dateCache.now() + " " + name + " " + format(msg,arg0,arg1));
+ }
+
+ public void debug(String msg,Throwable th)
+ {
+ if (debug)
+ {
+ if (out == null) return;
+ /* a bit of filtering in debug mode */
+ if (debug && (msg.startsWith("loaded class") || msg.startsWith("loaded interface"))) {
+ return;
+ }
+ logString(_dateCache.now()+" "+msg);
+ logStackTrace(th);
+ }
+ }
+
+ public void debug(String msg,Object arg0, Object arg1)
+ {
+ if (debug)
+ {
+ if (out == null) return;
+ /* a bit of filtering in debug mode */
+ if (debug && (msg.startsWith("loaded class") || msg.startsWith("loaded interface"))) {
+ return;
+ }
+ logString(_dateCache.now()+" "+format(msg,arg0,arg1));
+ }
+ }
+
+ public void warn(String msg,Object arg0, Object arg1)
+ {
+ if (out == null) return;
+ logString(_dateCache.now()+" "+format(msg,arg0,arg1));
+ }
+
+ public void warn(String msg, Throwable th)
+ {
+ if (out == null) return;
+ logString(_dateCache.now()+" "+msg);
+ logStackTrace(th);
+ }
+
+ public Logger getLogger(String name) {
+ if ((name==null && this.name==null) ||
+ (name!=null && name.equals(this.name)))
+ return this;
+ return new JettyLogger(name);
+ }
+
+ /*
+ * private helpers
+ */
+
+ private synchronized void logString(String msg) {
+ out.println(msg);
+ out.flush();
+ }
+
+ private synchronized void logStackTrace(Throwable th) {
+ th.printStackTrace(out);
+ out.flush();
+ }
+
+ private String format(String msg, Object arg0, Object arg1)
+ {
+ int i0=msg.indexOf("{}");
+ int i1=i0<0?-1:msg.indexOf("{}",i0+2);
+
+ if (arg1!=null && i1>=0)
+ msg=msg.substring(0,i1)+arg1+msg.substring(i1+2);
+ if (arg0!=null && i0>=0)
+ msg=msg.substring(0,i0)+arg0+msg.substring(i0+2);
+ return msg;
+ }
+
+}
Added: velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java?view=auto&rev=493738
==============================================================================
--- velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java (added)
+++ velocity/tools/trunk/src/test/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java Sun Jan 7 07:18:19 2007
@@ -0,0 +1,309 @@
+package org.apache.velocity.tools.test.blackbox;
+
+/*
+ * 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.regex.Pattern;
+import java.util.regex.Matcher;
+import java.io.PrintWriter;
+import java.io.IOException;
+
+import org.junit.*;
+
+import static org.junit.Assert.*;
+
+import com.meterware.httpunit.HTMLElement;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebForm;
+import com.meterware.httpunit.HttpUnitOptions;
+
+
+/**
+ * <p>Generic tools whitebox tests.</p>
+ *
+ * @author <a href="mailto:cbrisson@apache.org">Claude Brisson</a>
+ * @since Velocity Tools 1.3
+ * @version $Id$
+ */
+
+
+public class ViewToolsTests {
+
+ private static final String ROOT_URL = "http://localhost:@test.webcontainer.port@/";
+
+ public static @BeforeClass void initViewToolsTests() throws Exception {
+ }
+
+ /******* Helpers **********/
+
+ /**
+ * Utility function to check the text content of an HTML element
+ * @param resp web response
+ * @param id HTML element id
+ * @param text expected text
+ * @throws Exception
+ */
+ private void checkText(WebResponse resp,String id,String text) throws Exception {
+ HTMLElement element = resp.getElementWithID(id);
+ assertNotNull(element);
+ assertEquals(text,element.getText());
+ }
+
+ /**
+ * Utility function to check the text content of an HTML element
+ * @param resp web response
+ * @param id HTML element id
+ * @param text expected start of the text
+ * @throws Exception
+ */
+ private void checkTextStart(WebResponse resp,String id,String text) throws Exception {
+ HTMLElement element = resp.getElementWithID(id);
+ assertNotNull(element);
+ assertTrue(element.getText().startsWith(text));
+ }
+
+ /**
+ * Utility function to check the text content of an HTML element
+ * @param resp web response
+ * @param id HTML element id
+ * @param text expected contained text
+ * @throws Exception
+ */
+ private void checkTextContent(WebResponse resp,String id,String text) throws Exception {
+ HTMLElement element = resp.getElementWithID(id);
+ assertNotNull(element);
+ assertTrue(element.getText().indexOf(text) != -1);
+ }
+
+ /**
+ * Utility function to check the text content of an HTML element
+ * @param resp web response
+ * @param id HTML element id
+ * @param regex expected regex
+ * @throws Exception
+ */
+ private void checkTextRegex(WebResponse resp,String id,String regex) throws Exception {
+ HTMLElement element = resp.getElementWithID(id);
+ assertNotNull(element);
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(element.getText());
+ assertTrue(matcher.matches());
+ }
+
+ /**
+ *
+ * @param orig original web response
+ * @param formname form name
+ * @param paramname parameter name
+ * @param value parameter value
+ * @return new web response
+ * @throws Exception
+ */
+ private WebResponse submitWithParam(WebResponse orig, String formname, String paramname, String value) throws Exception {
+ WebForm form = orig.getFormWithName(formname);
+ form.setParameter(paramname,value);
+ return form.submit();
+ }
+
+ /**
+ * Used for debugging testcases
+ * @param resp webresponse
+ */
+ private void dump(WebResponse resp) {
+ try {
+ PrintWriter pw = new PrintWriter("/tmp/dump.html");
+ pw.println(resp.getText());
+ pw.flush();
+ pw.close();
+ } catch (IOException ioe) {
+
+ }
+ }
+
+
+ /******* Tests **********/
+
+ public @Test void testBrowserSnifferTool() throws Exception {
+ WebConversation conv = new WebConversation();
+ WebRequest req = new GetMethodWebRequest(ROOT_URL+"browser.vm");
+ WebResponse resp = conv.getResponse(req);
+
+ /* check we are identified as a Java (HttpUnit) client */
+ checkText(resp,"Java","true");
+ }
+
+ public @Test void testContextTool() throws Exception {
+ WebConversation conv = new WebConversation();
+ WebRequest req = new GetMethodWebRequest(ROOT_URL+"context.vm");
+ WebResponse resp = conv.getResponse(req);
+
+ /* check that getThis() is a ChainedContext instance */
+ checkTextStart(resp,"this","org.apache.velocity.tools.view.context.ChainedContext");
+
+ /* check contains('context') */
+ resp = submitWithParam(resp,"contains","contains","context");
+ checkText(resp,"contains","true");
+
+ /* check get('context') */
+ resp = submitWithParam(resp,"get","get","context");
+ checkTextStart(resp,"get","org.apache.velocity.tools.view.tools.ContextTool");
+
+ /* check keys (the only expected uppercase is in 'velocityCount') */
+ checkTextRegex(resp,"keys","^\\[[a-z_C]+(?:,\\s*[a-z_C]+)*\\]$");
+
+ /* check toolbox */
+ checkTextRegex(resp,"toolbox","^\\{[a-z_C]+=.*(?:,\\s*[a-z_C]+=.*)*\\}$");
+
+ /* check values */
+ checkTextRegex(resp,"values","^\\[.*\\]$");
+ }
+
+ public @Test void testCookiesTool() throws Exception {
+ WebConversation conv = new WebConversation();
+ WebRequest req = new GetMethodWebRequest(ROOT_URL+"cookies.vm");
+ WebResponse resp = conv.getResponse(req);
+
+ /* check all */
+ checkTextStart(resp,"all","[Ljavax.servlet.http.Cookie;");
+
+ /* check get('JSESSIONID') */
+ resp = submitWithParam(resp,"get","get","JSESSIONID");
+ checkTextStart(resp,"get","javax.servlet.http.Cookie");
+
+ /* check add('foo','bar') */
+ WebForm form = resp.getFormWithName("add2");
+ form.setParameter("add1","foo");
+ form.setParameter("add2","bar");
+ resp = form.submit();
+ resp = submitWithParam(resp,"get","get","foo");
+ checkTextStart(resp,"get","javax.servlet.http.Cookie");
+ }
+
+ public @Test void testLinkTool() throws Exception {
+ WebConversation conv = new WebConversation();
+ WebRequest req = new GetMethodWebRequest(ROOT_URL+"link.vm");
+ WebResponse resp = conv.getResponse(req);
+
+ /* check anchor(foo) and anchor */
+ resp = submitWithParam(resp,"anchor","anchor","foo");
+ checkText(resp,"anchor","#foo");
+ checkText(resp,"altanchor","#foo");
+
+ /* check uri(bar) and uri */
+ resp = submitWithParam(resp,"uri","uri","bar");
+ checkText(resp,"uri","bar");
+ checkText(resp,"alturi","bar");
+
+ /* check relative(foo) */
+ resp = submitWithParam(resp,"relative","relative","foo");
+ checkText(resp,"relative","/foo");
+
+ /* check absolute(bar) */
+ resp = submitWithParam(resp,"absolute","absolute","bar");
+ checkText(resp,"absolute",ROOT_URL + "bar");
+
+ /* check contextURL */
+ checkText(resp,"contextURL",ROOT_URL.substring(0,ROOT_URL.length()-1));
+
+ /* check contextPath */
+ checkText(resp,"contextPath","");
+
+ /* check requestPath */
+ checkText(resp,"requestPath","/link.vm");
+
+ /* check baseRef */
+ checkText(resp,"baseRef",ROOT_URL+"link.vm");
+
+ /* check self */
+ checkText(resp,"self","/link.vm");
+
+ /* check encodeURL */
+ resp = submitWithParam(resp,"encodeURL","encodeURL",": /");
+ checkText(resp,"encodeURL","%3A+%2F");
+ }
+
+ public @Test void testParameterParserTool() throws Exception {
+ WebConversation conv = new WebConversation();
+ WebRequest req = new GetMethodWebRequest(ROOT_URL+"params.vm?foo=bar&b=false&n=55&d=1.2");
+ WebResponse resp = conv.getResponse(req);
+
+ /* check exists(foo) */
+ resp = submitWithParam(resp,"exists","exists","foo");
+ checkText(resp,"exists","true");
+
+ /* check get(foo) */
+ resp = submitWithParam(resp,"get","get","foo");
+ checkText(resp,"get","bar");
+
+ /* check getString(foo) */
+ resp = submitWithParam(resp,"getString","getString","foo");
+ checkText(resp,"getString","bar");
+
+ /* check getBoolean(b) */
+ resp = submitWithParam(resp,"getBoolean","getBoolean","b");
+ checkText(resp,"getBoolean","false");
+
+ /* check getNumber(n) */
+ resp = submitWithParam(resp,"getNumber","getNumber","n");
+ checkText(resp,"getNumber","55");
+
+ /* check getDouble(d) */
+ resp = submitWithParam(resp,"getDouble","getDouble","d");
+ checkText(resp,"getDouble","1.2");
+
+ /* check getInteger(n) */
+ resp = submitWithParam(resp,"getInteger","getInteger","n");
+ checkText(resp,"getInteger","55");
+
+ /* check getStrings(foo) */
+ resp = submitWithParam(resp,"getStrings","getStrings","foo");
+ checkTextStart(resp,"getStrings","[Ljava.lang.String;@");
+
+ /* check getBooleans(b) */
+ resp = submitWithParam(resp,"getBooleans","getBooleans","b");
+ checkTextStart(resp,"getBooleans","[Ljava.lang.Boolean;@");
+
+ /* check getNumbers(n) */
+ resp = submitWithParam(resp,"getNumbers","getNumbers","n");
+ checkTextStart(resp,"getNumbers","[Ljava.lang.Number;@");
+
+ /* check getDoubles(d) */
+ resp = submitWithParam(resp,"getDoubles","getDoubles","d");
+ checkTextStart(resp,"getDoubles","[D@");
+
+ /* check getInts(n) */
+ resp = submitWithParam(resp,"getInts","getInts","n");
+ checkTextStart(resp,"getInts","[I@");
+
+ /* check getString(bar,foo) */
+ WebForm form = resp.getFormWithName("getString2");
+ form.setParameter("getString1","'bar'");
+ form.setParameter("getString2","'foo'");
+ resp = form.submit();
+ checkText(resp,"getString2","foo");
+
+ /* TODO other getters with default values */
+
+ /* check all */
+ checkTextRegex(resp,"all","^\\{.*\\}$");
+ }
+}
Added: velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java?view=auto&rev=493738
==============================================================================
--- velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java (added)
+++ velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java Sun Jan 7 07:18:19 2007
@@ -0,0 +1,146 @@
+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.io.File;
+import java.io.FileInputStream;
+import java.util.Map;
+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.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.view.XMLToolboxManager;
+
+
+
+/**
+ * <p>Generic tools whitebox tests.</p>
+ *
+ * @author <a href="mailto:cbrisson@apache.org">Claude Brisson</a>
+ * @since Velocity Tools 1.3
+ * @version $Id$
+ */
+
+public class GenericToolsTests {
+
+ private static final String TOOLBOX_PATH = "@test.conf.dir@/whiteboxtest-toolbox.xml";
+
+ private static Map toolbox = null;
+
+ public static @BeforeClass void initGenericToolsTests() throws Exception {
+ XMLToolboxManager manager = new XMLToolboxManager();
+ manager.load(new FileInputStream(new File(TOOLBOX_PATH)));
+ toolbox = manager.getToolbox(null);
+ }
+
+ public @Test void testAlternatorTool() {
+ AlternatorTool alternatorTool = (AlternatorTool)toolbox.get("alternator");
+ assertNotNull(alternatorTool);
+ /* test automatic alternator */
+ Alternator auto = alternatorTool.auto(new String[] {"red","blue","yellow"});
+ assertEquals("red",auto.getCurrent());
+ assertEquals("red",auto.getNext());
+ assertEquals("blue",auto.toString());
+ assertEquals("yellow",auto.toString());
+ assertEquals("red",auto.toString());
+ /* test manual alternator (use 'make()' and not 'manual()' since we define the default to be manual in toolbox.xml*/
+ Alternator manual = alternatorTool.make(new String[] {"red","blue","yellow"});
+ assertEquals("red",manual.toString());
+ assertEquals("red",manual.toString());
+ manual.shift();
+ assertEquals("blue",manual.toString());
+ manual.shift();
+ manual.shift();
+ assertEquals("red",manual.toString());
+ }
+
+ public @Test void testDateTool() { /* TODO still incomplete */
+ DateTool dateTool = (DateTool)toolbox.get("date");
+ assertNotNull(dateTool);
+ Date date = new GregorianCalendar(2007,0,2).getTime();
+ String disp = "2007-01-02";
+ String disp2 = "2007/01/02";
+ /* check configured format */
+ assertEquals("yyyy-MM-dd",dateTool.getFormat());
+ /* test formatting */
+ assertEquals(disp,dateTool.format(date));
+ assertEquals(disp2,dateTool.format("yyyy/MM/dd",date));
+ /* test parsing */
+ assertEquals(2007,dateTool.getYear(disp));
+ assertEquals(0,dateTool.getMonth(disp));
+ assertEquals(2,dateTool.getDay(disp));
+ }
+
+ public @Test void testEscapeTool() {
+ EscapeTool escapeTool = (EscapeTool)toolbox.get("esc");
+ assertNotNull(escapeTool);
+ /* java */
+ assertEquals("\\uFFFF\\b\\n\\t\\f\\r\\\"\\\\",escapeTool.java("\uFFFF\b\n\t\f\r\"\\"));
+ /* javascript */
+ assertEquals("\\uFFFF\\b\\n\\t\\f\\r\\\"\\'\\\\",escapeTool.javascript("\uFFFF\b\n\t\f\r\"'\\"));
+ /* html */
+ assertEquals(""&<> ",escapeTool.html("\"&<>"+(char)160));
+ /* http */
+ assertEquals("+%40",escapeTool.http(" @"));
+ /* sql */
+ assertEquals("''",escapeTool.sql("'"));
+ /* xml */
+ assertEquals(""&<>",escapeTool.html("\"&<>"));
+ }
+
+ public @Test void testMathTool() {
+ MathTool mathTool = (MathTool)toolbox.get("math");
+ assertNotNull(mathTool);
+ assertEquals(1,mathTool.abs(-1));
+ assertEquals(2,mathTool.add(1,1));
+ assertEquals(3,mathTool.ceil(2.5));
+ assertEquals(4,mathTool.div(8,2));
+ assertEquals(5,mathTool.floor(5.1));
+ assertEquals(6,mathTool.getAverage(new long[] {5,6,7}));
+ /* getTotal() watches the type of its first argument, so assertEquals needs a long */
+ assertEquals((long)7,mathTool.getTotal(new long[] {2,2,3}));
+ assertEquals(8,mathTool.idiv(130,16));
+ assertEquals(9,mathTool.max(9,-10));
+ assertEquals(10,mathTool.min(10,20));
+ assertEquals(11,mathTool.mod(37,13));
+ assertEquals(12,mathTool.mul(3,4));
+ assertEquals(13,mathTool.round(12.8));
+ assertEquals(14.2,mathTool.roundTo(1,14.18));
+ assertEquals(15,mathTool.sub(30,15));
+ assertEquals(16,mathTool.pow(4,2));
+ assertEquals(17,mathTool.toInteger("17"));
+ assertEquals(18.1,mathTool.toDouble("18.1"));
+ }
+
+ public @Test void testNumberTool() {
+ NumberTool numberTool = (NumberTool)toolbox.get("number");
+ assertNotNull(numberTool);
+// assertEquals()
+ }
+}