summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-25 00:09:28 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-25 00:09:28 +0000
commitbfbc84720aa11a2f54d87f36d1741b46fe1ed43c (patch)
tree721fd8e4136773a9501e84d4513469867815bde8
parentdbed306fd58a4007be3df458e571bf4fd4302dce (diff)
Add more test cases for XPath
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@747620 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java48
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java2
-rw-r--r--java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java45
3 files changed, 86 insertions, 9 deletions
diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
index ffabad5644..f015fc90fb 100644
--- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
@@ -52,9 +52,55 @@ public class PolicyXPathFunction implements XPathFunction {
}
public Object evaluate(List args) throws XPathFunctionException {
+ System.out.println(functionName + "(" + args + ")");
// FIXME: [rfeng] To be implemented
String arg = (String)args.get(0);
- System.out.println(functionName + "(" + arg + ")");
+ if (InterfaceRef.equals(functionName)) {
+ return evaluateInterface(arg);
+ } else if (OperationRef.equals(functionName)) {
+ String[] params = arg.split("/");
+ if (params.length != 2) {
+ throw new IllegalArgumentException("Invalid argument: " + arg);
+ }
+ String interfaceName = params[0];
+ String operationName = params[1];
+ return evaluateOperation(interfaceName, operationName);
+ } else if (MessageRef.equals(functionName)) {
+ String[] params = arg.split("/");
+ if (params.length != 3) {
+ throw new IllegalArgumentException("Invalid argument: " + arg);
+ }
+ String interfaceName = params[0];
+ String operationName = params[1];
+ String messageName = params[2];
+ return evaluateMessage(interfaceName, operationName, messageName);
+ } else if (URIRef.equals(functionName)) {
+ return evaluateURI(arg);
+ } else if (IntentRefs.equals(functionName)) {
+ String[] intents = arg.split("(\\s)+");
+ return evaluateIntents(intents);
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+
+ private Boolean evaluateInterface(String interfaceName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateOperation(String interfaceName, String operationName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateMessage(String interfaceName, String operationName, String messageName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateURI(String uri) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateIntents(String[] intents) {
return Boolean.FALSE;
}
diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
index 733b208de7..2d04a27cd7 100644
--- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
@@ -60,7 +60,7 @@ public class PolicyXPathFunctionResolver implements XPathFunctionResolver {
if (arity == 1) {
return new PolicyXPathFunction(namespaceContext, functionName);
} else {
- return null;
+ throw new IllegalArgumentException("Invalid number of arguments: " + arity);
}
}
return null;
diff --git a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
index fea1afb941..7b647819b4 100644
--- a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
+++ b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
@@ -39,28 +39,59 @@ import org.xml.sax.InputSource;
*
*/
public class PolicyXPathFunctionResolverTestCase {
- private static XPathFactory factory;
+ private static XPath xpath;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
- factory = XPathFactory.newInstance();
+ XPathFactory factory = XPathFactory.newInstance();
+ xpath = factory.newXPath();
+ xpath.setNamespaceContext(new NamespaceContextImpl());
+ xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext()));
}
@Test
- public void testXPath() throws Exception {
- XPath xpath = factory.newXPath();
- xpath.setNamespaceContext(new NamespaceContextImpl());
- xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext()));
+ public void testIntentsRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]");
+ 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("//sca:composite//sca:component[sca:IntentRefs('sca:confidentiality')]");
+ XPathExpression exp = xpath.compile("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]");
Object result = exp.evaluate(xml, XPathConstants.NODESET);
Assert.assertTrue(result instanceof NodeList);
NodeList nodes = (NodeList)result;
// Assert.assertEquals(1, nodes.getLength());
}
+
+ @Test
+ public void testInterfaceRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]");
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testOperationRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]");
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
/**
* @throws java.lang.Exception