From agila-commits-return-56-apmail-incubator-agila-commits-archive=www.apache.org@incubator.apache.org Sun Aug 14 11:11:41 2005 Return-Path: Delivered-To: apmail-incubator-agila-commits-archive@www.apache.org Received: (qmail 95140 invoked from network); 14 Aug 2005 11:11:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Aug 2005 11:11:41 -0000 Received: (qmail 73721 invoked by uid 500); 14 Aug 2005 11:11:41 -0000 Mailing-List: contact agila-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: agila-dev@incubator.apache.org Delivered-To: mailing list agila-commits@incubator.apache.org Received: (qmail 73708 invoked by uid 99); 14 Aug 2005 11:11:41 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 14 Aug 2005 04:11:40 -0700 Received: (qmail 95136 invoked by uid 65534); 14 Aug 2005 11:11:40 -0000 Message-ID: <20050814111140.95134.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r232595 - in /incubator/agila/trunk/modules/bpm/src: java/org/apache/agila/dao/ java/org/apache/agila/dao/jdbc/ test/org/apache/agila/dao/jdbc/ Date: Sun, 14 Aug 2005 11:11:39 -0000 To: agila-commits@incubator.apache.org From: clim@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: clim Date: Sun Aug 14 04:11:13 2005 New Revision: 232595 URL: http://svn.apache.org/viewcvs?rev=232595&view=rev Log: * Added Instance DAO * Refactored test cases Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java (with props) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java (with props) incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java (with props) incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java (with props) Modified: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java (props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java (contents, props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java (props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java (props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java (props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java (props changed) incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java (props changed) incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java (contents, props changed) incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java (props changed) Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java?rev=232595&r1=232594&r2=232595&view=diff ============================================================================== --- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java (original) +++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java Sun Aug 14 04:11:13 2005 @@ -20,6 +20,7 @@ import org.apache.agila.engine.InstanceID; import org.apache.agila.model.BusinessProcessID; import org.apache.agila.services.InstanceServiceInfo; +import org.apache.agila.dao.jdbc.InstanceException; import java.util.Map; import java.util.List; @@ -29,14 +30,14 @@ */ public interface InstanceDAO { - Instance newInstance( BusinessProcessID processID, Map params); + Instance newInstance( BusinessProcessID processID, Map params) throws InstanceException; - void saveInstance(Instance instance); + void saveInstance(Instance instance) throws InstanceException; - Instance getInstanceByID( InstanceID id); + Instance getInstanceByID( InstanceID id) throws InstanceException; - List listInstanceInfo(); + List listInstanceInfo() throws InstanceException; - InstanceServiceInfo getInstanceServiceInfo(); + InstanceServiceInfo getInstanceServiceInfo() throws InstanceException; } Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java?rev=232595&view=auto ============================================================================== --- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java (added) +++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java Sun Aug 14 04:11:13 2005 @@ -0,0 +1,426 @@ +/* + * Copyright 2004 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. + */ + +package org.apache.agila.dao.jdbc; + +import javax.sql.DataSource; +import java.util.Map; +import java.util.List; +import java.util.ArrayList; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.ResultSet; +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ByteArrayInputStream; + +import org.apache.agila.dao.InstanceDAO; +import org.apache.agila.dao.BusinessProcessDAO; +import org.apache.agila.engine.Instance; +import org.apache.agila.engine.InstanceID; +import org.apache.agila.model.BusinessProcessID; +import org.apache.agila.model.BusinessProcess; +import org.apache.agila.services.InstanceServiceInfo; +import org.apache.agila.services.InstanceInfo; +import org.apache.agila.impl.InstanceImpl; + +/** + * $Id$ + */ +public class InstanceDAOJdbc implements InstanceDAO { + + private BusinessProcessDAO businessProcessDAO; + private DataSource dataSource; + + public Instance newInstance( BusinessProcessID processID, Map params ) throws InstanceException { + + Instance retVal = null; + Connection connection = null; + + try { + + BusinessProcess businessProcess = businessProcessDAO.getGraphByID( processID ); + + String sql = "insert into bpm_instance" + + " ( instanceid, processid, graphname, params, status )" + + " values ( ?, ?, ?, ?, ? )"; + + int instanceID = generateKey(); + + connection = dataSource.getConnection(); + + PreparedStatement preparedStatement = + connection.prepareStatement( sql ); + + preparedStatement.setInt( 1, instanceID ); + preparedStatement.setInt( 2, processID.getID() ); + preparedStatement.setString( 3, businessProcess.getName() ); + preparedStatement.setBytes( 4, serializeAppParam( params ) ); + preparedStatement.setInt( 5, Instance.STATUS_RUNNING ); + preparedStatement.execute(); + preparedStatement.close(); + + // Retrieve the created instance + retVal = getInstanceByID( new InstanceID( instanceID ) ); + + } catch ( SQLException e ) { + + throw new InstanceException( e ); + + } catch ( BusinessProcessException e ) { + + throw new InstanceException( e ); + + } finally { + + if ( connection != null ) { + try { + connection.close(); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + } + + return retVal; + + } + + public void saveInstance( Instance instance ) throws InstanceException { + + Connection connection = null; + + try { + + String sql = "update bpm_instance" + + " set params = ?, stepdate = ?, status = ?" + + " where instanceid = " + instance.getInstanceID().getID(); + + connection = dataSource.getConnection(); + + connection.setAutoCommit( false ); + + PreparedStatement statement = connection.prepareStatement( sql ); + statement.setBytes( 1, + serializeAppParam( instance.getInstanceVariables() ) ); + + if ( instance.getStartDate() != null ) { + statement.setDate( 2, new java.sql.Date( + instance.getStartDate().getTime() ) ); + } else { + statement.setDate( 2, null ); + } + + statement.setInt( 3, instance.getStatus() ); + + statement.execute(); + connection.commit(); + statement.close(); + + } catch ( SQLException e ) { + + throw new InstanceException( e ); + + } finally { + + if ( connection != null ) { + try { + connection.close(); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + } + + } + + public Instance getInstanceByID( InstanceID id ) throws InstanceException { + + InstanceImpl retVal = null; + + Connection connection = null; + + try { + + String sql = "select * from bpm_instance" + + " where instanceid = " + id.getID(); + + connection = dataSource.getConnection(); + Statement statement = connection.createStatement(); + ResultSet result = statement.executeQuery( sql ); + result.next(); + + retVal = new InstanceImpl(); + retVal.setInstanceID( new InstanceID( + result.getInt( "instanceid" ) ) ); + retVal.setBusinessProcessID( new BusinessProcessID( + result.getInt( "processid" ) ) ); + retVal.setGraphName( result.getString( "graphname" ) ); + retVal.setInstanceVariables( + deserializeAppParam( result.getBytes( "params" ) ) ); + retVal.setStartDate( result.getDate( "startdate" ) ); + retVal.setLastStepDate( result.getDate( "stepdate" ) ); + retVal.setStatus( result.getInt( "status" ) ); + + result.close(); + statement.close(); + + } catch ( SQLException e ) { + + throw new InstanceException( e ); + + } finally { + + if ( connection != null ) { + try { + connection.close(); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + } + + return retVal; + + } + + public List listInstanceInfo() throws InstanceException { + + List retVal = null; + + Connection connection = null; + + try { + + String sql = "select instanceid from bpm_instance"; + + connection = dataSource.getConnection(); + + Statement statement = connection.createStatement(); + ResultSet result = statement.executeQuery( sql ); + + retVal = new ArrayList(); + + while ( result.next() ) { + Instance instance = getInstanceByID( + new InstanceID( result.getInt( "instanceid" ) ) ); + + InstanceInfo ii = new InstanceInfo( instance ); + + retVal.add( ii ); + } + + result.close(); + statement.close(); + + } catch ( SQLException e ) { + + throw new InstanceException( e ); + + } finally { + + if ( connection != null ) { + try { + connection.close(); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + } + + return retVal; + + } + + public InstanceServiceInfo getInstanceServiceInfo() throws InstanceException { + + InstanceServiceInfo retVal = null; + + Connection connection = null; + + try { + + int stopped = 0; + int suspended = 0; + int running = 0; + int completed = 0; + + String sql = "select * from bpm_instance"; + + connection = dataSource.getConnection(); + + Statement statement = connection.createStatement(); + ResultSet result = statement.executeQuery( sql ); + + while ( result.next() ) { + int status = result.getInt( "status" ); + + switch ( status ) { + case Instance.STATUS_STOPPED: + stopped++; + break; + + case Instance.STATUS_SUSPENDED: + suspended++; + break; + + case Instance.STATUS_RUNNING: + running++; + break; + + case Instance.STATUS_COMPLETE: + completed++; + break; + } + } + + result.close(); + statement.close(); + + retVal = new InstanceServiceInfo( running, suspended, stopped, + completed ); + + } catch ( SQLException e ) { + + throw new InstanceException( e ); + + } finally { + + if ( connection != null ) { + try { + connection.close(); + } catch ( SQLException e ) { + e.printStackTrace(); + } + } + + } + + return retVal; + + } + + public void setBusinessProcess( BusinessProcessDAO businessProcessDAO ) { + this.businessProcessDAO = businessProcessDAO; + } + + public void setDataSource( DataSource dataSource ) { + this.dataSource = dataSource; + } + + private byte[] serializeAppParam( Map appParams ) { + + byte[] retVal = null; + + try { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream( byteStream ); + out.writeObject( appParams ); + out.close(); + retVal = byteStream.toByteArray(); + } catch( IOException e ) { + throw new RuntimeException( e ); + } + + return retVal; + + } + + private Map deserializeAppParam( byte[] appParam ) { + + Map retVal = null; + + try { + ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( appParam ) ); + retVal = (Map)in.readObject(); + } catch( IOException e ) { + throw new RuntimeException( e ); + } catch( ClassNotFoundException e ) { + throw new RuntimeException( e ); + } + + return retVal; + + } + + /** + * Generates a unique key + */ + public int generateKey() { + int retVal = 0; + + Connection connection = null; + + try { + + connection = dataSource.getConnection(); + connection.setAutoCommit(false); + + // Remove previous value + String sql = "delete from bpm_unique_key"; + Statement statement = connection.createStatement(); + statement.execute( sql ); + connection.commit(); + statement.close(); + + // Insert new value + sql = "insert into bpm_unique_key ( tstamp ) values ( ? )"; + PreparedStatement preparedStatement = + connection.prepareStatement( sql ); + + preparedStatement.setDate( 1, new java.sql.Date( + new java.util.Date().getTime() ) ); + + preparedStatement.execute(); + connection.commit(); + preparedStatement.close(); + + // Retrieve new key + sql = "select * from bpm_unique_key"; + statement = connection.createStatement(); + ResultSet result = statement.executeQuery( sql ); + result.next(); + retVal = result.getInt( "next_hi" ); + + result.close(); + statement.close(); + } catch( SQLException e ) { + e.printStackTrace(); + } + finally { + if (connection != null) { + try { + connection.close(); + } + catch (SQLException e) { + e.printStackTrace(); + } + } + } + + return retVal; + } + +} Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceDAOJdbc.java ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java?rev=232595&view=auto ============================================================================== --- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java (added) +++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java Sun Aug 14 04:11:13 2005 @@ -0,0 +1,36 @@ +/* + * Copyright 2004 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. + */ + +package org.apache.agila.dao.jdbc; + +/** + * $Id$ + */ +public class InstanceException extends Exception { + + public InstanceException( String message ) { + super( message ); + } + + public InstanceException( Throwable cause ) { + super( cause ); + } + + public InstanceException( String message, Throwable cause ) { + super( message, cause ); + } + +} Propchange: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/InstanceException.java ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java?rev=232595&view=auto ============================================================================== --- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java (added) +++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java Sun Aug 14 04:11:13 2005 @@ -0,0 +1,80 @@ +/* + * Copyright 2004 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. + */ + +package org.apache.agila.dao.jdbc; + +import javax.sql.DataSource; +import java.util.Properties; +import java.io.InputStream; + +import junit.framework.TestCase; + +/** + * $Id$ + */ +public abstract class AbstractDAOTestSupport extends TestCase { + + protected DataSource dataSource; + + protected void setUp() throws Exception { + + Properties properties = getConnectionSetting(); + + dataSource = new MockDataSource( + properties.getProperty( "jdbc.url" ), + properties.getProperty( "jdbc.username" ), + properties.getProperty( "jdbc.password" ), + properties.getProperty( "jdbc.driver" ) ); + + onSetup(); + + } + + protected void tearDown() throws Exception { + + onTearDown(); + + } + + protected abstract void onSetup() throws Exception; + + protected abstract void onTearDown() throws Exception; + + + private Properties getConnectionSetting() throws Exception { + + Properties properties; + + try { + + InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream( "jdbc.properties" ); + if ( input == null ) { + input = getClass().getClassLoader().getResourceAsStream( "jdbc.properties" ); + } + + properties = new Properties(); + properties.load( input ); + + } catch ( Exception e ) { + + throw e; + + } + + return properties; + } + +} Propchange: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/AbstractDAOTestSupport.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java?rev=232595&r1=232594&r2=232595&view=diff ============================================================================== --- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java (original) +++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java Sun Aug 14 04:11:13 2005 @@ -17,36 +17,29 @@ package org.apache.agila.dao.jdbc; import javax.sql.DataSource; -import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.Reader; -import java.util.Properties; -import java.util.List; -import java.sql.Statement; import java.sql.Connection; import java.sql.SQLException; +import java.sql.Statement; +import java.util.List; -import junit.framework.TestCase; -import org.apache.agila.model.BusinessProcessID; import org.apache.agila.model.BusinessProcess; -import org.apache.agila.util.XMLUtil; +import org.apache.agila.model.BusinessProcessID; import org.apache.agila.util.DBHelper; +import org.apache.agila.util.XMLUtil; /** * $Id$ */ -public class BusinessProcessDAOJdbcTest extends TestCase { +public class BusinessProcessDAOJdbcTest extends AbstractDAOTestSupport { private BusinessProcessDAOJdbc businessProcessDAO; - private MockDataSource dataSource; + private BusinessProcess businessProcess; public void testAddGraph() throws BusinessProcessException { - Reader reader = new InputStreamReader( - getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) ); - BusinessProcess businessProcess = XMLUtil.deserializeXML( reader ); - BusinessProcessID businessProcessID = businessProcessDAO.addGraph( businessProcess ); assertNotNull( businessProcessID ); @@ -55,10 +48,6 @@ public void testGetGraphyByID() throws BusinessProcessException { - Reader reader = new InputStreamReader( - getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) ); - BusinessProcess businessProcess = XMLUtil.deserializeXML( reader ); - BusinessProcessID businessProcessID = businessProcessDAO.addGraph( businessProcess ); @@ -89,10 +78,6 @@ public void testGetGraphIDByName() throws BusinessProcessException { - Reader reader = new BufferedReader( new InputStreamReader( - getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) ) ); - BusinessProcess businessProcess = XMLUtil.deserializeXML( reader ); - BusinessProcessID businessProcessID = businessProcessDAO.addGraph( businessProcess ); @@ -101,15 +86,11 @@ } - protected void setUp() throws Exception { - - Properties properties = getConnectionSetting(); + protected void onSetup() throws Exception { - dataSource = new MockDataSource( - properties.getProperty( "jdbc.url" ), - properties.getProperty( "jdbc.username" ), - properties.getProperty( "jdbc.password" ), - properties.getProperty( "jdbc.driver" ) ); + Reader reader = new InputStreamReader( + getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) ); + businessProcess = XMLUtil.deserializeXML( reader ); initializeDBTables( dataSource ); @@ -118,7 +99,7 @@ } - protected void tearDown() throws Exception { + protected void onTearDown() throws Exception { Connection connection = dataSource.getConnection(); connection.createStatement().execute( "SHUTDOWN" ); @@ -143,26 +124,4 @@ } - private Properties getConnectionSetting() throws Exception { - - Properties properties; - - try { - - InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream( "jdbc.properties" ); - if ( input == null ) { - input = getClass().getClassLoader().getResourceAsStream( "jdbc.properties" ); - } - - properties = new Properties(); - properties.load( input ); - - } catch ( Exception e ) { - - throw e; - - } - - return properties; - } } Propchange: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java?rev=232595&view=auto ============================================================================== --- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java (added) +++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java Sun Aug 14 04:11:13 2005 @@ -0,0 +1,146 @@ +/* + * Copyright 2004 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. + */ + +package org.apache.agila.dao.jdbc; + +import javax.sql.DataSource; +import java.io.InputStreamReader; +import java.io.Reader; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.agila.engine.Instance; +import org.apache.agila.model.BusinessProcess; +import org.apache.agila.model.BusinessProcessID; +import org.apache.agila.services.InstanceServiceInfo; +import org.apache.agila.util.DBHelper; +import org.apache.agila.util.XMLUtil; + +/** + * $Id$ + */ +public class InstanceDAOJdbcTest extends AbstractDAOTestSupport { + + private BusinessProcessDAOJdbc businessProcessDAO; + private InstanceDAOJdbc instanceDAO; + private BusinessProcess businessProcess; + + public void testNewInstance() throws BusinessProcessException, InstanceException { + + BusinessProcessID businessProcessID = businessProcessDAO.addGraph( + businessProcess ); + + Map appParams = new HashMap(); + appParams.put( "numdays", "40" ); + appParams.put( "reason", "Expedition to Mount Everest" ); + + Instance instance = instanceDAO.newInstance( businessProcessID, appParams ); + assertNotNull( instance ); + + } + + public void testSaveInstance() throws BusinessProcessException, InstanceException { + + BusinessProcessID businessProcessID = businessProcessDAO.addGraph( + businessProcess ); + + Map appParams = new HashMap(); + appParams.put( "numdays", "40" ); + appParams.put( "reason", "Expedition to Mount Everest" ); + Instance instance = instanceDAO.newInstance( businessProcessID, appParams ); + + instance.setStatus( Instance.STATUS_SUSPENDED ); + instanceDAO.saveInstance( instance ); + + Instance retrievedInstance = instanceDAO.getInstanceByID( instance.getInstanceID() ); + + assertEquals( instance.getInstanceID(), retrievedInstance.getInstanceID() ); + assertEquals( instance.getBusinessProcessID(), retrievedInstance.getBusinessProcessID() ); + assertEquals( instance.getGraphName(), retrievedInstance.getGraphName() ); + assertEquals( Instance.STATUS_SUSPENDED, retrievedInstance.getStatus() ); + assertEquals( instance.getStartDate(), retrievedInstance.getStartDate() ); + assertEquals( instance.getLastStepDate(), retrievedInstance.getLastStepDate() ); + + } + + public void testGetInstanceByID() { + + // TODO: Add test case + + } + + public void testListInstanceInfo() throws InstanceException { + + List instances = instanceDAO.listInstanceInfo(); + assertNotNull( "instances should not be null", instances ); + + } + + public void testGetInstanceServiceInfo() throws InstanceException { + + InstanceServiceInfo instanceServiceInfo = instanceDAO.getInstanceServiceInfo(); + + assertNotNull( "InstanceServiceInfo should not be null", instanceServiceInfo ); + + } + + protected void onSetup() throws Exception { + + Reader reader = new InputStreamReader( + getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) ); + businessProcess = XMLUtil.deserializeXML( reader ); + + initializeDBTables( dataSource ); + + businessProcessDAO = new BusinessProcessDAOJdbc(); + businessProcessDAO.setDataSource( dataSource ); + + instanceDAO = new InstanceDAOJdbc(); + instanceDAO.setBusinessProcess( businessProcessDAO ); + instanceDAO.setDataSource( dataSource ); + + } + + protected void onTearDown() throws Exception { + + Connection connection = dataSource.getConnection(); + connection.createStatement().execute( "SHUTDOWN" ); + + } + + private void initializeDBTables( DataSource dataSource ) throws SQLException { + + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement(); + + statement.addBatch( DBHelper.businessProcess ); + statement.addBatch( DBHelper.instance ); + statement.addBatch( DBHelper.task ); + statement.addBatch( DBHelper.token ); + statement.addBatch( DBHelper.uniqueKey ); + statement.addBatch( DBHelper.userInfo ); + + statement.executeBatch(); + + connection.close(); + + } + +} Propchange: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/InstanceDAOJdbcTest.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java ------------------------------------------------------------------------------ svn:keywords = Id