ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mszef...@apache.org
Subject svn commit: r590546 - in /ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar: ./ jdbc/ jdbc/JdbcExternalVariableEngineTest.java
Date Wed, 31 Oct 2007 02:45:57 GMT
Author: mszefler
Date: Tue Oct 30 19:45:57 2007
New Revision: 590546

URL: http://svn.apache.org/viewvc?rev=590546&view=rev
Log:
experimental: external variables

Added:
    ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/
    ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/
    ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java
  (with props)

Added: ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java
URL: http://svn.apache.org/viewvc/ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java?rev=590546&view=auto
==============================================================================
--- ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java
(added)
+++ ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java
Tue Oct 30 19:45:57 2007
@@ -0,0 +1,137 @@
+package org.apache.ode.bpel.evar.jdbc;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.ode.bpel.engine.extvar.ExternalVariableConf;
+import org.apache.ode.bpel.engine.extvar.ExternalVariableConf.Variable;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.GUID;
+import org.apche.ode.bpel.evar.ExternalVariableModule.Locator;
+import org.apche.ode.bpel.evar.ExternalVariableModule.Value;
+import org.hsqldb.jdbc.jdbcDataSource;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+
+
+/**
+ * Test for the JDBC external variable engine.
+ * 
+ * @author Maciej Szefler <mszefler at gmail dot com>
+ *
+ */
+public class JdbcExternalVariableEngineTest extends TestCase {
+    
+    final Long _iid = 123L;
+    final QName _pid = new QName("foo", "pid");
+    
+    ExternalVariableConf _econf;
+    jdbcDataSource _ds;
+    JdbcExternalVariableEngine _engine;
+    Element _el1;
+
+    public void setUp() throws Exception {
+        _ds = new org.hsqldb.jdbc.jdbcDataSource();
+        _ds.setDatabase("jdbc:hsqldb:mem:" + new GUID().toString());
+        _ds.setUser("sa");
+       
+        Connection conn = _ds.getConnection();
+        Statement s = conn.createStatement();
+        s.execute("create table extvartable1 (" +
+                "id1 VARCHAR PRIMARY KEY," +
+                "_id2_ VARCHAR," +
+                "pid VARCHAR, " +
+                "iid INT," +
+                "cts DATETIME," +
+                "uts DATETIME," +
+                "foo VARCHAR," +
+                "bar VARCHAR );");
+        
+        _engine = new JdbcExternalVariableEngine();
+        _engine.registerDataSource("testds",_ds);
+        
+        _el1=DOMUtils.stringToDOM("<foobar><id2>ignored</id2><foo>foo</foo><bar>bar</bar></foobar>");
+    }
+    
+    @Test
+    public void testConfigurationParsing() throws Exception {
+        Document deploydoc = DOMUtils.parse(getClass().getResourceAsStream("evardeploy.xml"));
+        NodeList nl = deploydoc.getElementsByTagNameNS(ExternalVariableConf.EXTVARCONF_ELEMENT.getNamespaceURI(),

+                ExternalVariableConf.EXTVARCONF_ELEMENT.getLocalPart());
+
+        ArrayList<Element> al = new ArrayList<Element>();
+        for (int i = 0; i < nl.getLength(); ++i) {
+            al.add((Element)nl.item(i));
+        }
+        
+        assertTrue(al.size() >= 1);
+        _econf = new ExternalVariableConf(al);
+        assertEquals(al.size(), _econf.getVariables().size());
+    }
+
+    
+    @Test
+    public void testConfigure() throws Exception {
+        testConfigurationParsing();
+        for (Variable v :_econf.getVariables())
+            _engine.configure(_pid, v.extVariableId, v.configuration);
+    }
+    
+    
+    @Test
+    public void testInitWriteValue() throws Exception {
+        testConfigure();
+        
+        Locator locator = new Locator("evar1",_pid,_iid);
+        Value value = new Value(locator, _el1, null);
+        value = _engine.writeValue(value);
+        assertNotNull(value);
+        assertNotNull(value.locator);
+        assertTrue(value.locator.containsKey("id1"));
+        assertTrue(value.locator.containsKey("id2"));
+    }
+
+    @Test
+    public void testWriteUpdate() throws Exception {
+        testConfigure();
+        
+        Locator locator = new Locator("evar1",_pid,_iid);
+        Value value = new Value(locator, _el1, null);
+        value = _engine.writeValue(value);
+        String domstr = DOMUtils.domToStringLevel2(value.value);
+        Value newvalue = new Value(value.locator,DOMUtils.stringToDOM(domstr.replaceAll("<bar>bar</bar>",
"<bar>boohoo</bar>")),null);
+        _engine.writeValue(newvalue);
+        Value reread = _engine.readValue(newvalue.locator);
+        domstr = DOMUtils.domToString(reread.value);
+        assertTrue(domstr.contains("boohoo"));
+        assertFalse(domstr.contains(">bar<"));
+    }
+    
+    @Test
+    public void testRead() throws Exception {
+        testConfigure();
+        Locator locator = new Locator("evar1",_pid,_iid);
+        Value value = new Value(locator, _el1, null);
+        value = _engine.writeValue(value);
+        
+        
+        Value readVal = _engine.readValue(value.locator);
+        
+        assertEquals(_iid,readVal.locator.iid);
+        assertEquals(_pid,readVal.locator.pid);
+        assertEquals(2, readVal.locator.size());
+        assertTrue(readVal.locator.containsKey("id1"));
+        assertTrue(readVal.locator.containsKey("id2"));
+        assertEquals(value.locator.get("id1"), readVal.locator.get("id1"));
+        assertEquals(value.locator.get("id2"), readVal.locator.get("id2"));
+
+    }
+}

Propchange: ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/evar/jdbc/JdbcExternalVariableEngineTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message