From 5eb8043a5abd44f4df8bdd7de099b45a12a251fe Mon Sep 17 00:00:00 2001 From: bdaniel Date: Tue, 22 Jun 2010 15:25:22 +0000 Subject: Support policy XPath functions without ns prefixes and without a single node context git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@956919 13f79535-47bb-0310-9956-ffa450edef68 --- .../xml/PolicyXPathFunctionResolverTestCase.java | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy') diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java index fdbdcec1c9..d2b0775361 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java @@ -57,8 +57,8 @@ public class PolicyXPathFunctionResolverTestCase { @Test public void testIntentsRef() throws Exception { InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); - String str = "//sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]"; - str = normalize(str); + String str = "//sca:composite/sca:component[IntentRefs('sca:confidentiality')]"; + str = normalize(str, "sca"); // Test the rewrite of xpath so that the self:node() is passed into the SCA function XPathExpression exp = xpath.compile(str); Object result = exp.evaluate(xml, XPathConstants.NODESET); @@ -67,10 +67,35 @@ public class PolicyXPathFunctionResolverTestCase { Assert.assertEquals(1, nodes.getLength()); } + @Test + public void testIntentsRef2() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + String str = " //sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]"; + str = normalize(str, "sca"); + // Test the rewrite of xpath so that the self:node() is passed into the SCA function + XPathExpression exp = xpath.compile(str); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + Assert.assertEquals(1, nodes.getLength()); + } + + @Test + public void testIntentsRef3() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + String str = " IntentRefs('sca:confidentiality') "; + str = normalize(str, "sca"); + // Test the rewrite of xpath so that the self:node() is passed into the SCA function + XPathExpression exp = xpath.compile(str); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + Assert.assertEquals(1, nodes.getLength()); + } @Test public void testURIRef() throws Exception { InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); - XPathExpression exp = xpath.compile(normalize("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]")); + XPathExpression exp = xpath.compile(normalize("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]","sca")); Object result = exp.evaluate(xml, XPathConstants.NODESET); Assert.assertTrue(result instanceof NodeList); NodeList nodes = (NodeList)result; @@ -80,7 +105,7 @@ public class PolicyXPathFunctionResolverTestCase { @Test public void testInterfaceRef() throws Exception { InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); - XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]")); + XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]","sca")); Object result = exp.evaluate(xml, XPathConstants.NODESET); Assert.assertTrue(result instanceof NodeList); NodeList nodes = (NodeList)result; @@ -90,7 +115,7 @@ public class PolicyXPathFunctionResolverTestCase { @Test public void testOperationRef() throws Exception { InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); - XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]")); + XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]","sca")); Object result = exp.evaluate(xml, XPathConstants.NODESET); Assert.assertTrue(result instanceof NodeList); NodeList nodes = (NodeList)result; -- cgit v1.2.3