diff --git a/src/main/java/org/apache/commons/jxpath/ClassFunctions.java b/src/main/java/org/apache/commons/jxpath/ClassFunctions.java index ed0c13c3b..aeb51f771 100644 --- a/src/main/java/org/apache/commons/jxpath/ClassFunctions.java +++ b/src/main/java/org/apache/commons/jxpath/ClassFunctions.java @@ -92,17 +92,8 @@ public Function getFunction( final String namespace, final String name, Object[] parameters) { - return getFunction(namespace, name, parameters, new JXPathFilter()); - } - - public Function getFunction( - String namespace, - String name, - Object[] parameters, - JXPathFilter jxPathFilter) { - - // give chance to ClassFilter to filter out, if present - if (jxPathFilter != null && !jxPathFilter.exposeToXPath(functionClass.getName())) { + JXPathFilter jxPathFilter = new JXPathFilter(); + if (!jxPathFilter.exposeToXPath(functionClass.getName())) { throw new JXPathException( "Extension function is not allowed: " + (namespace != null ? namespace + ":" + name : name) + " (in " + functionClass.getName() + ")"); diff --git a/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java b/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java index 740623b43..dfd4e75c0 100644 --- a/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java +++ b/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java @@ -16,8 +16,6 @@ */ package org.apache.commons.jxpath; -import org.apache.commons.jxpath.ri.JXPathFilter; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -78,30 +76,12 @@ public Set getUsedNamespaces() { @Override public Function getFunction(final String namespace, final String name, final Object[] parameters) { - return getFunction(namespace, name, parameters, new JXPathFilter()); - } - - /** - * Returns a Function, if any, for the specified namespace, - * name and parameter types. - * @param namespace function namespace - * @param name function name - * @param parameters parameters - * @param jxPathFilter the XPath filter - * @return Function found - */ - public Function getFunction( - final String namespace, - final String name, - final Object[] parameters, - final JXPathFilter jxPathFilter) { - Object candidates = functionCache().get(namespace); + final Object candidates = functionCache().get(namespace); if (candidates instanceof Functions) { return ((Functions) candidates).getFunction( namespace, name, - parameters, - jxPathFilter); + parameters); } if (candidates instanceof List) { final List list = (List) candidates; @@ -111,8 +91,7 @@ public Function getFunction( ((Functions) list.get(i)).getFunction( namespace, name, - parameters, - jxPathFilter); + parameters); if (function != null) { return function; } diff --git a/src/main/java/org/apache/commons/jxpath/Functions.java b/src/main/java/org/apache/commons/jxpath/Functions.java index bdad84c49..d3788c5c0 100644 --- a/src/main/java/org/apache/commons/jxpath/Functions.java +++ b/src/main/java/org/apache/commons/jxpath/Functions.java @@ -16,8 +16,6 @@ */ package org.apache.commons.jxpath; -import org.apache.commons.jxpath.ri.JXPathFilter; - import java.util.Set; /** @@ -45,15 +43,4 @@ public interface Functions { * @return Function */ Function getFunction(String namespace, String name, Object[] parameters); - - /** - * Returns a Function, if any, for the specified namespace, - * name and parameter types. - * @param namespace ns - * @param name function name - * @param parameters Object[] - * @param jxPathFilter the XPath filter - * @return Function - */ - Function getFunction(String namespace, String name, Object[] parameters, JXPathFilter jxPathFilter); } diff --git a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java index c7c43efdf..3a2e4a1ee 100644 --- a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java +++ b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java @@ -26,7 +26,6 @@ import org.apache.commons.jxpath.functions.ConstructorFunction; import org.apache.commons.jxpath.functions.MethodFunction; -import org.apache.commons.jxpath.ri.JXPathFilter; import org.apache.commons.jxpath.util.ClassLoaderUtil; import org.apache.commons.jxpath.util.MethodLookupUtils; import org.apache.commons.jxpath.util.TypeUtils; @@ -117,36 +116,6 @@ public Function getFunction( final String namespace, final String name, Object[] parameters) { - return getFunction(namespace, name, parameters, new JXPathFilter()); - } - - /** - * Returns a {@link Function}, if found, for the specified namespace, - * name and parameter types. - *
- * @param namespace - if it is not the same as specified in the - * construction, this method returns null - * @param name - name of the method, which can one these forms: - *
nodeSet
.
*
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
index 6899ab753..282ec2403 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
@@ -36,6 +36,18 @@ public static TestSuite suite()
return new TestSuite(JXPath172DynamicTest.class);
}
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("jxpath.class.allow", "*");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("jxpath.class.allow");
+ super.tearDown();
+ }
+
public void testIssue172_propertyExistAndIsNotNull()
{
final JXPathContext context = getContext("ciao", false);
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
index 7aeb21b8d..4ca43e7d2 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
@@ -18,8 +18,18 @@
import java.util.*;
-import org.apache.commons.jxpath.*;
-import org.apache.commons.jxpath.ri.JXPathFilter;
+import org.apache.commons.jxpath.JXPathTestCase;
+import org.apache.commons.jxpath.Functions;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.TestBean;
+import org.apache.commons.jxpath.Variables;
+import org.apache.commons.jxpath.FunctionLibrary;
+import org.apache.commons.jxpath.ClassFunctions;
+import org.apache.commons.jxpath.PackageFunctions;
+import org.apache.commons.jxpath.NodeSet;
+import org.apache.commons.jxpath.Function;
+import org.apache.commons.jxpath.ExpressionContext;
+import org.apache.commons.jxpath.Pointer;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.JXPath11CompatibleTypeConverter;
import org.apache.commons.jxpath.util.TypeConverter;
@@ -33,7 +43,6 @@ public class ExtensionFunctionTest extends JXPathTestCase {
private JXPathContext context;
private TestBean testBean;
private TypeConverter typeConverter;
- JXPathFilter jxPathFilter = new JXPathFilter();
@Override
public void setUp() {
@@ -50,9 +59,9 @@ public void setUp() {
lib.addFunctions(new ClassFunctions(TestFunctions2.class, "test"));
lib.addFunctions(new PackageFunctions("", "call"));
lib.addFunctions(
- new PackageFunctions(
- "org.apache.commons.jxpath.ri.compiler.",
- "jxpathtest"));
+ new PackageFunctions(
+ "org.apache.commons.jxpath.ri.compiler.",
+ "jxpathtest"));
lib.addFunctions(new PackageFunctions("", null));
context.setFunctions(lib);
context.getVariables().declareVariable("List.class", List.class);
@@ -69,76 +78,76 @@ public void tearDown() {
}
public void testConstructorLookup() {
- final Object[] args = { Integer.valueOf(1), "x" };
+ final Object[] args = {Integer.valueOf(1), "x"};
final Function func = functions.getFunction("test", "new", args);
assertEquals(
- "test:new(1, x)",
- func.invoke(new Context(null), args).toString(),
- "foo=1; bar=x");
+ "test:new(1, x)",
+ func.invoke(new Context(null), args).toString(),
+ "foo=1; bar=x");
}
public void testConstructorLookupWithExpressionContext() {
- final Object[] args = { "baz" };
+ final Object[] args = {"baz"};
final Function func = functions.getFunction("test", "new", args);
assertEquals(
- "test:new('baz')",
- func.invoke(new Context(Integer.valueOf(1)), args).toString(),
- "foo=1; bar=baz");
+ "test:new('baz')",
+ func.invoke(new Context(Integer.valueOf(1)), args).toString(),
+ "foo=1; bar=baz");
}
public void testStaticMethodLookup() {
- final Object[] args = { Integer.valueOf(1), "x" };
+ final Object[] args = {Integer.valueOf(1), "x"};
final Function func = functions.getFunction("test", "build", args);
assertEquals(
- "test:build(1, x)",
- func.invoke(new Context(null), args).toString(),
- "foo=1; bar=x");
+ "test:build(1, x)",
+ func.invoke(new Context(null), args).toString(),
+ "foo=1; bar=x");
}
public void testStaticMethodLookupWithConversion() {
- final Object[] args = { "7", Integer.valueOf(1)};
+ final Object[] args = {"7", Integer.valueOf(1)};
final Function func = functions.getFunction("test", "build", args);
assertEquals(
- "test:build('7', 1)",
- func.invoke(new Context(null), args).toString(),
- "foo=7; bar=1");
+ "test:build('7', 1)",
+ func.invoke(new Context(null), args).toString(),
+ "foo=7; bar=1");
}
public void testMethodLookup() {
- final Object[] args = { new TestFunctions()};
+ final Object[] args = {new TestFunctions()};
final Function func = functions.getFunction("test", "getFoo", args);
assertEquals(
- "test:getFoo($test, 1, x)",
- func.invoke(new Context(null), args).toString(),
- "0");
+ "test:getFoo($test, 1, x)",
+ func.invoke(new Context(null), args).toString(),
+ "0");
}
public void testStaticMethodLookupWithExpressionContext() {
final Object[] args = {};
final Function func = functions.getFunction("test", "path", args);
assertEquals(
- "test:path()",
- func.invoke(new Context(Integer.valueOf(1)), args),
- "1");
+ "test:path()",
+ func.invoke(new Context(Integer.valueOf(1)), args),
+ "1");
}
public void testMethodLookupWithExpressionContext() {
- final Object[] args = { new TestFunctions()};
+ final Object[] args = {new TestFunctions()};
final Function func = functions.getFunction("test", "instancePath", args);
assertEquals(
- "test:instancePath()",
- func.invoke(new Context(Integer.valueOf(1)), args),
- "1");
+ "test:instancePath()",
+ func.invoke(new Context(Integer.valueOf(1)), args),
+ "1");
}
public void testMethodLookupWithExpressionContextAndArgument() {
- final Object[] args = { new TestFunctions(), "*" };
+ final Object[] args = {new TestFunctions(), "*"};
final Function func = functions.getFunction("test", "pathWithSuffix", args);
assertEquals(
- "test:pathWithSuffix('*')",
- func.invoke(new Context(Integer.valueOf(1)), args),
- "1*");
+ "test:pathWithSuffix('*')",
+ func.invoke(new Context(Integer.valueOf(1)), args),
+ "1*");
}
public void testAllocation() {
@@ -148,21 +157,21 @@ public void testAllocation() {
// Allocate new object using PackageFunctions and class name
assertXPathValue(
- context,
- "string(jxpathtest:TestFunctions.new())",
- "foo=0; bar=null");
+ context,
+ "string(jxpathtest:TestFunctions.new())",
+ "foo=0; bar=null");
// Allocate new object using a fully qualified class name
assertXPathValue(
- context,
- "string(" + TestFunctions.class.getName() + ".new())",
- "foo=0; bar=null");
+ context,
+ "string(" + TestFunctions.class.getName() + ".new())",
+ "foo=0; bar=null");
// Allocate new object using a custom constructor
assertXPathValue(
- context,
- "string(test:new(3, 'baz'))",
- "foo=3; bar=baz");
+ context,
+ "string(test:new(3, 'baz'))",
+ "foo=3; bar=baz");
// Allocate new object using a custom constructor - type conversion
assertXPathValue(context, "string(test:new('3', 4))", "foo=3; bar=4.0");
@@ -191,9 +200,9 @@ public void testMethodCall() {
// Method with two arguments
assertXPathValue(
- context,
- "string(test:setFooAndBar($test, 7, 'biz'))",
- "foo=7; bar=biz");
+ context,
+ "string(test:setFooAndBar($test, 7, 'biz'))",
+ "foo=7; bar=biz");
}
public void testCollectionMethodCall() {
@@ -203,14 +212,14 @@ public void testCollectionMethodCall() {
context.getVariables().declareVariable("myList", list);
assertXPathValue(
- context,
- "size($myList)",
- Integer.valueOf(1));
+ context,
+ "size($myList)",
+ Integer.valueOf(1));
assertXPathValue(
- context,
- "size(beans)",
- Integer.valueOf(2));
+ context,
+ "size(beans)",
+ Integer.valueOf(2));
context.getValue("add($myList, 'hello')");
assertEquals("After adding an element", 2, list.size());
@@ -223,21 +232,21 @@ public void testCollectionMethodCall() {
public void testStaticMethodCall() {
assertXPathValue(
- context,
- "string(test:build(8, 'goober'))",
- "foo=8; bar=goober");
+ context,
+ "string(test:build(8, 'goober'))",
+ "foo=8; bar=goober");
// Call a static method using PackageFunctions and class name
assertXPathValue(
- context,
- "string(jxpathtest:TestFunctions.build(8, 'goober'))",
- "foo=8; bar=goober");
+ context,
+ "string(jxpathtest:TestFunctions.build(8, 'goober'))",
+ "foo=8; bar=goober");
// Call a static method with a fully qualified class name
assertXPathValue(
- context,
- "string(" + TestFunctions.class.getName() + ".build(8, 'goober'))",
- "foo=8; bar=goober");
+ context,
+ "string(" + TestFunctions.class.getName() + ".build(8, 'goober'))",
+ "foo=8; bar=goober");
// Two ClassFunctions are sharing the same prefix.
// This is TestFunctions2
@@ -252,60 +261,60 @@ public void testExpressionContext() {
// The function uses ExpressionContext to get to the current
// node.
assertXPathValue(
- context,
- "//.[test:isMap()]/Key1",
- "Value 1");
+ context,
+ "//.[test:isMap()]/Key1",
+ "Value 1");
// The function gets all
// nodes in the context that match the pattern.
assertXPathValue(
- context,
- "count(//.[test:count(strings) = 3])",
- Double.valueOf(7));
+ context,
+ "count(//.[test:count(strings) = 3])",
+ Double.valueOf(7));
// The function receives a collection of strings
// and checks their type for testing purposes
assertXPathValue(
- context,
- "test:count(//strings)",
- Integer.valueOf(21));
+ context,
+ "test:count(//strings)",
+ Integer.valueOf(21));
// The function receives a collection of pointers
// and checks their type for testing purposes
assertXPathValue(
- context,
- "test:countPointers(//strings)",
- Integer.valueOf(21));
+ context,
+ "test:countPointers(//strings)",
+ Integer.valueOf(21));
// The function uses ExpressionContext to get to the current
// pointer and returns its path.
assertXPathValue(
- context,
- "/beans[contains(test:path(), '[2]')]/name",
- "Name 2");
+ context,
+ "/beans[contains(test:path(), '[2]')]/name",
+ "Name 2");
}
public void testCollectionReturn() {
assertXPathValueIterator(
- context,
- "test:collection()/name",
- list("foo", "bar"));
+ context,
+ "test:collection()/name",
+ list("foo", "bar"));
assertXPathPointerIterator(
- context,
- "test:collection()/name",
- list("/.[1]/name", "/.[2]/name"));
+ context,
+ "test:collection()/name",
+ list("/.[1]/name", "/.[2]/name"));
assertXPathValue(
- context,
- "test:collection()/name",
- "foo");
+ context,
+ "test:collection()/name",
+ "foo");
assertXPathValue(
- context,
- "test:collection()/@name",
- "foo");
+ context,
+ "test:collection()/@name",
+ "foo");
final List list = new ArrayList();
list.add("foo");
@@ -314,38 +323,38 @@ public void testCollectionReturn() {
final Object values = context.getValue("test:items($list)");
assertTrue("Return type: ", values instanceof Collection);
assertEquals(
- "Return values: ",
- list,
- new ArrayList((Collection) values));
+ "Return values: ",
+ list,
+ new ArrayList((Collection) values));
}
public void testNodeSetReturn() {
assertXPathValueIterator(
- context,
- "test:nodeSet()/name",
- list("Name 1", "Name 2"));
+ context,
+ "test:nodeSet()/name",
+ list("Name 1", "Name 2"));
assertXPathValueIterator(
- context,
- "test:nodeSet()",
- list(testBean.getBeans()[0], testBean.getBeans()[1]));
+ context,
+ "test:nodeSet()",
+ list(testBean.getBeans()[0], testBean.getBeans()[1]));
assertXPathPointerIterator(
- context,
- "test:nodeSet()/name",
- list("/beans[1]/name", "/beans[2]/name"));
+ context,
+ "test:nodeSet()/name",
+ list("/beans[1]/name", "/beans[2]/name"));
assertXPathValueAndPointer(
- context,
- "test:nodeSet()/name",
- "Name 1",
- "/beans[1]/name");
+ context,
+ "test:nodeSet()/name",
+ "Name 1",
+ "/beans[1]/name");
assertXPathValueAndPointer(
- context,
- "test:nodeSet()/@name",
- "Name 1",
- "/beans[1]/@name");
+ context,
+ "test:nodeSet()/@name",
+ "Name 1",
+ "/beans[1]/@name");
assertEquals(2, ((Number) context.getValue("count(test:nodeSet())")).intValue());
@@ -354,35 +363,32 @@ public void testNodeSetReturn() {
public void testEstablishNodeSetBaseline() {
assertXPathValue(
- context,
- "test:isInstance(//strings, $List.class)",
- Boolean.TRUE);
+ context,
+ "test:isInstance(//strings, $List.class)",
+ Boolean.TRUE);
assertXPathValue(
- context,
- "test:isInstance(//strings, $NodeSet.class)",
- Boolean.FALSE);
+ context,
+ "test:isInstance(//strings, $NodeSet.class)",
+ Boolean.FALSE);
}
public void testBCNodeSetHack() {
TypeUtils.setTypeConverter(new JXPath11CompatibleTypeConverter());
assertXPathValue(
- context,
- "test:isInstance(//strings, $List.class)",
- Boolean.FALSE);
+ context,
+ "test:isInstance(//strings, $List.class)",
+ Boolean.FALSE);
assertXPathValue(
- context,
- "test:isInstance(//strings, $NodeSet.class)",
- Boolean.TRUE);
+ context,
+ "test:isInstance(//strings, $NodeSet.class)",
+ Boolean.TRUE);
}
public void testClassFunctionsWithoutClassFilter() {
Function classFunction = null;
try {
Functions iFunctions = new ClassFunctions(TestFunctions3.class, "test3");
-
- jxPathFilter.init();
-
- classFunction = iFunctions.getFunction("test3", "testFunction3Method1", null, jxPathFilter);
+ classFunction = iFunctions.getFunction("test3", "testFunction3Method1", null);
} catch (Throwable t) {
System.err.println(t.getMessage());
assertTrue((t.getMessage().contains("Extension function is not allowed: test3:testFunction3Method1 (in org.apache.commons.jxpath.ri.compiler.TestFunctions3)")));
@@ -395,10 +401,7 @@ public void testClassFunctionsWithClassFilter() {
Function classFunction = null;
try {
Functions iFunctions = new ClassFunctions(TestFunctions2.class, "test");
-
- jxPathFilter.init();
-
- classFunction = iFunctions.getFunction("test", "increment", new Object[]{8}, jxPathFilter);
+ classFunction = iFunctions.getFunction("test", "increment", new Object[]{8});
} catch (Throwable t) {
fail(t.getMessage());
} finally {
@@ -409,11 +412,8 @@ public void testClassFunctionsWithClassFilter() {
public void testPackageFunctionsWithoutClassFilter() {
Function packageFunction = null;
try {
- Functions iFunctions = new PackageFunctions("org.apache.commons.jxpath.ri.compiler.","jxpathtests");
-
- jxPathFilter.init();
-
- packageFunction = iFunctions.getFunction("jxpathtests", "TestFunctions3.testFunction3Method1", null, jxPathFilter);
+ Functions iFunctions = new PackageFunctions("org.apache.commons.jxpath.ri.compiler.", "jxpathtests");
+ packageFunction = iFunctions.getFunction("jxpathtests", "TestFunctions3.testFunction3Method1", null);
throw new Exception("testPackageFunctionsWithClassFilter() failed.");
} catch (Throwable t) {
assertTrue((t.getMessage().contains("Cannot invoke extension function jxpathtests:TestFunctions3.testFunction3Method1; org.apache.commons.jxpath.ri.compiler.TestFunctions3"))
@@ -427,11 +427,9 @@ public void testPackageFunctionsWithClassFilter() {
Function packageFunction = null;
String defaultAllowList = System.getProperty("jxpath.class.allow");
try {
- Functions iFunctions = new PackageFunctions("org.apache.commons.jxpath.ri.compiler.","jxpathtests");
+ Functions iFunctions = new PackageFunctions("org.apache.commons.jxpath.ri.compiler.", "jxpathtests");
System.setProperty("jxpath.class.allow", defaultAllowList + ",org.apache.commons.jxpath.ri.compiler.TestFunctions3");
- jxPathFilter.init();
-
- packageFunction = iFunctions.getFunction("jxpathtests", "TestFunctions3.testFunction3Method1", null, jxPathFilter);
+ packageFunction = iFunctions.getFunction("jxpathtests", "TestFunctions3.testFunction3Method1", null);
} catch (Throwable t) {
fail(t.getMessage());
} finally {
@@ -441,48 +439,34 @@ public void testPackageFunctionsWithClassFilter() {
}
public void testJXPathContextFunctionsWithoutClassFilter() {
- String failedMethods = null;
+ String failedMethods = "";
try {
- jxPathFilter.init();
-
- try {
- context.iterate("java.lang.Thread.sleep(5000)");
- throw new Exception("testJXPathContextFunctionsWithClassFilter() failed for iterate()");
- } catch (Throwable t) {
- if ((t.getMessage().indexOf("Cannot invoke extension function java.lang.Thread.sleep; java.lang.Thread") > -1)
- || (t.getMessage().indexOf("java.lang.ClassNotFoundException: java.lang.Thread") > -1)) {
- //success
- } else {
- failedMethods = "org.apache.commons.jxpath.JXPathContext.iterate()";
- }
- }
-
- try {
- context.selectSingleNode("java.lang.Thread.sleep(5000)");
- throw new Exception("testJXPathContextFunctionsWithClassFilter() failed for iterate()");
- } catch (Throwable t) {
- if ((t.getMessage().indexOf("Cannot invoke extension function java.lang.Thread.sleep; java.lang.Thread") > -1)
- || (t.getMessage().indexOf("java.lang.ClassNotFoundException: java.lang.Thread") > -1)) {
- //success
- } else {
- failedMethods += ("".equals(failedMethods) ? "org.apache.commons.jxpath.JXPathContext.selectSingleNode()" : ", org.apache.commons.jxpath.JXPathContext.selectSingleNode()");
- }
+ context.iterate("java.lang.Thread.sleep(5000)");
+ throw new Exception("testJXPathContextFunctionsWithClassFilter() failed for iterate()");
+ } catch (Throwable t) {
+ if (!t.getMessage().contains("Cannot invoke extension function java.lang.Thread.sleep; java.lang.Thread")
+ && !t.getMessage().contains("java.lang.ClassNotFoundException: java.lang.Thread")) {
+ failedMethods = "org.apache.commons.jxpath.JXPathContext.iterate()";
}
+ }
+ try {
+ context.selectSingleNode("java.lang.Thread.sleep(5000)");
+ throw new Exception("testJXPathContextFunctionsWithClassFilter() failed for iterate()");
} catch (Throwable t) {
- fail(t.getMessage());
- } finally {
- if (failedMethods != null) {
- fail("Problem exists in: " + failedMethods);
+ if (!(t.getMessage().contains("Cannot invoke extension function java.lang.Thread.sleep; java.lang.Thread"))
+ && !(t.getMessage().contains("java.lang.ClassNotFoundException: java.lang.Thread"))) {
+ failedMethods += ("".equals(failedMethods) ? "org.apache.commons.jxpath.JXPathContext.selectSingleNode()" : ", org.apache.commons.jxpath.JXPathContext.selectSingleNode()");
}
}
+ if (!failedMethods.isEmpty()) {
+ fail("Failed filtering for methods: " + failedMethods);
+ }
}
public void testJXPathContextFunctionsWithClassFilter() {
try {
System.setProperty("jxpath.class.allow", "java.lang.Thread");
- jxPathFilter.init();
-
long t = System.currentTimeMillis();
context.iterate("java.lang.Thread.sleep(5000)");
t = System.currentTimeMillis() - t;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
index 4c97e2bbd..db693ac02 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
@@ -24,14 +24,24 @@
/**
* Test aliased/doubled XML namespace iteration; JXPATH-125.
- *
*/
public class AliasedNamespaceIterationTest extends JXPathTestCase {
protected JXPathContext context;
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("jxpath.class.allow", "*");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("jxpath.class.allow");
+ super.tearDown();
+ }
+
protected DocumentContainer createDocumentContainer(final String model) {
- final DocumentContainer result = new DocumentContainer(JXPathTestCase.class
- .getResource("IterateAliasedNS.xml"), model);
+ final DocumentContainer result = new DocumentContainer(JXPathTestCase.class.getResource("IterateAliasedNS.xml"), model);
return result;
}
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
index bdbe0ab4e..e0f826386 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
@@ -26,6 +26,18 @@
public class XMLSpaceTest extends JXPathTestCase {
protected JXPathContext context;
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("jxpath.class.allow", "*");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("jxpath.class.allow");
+ super.tearDown();
+ }
+
protected DocumentContainer createDocumentContainer(final String model) {
return new DocumentContainer(JXPathTestCase.class
.getResource("XmlSpace.xml"), model);
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
index afa65c487..cfe11b7af 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
@@ -27,6 +27,18 @@
public class XMLUpperCaseElementsTest extends JXPathTestCase {
protected JXPathContext context;
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("jxpath.class.allow", "*");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("jxpath.class.allow");
+ super.tearDown();
+ }
+
protected DocumentContainer createDocumentContainer(final String model) {
return new DocumentContainer(JXPathTestCase.class.getResource("VendorUpper.xml"), model);
}
diff --git a/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java b/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
index 0b8159240..be1830f5f 100644
--- a/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
+++ b/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
@@ -38,7 +38,19 @@
*/
public class JXPathServletContextTest extends TestCase {
- private ServletContext getServletContext() {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ System.setProperty("jxpath.class.allow", "*");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ System.clearProperty("jxpath.class.allow");
+ super.tearDown();
+ }
+
+ private ServletContext getServletContext() {
final MockServletContext context = new MockServletContext();
context.setAttribute("app", "OK");