You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/05/09 22:18:03 UTC
svn commit: r169351 [11/12] - in /incubator/beehive/trunk/system-controls:
./ ant/ external/ external/commons/ external/ejb/ external/jms/ src/
src/ejb/ src/ejb/org/ src/ejb/org/apache/ src/ejb/org/apache/beehive/
src/ejb/org/apache/beehive/controls/
src/ejb/org/apache/beehive/controls/system/
src/ejb/org/apache/beehive/controls/system/ejb/ src/ejb/schema/ src/jdbc/
src/jdbc/org/ src/jdbc/org/apache/ src/jdbc/org/apache/beehive/
src/jdbc/org/apache/beehive/controls/
src/jdbc/org/apache/beehive/controls/system/
src/jdbc/org/apache/beehive/controls/system/jdbc/
src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ src/jms/
src/jms/org/ src/jms/org/apache/ src/jms/org/apache/beehive/
src/jms/org/apache/beehive/controls/
src/jms/org/apache/beehive/controls/system/
src/jms/org/apache/beehive/controls/system/jms/
src/jms/org/apache/beehive/controls/system/jms/impl/
src/jms/org/apache/beehive/controls/system/jndi/
src/jms/org/apache/beehive/controls/system/jndi/impl/ src/webservice/
src/webservice/org/ src/webservice/org/apache/
src/webservice/org/apache/beehive/
src/webservice/org/apache/beehive/controls/
src/webservice/org/apache/beehive/controls/system/
src/webservice/org/apache/beehive/controls/system/webservice/
src/webservice/org/apache/beehive/controls/system/webservice/generator/
src/webservice/org/apache/beehive/controls/system/webservice/jaxrpc/
src/webservice/org/apache/beehive/controls/system/webservice/utils/ test/
test/ant/ test/conf/ test/src/ test/src/jdbc/ test/src/jdbc/controls/
test/src/jdbc/controls/org/ test/src/jdbc/controls/org/apache/
test/src/jdbc/controls/org/apache/beehive/
test/src/jdbc/controls/org/apache/beehive/controls/
test/src/jdbc/controls/org/apache/beehive/controls/system/
test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/
test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/
test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/dbconnection/
test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/errors/
test/src/jdbc/controls/org/apache/beehive/controls/system/jdbc/test/results/
test/src/jdbc/controls/schemas/ test/src/jdbc/controls/schemas/badusers/
test/src/jdbc/controls/schemas/users/ test/src/jdbc/jdbc-container/
test/src/jdbc/jdbc-container/application/ test/src/jdbc/jdbc-container/src/
test/src/jdbc/jdbc-container/src/org/
test/src/jdbc/jdbc-container/src/org/apache/
test/src/jdbc/jdbc-container/src/org/apache/beehive/
test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/
test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/
test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/
test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/
test/src/jdbc/jdbc-container/webapp/
test/src/jdbc/jdbc-container/webapp/WEB-INF/
test/src/jdbc/jdbc-container/webapp/conf/
test/src/jdbc/jdbc-container/webapp/conf/Catalina/
test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/
test/src/jdbc/junitTests/ test/src/jdbc/junitTests/org/
test/src/jdbc/junitTests/org/apache/
test/src/jdbc/junitTests/org/apache/beehive/
test/src/jdbc/junitTests/org/apache/beehive/controls/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/sqlparser/
test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/utils/
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/build.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/build.xml?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/build.xml (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/build.xml Mon May 9 13:17:58 2005
@@ -0,0 +1,237 @@
+<?xml version="1.0"?>
+<!--
+Copyright 2005 BEA Systems, Inc.
+
+Licensed 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.
+-->
+<project name="JdbcControl Container Cactus Unit Tests" basedir=".">
+
+ <dirname property="my.home" file="${ant.file}"/>
+ <!--
+ <property name="jdbcc.home" location="${my.home}/../.."/>
+ <import file="${jdbcc.home}/jdbccontrol-imports.xml"/>
+ -->
+ <import file="../../../ant/test-imports.xml"/>
+
+ <property environment="os"/>
+ <property name="cactus.home" location="${os.CACTUS_HOME}"/>
+ <property name="catalina.home" location="${os.CATALINA_HOME}"/>
+
+ <!-- Generic properties -->
+ <property name="debug" value="on"/>
+ <property name="optimize" value="off"/>
+ <property name="deprecation" value="off"/>
+
+ <property name="src.cactus.dir" location="${my.home}/src"/>
+ <property name="src.webapp.dir" location="${my.home}/webapp"/>
+
+ <!-- Global project properties -->
+ <property name="project.name.text" value="JdbcControl Container Test"/>
+ <property name="project.name.file" value="jdbccontrol"/>
+ <property name="project.version" value="1.7"/>
+
+ <!-- Libraries required for the Cactus tests -->
+ <property name="aspectjrt.jar"
+ location="${cactus.home}/lib/aspectjrt-1.2.1.jar"/>
+ <property name="cactus.jar"
+ location="${cactus.home}/lib/cactus-1.7.jar"/>
+ <property name="cactus.ant.jar"
+ location="${cactus.home}/lib/cactus-ant-1.7.jar"/>
+ <property name="commons.httpclient.jar"
+ location="${cactus.home}/lib/commons-httpclient-2.0.2.jar"/>
+ <property name="commons.logging.jar"
+ location="${cactus.home}/lib/commons-logging-1.0.4.jar"/>
+ <property name="junit.jar"
+ location="${cactus.home}/lib/junit-3.8.1.jar"/>
+ <path id="cactus.classpath">
+ <pathelement location="${aspectjrt.jar}"/>
+ <pathelement location="${cactus.jar}"/>
+ <pathelement location="${cactus.ant.jar}"/>
+ <pathelement location="${commons.httpclient.jar}"/>
+ <pathelement location="${commons.logging.jar}"/>
+ <pathelement location="${junit.jar}"/>
+ </path>
+
+ <!-- load the ant cactus tasks -->
+ <taskdef resource="cactus.tasks" classpathref="cactus.classpath"/>
+ <taskdef name="apt" classname="org.apache.beehive.controls.runtime.generator.AptTask"
+ classpathref="controls.dependency.path" onerror="report"/>
+
+ <!-- Destination locations for the build -->
+ <property name="module.name" value="jdbc-container"/>
+ <property name="module.dir" location="${test.src.dir}/jdbc/${module.name}"/>
+ <property name="module.classes.dir" location="${test.classes.dir}/${module.name}"/>
+ <property name="module.gensrc.dir" location="${test.classes.dir}/${module.name}-generated-src"/>
+ <property name="module.classes.cactus.dir" location="${module.classes.dir}/cactus"/>
+
+ <!--
+ <property name="target.dir" location="${jdbcc.home}/build/container"/>
+ <property name="target.gensrc.dir" location="${jdbcc.home}/build/container/gensrc"/>
+ <property name="target.classes.dir" location="${target.dir}/classes"/>
+ <property name="target.classes.cactus.dir" location="${target.classes.dir}/cactus"/>
+ -->
+
+ <!-- class path for running these tests -->
+ <path id="test.classpath">
+ <!--<pathelement location="${testcontrols.jar}"/>-->
+ <path refid="test-controls.dependency.path"/>
+ <pathelement location="${module.classes.cactus.dir}"/>
+ <!--<pathelement location="${target.classes.cactus.dir}"/>-->
+ <pathelement location="${test.classes.dir}/junitTests"/>
+ <!-- <pathelement location="${jdbcc.build.dir}/test/classes/units"/> -->
+ <!--<pathelement location="${jdbcc.jar}"/>-->
+ <path refid="jdbc-control.dependency.path"/>
+ <path refid="controls.dependency.path"/>
+ <path refid="xbean.dependency.path"/>
+ <path refid="log4j.dependency.path"/>
+ <path refid="velocity.dependency.path"/>
+ <path refid="tools.dependency.path"/>
+ <path refid="derby.dependency.path"/>
+ <path refid="junit.dependency.path"/>
+ <path refid="commons-discovery.dependency.path"/>
+ <path refid="commons-codec.dependency.path"/>
+ </path>
+
+
+ <!--
+ ========================================================================
+ Clean generated files (including distributables)
+ ========================================================================
+ -->
+ <target name="clean" description="Clean all generated files">
+ <delete dir="${module.classes.dir}"/>
+ <delete dir="${module.gensrc.dir}"/>
+ <delete dir="${module.classes.cactus.dir}"/>
+ </target>
+
+
+ <!--
+ ========================================================================
+ Build the catus test file.
+ ========================================================================
+ -->
+ <target name="compile.cactus">
+
+ <mkdir dir="${module.classes.cactus.dir}"/>
+ <apt srcdir="${src.cactus.dir}"
+ gendir="${module.gensrc.dir}"
+ destdir="${module.classes.cactus.dir}"
+ compileByExtension="true"
+ debug="${compiler.debug}"
+ srcExtensions="*.jcx,*.jcs,*.java">
+ <classpath>
+ <path refid="cactus.classpath"/>
+ <path refid="test.classpath"/>
+ </classpath>
+ </apt>
+ </target>
+
+ <!--
+ ========================================================================
+ Run the tests on the containers for which the Ant property
+ "cactus.home.[container name]" has been defined.
+ ========================================================================
+ -->
+ <target name="test.prepare" depends="test.war">
+ <!-- Prepare the directories for the JUnit reports -->
+ </target>
+
+
+ <!--
+ ========================================================================
+ Create the war file that will hold the Cactus tests. At this point in
+ time, as there isn't a <cactifyear> Ant task, we need to create
+ manually a war file even if our application doesn't need one.
+ ========================================================================
+ -->
+ <target name="test.war" depends="compile.cactus">
+
+ <war warfile="${test.lib.dir}/${project.name.file}.war"
+ webxml="${src.webapp.dir}/WEB-INF/web.xml">
+ </war>
+
+ <!-- Cactify the web-app archive -->
+ <cactifywar srcfile="${test.lib.dir}/${project.name.file}.war"
+ destfile="${test.lib.dir}/${project.name.file}-cactified.war"
+ mergewebxml="${src.webapp.dir}/WEB-INF/cactus-web.xml">
+
+ <classes dir="${module.classes.cactus.dir}"/>
+ <classes dir="${test.classes.dir}/junitTests"/>
+ <classes dir="${test.classes.dir}/controls"/>
+
+ <!-- Needed for Clover coverage reports -->
+ <lib file="${clover.jar}"/>
+
+ <lib file="${build.lib.dir}/${jdbccontrol.jar.name}"/>
+ <lib file="${beehive.home}/controls/build/jars/controls.jar"/>
+ <lib file="${beehive.home}/external/xmlbeans/apache-xbean.jar"/>
+ <lib file="${beehive.home}/external/commons/commons-codec-1.3.jar"/>
+ <lib file="${beehive.home}/external/commons/commons-discovery-0.2.jar"/>
+ <lib file="${beehive.home}/external/log4j/log4j-1.2.8.jar"/>
+ <lib file="${beehive.home}/installed/jsr173/jsr173_1.0_api.jar"/>
+ <lib file="${beehive.home}/external/derby/derby_46005.jar"/>
+ </cactifywar>
+ </target>
+
+ <!--
+ ========================================================================
+ Run the cactus tests.
+ ========================================================================
+ -->
+ <target name="test" depends="clean, test.prepare"
+ description="Run the tests on the defined containers">
+
+ <!-- NOTE: Temporary location for now -->
+ <property name="cactus.testlog.dir" location="${test.lib.dir}/jdbc-container-logs"/>
+ <property name="test.derby.dir" location="${test.lib.dir}/derby"/>
+ <mkdir dir="${cactus.testlog.dir}"/>
+ <mkdir dir="${test.derby.dir}"/>
+
+ <!-- Run the tests -->
+ <cactus warfile="${test.lib.dir}/${project.name.file}-cactified.war"
+ fork="yes" failureproperty="tests.failed">
+ <sysproperty key="derby.system.home" value="${test.derby.dir}"/>
+ <classpath>
+ <path refid="cactus.classpath"/>
+ <path refid="test.classpath"/>
+ </classpath>
+ <containerset>
+
+ <!-- tomcat5x -->
+ <!-- <tomcat5x dir="${catalina.home}" port="8080" if="tomcat5x"> -->
+ <tomcat5x dir="${catalina.home}">
+ <conf dir="${my.home}/webapp/conf"/>
+ </tomcat5x>
+
+ </containerset>
+ <formatter type="brief" usefile="false"/>
+ <formatter type="xml"/>
+ <batchtest todir="${cactus.testlog.dir}">
+ <fileset dir="${src.cactus.dir}">
+ <include name="**/Test*.java"/>
+ <exclude name="**/Test*All.java"/>
+ <exclude name="**/Test*ClientInitializer.java"/>
+ </fileset>
+ </batchtest>
+ </cactus>
+
+ <!-- Generate the JUnit reports -->
+ <junitreport todir="${cactus.testlog.dir}">
+ <fileset dir="${cactus.testlog.dir}" includes="TEST-*.xml"/>
+ <report todir="${cactus.testlog.dir}" format="frames"/>
+ </junitreport>
+
+ <fail if="tests.failed">At least one test failed!</fail>
+ </target>
+
+</project>
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/TestJdbcControlContainer.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/TestJdbcControlContainer.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/TestJdbcControlContainer.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/src/org/apache/beehive/controls/system/jdbc/containertest/TestJdbcControlContainer.java Mon May 9 13:17:58 2005
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.containertest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.cactus.ServletTestSuite;
+import org.apache.beehive.controls.system.jdbc.test.dbconnection.DataSourceConnectionCtrl;
+import org.apache.beehive.controls.system.jdbc.units.errors.ErrorPathsTest;
+import org.apache.beehive.controls.system.jdbc.units.results.DBMultiRowResultsTest;
+import org.apache.beehive.controls.system.jdbc.units.results.DBSingleRowResultsTest;
+import org.apache.beehive.controls.system.jdbc.units.results.JdbcTypesTest;
+import org.apache.beehive.controls.system.jdbc.units.results.XmlBeanResultsTest;
+import org.apache.beehive.controls.system.jdbc.units.sqlparser.SqlParserTest;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ */
+public class TestJdbcControlContainer extends TestCase {
+
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ private DataSourceConnectionCtrl ctrl;
+
+ /**
+ * Wrap the standalone Junit tests in Cactus.
+ *
+ * @return
+ */
+ public static Test suite() {
+ ServletTestSuite suite = new ServletTestSuite();
+ suite.addTestSuite(TestJdbcControlContainer.class);
+ suite.addTestSuite(DBSingleRowResultsTest.class);
+ suite.addTestSuite(DBMultiRowResultsTest.class);
+ suite.addTestSuite(XmlBeanResultsTest.class);
+ suite.addTestSuite(JdbcTypesTest.class);
+ suite.addTestSuite(SqlParserTest.class);
+ suite.addTestSuite(ErrorPathsTest.class);
+ return suite;
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ _controlContext = ControlThreadContext.getContext();
+ TestJdbcControlContainerClientInitializer.initialize(_controlContext, this);
+ }
+
+ public void testDataSourceConnection() throws SQLException {
+ Connection conn = ctrl.getConnection();
+ assertNotNull(conn);
+ }
+}
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/cactus-web.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/cactus-web.xml?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/cactus-web.xml (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/cactus-web.xml Mon May 9 13:17:58 2005
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <!-- Put Cactus specific definitions here. Note that by default
+ the <cactifywar> Ant task automatically adds Servlet, Filter
+ and JSP redirector definitions and mappings. You only need
+ to edit this file if you want to change these defaults or
+ add other definitions required for Cactus testing. -->
+
+</web-app>
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/web.xml?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/web.xml (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/WEB-INF/web.xml Mon May 9 13:17:58 2005
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <filter>
+ <filter-name>ControlFilter</filter-name>
+ <filter-class>org.apache.beehive.controls.runtime.servlet.ControlFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>ControlFilter</filter-name>
+ <url-pattern>*.jws</url-pattern>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <resource-ref>
+ <description>DB Connection</description>
+ <res-ref-name>jdbc/TestDB</res-ref-name>
+ <res-type>javax.sql.DataSource</res-type>
+ <res-auth>Container</res-auth>
+ </resource-ref>
+
+</web-app>
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/context.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/context.xml?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/context.xml (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/jdbc-container/webapp/conf/Catalina/localhost/context.xml Mon May 9 13:17:58 2005
@@ -0,0 +1,72 @@
+<?xml version='1.0' encoding='utf-8'?>
+
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+<Context path="/jdbccontrol-cactified"
+ debug="5" reloadable="true" crossContext="true" override="true">
+
+ <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_dataWeb_log." suffix=".txt" timestamp="true"/>
+
+ <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"/>
+
+ <ResourceParams name="jdbc/TestDB">
+
+ <parameter>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </parameter>
+
+ <parameter>
+ <name>driverClassName</name>
+ <value>org.apache.derby.jdbc.EmbeddedDriver</value>
+ </parameter>
+
+ <parameter>
+ <name>url</name>
+ <value>jdbc:derby:TestDB;create=true</value>
+ </parameter>
+
+ <!-- Maximum number of dB connections in pool. Make sure you
+ configure your mysqld max_connections large enough to handle
+ all of your db connections. Set to 0 for no limit.
+ -->
+ <parameter>
+ <name>maxActive</name>
+ <value>100</value>
+ </parameter>
+
+ <!-- Maximum number of idle dB connections to retain in pool.
+ Set to 0 for no limit.
+ -->
+ <parameter>
+ <name>maxIdle</name>
+ <value>30</value>
+ </parameter>
+
+ <!-- Maximum time to wait for a dB connection to become available
+ in ms, in this example 10 seconds. An Exception is thrown if
+ this timeout is exceeded. Set to -1 to wait indefinitely.
+ -->
+ <parameter>
+ <name>maxWait</name>
+ <value>10000</value>
+ </parameter>
+
+ </ResourceParams>
+</Context>
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/build.xml
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/build.xml?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/build.xml (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/build.xml Mon May 9 13:17:58 2005
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+
+<project name="Beehive/SystemControls/JUnitTests" default="build" basedir=".">
+
+ <import file="../../../ant/test-imports.xml"/>
+
+ <taskdef name="apt" classname="org.apache.beehive.controls.runtime.generator.AptTask"
+ classpathref="controls.dependency.path" onerror="report"/>
+ <taskdef name="control-jar" classname="org.apache.beehive.controls.runtime.packaging.ControlJarTask"
+ classpathref="controls.dependency.path" onerror="report"/>
+
+ <property name="module.name" value="junitTests"/>
+ <property name="module.dir" location="${test.src.dir}/jdbc/${module.name}"/>
+ <property name="module.gensrc.dir" location="${test.classes.dir}/${module.name}-generated-src"/>
+ <property name="module.classes.dir" location="${test.classes.dir}/${module.name}"/>
+ <property name="module.jar" location="${test.lib.dir}/${test-units.jar.name}"/>
+
+ <path id="junit.classpath">
+ <path refid="test-controls.dependency.path"/>
+ <path refid="jdbc-control.dependency.path"/>
+ <path refid="controls.dependency.path"/>
+ <path refid="xbean.dependency.path"/>
+ <path refid="junit.dependency.path"/>
+ <path refid="log4j.dependency.path"/>
+ <path refid="velocity.dependency.path"/>
+ <path refid="servlet.dependency.path"/>
+ </path>
+
+ <target name="build">
+ <echo>compile module: ${module.name}</echo>
+ <echo>output directory: ${test.lib.dir}</echo>
+ <echo>debug: ${compile.debug}</echo>
+
+ <mkdir dir="${module.classes.dir}"/>
+ <mkdir dir="${module.gensrc.dir}"/>
+
+ <!-- now build the unit tests -->
+ <apt srcdir="${module.dir}"
+ destdir="${module.classes.dir}"
+ gendir="${module.gensrc.dir}"
+ classpathref="junit.classpath"
+ compileByExtension="true"
+ debug="${compiler.debug}"
+ nowarn="${compiler.nowarn}"
+ srcExtensions="*.java">
+ </apt>
+
+ <control-jar destfile="${module.jar}" basedir="${module.classes.dir}"/>
+ </target>
+
+ <target name="clean">
+ <delete dir="${module.classes.dir}"/>
+ <delete file="${module.jar}"/>
+ </target>
+
+</project>
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/DBConnectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/DBConnectionTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/DBConnectionTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/dbconnection/DBConnectionTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.dbconnection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.test.dbconnection.DriverManagerConnectionCtrl;
+import org.apache.beehive.controls.system.jdbc.test.dbconnection.DriverManagerConnectionCtrlAuth;
+import org.apache.beehive.controls.system.jdbc.test.dbconnection.DriverManagerConnectionCtrlProps;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.sql.ResultSet;
+
+/**
+ *
+ */
+public class DBConnectionTest extends TestCase {
+ private static final Logger _logger = Logger.getLogger(DBConnectionTest.class);
+
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public DriverManagerConnectionCtrl testCtrl;
+ @Control
+ public DriverManagerConnectionCtrlAuth testAuthCtrl;
+ @Control
+ public DriverManagerConnectionCtrlProps testPropsCtrl;
+
+ public void setUp() throws Exception {
+ // BasicConfigurator.configure();
+ super.setUp();
+ _controlContext = TestContextInitializer.initContext(this);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ _controlContext.endContext();
+ }
+
+
+ public void testDriverMgrConnection_simple() throws Exception {
+ assertNotNull(testCtrl);
+ testCtrl.getConnection();
+ }
+
+ public void testDriverMgrConnection_auth() throws Exception {
+
+ // add authentication and test
+ Connection conn = DriverManager.getConnection("jdbc:derby:MyDBAuth;create=true");
+ Statement s = conn.createStatement();
+
+ // Setting and Confirming requireAuthentication
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.connection.requireAuthentication', 'true')");
+ ResultSet rs = s.executeQuery(
+ "VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY(" +
+ "'derby.connection.requireAuthentication')");
+ rs.next();
+ //System.out.println(rs.getString(1));
+
+ // Setting authentication scheme to Derby
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.authentication.provider', 'BUILTIN')");
+
+ // Creating some sample users
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.user.foo', 'bar')");
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.user.test', 'test')");
+
+ // Setting default connection mode to no access
+ // (user authorization)
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.database.defaultConnectionMode', 'noAccess')");
+ // Confirming default connection mode
+ rs = s.executeQuery (
+ "VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY(" +
+ "'derby.database.defaultConnectionMode')");
+ rs.next();
+ assertEquals(rs.getString(1), "noAccess");
+
+ // Defining read-write users
+ s.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
+ "'derby.database.fullAccessUsers', 'foo')");
+
+ conn.close();
+
+ assertNotNull(testAuthCtrl);
+ testAuthCtrl.getConnection();
+ }
+
+ public void testDriverMgrConnection_props() throws Exception {
+ assertNotNull(testPropsCtrl);
+ testPropsCtrl.getConnection();
+ }
+
+ public DBConnectionTest(String name) { super(name); }
+
+ public static Test suite() { return new TestSuite(DBConnectionTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/ErrorPathsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/ErrorPathsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/ErrorPathsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/errors/ErrorPathsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.errors;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.ControlException;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.test.errors.ErrorsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+/**
+ * Tests dbcontrol error handling and recovery
+ */
+public final class ErrorPathsTest extends TestCase {
+
+ private static final Logger _logger = Logger.getLogger(ErrorPathsTest.class);
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public ErrorsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName="java:/comp/env/jdbc/TestDB")
+ private ErrorsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ ErrorPathsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ // setup the database
+ Connection conn = testCtrl.getConnection();
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("DROP TABLE USERS");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("CREATE TABLE USERS (FNAME VARCHAR(32), USERID INT)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester1', 21)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester2', 22)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester3', 23)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester4', 24)");
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test for a control method missing an @SQL annotation
+ //
+ public void testMissingSQLAnnotation() throws Exception {
+
+ assertNotNull(testCtrl);
+
+ try {
+ testCtrl.getAllUsersBad1();
+ fail("A ControlException should be raised when the @SQL annoation is missing from a dbControl method.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // test for a failed object mapping
+ //
+ public void testFailedObjectMapping() throws Exception {
+ try {
+ testCtrl.getAUserBad1("tester1");
+ fail("A ControlException should be raised when an ResultSet->Object mapping fails.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // test for a failed object mapping to a object type mismatch
+ //
+ public void testObjectMappingMismatch() throws Exception {
+ try {
+ testCtrl.getAUserBad3("tester1");
+ fail("A ControlException should be raised when an ResultSet->Object mapping fails due to type mismatch.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // test for a failed XML object mapping
+ //
+ public void testFailedXmlObjectMapping() throws Exception {
+ try {
+ testCtrl.getAUserBad4("tester2");
+ fail("A ControlException should be raised when an ResultSet->XmlObject mapping fails due to type mismatch.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // test a null value in an sql: substitution cmd
+ //
+// public void testNullSqlSubValue() throws Exception {
+// testCtrl.getAUserBad5(null);
+// }
+
+ public ErrorPathsTest(String name) throws Exception { super(name); }
+
+ public static Test suite() { return new TestSuite(ErrorPathsTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBMultiRowResultsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.framework.TestCase;
+import org.apache.beehive.controls.api.ControlException;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+
+import javax.sql.RowSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ *
+ */
+public class DBMultiRowResultsTest extends TestCase {
+ private static final Logger _logger = Logger.getLogger(DBMultiRowResultsTest.class);
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public ResultsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName="java:/comp/env/jdbc/TestDB")
+ private ResultsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ //BasicConfigurator.configure();
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ DBMultiRowResultsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ Connection conn = testCtrl.getConnection();
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("DROP TABLE USERS");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("CREATE TABLE USERS (FNAME VARCHAR(32), USERID INT)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester1', 21)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester2', 22)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester3', 23)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester4', 24)");
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test array return type
+ //
+ public void testArrayReturnType() throws Exception {
+
+ ResultsTestCtrl.Customer[] customers = testCtrl.getCustomerArray();
+ assertNotNull(customers);
+ assertEquals(customers.length, 4);
+ assertEquals(customers[0].getFname(), "tester1");
+ assertEquals(customers[3].userid, 24);
+ }
+
+ //
+ // test array return type, restricted array size returned (2)
+ //
+ public void testArrayReturnTypeMaxSize() throws Exception {
+
+ ResultsTestCtrl.Customer[] customers = testCtrl.getCustomerArrayLimitedSize();
+ assertNotNull(customers);
+ assertEquals(customers.length, 2);
+ }
+
+ //
+ // test array return type, restricted array size returned (2), restricted maxrows (1)
+ //
+ public void testArrayReturnTypeMaxSize2() throws Exception {
+
+ ResultsTestCtrl.Customer[] customers = testCtrl.getCustomerArrayLimitedSize2();
+ assertNotNull(customers);
+ assertEquals(customers.length, 1);
+ }
+
+ //
+ // test array return type, restricted array size returned (2), restricted maxrows (4)
+ //
+ public void testArrayReturnTypeMaxSize3() throws Exception {
+
+ ResultsTestCtrl.Customer[] customers = testCtrl.getCustomerArrayLimitedSize3();
+ assertNotNull(customers);
+ assertEquals(customers.length, 2);
+ }
+
+ //
+ // test max rows, value of 1
+ //
+ public void testMaxRows1() throws Exception {
+
+ ResultsTestCtrl.Customer[] customers = testCtrl.getCustomerArrayLimitedSize4();
+ assertNotNull(customers);
+ assertEquals(customers.length, 1);
+ }
+
+ //
+ // test array of HashMap return type
+ //
+ public void testArrayHashMapReturnType() throws Exception {
+
+ HashMap[] customerHashMap = testCtrl.getCustomerHashMapArray(22);
+ assertTrue(customerHashMap.length > 0);
+ assertEquals(customerHashMap[0].get("FNAME"), "tester2");
+ assertEquals(customerHashMap[0].get("USERID"), 22);
+ }
+
+
+ //
+ // test EMPTY array of HashMap return type
+ //
+ public void testEmptyArrayHashMapReturnType() throws Exception {
+
+ HashMap[] customerHashMap = testCtrl.getCustomerHashMapArray(1000);
+ assertEquals(customerHashMap.length, 0);
+ }
+
+ //
+ // test Iterator return type
+ //
+ public void testIteratorReturnType() throws Exception {
+
+ Iterator customersIterator = testCtrl.getCustomerIterator();
+ assertNotNull(customersIterator);
+ int idCheck = 21;
+ assertTrue(customersIterator.hasNext());
+ while (customersIterator.hasNext()) {
+ ResultsTestCtrl.Customer c = (ResultsTestCtrl.Customer) customersIterator.next();
+ assertEquals(idCheck, c.userid);
+ idCheck++;
+ }
+ assertEquals(idCheck, 25);
+ }
+
+ //
+ // test RowSet return type, defines its own rowset mapper
+ //
+ public void testRowSetReturnType() throws Exception {
+
+ RowSet customersRowSet = testCtrl.getAllUsersINRS();
+ assertNotNull(customersRowSet);
+
+ customersRowSet.beforeFirst();
+ customersRowSet.next();
+ assertEquals(customersRowSet.getInt("USERID"), 21);
+
+ }
+
+ //
+ // test scrollable result set feature, sensitive / updateable
+ //
+ public void testScrollableInsensitiveUpdateablepResultSet() throws Exception {
+ try {
+ ResultSet rs = testCtrl.getScrollableResultSet_IU();
+ fail("This feature has not been impelented in Derby yet (1/19/2005), need to add test case once it has.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // test scrollable result set feature, forward only / updateable
+ //
+ public void testScrollableSensitiveResultSet() throws Exception {
+ try {
+ ResultSet rs = testCtrl.getScrollableResultSet_SR();
+ fail("This feature has not been impelented in Derby yet (1/19/2005), need to add test case once it has.");
+ } catch (ControlException ce) {
+ assertTrue(true);
+ }
+// rs.afterLast();
+// rs.beforeFirst();
+// rs.next();
+// rs.next();
+// assertEquals(rs.getInt(2), 22);
+// rs.close();
+ }
+
+ //
+ // test holdable result set cursors
+ //
+ public void testResultSetHoldability() throws Exception {
+ ResultSet rs = testCtrl.getResultSetHoldablity();
+ }
+
+ //
+ // test for fetchSize / fetchDirection
+ //
+ public void testFetchSizeDirection() throws Exception {
+ ResultSet rs = testCtrl.getFetchOptmizedResultSet();
+ rs.next();
+ assertEquals(rs.getInt(2), 21);
+ }
+
+ //
+ // test single column result set mapping
+ //
+ public void testSingleColumnResultSetMapping() throws Exception {
+ String fnames[] = testCtrl.getFnameColumn();
+ assertEquals(fnames[1], "tester2");
+ assertEquals(fnames[3], "tester4");
+ }
+
+ public DBMultiRowResultsTest(String name) throws Exception {
+ super(name);
+ }
+
+ public static Test suite() { return new TestSuite(DBMultiRowResultsTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBSingleRowResultsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBSingleRowResultsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBSingleRowResultsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/DBSingleRowResultsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,332 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests dbcontrol results for single row result sets
+ */
+public class DBSingleRowResultsTest extends TestCase {
+
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ private ResultsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName="java:/comp/env/jdbc/TestDB")
+ private ResultsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ DBSingleRowResultsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ Connection conn = testCtrl.getConnection();
+
+ // setup the database
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("DROP TABLE users");
+ s.executeUpdate("DROP TABLE usergen");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("CREATE TABLE USERS (FNAME VARCHAR(32), USERID INT)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester1', 21)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester2', 22)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester3', 23)");
+ s.executeUpdate("INSERT INTO USERS VALUES ('tester4', 24)");
+
+ s.executeUpdate("CREATE TABLE usergen (user_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1) CONSTRAINT people_pk PRIMARY KEY, person VARCHAR(128))");
+ s.executeUpdate("INSERT INTO usergen (person) VALUES ('genmeakey')");
+
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test query return ResultSet
+ //
+ public void testResultSetReturnType() throws Exception {
+
+ assertNotNull(testCtrl);
+
+ ResultSet rs = testCtrl.getAllUsers();
+ assertNotNull(rs);
+ rs.next();
+ String name = rs.getString("FNAME");
+ assertEquals(name, "tester1");
+ rs.close();
+ }
+
+ //
+ // test query with sql: escape, returns ResultSet
+ //
+ public void testSqlEscapeResultSet() throws Exception {
+
+ ResultSet rs = testCtrl.getSomeUser("tester4");
+ assertNotNull(rs);
+ rs.next();
+ String name = rs.getString("FNAME");
+ assertEquals(name, "tester4");
+ rs.close();
+
+ rs = testCtrl.getSomeUser(24);
+ assertNotNull(rs);
+ rs.next();
+ name = rs.getString("FNAME");
+ assertEquals(name, "tester4");
+ rs.close();
+ }
+
+ //
+ // test query with sql: escape
+ //
+ public void testSqlEscape() throws Exception {
+
+ ResultSet rs = testCtrl.getJustOneUser("fname='tester4'");
+ assertNotNull(rs);
+ rs.next();
+ String name = rs.getString("FNAME");
+ assertEquals(name, "tester4");
+ rs.close();
+ }
+
+ //
+ // param sub from object getter method
+ //
+ public void testGetUserWithObj() throws Exception {
+ ResultsTestCtrl.CustomerInput1 ci = new ResultsTestCtrl.CustomerInput1();
+ ci.setUserid(22);
+ String c = testCtrl.getSomeUser(ci);
+ assertEquals("tester2",c);
+ }
+
+ //
+ // param sub from object field
+ //
+ public void testGetUserWithObj2() throws Exception {
+ ResultsTestCtrl.CustomerInput2 ci = new ResultsTestCtrl.CustomerInput2();
+ ci.userid = 23;
+ String c = testCtrl.getSomeUser(ci);
+ assertEquals("tester3",c);
+ }
+
+ //
+ // param sub from map
+ //
+ public void testGetUserWithObj3() throws Exception {
+ HashMap map = new HashMap();
+ map.put("userid", 21);
+ String c = testCtrl.getSomeUser(map);
+ assertEquals("tester1",c);
+ }
+
+ //
+ // param sub from nested object
+ //
+ public void testGetUserWithObj4() throws Exception {
+ ResultsTestCtrl.CustomerWrapper cw = new ResultsTestCtrl.CustomerWrapper();
+ cw.c = new ResultsTestCtrl.CustomerInput2();
+ cw.c.userid = 22;
+ String c = testCtrl.getSomeUser(cw);
+ assertEquals("tester2", c);
+ }
+
+ //
+ // param sub from object getter method, inherited from base class
+ //
+ public void testGetUserWithObj5() throws Exception {
+ ResultsTestCtrl.CustomerInput3 ci = new ResultsTestCtrl.CustomerInput3();
+ ci.setUserid(22);
+ String c = testCtrl.getSomeUser(ci);
+ assertEquals("tester2",c);
+ }
+
+ //
+ // param sub from object getter method, inherited from base class
+ //
+ public void testGetUserWithObj6() throws Exception {
+ ResultsTestCtrl.CustomerInput4 ci = new ResultsTestCtrl.CustomerInput4();
+ ci.userid = 22;
+ String c = testCtrl.getSomeUser(ci);
+ assertEquals("tester2",c);
+ }
+
+
+ //
+ // test HashMap return type
+ //
+ public void testHashMapReturnType() throws Exception {
+
+ HashMap customerHashMap = testCtrl.getCustomerHashMap(23);
+ assertNotNull(customerHashMap);
+ assertEquals(customerHashMap.get("FNAME"), "tester3");
+ }
+
+ //
+ // test Map return type
+ //
+ public void testMapReturnType() throws Exception {
+
+ Map customerMap = testCtrl.getCustomerMap(22);
+ assertNotNull(customerMap);
+ assertEquals(customerMap.get("FNAME"), "tester2");
+ }
+
+ //
+ // test null / both Object and int return Types
+ //
+ public void testNullReturnType() throws Exception {
+
+ int prim = testCtrl.getNoUsers(111);
+ assertEquals(prim, 0);
+
+ ResultsTestCtrl.Customer customer = testCtrl.getACustomer(111);
+ assertNull(customer);
+ }
+
+ //
+ // test Object return type
+ //
+ public void testObjectReturnType() throws Exception {
+
+ ResultsTestCtrl.Customer customer = testCtrl.getACustomer(23);
+ assertNotNull(customer);
+ assertEquals(customer.getFname(), "tester3");
+ assertEquals(customer.userid, 23);
+ }
+
+ //
+ // add some new users to the table using batch update
+ //
+ public void testBatchUpdate() throws Exception {
+
+ int[] results = testCtrl.doABatchUpdate(new String[]{"tester44", "tester55", "tester66"}, new int[]{44, 55, 66});
+ assertEquals(1, results[0]);
+ assertEquals(1, results[1]);
+ assertEquals(1, results[2]);
+ }
+
+ //
+ // get the generated keys from the SQL statement
+ //
+ public void testGenKeys() throws Exception {
+ ResultSet rs = testCtrl.getGenKeys("genmeanotherkey");
+ assertNotNull(rs);
+
+ rs.next();
+ int generatedId = rs.getInt(1);
+ assertEquals(generatedId, 2);
+ rs.close();
+ }
+
+ //
+ // get the generated keys from the SQL statement -- with specified column names
+ //
+ public void testGenKeysWithColumnNames() throws Exception {
+ try {
+ /* ResultSet rs = */testCtrl.getGenKeys2("genmeanotherkey2");
+ fail("This feature has not been impelented in Derby yet (1/1/2005), need to add test case once it has.");
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ //
+ // get the generated keys from the SQL statement -- with specified column names and return type mapping
+ //
+ public void testGenKeysReturnTypeMapping() throws Exception {
+ int result = testCtrl.getGenKeys3("genmeanotherkey3");
+ assertEquals(result, 2);
+ }
+
+ //
+ // get the generated keys from the SQL statement -- with specified column names and return type mapping
+ //
+ public void testGenKeysReturnTypeMapping2() throws Exception {
+ String result = testCtrl.getGenKeys4("genmeanotherkey4");
+ assertEquals(result, "2");
+ }
+
+ //
+ // get the generated keys from the SQL statement -- with specified column names and return type mapping
+ //
+ public void testGenKeysReturnTypeMapping3() throws Exception {
+ int[] result = testCtrl.getGenKeys5("genmeanotherkey5");
+ assertEquals(result[0], 2);
+ }
+
+ //
+ // get the generated keys from the SQL statement -- with specified column indexes
+ //
+ public void testGenKeysReturnTypeMapping4() throws Exception {
+ try {
+ /*ResultSet rs = */testCtrl.getGenKeys6("genmeanotherkey6");
+ fail("This feature has not been impelented in Derby yet (1/1/2005), need to add test case once it has.");
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+
+ public DBSingleRowResultsTest(String name) throws Exception {
+ super(name);
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ }
+
+ public static Test suite() {
+ return new TestSuite(DBSingleRowResultsTest.class);
+ }
+
+ public static void main(String[] args) throws Exception {
+ junit.textui.TestRunner.run(suite());
+ }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/JdbcTypesTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/JdbcTypesTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/JdbcTypesTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/JdbcTypesTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+
+import javax.sql.rowset.serial.SerialBlob;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.Time;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * Tests dbcontrol results for single row result sets
+ */
+public class JdbcTypesTest extends TestCase {
+
+ private static final Logger _logger = Logger.getLogger(JdbcTypesTest.class);
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public ResultsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName="java:/comp/env/jdbc/TestDB")
+ private ResultsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ JdbcTypesTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ // setup the database
+ Connection conn = testCtrl.getConnection();
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("DROP TABLE blob_table");
+ s.executeUpdate("DROP TABLE clob_table");
+ s.executeUpdate("DROP TABLE basic_types");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("CREATE TABLE blob_table (id INT, BLB BLOB(4k))");
+ s.executeUpdate("CREATE TABLE clob_table (id INT, CLB CLOB(8k))");
+ s.executeUpdate("INSERT INTO clob_table VALUES (1234, 'thisisaclob1')");
+ s.executeUpdate("INSERT INTO clob_table VALUES (5678, 'thisisaclob2')");
+
+ StringBuilder sqlStr = new StringBuilder(
+ "CREATE TABLE basic_types ("
+ + "c CHAR, ca CHAR(10), vc VARCHAR(20), lvc LONG VARCHAR,"
+ + "bin CHAR FOR BIT DATA, varbin VARCHAR(1024) FOR BIT DATA, lvarbin LONG VARCHAR FOR BIT DATA,"
+ + "sint SMALLINT, i INT, bint BIGINT, r REAL, dp DOUBLE PRECISION,"
+ + "d DECIMAL, nu NUMERIC, dt DATE, t TIME, ts TIMESTAMP)");
+ s.executeUpdate(sqlStr.toString());
+
+ sqlStr = new StringBuilder(
+ "INSERT INTO basic_types VALUES("
+ + "'c', 'chararray', 'varcharvalue', 'longvarcharvalue',"
+ + "X'DE', X'bcff', X'aacc',"
+ + "32767, 2147483647, 9223372036854775807, 3.402E+38, 1.79769E+308,"
+ + "123.4567, 123.4567, '2005-02-23', '09:45:13', TIMESTAMP('2005-02-23 09:46:17'))");
+ s.executeUpdate(sqlStr.toString());
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test Character, single char
+ //
+ public void testCharacter() throws Exception {
+ String chars = testCtrl.getChar();
+ assertEquals(chars,"c");
+ }
+
+ //
+ // test Character - char string
+ //
+ public void testCharacter2() throws Exception {
+ String chars = testCtrl.getChar2();
+ assertEquals(chars,"chararray ");
+ }
+
+ //
+ // test varchar
+ //
+ public void testVarchar() throws Exception {
+ String chars = testCtrl.getVarchar();
+ assertEquals(chars,"varcharvalue");
+ }
+
+ //
+ // test long varchar
+ //
+ public void testLongvarchar() throws Exception {
+ String chars = testCtrl.getLongvarchar();
+ assertEquals(chars,"longvarcharvalue");
+ }
+
+ //
+ // test fixed length binary
+ //
+ public void testFixedLengthBinary() throws Exception {
+ ResultsTestCtrl.Binary bin = testCtrl.getFixedLengthBinary();
+ assertEquals(bin.getBin()[0], -34);
+ }
+
+ //
+ // test variable length binary
+ //
+ public void testVariableLengthBinary() throws Exception {
+ ResultsTestCtrl.Binary bin = testCtrl.getVarLengthBinary();
+ assertEquals(bin.getVarbin()[0], -68);
+ }
+
+ //
+ // test long variable length binary
+ //
+ public void testLongBinary() throws Exception {
+ ResultsTestCtrl.Binary bin = testCtrl.getLongVarLengthBinary();
+ assertEquals(bin.getLvarbin()[0], -86);
+ }
+
+ //
+ // test small int
+ //
+ public void testSmallInt() throws Exception {
+ short smallInt = testCtrl.getSmallIntValue();
+ assertEquals(32767, smallInt);
+ }
+
+ //
+ // test small int
+ //
+ public void testSmallInt2() throws Exception {
+ Short smallInt = testCtrl.getSmallIntValue2();
+ assertEquals(32767, smallInt.shortValue());
+ }
+
+
+ //
+ // test int
+ //
+ public void testInt() throws Exception {
+ int i = testCtrl.getIntValue();
+ assertEquals(2147483647, i);
+ }
+
+ //
+ // test int
+ //
+ public void testInt2() throws Exception {
+ Integer i = testCtrl.getIntValue2();
+ assertEquals(2147483647, i.intValue());
+ }
+
+ //
+ // test big int
+ //
+ public void testBigInt() throws Exception {
+ long i = testCtrl.getBigIntValue();
+ assertEquals(9223372036854775807L, i);
+ }
+
+ //
+ // test big int
+ //
+ public void testBigInt2() throws Exception {
+ Long i = testCtrl.getBigIntValue2();
+ assertEquals(9223372036854775807L, i.longValue());
+ }
+
+ //
+ // test real
+ //
+ public void testReal() throws Exception {
+ float f = testCtrl.getRealValue();
+ assertEquals(3.402E+38f, f);
+ }
+
+ //
+ // test real
+ //
+ public void testReal2() throws Exception {
+ Float f = testCtrl.getRealValue2();
+ assertEquals(3.402E+38f, f.floatValue());
+ }
+
+ //
+ // test double precision
+ //
+ public void testDoublePrecision() throws Exception {
+ double d = testCtrl.getDoubleValue();
+ assertEquals(1.79769E+308, d);
+ }
+
+ //
+ // test double precision
+ //
+ public void testDoublePrecision2() throws Exception {
+ Double d = testCtrl.getDoubleValue2();
+ assertEquals(1.79769E+308, d.doubleValue());
+ }
+
+ //
+ // test decimal
+ //
+ public void testDecimal() throws Exception {
+ BigDecimal d = testCtrl.getDecimalValue();
+ assertEquals(123.0, d.doubleValue());
+ }
+
+ //
+ // test numeric
+ //
+ public void testNumeric() throws Exception {
+ BigDecimal d = testCtrl.getNumericValue();
+ assertEquals(123.0, d.doubleValue());
+ }
+
+ //
+ // test date
+ //
+ public void testDate() throws Exception {
+ Date d = testCtrl.getDateValue();
+ assertEquals("Wed Feb 23 00:00:00 MST 2005", d.toString());
+ }
+
+ //
+ // test time
+ //
+ public void testTime() throws Exception {
+ Time t = testCtrl.getTimeValue();
+ assertEquals("09:45:13", t.toString());
+ }
+
+ //
+ // test timestamp
+ //
+ public void testTimestamp() throws Exception {
+ Date d = testCtrl.getTimestampValue();
+ assertEquals("Wed Feb 23 09:46:17 MST 2005", d.toString());
+ }
+
+ public void testBlob() throws Exception {
+
+ assertNotNull(testCtrl);
+
+ //
+ // attempt to insert a blob value
+ //
+ Blob myBlob = new SerialBlob(new byte[] {1,2,3});
+ int result = testCtrl.insertABlob(123, myBlob);
+ assertEquals(result,1);
+
+ //
+ // retrieve the blob value just inserted and validate
+ //
+ ResultsTestCtrl.BlobInfo b = testCtrl.getABlob(123);
+ assertNotNull(b);
+ byte[] check = b.getBlb().getBytes(1,3);
+ assertEquals(check[0], 1);
+ }
+
+ public void testClob() throws Exception {
+
+ assertNotNull(testCtrl);
+
+ //
+ // get a clob and validate
+ //
+ Clob c = testCtrl.getAClob(1234);
+ assertNotNull(c);
+ assertEquals(c.getSubString(1,3), "thi");
+ }
+
+ public JdbcTypesTest(String name) throws Exception { super(name); }
+
+ public static Test suite() { return new TestSuite(JdbcTypesTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/StoredProcsDBResultsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/StoredProcsDBResultsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/StoredProcsDBResultsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/StoredProcsDBResultsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.Types;
+
+/**
+ * Unit tests for stored procedures
+ */
+public class StoredProcsDBResultsTest extends TestCase {
+ private static final Logger _logger = Logger.getLogger(StoredProcsDBResultsTest.class);
+
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public ResultsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName="java:/comp/env/jdbc/TestDB")
+ private ResultsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+// BasicConfigurator.configure();
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ StoredProcsDBResultsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ Connection conn = testCtrl.getConnection();
+
+ // setup the database
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("DROP TABLE PRODUCTS");
+ s.executeUpdate("DROP PROCEDURE getExpensiveProductsSP");
+ s.executeUpdate("DROP PROCEDURE getExpensiveProductSP");
+ s.executeUpdate("DROP PROCEDURE getProductsByColorSP");
+ s.executeUpdate("DROP PROCEDURE getProductSP");
+ } catch (Exception e) {}
+
+ s.executeUpdate("CREATE TABLE PRODUCTS (SKU INT, PRODUCT_NAME VARCHAR(128), PRICE FLOAT, COLOR VARCHAR(64))");
+ s.executeUpdate("INSERT INTO PRODUCTS VALUES (112233, 'Widget 1', 99.99, 'red')");
+ s.executeUpdate("INSERT INTO PRODUCTS VALUES (445566, 'Widget 2', 66.66, 'green')");
+ s.executeUpdate("INSERT INTO PRODUCTS VALUES (778899, 'Widget 3', 121.22, 'blue')");
+ s.executeUpdate("INSERT INTO PRODUCTS VALUES (2357, 'Widget 4', 1099.99, 'red')");
+
+ s.executeUpdate("CREATE PROCEDURE getExpensiveProductsSP(OUT productNames VARCHAR(128)) " +
+ "PARAMETER STYLE JAVA " +
+ "READS SQL DATA " +
+ "LANGUAGE JAVA " +
+ "EXTERNAL NAME 'org.apache.beehive.controls.system.jdbc.units.utils.StoredProcedures.getExpensiveProductsSP'");
+
+ s.executeUpdate("CREATE PROCEDURE getExpensiveProductSP(OUT productName VARCHAR(128)) " +
+ "PARAMETER STYLE JAVA " +
+ "READS SQL DATA " +
+ "LANGUAGE JAVA " +
+ "EXTERNAL NAME 'org.apache.beehive.controls.system.jdbc.units.utils.StoredProcedures.getExpensiveProductSP'");
+
+ s.executeUpdate("CREATE PROCEDURE getProductsByColorSP(IN color VARCHAR(64), OUT productNames VARCHAR(128)) " +
+ "PARAMETER STYLE JAVA " +
+ "READS SQL DATA " +
+ "LANGUAGE JAVA " +
+ "EXTERNAL NAME 'org.apache.beehive.controls.system.jdbc.units.utils.StoredProcedures.getProductsByColorSP'");
+ s.close();
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+
+ //
+ // simple sp which does not do a database query in the sp
+ //
+ public void testSimpleSP() throws Exception {
+
+ assertNotNull(testCtrl);
+
+ JdbcControl.SQLParameter[] params = new JdbcControl.SQLParameter[1];
+ params[0] = new JdbcControl.SQLParameter(new String(), Types.VARCHAR, JdbcControl.SQLParameter.OUT);
+ testCtrl.getExpensiveProduct(params);
+ assertEquals(params[0].value, "foo");
+ }
+
+ //
+ // sp which does a database query
+ //
+ public void testSP() throws Exception {
+ assertNotNull(testCtrl);
+
+ JdbcControl.SQLParameter[] params = new JdbcControl.SQLParameter[1];
+ params[0] = new JdbcControl.SQLParameter(new String[8], Types.VARCHAR, JdbcControl.SQLParameter.OUT);
+ testCtrl.getExpensiveProducts(params);
+ assertEquals(params[0].value, "Widget 4");
+ }
+
+ //
+ // sp which does a database query and uses IN and OUT params
+ //
+ public void testSPOutParams() throws Exception {
+ assertNotNull(testCtrl);
+
+ JdbcControl.SQLParameter[] params = new JdbcControl.SQLParameter[2];
+ params[0] = new JdbcControl.SQLParameter("red", Types.VARCHAR, JdbcControl.SQLParameter.IN);
+ params[1] = new JdbcControl.SQLParameter(new String[8], Types.VARCHAR, JdbcControl.SQLParameter.OUT);
+ testCtrl.getProductsByColor(params);
+ assertEquals(params[1].value, "Widget 1,Widget 4,");
+ }
+
+ //
+ // create a stored proc with the dbControl then run it -- only contains IN parameters
+ //
+ public void testSPGeneration() throws Exception {
+ assertNotNull(testCtrl);
+
+ testCtrl.createStoredProc();
+ testCtrl.getProduct("red", 1234);
+ }
+
+ public StoredProcsDBResultsTest(String name) throws Exception {
+ super(name);
+
+ }
+
+ public static Test suite() { return new TestSuite(StoredProcsDBResultsTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/TxResultsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/TxResultsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/TxResultsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/TxResultsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.test.results.TxTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+import test.customerDb.XStoogeRowDocument;
+import test.customerDb.SMLXSizeType;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+
+/**
+ * Transaction tests -- sanity check for db tx support
+ */
+public class TxResultsTest extends TestCase {
+
+ private static final Logger _logger = Logger.getLogger(TxResultsTest.class);
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public TxTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName = "java:/comp/env/jdbc/TestDB")
+ private TxTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ TxResultsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ Connection conn = testCtrl.getConnection();
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("drop table TX_USERS");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("create table TX_USERS (STOOGE_NAME varchar(32), STOOGE_PECKINGORDER int, STOOGE_PANTSIZE varchar(16))");
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test transaction
+ //
+ public void testTxSupport() throws Exception {
+
+ Connection con = testCtrl.getConnection();
+ con.setAutoCommit(false);
+ testCtrl.insertUserRow("moe", 1, "small");
+ con.commit();
+ }
+
+ //
+ // test test transaction commit
+ //
+ public void testTxCommit() throws Exception {
+
+ Connection con = testCtrl.getConnection();
+ con.setAutoCommit(false);
+ testCtrl.insertUserRow("larry", 1, "small");
+ testCtrl.insertUserRow("shemp", 1, "small");
+ con.commit();
+ }
+
+ //
+ // test test transaction rollback
+ //
+ public void testTxRollback() throws Exception {
+
+ Connection con = testCtrl.getConnection();
+ con.setAutoCommit(false);
+ assertFalse(con.getAutoCommit());
+ testCtrl.insertUserRow("curley", 1, "small");
+ con.rollback();
+
+ String nm = testCtrl.getAUser("curley");
+ System.out.println("MN IS : x"+nm);
+ assertNull(nm);
+ con.commit();
+ }
+
+
+ public TxResultsTest(String name) throws Exception {
+ super(name);
+ }
+
+ public static Test suite() { return new TestSuite(TxResultsTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+
Added: incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/XmlBeanResultsTest.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/XmlBeanResultsTest.java?rev=169351&view=auto
==============================================================================
--- incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/XmlBeanResultsTest.java (added)
+++ incubator/beehive/trunk/system-controls/test/src/jdbc/junitTests/org/apache/beehive/controls/system/jdbc/units/results/XmlBeanResultsTest.java Mon May 9 13:17:58 2005
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+package org.apache.beehive.controls.system.jdbc.units.results;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.context.ControlContainerContext;
+import org.apache.beehive.controls.api.context.ControlThreadContext;
+import org.apache.log4j.Logger;
+import org.apache.beehive.controls.system.jdbc.JdbcControl;
+import org.apache.beehive.controls.system.jdbc.test.results.ResultsTestCtrl;
+import org.apache.beehive.controls.system.jdbc.units.utils.TestContextInitializer;
+import test.customerDb.XStoogeRowDocument;
+import test.customerDb.SMLXSizeType;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+/**
+ *
+ */
+public class XmlBeanResultsTest extends TestCase {
+
+ private static final Logger _logger = Logger.getLogger(XmlBeanResultsTest.class);
+ private ControlContainerContext _controlContext = null;
+
+ @Control
+ public ResultsTestCtrl testCtrl;
+
+ @Control
+ @JdbcControl.ConnectionDataSource(jndiName = "java:/comp/env/jdbc/TestDB")
+ private ResultsTestCtrl testCtrl_ds;
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+
+ _controlContext = ControlThreadContext.getContext();
+ if (_controlContext == null) {
+ _controlContext = TestContextInitializer.initContext(this);
+ } else {
+ XmlBeanResultsTestClientInitializer.initialize(_controlContext, this);
+ testCtrl = testCtrl_ds;
+ }
+
+ Connection conn = testCtrl.getConnection();
+ Statement s = conn.createStatement();
+ try {
+ s.executeUpdate("drop table XBEAN_USERS");
+ } catch (Exception e) {
+ }
+
+ s.executeUpdate("create table XBEAN_USERS (STOOGE_NAME varchar(32), STOOGE_PECKINGORDER int, STOOGE_PANTSIZE varchar(16))");
+ s.executeUpdate("insert into XBEAN_USERS values ('larry', 3, 'small')");
+ s.executeUpdate("insert into XBEAN_USERS values ('moe', 1, 'medium')");
+ s.executeUpdate("insert into XBEAN_USERS values ('curley', 2, 'xlarge')");
+ s.executeUpdate("insert into XBEAN_USERS values ('shemp', 4, 'large')");
+ conn = null;
+ }
+
+ public void tearDown() throws Exception {
+ _controlContext.endContext();
+ super.tearDown();
+ }
+
+ //
+ // test XmlBean return type
+ //
+ public void testXmlBeanReturnType() throws Exception {
+
+ XStoogeRowDocument.XStoogeRow customerXmlObj = testCtrl.getAUserXmlBean("moe");
+ assertNotNull(customerXmlObj);
+
+ assertEquals(1, customerXmlObj.getSTOOGEPECKINGORDER());
+ assertEquals("moe", customerXmlObj.getSTOOGENAME());
+ assertEquals("medium", customerXmlObj.getSTOOGEPANTSIZE().toString());
+ }
+
+ //
+ // test XmlBean array return type
+ //
+ public void testXmlBeanArrayReturnType() throws Exception {
+
+ XStoogeRowDocument.XStoogeRow[] customersXml = testCtrl.getAllUserXmlBean();
+ assertNotNull(customersXml);
+
+ assertEquals(customersXml.length, 4);
+ assertEquals("larry", customersXml[0].getSTOOGENAME());
+ assertEquals(3, customersXml[0].getSTOOGEPECKINGORDER());
+ assertEquals("small", customersXml[0].getSTOOGEPANTSIZE().toString());
+
+ assertEquals("moe", customersXml[1].getSTOOGENAME());
+ assertEquals(1, customersXml[1].getSTOOGEPECKINGORDER());
+ assertEquals("medium", customersXml[1].getSTOOGEPANTSIZE().toString());
+
+ assertEquals("curley", customersXml[2].getSTOOGENAME());
+ assertEquals(2, customersXml[2].getSTOOGEPECKINGORDER());
+ assertEquals("xlarge", customersXml[2].getSTOOGEPANTSIZE().toString());
+
+ assertEquals("shemp", customersXml[3].getSTOOGENAME());
+ assertEquals(4, customersXml[3].getSTOOGEPECKINGORDER());
+ assertEquals("large", customersXml[3].getSTOOGEPANTSIZE().toString());
+ }
+
+ //
+ // insert an xmlbean
+ //
+ public void testInsertXmlBean() throws Exception {
+ XStoogeRowDocument.XStoogeRow stooge = XStoogeRowDocument.XStoogeRow.Factory.newInstance();
+ assertNotNull(stooge);
+ stooge.setSTOOGENAME("fred");
+ stooge.setSTOOGEPECKINGORDER(9);
+ stooge.setSTOOGEPANTSIZE(SMLXSizeType.Enum.forString("small"));
+ testCtrl.insertAXmlBean(stooge);
+
+ XStoogeRowDocument.XStoogeRow res = testCtrl.getAUserXmlBean("fred");
+ assertEquals(9, res.getSTOOGEPECKINGORDER());
+ assertEquals("fred", res.getSTOOGENAME());
+ assertEquals("small", res.getSTOOGEPANTSIZE().toString());
+ }
+
+ public XmlBeanResultsTest(String name) throws Exception {
+ super(name);
+ }
+
+ public static Test suite() { return new TestSuite(XmlBeanResultsTest.class); }
+
+ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }
+}
+