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 2008/01/10 03:36:15 UTC
svn commit: r610650 - in /velocity/tools/trunk: examples/showcase/demo.vm
src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java
Author: nbubna
Date: Wed Jan 9 18:35:54 2008
New Revision: 610650
URL: http://svn.apache.org/viewvc?rev=610650&view=rev
Log:
resync $context showcase with ViewToolTests
Modified:
velocity/tools/trunk/examples/showcase/demo.vm
velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java
Modified: velocity/tools/trunk/examples/showcase/demo.vm
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/examples/showcase/demo.vm?rev=610650&r1=610649&r2=610650&view=diff
==============================================================================
--- velocity/tools/trunk/examples/showcase/demo.vm (original)
+++ velocity/tools/trunk/examples/showcase/demo.vm Wed Jan 9 18:35:54 2008
@@ -21,7 +21,7 @@
* $toolname -> should be the context key of the tool
* $toolclass -> should be the actual Class of the tool
* $toollink -> a URL for the javadoc of the tool Class on velocity.apache.org
- * This is usually set copying the $doclink reference that is set
+ * This is usually set by copying the $doclink reference that is set
* whenever the #doclink() macro is used.
* Optionally, you can also set:
* $toolDemo -> to specify the default text for the full demo at the bottom
@@ -47,21 +47,20 @@
</form>
<th>$demo.description</th>
</tr>
-## generate a demo for each method
-#foreach( $method in $tool.methods )
-#if( $method.signature != 'configure(Map)' )
+## generate a demo for each method (except the configure(Map) method)
+#foreach( $method in $loop.watch($tool.methods).exclude('method configure(java.util.Map)') )
<tr>
## create a fake call of the method to use as the name/signature
#set( $call = "${esc.d}${toolname}.#if( !$method.takesParameters() && $method.propertyName )$method.propertyName#else$method.signature#end" )
- <td valign="top" id="${method.javadocRef}"><a href="$toollink#$method.javadocRef">$call</a></td>
+ <td valign="top"><a href="$toollink#$method.javadocRef">$call</a></td>
#if( !$method.takesParameters() )
## simply call the method
#set( $result = $call )
#set( $result = $render.eval($call) )
- <td valign="top">#if( $result == $call )$text.demo.nullResult#else$result#end</td>
+ <td valign="top" id="${method.javadocRef}">#if( $result == $call )$text.demo.nullResult#else$result#end</td>
#else
## create a form to allow the user to input values and call the method
- <form method="get" action="$link.self.anchor($method.javadocRef)"> ## HttpUnit doesn't like anchor-only links
+ <form method="get" name="$method.uniqueName" action="$link.self.anchor($method.javadocRef)"> ## HttpUnit doesn't like anchor-only links
<td valign="top">
<nobr>
## create a text field for each parameter
@@ -91,7 +90,7 @@
<br>
$call
=
- <div>#if( $result == $call )$demo.nullResult#else$result#end</div>
+ <div id="$method.javadocRef">#if( $result == $call )$demo.nullResult#else$result#end</div>
#end
## maintain all params for other method demos
#foreach( $param in $params.all.keySet() )
@@ -130,7 +129,6 @@
#end
<td valign="top">$desc</td>
</tr>
-#end
#end
<tr>
## create a space for an extended, custom, one line demo
Modified: velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java?rev=610650&r1=610649&r2=610650&view=diff
==============================================================================
--- velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java (original)
+++ velocity/tools/trunk/src/test/java/org/apache/velocity/tools/test/blackbox/ViewToolsTests.java Wed Jan 9 18:35:54 2008
@@ -85,6 +85,21 @@
* Utility function to check the text content of an HTML element
* @param resp web response
* @param id HTML element id
+ * @param start expected start of the text
+ * @param end expected end of the text
+ * @throws Exception
+ */
+ private void checkTextStartEnd(WebResponse resp,String id,String start,String end) throws Exception {
+ HTMLElement element = resp.getElementWithID(id);
+ assertNotNull(element);
+ assertTrue(element.getText().startsWith(start));
+ assertTrue(element.getText().endsWith(end));
+ }
+
+ /**
+ * 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
*/
@@ -106,7 +121,10 @@
assertNotNull(element);
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(element.getText());
- assertTrue(matcher.matches());
+ if (!matcher.matches())
+ {
+ fail(element.getText()+" did not match "+regex);
+ }
}
/**
@@ -157,24 +175,24 @@
WebResponse resp = conv.getResponse(req);
/* check that getThis() is a ChainedContext instance */
- checkTextStart(resp,"this","org.apache.velocity.tools.view.context.ChainedContext");
+ checkTextStart(resp,"getThis()","org.apache.velocity.tools.view.ViewToolContext");
/* check contains('context') */
- resp = submitWithParam(resp,"contains","contains","context");
- checkText(resp,"contains","true");
+ resp = submitWithParam(resp,"contains_Object","contains_Object1","'context'");
+ checkText(resp,"contains(java.lang.Object)","true");
/* check get('context') */
- resp = submitWithParam(resp,"get","get","context");
- checkTextStart(resp,"get","org.apache.velocity.tools.view.ContextTool");
+ resp = submitWithParam(resp,"get_Object","get_Object1","'context'");
+ checkTextStart(resp,"get(java.lang.Object)","org.apache.velocity.tools.view.ContextTool");
/* check keys (the only expected uppercase is in 'velocityCount') */
- checkTextRegex(resp,"keys","^\\[[a-z_A-Z]+(?:,\\s*[a-z_A-Z]+)*\\]$");
+ checkTextRegex(resp,"getKeys()","^\\[[a-z_A-Z]+(?:,\\s*[a-z_A-Z]+)*\\]$");
/* check toolbox */
- checkTextRegex(resp,"toolbox","^\\{[a-z_A-Z]+=.*(?:,\\s*[a-z_A-Z]+=.*)*\\}$");
+ checkTextRegex(resp,"getToolbox()","^\\{[a-z_A-Z]+=.*(?:,\\s*[a-z_A-Z]+=.*)*\\}$");
/* check values */
- checkTextRegex(resp,"values","^\\[.*\\]$");
+ checkTextStartEnd(resp,"getValues()","[","]");
}
public @Test void testCookiesTool() throws Exception {