commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1716199 - in /commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177: ./ JXPathVariablesResolver.java TestJxPath177.java
Date Tue, 24 Nov 2015 16:27:47 GMT
Author: britter
Date: Tue Nov 24 16:27:46 2015
New Revision: 1716199

URL: http://svn.apache.org/viewvc?rev=1716199&view=rev
Log:
Add test case proofing that JXPATH-177 is not a problem. Thanks to Martin Xarx and Uwe Barthel.
This also fixes #5 from github.

Added:
    commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/
    commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/JXPathVariablesResolver.java
    commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/TestJxPath177.java

Added: commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/JXPathVariablesResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/JXPathVariablesResolver.java?rev=1716199&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/JXPathVariablesResolver.java
(added)
+++ commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/JXPathVariablesResolver.java
Tue Nov 24 16:27:46 2015
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jxpath.ri.jx177;
+
+import org.apache.commons.jxpath.Variables;
+
+public class JXPathVariablesResolver implements Variables
+{
+
+    private static final long serialVersionUID = -1106360826446119597L;
+
+    public static final String ROOT_VAR = "__root";
+
+    private final Object root;
+
+    public JXPathVariablesResolver(Object root)
+    {
+        this.root = root;
+    }
+
+    public boolean isDeclaredVariable(String varName)
+    {
+        if (varName == null)
+        {
+            throw new IllegalArgumentException("varName");
+        }
+        return varName.equals(ROOT_VAR);
+    }
+
+    public Object getVariable(String varName)
+    {
+        if (varName == null)
+        {
+            throw new IllegalArgumentException("varName");
+        }
+        if (!varName.equals(ROOT_VAR))
+        {
+            throw new IllegalArgumentException("Variable is not declared: " + varName);
+        }
+
+        return root;
+    }
+
+    public void declareVariable(String varName, Object value)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void undeclareVariable(String varName)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+}

Added: commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/TestJxPath177.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/TestJxPath177.java?rev=1716199&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/TestJxPath177.java
(added)
+++ commons/proper/jxpath/trunk/src/test/java/org/apache/commons/jxpath/ri/jx177/TestJxPath177.java
Tue Nov 24 16:27:46 2015
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jxpath.ri.jx177;
+
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.Pointer;
+
+public class TestJxPath177 extends TestCase
+{
+    Map model = new HashMap();
+    {
+        
+        model.put("name", "ROOT name");
+        final HashMap x = new HashMap();
+        model.put("x", x);
+        x.put("name", "X name");
+    }
+
+    public void testJx177()
+    {
+        doTest("name", "ROOT name");
+        doTest("/x/name", "X name");
+        doTest("$__root/x/name", "X name");
+    }
+    public void testJx177_Union1()
+    {
+        doTest("$__root/x/name|name", "X name");
+        
+    }
+    public void testJx177_Union2()
+    {
+        doTest("$__root/x/unexisting|name", "ROOT name");
+        
+    }
+
+    private void doTest(String xp, String expected)
+    {
+        JXPathContext xpathContext = JXPathContext.newContext(model);
+        xpathContext.setVariables(new JXPathVariablesResolver(model));
+        Pointer p = xpathContext.getPointer(xp);
+        Object result = p.getNode();
+        assertNotNull(result);
+        assertEquals(expected, result);
+
+    }
+}



Mime
View raw message