incubator-agila-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r232593 - in /incubator/agila/trunk/modules/bpm/src: java/org/apache/agila/dao/ java/org/apache/agila/dao/jdbc/ test/org/apache/agila/dao/ test/org/apache/agila/dao/jdbc/
Date Sun, 14 Aug 2005 08:29:29 GMT
Author: clim
Date: Sun Aug 14 01:29:14 2005
New Revision: 232593

URL: http://svn.apache.org/viewcvs?rev=232593&view=rev
Log:
Refactored Business Process to have its own DAO.

Added:
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java
    incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java
    incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/BusinessProcessDAO.java
Sun Aug 14 01:29:14 2005
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.apache.agila.model.BusinessProcessID;
+import org.apache.agila.model.BusinessProcess;
+import org.apache.agila.dao.jdbc.BusinessProcessException;
+
+import java.util.List;
+
+/**
+ * $Id$
+ */
+public interface BusinessProcessDAO {
+
+    BusinessProcessID addGraph( BusinessProcess graph) throws BusinessProcessException;
+
+    BusinessProcess getGraphByID(BusinessProcessID id) throws BusinessProcessException;
+
+    List getAllProcessGraphs() throws BusinessProcessException;
+
+    BusinessProcessID getGraphIDByName(String name) throws BusinessProcessException;
+
+}

Added: 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=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java (added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/InstanceDAO.java Sun Aug
14 01:29:14 2005
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import org.apache.agila.engine.Instance;
+import org.apache.agila.engine.InstanceID;
+import org.apache.agila.model.BusinessProcessID;
+import org.apache.agila.services.InstanceServiceInfo;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * $Id$
+ */
+public interface InstanceDAO {
+
+    Instance newInstance( BusinessProcessID processID, Map params);
+
+    void saveInstance(Instance instance);
+
+    Instance getInstanceByID( InstanceID id);
+
+    List listInstanceInfo();
+
+    InstanceServiceInfo getInstanceServiceInfo();
+
+}

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java (added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TaskDAO.java Sun Aug 14
01:29:14 2005
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import org.apache.agila.services.task.TaskID;
+import org.apache.agila.services.task.Task;
+import org.apache.agila.services.user.UserID;
+import org.apache.agila.services.user.GroupID;
+import org.apache.agila.engine.InstanceID;
+
+import java.util.List;
+
+/**
+ * $Id$
+ */
+public interface TaskDAO {
+
+    TaskID updateTask( Task task);
+
+    TaskID insertTask(Task task);
+
+    List getTasksForUser( UserID userID, int status);
+
+    List getTasksForGroups( GroupID[] teamIDs, int status);
+
+    List getTasksForInstance( InstanceID instanceID, int status );
+
+    Task getTaskByID(TaskID taskID);
+
+    boolean lockTaskForUser(TaskID taskID, UserID userID);
+
+    void unlockTaskForUser(TaskID taskID, UserID userID);
+
+    int setTaskStatusForInstance(InstanceID instanceID, int oldStatus, int newStatus);
+
+}

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java (added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/TokenDAO.java Sun Aug
14 01:29:14 2005
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.apache.agila.engine.InstanceID;
+import org.apache.agila.engine.Token;
+import org.apache.agila.engine.TokenID;
+import org.apache.agila.model.NodeID;
+
+import java.util.List;
+
+/**
+ * $Id$
+ */
+public interface TokenDAO {
+
+    List getActiveTokensForInstance( InstanceID instanceID);
+
+    boolean saveToken( Token t);
+
+    Token newToken(InstanceID instanceID, NodeID nodeID, int state);
+
+    Token getTokenByID( TokenID tokenID);
+
+}

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java (added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/UserDAO.java Sun Aug 14
01:29:14 2005
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.apache.agila.services.user.UserInfo;
+import org.apache.agila.services.user.UserID;
+
+import java.util.List;
+
+/**
+ * $Id$
+ */
+public interface UserDAO {
+
+    UserInfo getUserFromPrincipal(String principalName);
+
+    UserInfo getUserInfo( UserID id);
+
+    UserID addUser(UserInfo newUser);
+
+    List listAllUserInfo();
+
+    void saveUser(UserInfo info);
+
+}

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbc.java
Sun Aug 14 01:29:14 2005
@@ -0,0 +1,278 @@
+/*
+ * 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.StringReader;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.agila.dao.BusinessProcessDAO;
+import org.apache.agila.impl.BusinessProcessImpl;
+import org.apache.agila.model.BusinessProcess;
+import org.apache.agila.model.BusinessProcessID;
+import org.apache.agila.util.XMLUtil;
+
+/**
+ * $Id$
+ */
+public class BusinessProcessDAOJdbc implements BusinessProcessDAO {
+
+    private DataSource dataSource;
+
+    public BusinessProcessID addGraph( BusinessProcess graph ) throws BusinessProcessException
{
+
+        BusinessProcessID retVal = null;
+        Connection connection = null;
+
+        try {
+
+            connection = dataSource.getConnection();
+
+            String sql = "insert into bpm_businessprocess" +
+                " ( businessprocessid, name, xml ) values ( ?, ?, ? )";
+
+            int businessProcessID = generateKey();
+
+            PreparedStatement statement = connection.prepareStatement( sql );
+            statement.setInt( 1, businessProcessID );
+            statement.setString( 2, graph.getName() );
+            statement.setString( 3, graph.getGraphAsXML() );
+            statement.execute();
+            statement.close();
+
+            retVal = new BusinessProcessID( businessProcessID );
+
+        } catch ( SQLException e ) {
+
+            throw new BusinessProcessException( e );
+
+        } finally {
+
+            if ( connection != null ) {
+                try {
+                    connection.close();
+                } catch ( SQLException e ) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+        return retVal;
+
+    }
+
+    public BusinessProcess getGraphByID( BusinessProcessID businessProcessID ) throws BusinessProcessException
{
+
+        BusinessProcessImpl retVal = null;
+
+        Connection connection = null;
+
+        try {
+
+            String sql = "select businessprocessid, xml" +
+                " from bpm_businessprocess" +
+                " where businessprocessid = " + businessProcessID.getID();
+
+            connection = dataSource.getConnection();
+
+            Statement statement = connection.createStatement();
+            ResultSet result = statement.executeQuery( sql );
+            result.next();
+
+            String xml = result.getString( "xml" );
+            retVal = (BusinessProcessImpl)XMLUtil.deserializeXML(
+                new StringReader( xml ) );
+            retVal.setBusinessProcessID( businessProcessID );
+
+            result.close();
+            statement.close();
+
+        } catch ( SQLException e ) {
+
+            throw new BusinessProcessException( e );
+
+        } finally {
+
+            if ( connection != null ) {
+                try {
+                    connection.close();
+                } catch ( SQLException e ) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+        return retVal;
+
+    }
+
+    public List getAllProcessGraphs() throws BusinessProcessException {
+
+        List retVal = new ArrayList();
+
+        Connection connection = null;
+
+        try {
+
+            String sql = "select businessprocessid from bpm_businessprocess";
+
+            connection = dataSource.getConnection();
+            Statement statement = connection.createStatement();
+            ResultSet result = statement.executeQuery( sql );
+
+            while ( result.next() ) {
+                retVal.add( getGraphByID( new BusinessProcessID(
+                    result.getInt( "businessprocessid" ) ) ) );
+            }
+
+            result.close();
+            statement.close();
+
+        } catch ( SQLException e ) {
+
+            throw new BusinessProcessException( e );
+
+        } finally {
+
+            if ( connection != null ) {
+                try {
+                    connection.close();
+                } catch ( SQLException e ) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+        return retVal;
+
+    }
+
+    public BusinessProcessID getGraphIDByName( String name ) throws BusinessProcessException
{
+
+        BusinessProcessID retVal = null;
+
+        Connection connection = null;
+
+        try {
+
+            String sql = "select businessprocessid, name" +
+                " from bpm_businessprocess" +
+                " where name = '" + name + "'";
+
+            connection = dataSource.getConnection();
+
+            Statement statement = connection.createStatement();
+            ResultSet result = statement.executeQuery( sql );
+            result.next();
+
+            int id = result.getInt( "businessprocessid" );
+            retVal = new BusinessProcessID( id );
+
+            result.close();
+            statement.close();
+
+        } catch ( SQLException e ) {
+
+            throw new BusinessProcessException( e );
+
+        } finally {
+
+            if ( connection != null ) {
+                try {
+                    connection.close();
+                } catch ( SQLException e ) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+        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;
+    }
+
+    public void setDataSource( DataSource dataSource ) {
+        this.dataSource = dataSource;
+    }
+}

Added: incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/java/org/apache/agila/dao/jdbc/BusinessProcessException.java
Sun Aug 14 01:29:14 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 BusinessProcessException extends Exception {
+
+    public BusinessProcessException( String message ) {
+        super( message );
+    }
+
+    public BusinessProcessException( Throwable cause ) {
+        super( cause );
+    }
+
+    public BusinessProcessException( String message, Throwable cause ) {
+        super( message, cause );
+    }
+
+}

Added: 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=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/BusinessProcessDAOJdbcTest.java
Sun Aug 14 01:29:14 2005
@@ -0,0 +1,168 @@
+/*
+ * 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.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 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.util.DBHelper;
+
+/**
+ * $Id$
+ */
+public class BusinessProcessDAOJdbcTest extends TestCase {
+
+    private BusinessProcessDAOJdbc businessProcessDAO;
+    private MockDataSource dataSource;
+
+    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 );
+
+    }
+
+    public void testGetGraphyByID() throws BusinessProcessException {
+
+        Reader reader = new InputStreamReader(
+            getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" ) );
+        BusinessProcess businessProcess = XMLUtil.deserializeXML( reader );
+
+        BusinessProcessID businessProcessID = businessProcessDAO.addGraph(
+            businessProcess );
+
+        BusinessProcess bpFromQuery = businessProcessDAO.getGraphByID( businessProcessID
);
+
+        assertEquals( businessProcessID, bpFromQuery.getBusinessProcessID() );
+        assertEquals( businessProcess.getName(), bpFromQuery.getName() );
+        assertEquals( businessProcess.getGraphAsXML(), bpFromQuery.getGraphAsXML() );
+
+    }
+
+    public void testGetAllProcessGraphs() throws BusinessProcessException {
+
+        // Populate the bpm_businessprocess table just in case it is empty
+        for ( int i = 0; i < 10; i++ ) {
+            BufferedReader reader = new BufferedReader( new InputStreamReader(
+                getClass().getClassLoader().getResourceAsStream( "LeaveApplication.xml" )
) );
+            BusinessProcess businessProcess = XMLUtil.deserializeXML( reader );
+
+            businessProcessDAO.addGraph( businessProcess );
+        }
+
+        List graphs = businessProcessDAO.getAllProcessGraphs();
+
+        assertTrue( graphs.size() >= 10 );
+
+    }
+
+    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 );
+
+        assertEquals( businessProcessID, businessProcessDAO.getGraphIDByName(
+            businessProcess.getName() ) );
+
+    }
+
+    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" ) );
+
+        initializeDBTables( dataSource );
+
+        businessProcessDAO = new BusinessProcessDAOJdbc();
+        businessProcessDAO.setDataSource( dataSource );
+
+    }
+
+    protected void tearDown() 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();
+
+    }
+
+    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;
+    }
+}

Added: incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java
URL: http://svn.apache.org/viewcvs/incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java?rev=232593&view=auto
==============================================================================
--- incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java
(added)
+++ incubator/agila/trunk/modules/bpm/src/test/org/apache/agila/dao/jdbc/MockDataSource.java
Sun Aug 14 01:29:14 2005
@@ -0,0 +1,108 @@
+/*
+ * 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.sql.Connection;
+import java.sql.SQLException;
+import java.sql.DriverManager;
+import java.io.PrintWriter;
+
+/**
+ * $Id$
+ */
+public class MockDataSource implements DataSource {
+
+    private String url;
+    private String username;
+    private String password;
+
+    public MockDataSource( String url, String username, String password, String driver )
{
+
+        setURL( url );
+        setUsername( username );
+        setPassword( password );
+        setDriverClassName( driver );
+
+    }
+
+    public void setURL( String url ) {
+        this.url = url;
+    }
+
+    public void setUsername( String username ) {
+        this.username = username;
+    }
+
+    public void setPassword( String password ) {
+        this.password = password;
+    }
+
+    public void setDriverClassName( String driverClassName ) {
+
+        try {
+
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            if( classLoader == null ) {
+                classLoader = getClass().getClassLoader();
+            }
+
+            Class.forName( driverClassName, true, classLoader );
+
+        } catch ( ClassNotFoundException ex ) {
+
+            throw new RuntimeException( "Could not load JDBC driver class:" + driverClassName
);
+        }
+
+    }
+
+    public Connection getConnection() throws SQLException {
+
+        return DriverManager.getConnection( url, username, password );
+
+    }
+
+    public Connection getConnection( String username, String password ) throws SQLException
{
+
+        return getConnection();
+
+    }
+
+    public PrintWriter getLogWriter() throws SQLException {
+
+        // Not implemented
+        return null;
+
+    }
+
+    public void setLogWriter( PrintWriter out ) throws SQLException {
+
+        // Not implemented
+    }
+
+    public void setLoginTimeout( int seconds ) throws SQLException {
+
+        // Not implemented
+    }
+
+    public int getLoginTimeout() throws SQLException {
+
+        // Not implemented
+        return 0;
+    }
+
+}



Mime
View raw message