You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ms...@apache.org on 2007/11/13 22:32:48 UTC
svn commit: r594646 - in
/ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc:
./ JdbcExternalVariableEngineTest.java
Author: mszefler
Date: Tue Nov 13 13:32:47 2007
New Revision: 594646
URL: http://svn.apache.org/viewvc?rev=594646&view=rev
Log:
Missing files.
Added:
ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/
ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableEngineTest.java (with props)
Added: ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableEngineTest.java
URL: http://svn.apache.org/viewvc/ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableEngineTest.java?rev=594646&view=auto
==============================================================================
--- ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableEngineTest.java (added)
+++ ode/branches/extvar/bpel-runtime/src/test/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableEngineTest.java Tue Nov 13 13:32:47 2007
@@ -0,0 +1,156 @@
+/*
+ * 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.ode.bpel.extvar.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.bpel.extvar.jdbc.JdbcExternalVariableModule;
+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;
+ JdbcExternalVariableModule _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 JdbcExternalVariableModule();
+ _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/extvar/jdbc/JdbcExternalVariableEngineTest.java
------------------------------------------------------------------------------
svn:eol-style = native