[Practicalxml-commits] SF.net SVN: practicalxml:[59] trunk/src/test/java/net/sf/practicalxml/xpath
Brought to you by:
kdgregory
From: Auto-Generated S. C. M. <pra...@li...> - 2008-12-20 12:35:26
|
Revision: 59 http://practicalxml.svn.sourceforge.net/practicalxml/?rev=59&view=rev Author: kdgregory Date: 2008-12-20 12:35:23 +0000 (Sat, 20 Dec 2008) Log Message: ----------- Add in-situ tests for Uppercase and Lowercase Modified Paths: -------------- trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java Modified: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java 2008-12-20 11:29:17 UTC (rev 58) +++ trunk/src/test/java/net/sf/practicalxml/xpath/function/TestLowercase.java 2008-12-20 12:35:23 UTC (rev 59) @@ -2,18 +2,53 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; import javax.xml.xpath.XPathFunctionException; - import org.w3c.dom.Element; +import org.w3c.dom.Node; import net.sf.practicalxml.AbstractTestCase; import net.sf.practicalxml.DomUtil; +import net.sf.practicalxml.XPathWrapper; public class TestLowercase extends AbstractTestCase { + public TestLowercase(String name) + { + super(name); + } + + +//---------------------------------------------------------------------------- +// Setup +//---------------------------------------------------------------------------- + + private Element _root; + private Element _child1; + private Element _child2; + private Element _child3; + + @Override + protected void setUp() throws Exception + { + _root = DomUtil.newDocument("foo"); + _child1 = DomUtil.appendChild(_root, "bar"); + _child2 = DomUtil.appendChild(_root, "baz"); + _child3 = DomUtil.appendChild(_root, "foo2"); + + DomUtil.setText(_root, "Test"); + DomUtil.setText(_child1, "Test1"); + DomUtil.setText(_child2, "Test2"); + } + + +//---------------------------------------------------------------------------- +// Test Cases +//---------------------------------------------------------------------------- + public void testConstruction() throws Exception { Lowercase fn = new Lowercase(); @@ -23,6 +58,7 @@ assertEquals(1, fn.getMaxArgCount()); } + public void testLiteralString() throws Exception { assertEquals( @@ -33,26 +69,17 @@ public void testNodeList() throws Exception { - Element root = DomUtil.newDocument("foo"); - Element child1 = DomUtil.appendChild(root, "bar"); - Element child2 = DomUtil.appendChild(root, "baz"); - DomUtil.setText(root, "Test"); - DomUtil.setText(child1, "Test2"); - DomUtil.setText(child2, "Test3"); - assertEquals( - "test2", - new Lowercase().evaluate(Arrays.asList(root.getChildNodes()))); + "test1", + new Lowercase().evaluate(Arrays.asList(_root.getChildNodes()))); } public void testEmptyNodeList() throws Exception { - Element root = DomUtil.newDocument("foo"); - assertEquals( "", - new Lowercase().evaluate(Arrays.asList(root.getChildNodes()))); + new Lowercase().evaluate(Arrays.asList(_child3.getChildNodes()))); } @@ -77,4 +104,16 @@ } } + + public void testInSitu() throws Exception + { + XPathWrapper xpath1 = new XPathWrapper("//*[ns:lowercase(text()) = 'test1']") + .bindFunction(new Lowercase(), "ns"); + List<Node> result1 = xpath1.evaluate(_root); + assertSame(_child1, result1.get(0)); + + XPathWrapper xpath2 = new XPathWrapper("//*[ns:lowercase(text()) = 'TEST1']") + .bindFunction(new Lowercase(), "ns"); + assertEquals(0, xpath2.evaluate(_root).size()); + } } Modified: trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java =================================================================== --- trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java 2008-12-20 11:29:17 UTC (rev 58) +++ trunk/src/test/java/net/sf/practicalxml/xpath/function/TestUppercase.java 2008-12-20 12:35:23 UTC (rev 59) @@ -2,18 +2,53 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; import javax.xml.xpath.XPathFunctionException; - import org.w3c.dom.Element; +import org.w3c.dom.Node; import net.sf.practicalxml.AbstractTestCase; import net.sf.practicalxml.DomUtil; +import net.sf.practicalxml.XPathWrapper; public class TestUppercase extends AbstractTestCase { + public TestUppercase(String name) + { + super(name); + } + + +//---------------------------------------------------------------------------- +// Setup +//---------------------------------------------------------------------------- + + private Element _root; + private Element _child1; + private Element _child2; + private Element _child3; + + @Override + protected void setUp() throws Exception + { + _root = DomUtil.newDocument("foo"); + _child1 = DomUtil.appendChild(_root, "bar"); + _child2 = DomUtil.appendChild(_root, "baz"); + _child3 = DomUtil.appendChild(_root, "foo2"); + + DomUtil.setText(_root, "Test"); + DomUtil.setText(_child1, "Test1"); + DomUtil.setText(_child2, "Test2"); + } + + +//---------------------------------------------------------------------------- +// Test Cases +//---------------------------------------------------------------------------- + public void testConstruction() throws Exception { Uppercase fn = new Uppercase(); @@ -23,6 +58,7 @@ assertEquals(1, fn.getMaxArgCount()); } + public void testLiteralString() throws Exception { assertEquals( @@ -33,26 +69,17 @@ public void testNodeList() throws Exception { - Element root = DomUtil.newDocument("foo"); - Element child1 = DomUtil.appendChild(root, "bar"); - Element child2 = DomUtil.appendChild(root, "baz"); - DomUtil.setText(root, "Test"); - DomUtil.setText(child1, "Test2"); - DomUtil.setText(child2, "Test3"); - assertEquals( - "TEST2", - new Uppercase().evaluate(Arrays.asList(root.getChildNodes()))); + "TEST1", + new Uppercase().evaluate(Arrays.asList(_root.getChildNodes()))); } public void testEmptyNodeList() throws Exception { - Element root = DomUtil.newDocument("foo"); - assertEquals( "", - new Lowercase().evaluate(Arrays.asList(root.getChildNodes()))); + new Uppercase().evaluate(Arrays.asList(_child3.getChildNodes()))); } @@ -77,4 +104,17 @@ } } + + public void testInSitu() throws Exception + { + XPathWrapper xpath1 = new XPathWrapper("//*[ns:uppercase(text()) = 'TEST1']") + .bindFunction(new Uppercase(), "ns"); + List<Node> result1 = xpath1.evaluate(_root); + assertSame(_child1, result1.get(0)); + + XPathWrapper xpath2 = new XPathWrapper("//*[ns:uppercase(text()) = 'test1']") + .bindFunction(new Uppercase(), "ns"); + assertEquals(0, xpath2.evaluate(_root).size()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |