ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r585201 - in /ode/trunk/extensions/e4x/src: main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java test/java/org/apache/ode/extension/e4x/JSOperationTest.java
Date Tue, 16 Oct 2007 17:29:39 GMT
Author: vanto
Date: Tue Oct 16 10:29:34 2007
New Revision: 585201

URL: http://svn.apache.org/viewvc?rev=585201&view=rev
Log:
minor fix wrt the CustomContextFactory
new testcase for manipulating node lists

Modified:
    ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
    ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java

Modified: ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java?rev=585201&r1=585200&r2=585201&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
(original)
+++ ode/trunk/extensions/e4x/src/main/java/org/apache/ode/extension/e4x/JSExtensionOperation.java
Tue Oct 16 10:29:34 2007
@@ -40,14 +40,7 @@
 	
 	public void run(ExtensionContext context, Element element) throws FaultException {
 
-		ContextFactory contextFactory = new ContextFactory() {
-			//Enforce usage of plain DOM
-			protected Factory getE4xImplementationFactory() {
-				return XMLLib.Factory.create("org.mozilla.javascript.xmlimpl.XMLLibImpl");
-			}
-		};
-
-		ContextFactory.initGlobal(contextFactory);
+		CustomContextFactory.init();
 		Context ctx = Context.enter();
 		try {
 			Scriptable scope = ctx.initStandardObjects();
@@ -61,5 +54,19 @@
 		} finally {
 			Context.exit();
 		}
+	}
+	
+	private static class CustomContextFactory extends ContextFactory {
+		//Enforce usage of plain DOM
+		protected Factory getE4xImplementationFactory() {
+			return XMLLib.Factory.create("org.mozilla.javascript.xmlimpl.XMLLibImpl");
+		}
+		
+		static void init() {
+			if (!ContextFactory.hasExplicitGlobal()) {
+				ContextFactory.initGlobal(new CustomContextFactory());
+			}
+		}
+		
 	}
 }

Modified: ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java
URL: http://svn.apache.org/viewvc/ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java?rev=585201&r1=585200&r2=585201&view=diff
==============================================================================
--- ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java
(original)
+++ ode/trunk/extensions/e4x/src/test/java/org/apache/ode/extension/e4x/JSOperationTest.java
Tue Oct 16 10:29:34 2007
@@ -21,6 +21,8 @@
 
 import org.apache.ode.test.MockExtensionContext;
 import org.apache.ode.utils.DOMUtils;
+import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.w3c.dom.Element;
 
@@ -29,7 +31,7 @@
  */
 public class JSOperationTest {
 
-	@Test public void test() throws Exception {
+	@Test public void testHelloWorld() throws Exception {
 		StringBuffer s = new StringBuffer();
 		s.append("var request = context.readVariable('request');\n");
 		s.append("request.TestPart += ' World';\n");
@@ -40,5 +42,26 @@
 		JSExtensionOperation jso = new JSExtensionOperation();
 		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s +
"]]></js:script>");
 		jso.run(c, e);
+		String res = DOMUtils.domToString(c.getVariables().get("request"));
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart>Hello
World</TestPart></message>", res);
 	}
+	
+	@Test public void testArrayCopy() throws Exception {
+		StringBuffer s = new StringBuffer();
+		s.append("var item = context.readVariable('item');\n");
+		s.append("var items = context.readVariable('items');\n");
+		s.append("items.TestPart.items.item += item.TestPart.item;\n");
+		s.append("items.TestPart.items.item.(@hyped=='true').price *= 2;");
+		s.append("context.writeVariable('items', items);\n");
+
+		MockExtensionContext c = new MockExtensionContext();
+		c.getVariables().put("item", DOMUtils.stringToDOM("<message><TestPart><item
hyped=\"true\"><name>BPEL consulting</name><price>3000</price></item></TestPart></message>"));
+		c.getVariables().put("items", DOMUtils.stringToDOM("<message><TestPart><items><item><name>WSDL
consulting</name><price>2500</price></item></items></TestPart></message>"));
+		JSExtensionOperation jso = new JSExtensionOperation();
+		Element e = DOMUtils.stringToDOM("<js:script xmlns:js=\"js\"><![CDATA[" + s +
"]]></js:script>");
+		jso.run(c, e);
+		String res = DOMUtils.domToString(c.getVariables().get("items"));
+		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message><TestPart><items><item><name>WSDL
consulting</name><price>2500</price></item><item hyped=\"true\"><name>BPEL
consulting</name><price>6000</price></item></items></TestPart></message>",
res);
+	}
+
 }



Mime
View raw message