tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r747620 - in /tuscany/java/sca/modules/policy-xml/src: main/java/org/apache/tuscany/sca/policy/xml/ test/java/org/apache/tuscany/sca/policy/xml/
Date Wed, 25 Feb 2009 00:09:29 GMT
Author: rfeng
Date: Wed Feb 25 00:09:28 2009
New Revision: 747620

URL: http://svn.apache.org/viewvc?rev=747620&view=rev
Log:
Add more test cases for XPath

Modified:
    tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
    tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
    tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java

Modified: tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java?rev=747620&r1=747619&r2=747620&view=diff
==============================================================================
--- tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
(original)
+++ tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
Wed Feb 25 00:09:28 2009
@@ -52,9 +52,55 @@
     }
 
     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;
     }
 

Modified: tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java?rev=747620&r1=747619&r2=747620&view=diff
==============================================================================
--- tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
(original)
+++ tuscany/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
Wed Feb 25 00:09:28 2009
@@ -60,7 +60,7 @@
             if (arity == 1) {
                 return new PolicyXPathFunction(namespaceContext, functionName);
             } else {
-                return null;
+                throw new IllegalArgumentException("Invalid number of arguments: " + arity);
             }
         }
         return null;

Modified: tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java?rev=747620&r1=747619&r2=747620&view=diff
==============================================================================
--- tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
(original)
+++ tuscany/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
Wed Feb 25 00:09:28 2009
@@ -39,28 +39,59 @@
  * 
  */
 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



Mime
View raw message