Ensure that Rhino 1.6R7 or later is used rather than the default Rhino on Java 1.6 which does not support E4X.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/bsf/branches/bsf3.x@947406 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java b/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java
index f4c467b..8aaab7a 100644
--- a/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java
+++ b/bsf-utils/src/test/java/org/apache/bsf/xml/JavaScriptXMLHelperTestCase.java
@@ -38,13 +38,7 @@
private XMLHelper xmlHelper;
public void testToOmElement() throws ScriptException {
- Object scriptXML;
- try {
- scriptXML = engine.eval("<a><b>petra</b></a>");
- } catch (ScriptException e) {
- System.out.println("*** Skipping testToOmElement() because engine does not support E4X: "+engine.getClass().getName());
- return;
- }
+ Object scriptXML = engine.eval("<a><b>petra</b></a>");
assertTrue(scriptXML instanceof XMLObject);
OMElement om = xmlHelper.toOMElement(scriptXML);
@@ -53,13 +47,7 @@
}
public void testToScriptXML() throws ScriptException {
- Object scriptXML;
- try {
- scriptXML = engine.eval("<a><b>petra</b></a>");
- } catch (ScriptException e) {
- System.out.println("*** Skipping testToScriptXML() because engine does not support E4X: "+engine.getClass().getName());
- return;
- }
+ Object scriptXML = engine.eval("<a><b>petra</b></a>");
assertTrue(scriptXML instanceof XMLObject);
OMElement om = xmlHelper.toOMElement(scriptXML);
@@ -73,7 +61,9 @@
public void setUp() {
ScriptEngineManager manager = new ScriptEngineManager();
- engine = manager.getEngineByExtension("js");
+ // The default Rhino implementation provided by Java 1.6 does not support E4X,
+ // so use the unique name supported by the 1.6R7 version factory.
+ engine = manager.getEngineByName("rhino-nonjdk");
xmlHelper = XMLHelper.getArgHelper(engine);
}
diff --git a/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/E4xAxiomTestCase.java b/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/E4xAxiomTestCase.java
index fa9c22e..83ca970 100644
--- a/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/E4xAxiomTestCase.java
+++ b/testing/e4x-1.6R7-Axiom/src/test/java/org/apache/bsf/testing/e4x/E4xAxiomTestCase.java
@@ -45,10 +45,6 @@
private ScriptEngine engine;
public void testInvokeFunctionInXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
- if (!engineSupportsE4X(engine, "testInvokeFunctionInXML()")){
- return;
- }
-
engine.eval("function isXML(xml) { return typeof xml == 'xml'; }" );
assertTrue(engine instanceof Invocable);
Invocable invocableScript = (Invocable) engine;
@@ -61,9 +57,6 @@
}
public void testInvokeFunctionOutXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
- if (!engineSupportsE4X(engine, "testInvokeFunctionOutXML()")){
- return;
- }
engine.eval("function hello(xml) { return <foo>{xml.b}</foo>; }" );
assertTrue(engine instanceof Invocable);
Invocable invocableScript = (Invocable) engine;
@@ -83,9 +76,6 @@
Bindings bindings = engine.createBindings();
bindings.put("o", o);
Object x = engine.eval("typeof o", bindings);
- if (!engineSupportsE4X(engine, "the rest of testE4X()")){
- return;
- }
assertEquals("xml", x);
}
@@ -97,18 +87,10 @@
}
protected void setUp() {
- engine = new ScriptEngineManager().getEngineByExtension("js");
+ // The default Rhino implementation provided by Java 1.6 does not support E4X,
+ // so use the unique name supported by the 1.6R7 version factory.
+ engine = new ScriptEngineManager().getEngineByName("rhino-nonjdk");
assertNotNull("Could not load js engine",engine);
xmlHelper = XMLHelper.getArgHelper(engine);
}
-
- private static boolean engineSupportsE4X(ScriptEngine engine, String message){
- final String name = engine.getClass().getName();
- // This engine does not support E4X
- if (name.equals("com.sun.script.javascript.RhinoScriptEngine")){
- System.out.println("*** "+name + " does not support E4X, skipping "+message);
- return false;
- }
- return true;
- }
}
diff --git a/testing/e4x/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java b/testing/e4x/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
index 2e97565..17e3859 100644
--- a/testing/e4x/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
+++ b/testing/e4x/src/test/java/org/apache/bsf/testing/e4x/HelloTestCase.java
@@ -64,16 +64,14 @@
// }
public void testE4X() throws ScriptException, XMLStreamException, FactoryConfigurationError {
- ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");
+ // The default Rhino implementation provided by Java 1.6 does not support E4X,
+ // so use the unique name supported by the 1.6R7 version factory.
+ ScriptEngine engine = new ScriptEngineManager().getEngineByName("rhino-nonjdk");
XMLHelper convertor = XMLHelper.getArgHelper(engine);
Object o = convertor.toScriptXML(createOMElement("<a><b>petra</b></a>"));
OMElement om = convertor.toOMElement(o);
assertEquals("<a><b>petra</b></a>", om.toString());
- if (!engineSupportsE4X(engine, "rest of testE4X()")){
- return;
- }
-
Bindings bindings = engine.createBindings();
bindings.put("o", o);
Object x = engine.eval("typeof o", bindings);
@@ -98,14 +96,4 @@
Context.exit();
}
}
-
- private static boolean engineSupportsE4X(ScriptEngine engine, String message){
- final String name = engine.getClass().getName();
- // This engine does not support E4X
- if (name.equals("com.sun.script.javascript.RhinoScriptEngine")){
- System.out.println("*** "+name + " does not support E4X, skipping "+message);
- return false;
- }
- return true;
- }
}