[jbpm-commits] JBoss JBPM SVN: r3909 - in jbpm3/trunk/modules/core/src: main/java/org/jbpm/job/executor and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Feb 17 22:40:51 EST 2009
Author: alex.guizar at jboss.com
Date: 2009-02-17 22:40:51 -0500 (Tue, 17 Feb 2009)
New Revision: 3909
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml
jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml
jbpm3/trunk/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java
Log:
JBPM-1812: fix tests that do not cleanup the database
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -28,9 +28,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.jbpm.AbstractJbpmTestCase;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
@@ -47,7 +45,6 @@
protected JbpmConfiguration jbpmConfiguration;
protected JbpmContext jbpmContext;
- protected SchemaExport schemaExport;
protected Session session;
protected GraphSession graphSession;
@@ -75,33 +72,35 @@
private void ensureCleanDatabase() {
boolean hasLeftOvers = false;
- DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) getJbpmConfiguration().getServiceFactory("persistence");
- Configuration configuration = dbPersistenceServiceFactory.getConfiguration();
- JbpmSchema jbpmSchema = new JbpmSchema(configuration);
+ DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) getJbpmConfiguration().getServiceFactory(
+ "persistence");
+ JbpmSchema jbpmSchema = new JbpmSchema(persistenceServiceFactory.getConfiguration());
+ Map<String, Long> recordCountPerTable = jbpmSchema.getRowsPerTable();
- Map<String, Integer> recordCountPerTable = jbpmSchema.getRecordCountPerTable();
- for (Map.Entry<String, Integer> entry : recordCountPerTable.entrySet()) {
- // String tableName = entry.getKey();
- Integer count = entry.getValue();
-
- if ((count == null) || (count != 0)) {
+ for (Map.Entry<String, Long> entry : recordCountPerTable.entrySet()) {
+ Long count = entry.getValue();
+ if (count != 0) {
hasLeftOvers = true;
// [JBPM-1812] Fix tests that don't cleanup the database
- // Only uncomment this if you intend to fix it. Otherwise it just generates noise.
- // System.err.println("FIXME: " + getClass().getName() + "." + getName() + " left " + count
- // + " records in " + tableName);
+ System.err.println("FIXME: "
+ + getClass().getName()
+ + "."
+ + getName()
+ + " left "
+ + count
+ + " records in "
+ + entry.getKey());
}
}
if (hasLeftOvers) {
- // TODO: JBPM-1781
- // jbpmSchema.cleanSchema();
+ jbpmSchema.cleanSchema();
}
}
protected String getHibernateDialect() {
- DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
- return factory.getConfiguration().getProperty(Environment.DIALECT);
+ DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+ return persistenceServiceFactory.getConfiguration().getProperty(Environment.DIALECT);
}
protected void beginSessionTransaction() {
@@ -189,12 +188,12 @@
if (System.currentTimeMillis() - startTime > timeout) {
fail("test execution exceeded treshold of " + timeout + " milliseconds");
}
- log.debug("waiting for the job executor to process more jobs");
+ log.debug("waiting for job executor to process more jobs");
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
- // keep going
+ fail("wait for job executor to process more jobs got interrupted");
}
}
}
@@ -250,7 +249,7 @@
jobExecutor.stopAndJoin();
}
catch (InterruptedException e) {
- throw new RuntimeException("waiting for job executor to stop and join got interrupted", e);
+ log.debug("wait for job executor to stop and join got interrupted", e);
}
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -44,9 +44,6 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Settings;
import org.hibernate.connection.ConnectionProvider;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.engine.Mapping;
-import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Table;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.TableMetadata;
@@ -66,6 +63,8 @@
ConnectionProvider connectionProvider = null;
Connection connection = null;
+ final List<SQLException> exceptions = new ArrayList<SQLException>();
+
public JbpmSchema(Configuration configuration) {
this.configuration = configuration;
this.settings = configuration.buildSettings();
@@ -80,62 +79,13 @@
}
public String[] getCleanSql() {
- Dialect dialect = settings.getDialect();
- String catalog = settings.getDefaultCatalogName();
- String schema = settings.getDefaultSchemaName();
- Mapping mapping = configuration.buildMapping();
-
- // loop over all foreign key constraints
- List<String> dropForeignKeysSql = new ArrayList<String>();
- List<String> createForeignKeysSql = new ArrayList<String>();
- List<String> deleteSql = new ArrayList<String>();
-
- for (Iterator<?> ti = configuration.getTableMappings(); ti.hasNext();) {
- Table table = (Table) ti.next();
- if (!table.isPhysicalTable()) continue;
-
- for (Iterator<?> fki = table.getForeignKeyIterator(); fki.hasNext();) {
- ForeignKey fk = (ForeignKey) fki.next();
- if (!fk.isPhysicalConstraint()) continue;
-
- // collect the drop foreign key sql
- String sqlDropString = fk.sqlDropString(dialect, catalog, schema);
- dropForeignKeysSql.add(sqlDropString);
-
- // and collect the create foreign key sql
- String sqlCreateString = fk.sqlCreateString(dialect, mapping, catalog, schema);
- createForeignKeysSql.add(sqlCreateString);
- }
- deleteSql.add("DELETE FROM " + table.getName());
- }
-
- // glue
- // - drop foreign key constraints
- // - delete contents of all tables
- // - create foreign key constraints
- // together to form the clean script
- return concat(dropForeignKeysSql, deleteSql, createForeignKeysSql);
+ return concat(getDropSql(), getCreateSql());
}
- private static String[] concat(List<?>... lists) {
- int length = 0;
- for (List<?> list : lists) {
- length += list.size();
- }
- String[] array = new String[length];
- int index = 0;
- for (List<?> list : lists) {
- for (Object element : list) {
- array[index++] = (String) element;
- }
- }
- return array;
- }
-
public List<String> getTableNames() {
List<String> tableNames = new ArrayList<String>();
- for (Iterator<?> iter = configuration.getTableMappings(); iter.hasNext();) {
- Table table = (Table) iter.next();
+ for (Iterator<?> i = configuration.getTableMappings(); i.hasNext();) {
+ Table table = (Table) i.next();
if (table.isPhysicalTable()) {
tableNames.add(table.getName());
}
@@ -143,16 +93,45 @@
return tableNames;
}
- public Map<String, Integer> getRecordCountPerTable() {
- Map<String, Integer> recordCounts = new HashMap<String, Integer>();
+ public List<String> getAvailableTableNames() {
try {
createConnection();
+ List<String> tableNames = new ArrayList<String>();
+
+ ResultSet resultSet = connection.getMetaData().getTables(settings.getDefaultCatalogName(),
+ settings.getDefaultSchemaName(), "JBPM_%", new String[] { "TABLE" });
+ try {
+ while (resultSet.next()) {
+ tableNames.add(resultSet.getString("TABLE_NAME"));
+ }
+ }
+ finally {
+ resultSet.close();
+ }
+ return tableNames;
+ }
+ catch (SQLException e) {
+ throw new JbpmException("could not get available table names", e);
+ }
+ finally {
+ closeConnection();
+ }
+ }
+
+ public Map<String, Long> getRowsPerTable() {
+ Map<String, Long> rowsPerTable = new HashMap<String, Long>();
+ try {
+ createConnection();
Statement statement = connection.createStatement();
for (String tableName : getTableNames()) {
String sql = "SELECT COUNT(*) FROM " + tableName;
ResultSet resultSet = statement.executeQuery(sql);
- resultSet.next();
- recordCounts.put(tableName, resultSet.getInt(1));
+ if (!resultSet.next()) throw new JbpmException("empty result set: " + sql);
+
+ long count = resultSet.getLong(1);
+ if (resultSet.wasNull()) throw new JbpmException("count was null: " + sql);
+
+ rowsPerTable.put(tableName, count);
resultSet.close();
}
statement.close();
@@ -163,7 +142,7 @@
finally {
closeConnection();
}
- return recordCounts;
+ return rowsPerTable;
}
public void dropSchema() {
@@ -264,6 +243,10 @@
}
}
+ public List<SQLException> getExceptions() {
+ return exceptions;
+ }
+
private Table findTableMapping(String tableName) {
for (Iterator<?> i = configuration.getTableMappings(); i.hasNext();) {
Table table = (Table) i.next();
@@ -350,12 +333,21 @@
void execute(String... sqls) throws SQLException {
boolean showSql = settings.isShowSqlEnabled();
+ exceptions.clear();
try {
createConnection();
Statement statement = connection.createStatement();
for (String sql : sqls) {
if (showSql) System.out.println(sql);
- statement.executeUpdate(sql);
+ log.debug(sql);
+ try {
+ statement.executeUpdate(sql);
+ }
+ catch (SQLException e) {
+ exceptions.add(e);
+ log.debug("unsuccessful: " + sql);
+ log.debug(e.getMessage());
+ }
}
statement.close();
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutor.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -4,6 +4,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
@@ -15,8 +16,8 @@
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmConfiguration;
-public class JobExecutor implements Serializable
-{
+public class JobExecutor implements Serializable {
+
private static final long serialVersionUID = 1L;
protected JbpmConfiguration jbpmConfiguration;
@@ -24,6 +25,8 @@
protected int nbrOfThreads;
protected int idleInterval;
protected int maxIdleInterval;
+ /** @deprecated this field was never used */
+ @Deprecated
protected int historyMaxSize;
protected int maxLockTime;
@@ -38,129 +41,115 @@
protected static String hostName;
- public synchronized void start()
- {
- if (!isStarted)
- {
+ public synchronized void start() {
+ if (!isStarted) {
log.debug("starting thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++)
- {
+ for (int i = 0; i < nbrOfThreads; i++) {
startThread();
}
- lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval, maxLockTime, lockBufferTime);
+ lockMonitorThread = new LockMonitorThread(jbpmConfiguration, lockMonitorInterval,
+ maxLockTime, lockBufferTime);
isStarted = true;
}
- else
- {
+ else {
log.debug("ignoring start: thread group '" + name + "' is already started'");
}
}
/**
- * signals to all threads in this job executor to stop. It may be that threads are in the middle of something and they will finish that first. Use {@link
- * #stopAndJoin()} in case you want a method that blocks until all the threads are actually finished.
- * @return a list of all the stopped threads. In case no threads were stopped an empty list will be returned.
+ * signals to all threads in this job executor to stop. Threads may be in the middle of processing
+ * a job and they will finish that first. Use {@link #stopAndJoin()} in case you want a method
+ * that blocks until all the threads are actually finished.
+ *
+ * @return a list of the stopped threads. In case no threads were stopped an empty list will be
+ * returned.
*/
- public synchronized List<Thread> stop()
- {
- List<Thread> stoppedThreads = new ArrayList<Thread>(threads.size());
- if (isStarted)
- {
+ public synchronized List<Thread> stop() {
+ List<Thread> stoppedThreads;
+ if (isStarted) {
log.debug("stopping thread group '" + name + "'...");
- for (int i = 0; i < nbrOfThreads; i++)
- {
+ isStarted = false;
+
+ stoppedThreads = new ArrayList<Thread>(threads.size());
+ for (int i = 0; i < nbrOfThreads; i++) {
stoppedThreads.add(stopThread());
}
-
- if (lockMonitorThread != null)
- lockMonitorThread.deactivate();
-
- isStarted = false;
+
+ if (lockMonitorThread != null) lockMonitorThread.deactivate();
}
- else
- {
+ else {
log.debug("ignoring stop: thread group '" + name + "' not started");
+ stoppedThreads = Collections.emptyList();
}
return stoppedThreads;
}
- public void stopAndJoin() throws InterruptedException
- {
- for (Thread thread : stop())
- {
+ public void stopAndJoin() throws InterruptedException {
+ for (Thread thread : stop()) {
thread.join();
}
-
- if (lockMonitorThread != null)
- lockMonitorThread.join();
+
+ if (lockMonitorThread != null) lockMonitorThread.join();
}
- protected synchronized void startThread()
- {
+ protected synchronized void startThread() {
String threadName = getNextThreadName();
Thread thread = createThread(threadName);
threads.put(threadName, thread);
+
log.debug("starting new job executor thread '" + threadName + "'");
thread.start();
}
- protected Thread createThread(String threadName)
- {
+ protected Thread createThread(String threadName) {
return new JobExecutorThread(threadName, this);
}
- protected String getNextThreadName()
- {
+ protected String getNextThreadName() {
return getThreadName(threads.size() + 1);
}
- protected String getLastThreadName()
- {
+ protected String getLastThreadName() {
return getThreadName(threads.size());
}
- private String getThreadName(int index)
- {
+ private String getThreadName(int index) {
return name + ":" + getHostAddress() + ":" + index;
}
- private static String getHostAddress()
- {
- if (hostName == null)
- {
- try
- {
+ private static String getHostAddress() {
+ if (hostName == null) {
+ try {
hostName = InetAddress.getLocalHost().getHostAddress();
}
- catch (UnknownHostException e)
- {
+ catch (UnknownHostException e) {
hostName = "127.0.0.1";
}
}
return hostName;
}
- protected synchronized Thread stopThread()
- {
+ protected synchronized Thread stopThread() {
String threadName = getLastThreadName();
- JobExecutorThread thread = (JobExecutorThread)threads.remove(threadName);
log.debug("removing job executor thread '" + threadName + "'");
- thread.deactivate();
+
+ Thread thread = threads.remove(threadName);
+ if (thread instanceof JobExecutorThread) {
+ JobExecutorThread jobThread = (JobExecutorThread) thread;
+ jobThread.deactivate();
+ }
return thread;
}
- public Set<Long> getMonitoredJobIds()
- {
+ public Set<Long> getMonitoredJobIds() {
return new HashSet<Long>(monitoredJobIds.values());
}
- public void addMonitoredJobId(String threadName, long jobId)
- {
+ public void addMonitoredJobId(String threadName, long jobId) {
monitoredJobIds.put(threadName, new Long(jobId));
}
- public void removeMonitoredJobId(String threadName)
- {
+ public void removeMonitoredJobId(String threadName) {
monitoredJobIds.remove(threadName);
}
@@ -169,36 +158,34 @@
* @deprecated <code>monitoredJobIds</code> is an internal control field
*/
@Deprecated
- public void setMonitoredJobIds(Map<String, Long> monitoredJobIds)
- {
+ public void setMonitoredJobIds(Map<String, Long> monitoredJobIds) {
throw new UnsupportedOperationException();
}
- public int getHistoryMaxSize()
- {
+ /** @deprecated this property was never used */
+ @Deprecated
+ public int getHistoryMaxSize() {
return historyMaxSize;
}
- public void setHistoryMaxSize(int historyMaxSize)
- {
+ /** @deprecated this property was never used */
+ @Deprecated
+ public void setHistoryMaxSize(int historyMaxSize) {
this.historyMaxSize = historyMaxSize;
}
- public int getIdleInterval()
- {
+ public int getIdleInterval() {
return idleInterval;
}
- public void setIdleInterval(int idleInterval)
- {
+ public void setIdleInterval(int idleInterval) {
this.idleInterval = idleInterval;
}
/**
* Tells whether this job executor has been {@linkplain #start() started}.
*/
- public boolean isStarted()
- {
+ public boolean isStarted() {
return isStarted;
}
@@ -207,38 +194,31 @@
* @deprecated <code>isStarted</code> is an internal control field
*/
@Deprecated
- public void setStarted(boolean isStarted)
- {
+ public void setStarted(boolean isStarted) {
throw new UnsupportedOperationException();
}
- public JbpmConfiguration getJbpmConfiguration()
- {
+ public JbpmConfiguration getJbpmConfiguration() {
return jbpmConfiguration;
}
- public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration)
- {
+ public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
this.jbpmConfiguration = jbpmConfiguration;
}
- public int getMaxIdleInterval()
- {
+ public int getMaxIdleInterval() {
return maxIdleInterval;
}
- public void setMaxIdleInterval(int maxIdleInterval)
- {
+ public void setMaxIdleInterval(int maxIdleInterval) {
this.maxIdleInterval = maxIdleInterval;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public void setName(String name)
- {
+ public void setName(String name) {
this.name = name;
}
@@ -246,8 +226,7 @@
* @deprecated Replaced by {{@link #getNbrOfThreads()}
*/
@Deprecated
- public int getSize()
- {
+ public int getSize() {
return nbrOfThreads;
}
@@ -255,13 +234,11 @@
* @deprecated Replaced by {@link #setNbrOfThreads(int)}
*/
@Deprecated
- public void setSize(int nbrOfThreads)
- {
+ public void setSize(int nbrOfThreads) {
this.nbrOfThreads = nbrOfThreads;
}
- public Map<String, Thread> getThreads()
- {
+ public Map<String, Thread> getThreads() {
return threads;
}
@@ -270,48 +247,39 @@
* @deprecated <code>threads</code> is an internal control field
*/
@Deprecated
- public void setThreads(Map<String, Thread> threads)
- {
+ public void setThreads(Map<String, Thread> threads) {
throw new UnsupportedOperationException();
}
- public int getMaxLockTime()
- {
+ public int getMaxLockTime() {
return maxLockTime;
}
- public void setMaxLockTime(int maxLockTime)
- {
+ public void setMaxLockTime(int maxLockTime) {
this.maxLockTime = maxLockTime;
}
- public int getLockBufferTime()
- {
+ public int getLockBufferTime() {
return lockBufferTime;
}
- public void setLockBufferTime(int lockBufferTime)
- {
+ public void setLockBufferTime(int lockBufferTime) {
this.lockBufferTime = lockBufferTime;
}
- public int getLockMonitorInterval()
- {
+ public int getLockMonitorInterval() {
return lockMonitorInterval;
}
- public void setLockMonitorInterval(int lockMonitorInterval)
- {
+ public void setLockMonitorInterval(int lockMonitorInterval) {
this.lockMonitorInterval = lockMonitorInterval;
}
- public int getNbrOfThreads()
- {
+ public int getNbrOfThreads() {
return nbrOfThreads;
}
- public void setNbrOfThreads(int nbrOfThreads)
- {
+ public void setNbrOfThreads(int nbrOfThreads) {
this.nbrOfThreads = nbrOfThreads;
}
Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableDeleteLog.hbm.xml 2009-02-18 03:40:51 UTC (rev 3909)
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
-
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@@ -9,6 +8,13 @@
<subclass name="org.jbpm.context.log.VariableDeleteLog"
extends="org.jbpm.context.log.VariableLog"
discriminator-value="D">
+
+ <many-to-one name="variableInstance"
+ column="VARIABLEINSTANCE_"
+ cascade="all"
+ insert="false"
+ update="false" />
+
</subclass>
</hibernate-mapping>
Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/context/log/VariableLog.hbm.xml 2009-02-18 03:40:51 UTC (rev 3909)
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
-
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
@@ -12,8 +11,6 @@
<many-to-one name="variableInstance"
column="VARIABLEINSTANCE_"
- class="org.jbpm.context.exe.VariableInstance"
- cascade="save-update"
foreign-key="FK_LOG_VARINST" />
</subclass>
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -31,54 +31,78 @@
byte[] bytes = getMultipleBlockBytes();
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertEquals(byteArray.byteBlocks.size(), retrievedByteArray.getByteBlocks().size());
assertTrue(Arrays.equals(byteArray.getBytes(), retrievedByteArray.getBytes()));
+
+ session.delete(retrievedByteArray);
}
public void testEmptyByteArray() {
byte[] bytes = new byte[0];
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertNull(retrievedByteArray.getBytes());
+
+ session.delete(retrievedByteArray);
}
public void testByteArrayCopy() {
byte[] bytes = getMultipleBlockBytes();
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
ByteArray copiedByteArray = new ByteArray(retrievedByteArray);
session.save(copiedByteArray);
+
newTransaction();
- retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(retrievedByteArray.getId()));
+ retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ retrievedByteArray.getId()));
copiedByteArray = (ByteArray) session.load(ByteArray.class, new Long(copiedByteArray.getId()));
assertNotSame(retrievedByteArray.getByteBlocks(), copiedByteArray.getByteBlocks());
- for (int i=0; i<retrievedByteArray.getByteBlocks().size(); i++) {
+
+ for (int i = 0; i < retrievedByteArray.getByteBlocks().size(); i++) {
byte[] retrievedBytes = (byte[]) retrievedByteArray.getByteBlocks().get(i);
byte[] copiedBytes = (byte[]) copiedByteArray.getByteBlocks().get(i);
+
assertNotSame(retrievedBytes, copiedBytes);
assertTrue(Arrays.equals(retrievedBytes, copiedBytes));
}
+
+ session.delete(copiedByteArray);
+ session.delete(retrievedByteArray);
}
public void testNullByteArray() {
byte[] bytes = null;
ByteArray byteArray = new ByteArray(bytes);
session.save(byteArray);
+
newTransaction();
- ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(byteArray.getId()));
+ ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
+ byteArray.getId()));
assertNull(retrievedByteArray.getBytes());
+
+ session.delete(retrievedByteArray);
}
private static byte[] getMultipleBlockBytes() {
- String text = "muchos bytes"; // (10 bytes)
- for (int i=0; i<8; i++) text+=text;
- // now text should be 2560 bytes
- return text.getBytes();
+ byte[] bytes = new byte[2560];
+ Arrays.fill(bytes, 0, 512, (byte) 67);
+ Arrays.fill(bytes, 512, 1024, (byte) 65);
+ Arrays.fill(bytes, 1024, 1536, (byte) 71);
+ Arrays.fill(bytes, 1536, 2048, (byte) 70);
+ Arrays.fill(bytes, 2048, 2560, (byte) 66);
+ return bytes;
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/db/JbpmSchemaDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -21,6 +21,8 @@
*/
package org.jbpm.db;
+import java.util.Map;
+
import org.hibernate.cfg.Configuration;
import org.jbpm.AbstractJbpmTestCase;
@@ -30,26 +32,32 @@
* @author thomas.diesler at jboss.com
* @since 06-Nov-2008
*/
-public class JbpmSchemaDbTest extends AbstractJbpmTestCase
-{
- public void testCleanSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
- jbpmSchema.cleanSchema();
+public class JbpmSchemaDbTest extends AbstractJbpmTestCase {
+
+ JbpmSchema jbpmSchema;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ jbpmSchema = new JbpmSchema(new Configuration().configure());
}
-
- public void testDropSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
+
+ public void testCreateSchema() {
+ jbpmSchema.createSchema();
+ assertEquals(28, jbpmSchema.getAvailableTableNames().size());
+ }
+
+ public void testDropSchema() {
jbpmSchema.dropSchema();
+ assertEquals(0, jbpmSchema.getAvailableTableNames().size());
}
- public void testCreateSchema()
- {
- Configuration config = new Configuration().configure();
- JbpmSchema jbpmSchema = new JbpmSchema(config);
- jbpmSchema.createSchema();
+ public void testCleanSchema() {
+ jbpmSchema.cleanSchema();
+ Map<String, Long> rowsPerTable = jbpmSchema.getRowsPerTable();
+ assertEquals(28, rowsPerTable.size());
+ for (long rowCount : rowsPerTable.values()) {
+ assertEquals(0, rowCount);
+ }
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -13,8 +14,7 @@
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-public class JobExecutorDbTest extends AbstractDbTestCase
-{
+public class JobExecutorDbTest extends AbstractDbTestCase {
static final int nbrOfConcurrentProcessExecutions = 20;
static final int timeout = 60000;
@@ -23,29 +23,30 @@
static List<Long> allocatedProcessIds = Collections.synchronizedList(new ArrayList<Long>());
@Override
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
- deployProcess();
getJbpmConfiguration().getJobExecutor().setNbrOfThreads(5);
}
@Override
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
getJbpmConfiguration().getJobExecutor().setNbrOfThreads(1);
- deleteProcess();
super.tearDown();
}
- public void testJobExecutor()
- {
- launchProcesses();
- processJobs(timeout);
- assertEquals(createExpectedResults(), collectedResults);
+ public void testJobExecutor() {
+ deployProcessDefinition();
+ try {
+ startProcessInstances();
+ processJobs(timeout);
+ assertEquals(getExpectedResults(), collectedResults);
+ }
+ finally {
+ deleteProcessDefinition();
+ }
}
- void deployProcess() {
+ void deployProcessDefinition() {
ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='bulk messages'>"
+ " <start-state>"
+ " <transition to='a' />"
@@ -98,23 +99,20 @@
+ "</process-definition>");
jbpmContext.deployProcessDefinition(processDefinition);
+ newTransaction();
}
- void launchProcesses()
- {
- for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++)
- {
- newTransaction();
+ void startProcessInstances() {
+ for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++) {
ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("bulk messages");
processInstance.signal();
+ newTransaction();
}
}
- Set<String> createExpectedResults()
- {
- Set<String> expectedResults = new TreeSet<String>();
- for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++)
- {
+ Set<String> getExpectedResults() {
+ Set<String> expectedResults = new HashSet<String>();
+ for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++) {
String prefix = (i < 10 ? "0" : "");
expectedResults.add(prefix + i + "a");
expectedResults.add(prefix + i + "b");
@@ -128,19 +126,16 @@
return expectedResults;
}
- void deleteProcess()
- {
+ void deleteProcessDefinition() {
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("bulk messages");
graphSession.deleteProcessDefinition(processDefinition);
}
- public static class AutomaticActivity implements ActionHandler
- {
+ public static class AutomaticActivity implements ActionHandler {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public void execute(ExecutionContext executionContext) throws Exception {
Long id = executionContext.getProcessInstance().getId();
String procIndex = getProcessIndex(id);
@@ -150,13 +145,11 @@
}
}
- public static class AsyncAction implements ActionHandler
- {
+ public static class AsyncAction implements ActionHandler {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public void execute(ExecutionContext executionContext) throws Exception {
Long id = executionContext.getProcessInstance().getId();
String procIndex = getProcessIndex(id);
@@ -166,10 +159,8 @@
}
}
- static synchronized String getProcessIndex(Long id)
- {
- if (allocatedProcessIds.contains(id) == false)
- allocatedProcessIds.add(id);
+ static synchronized String getProcessIndex(Long id) {
+ if (allocatedProcessIds.contains(id) == false) allocatedProcessIds.add(id);
int procIndex = allocatedProcessIds.indexOf(id);
String prefix = (procIndex < 10 ? "0" : "");
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/logging/exe/LoggingConfigDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -1,10 +1,12 @@
package org.jbpm.logging.exe;
-import org.hibernate.Query;
+import java.util.List;
+
import org.jbpm.JbpmConfiguration;
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.logging.log.ProcessLog;
public class LoggingConfigDbTest extends AbstractDbTestCase {
@@ -23,12 +25,15 @@
}
public void testLoggingconfiguration() {
- jbpmContext.deployProcessDefinition(new ProcessDefinition("logging"));
+ ProcessDefinition processDefinition = new ProcessDefinition("logging");
+ jbpmContext.deployProcessDefinition(processDefinition);
ProcessInstance processInstance = jbpmContext.newProcessInstance("logging");
processInstance.getContextInstance().setVariable("a", "1");
+
newTransaction();
+ List<?> logs = session.createCriteria(ProcessLog.class).list();
+ assertEquals(0, logs.size());
- Query query = session.createQuery("from org.jbpm.logging.log.ProcessLog");
- assertEquals(0, query.list().size());
+ graphSession.deleteProcessDefinition(processDefinition.getId());
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/seam/JobExecutorCustomizationTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -37,17 +37,15 @@
+ " <state name='end' />"
+ "</process-definition>");
jbpmContext.deployProcessDefinition(processDefinition);
+
newTransaction();
- try {
- jbpmContext.newProcessInstanceForUpdate("customjobexecution");
- processJobs(20 * 1000);
+ jbpmContext.newProcessInstanceForUpdate("customjobexecution");
- List<String> expectedJobEvents = Arrays.asList("before", "execute action", "after");
- assertEquals(expectedJobEvents, jobEvents);
- }
- finally {
- graphSession.deleteProcessDefinition(processDefinition.getId());
- }
+ processJobs(20 * 1000);
+ List<String> expectedJobEvents = Arrays.asList("before", "execute action", "after");
+ assertEquals(expectedJobEvents, jobEvents);
+
+ graphSession.deleteProcessDefinition(processDefinition.getId());
}
public static void addJobEvent(String event) {
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskInstanceDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -36,286 +35,251 @@
public class TaskInstanceDbTest extends AbstractDbTestCase {
- public void testTaskInstanceUnrelatedToAProcess()
- {
+ public void testTaskInstanceUnrelatedToAProcess() {
TaskInstance taskInstance = new TaskInstance("do laundry", "someoneelse");
session.save(taskInstance);
- long id = taskInstance.getId();
-
newTransaction();
- taskInstance = (TaskInstance)session.load(TaskInstance.class, new Long(id));
+ taskInstance = (TaskInstance) session.load(TaskInstance.class, taskInstance.getId());
assertNotNull(taskInstance);
assertEquals("do laundry", taskInstance.getName());
assertEquals("someoneelse", taskInstance.getActorId());
+
+ session.delete(taskInstance);
}
public void testTaskInstanceBasicLifeCycle() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
+
processInstance = saveAndReload(processInstance);
long tokenId = processInstance.getRootToken().getId();
- List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
+ List<TaskInstance> taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
assertEquals(1, taskInstances.size());
- TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
+
+ TaskInstance taskInstance = taskInstances.get(0);
assertFalse(taskInstance.hasEnded());
assertEquals(tokenId, taskInstance.getToken().getId());
// do some updates
taskInstance.end();
-
+
processInstance = saveAndReload(processInstance);
-
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
assertTrue(taskInstance.hasEnded());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
+
}
public void testTaskName() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
- processInstance = saveAndReload(processInstance);
- long tokenId = processInstance.getRootToken().getId();
- List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
+ processInstance = saveAndReload(processInstance);
+ List<TaskInstance> taskInstances = taskMgmtSession.findTaskInstancesByToken(processInstance.getRootToken()
+ .getId());
assertEquals(1, taskInstances.size());
- TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
+
+ TaskInstance taskInstance = taskInstances.get(0);
assertFalse(taskInstance.hasEnded());
assertEquals("clean ceiling", taskInstance.getName());
assertEquals("clean ceiling", taskInstance.getTask().getName());
// do some updates
taskInstance.setName("clean ceiling thoroughly");
-
+
processInstance = saveAndReload(processInstance);
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
-
assertEquals("clean ceiling thoroughly", taskInstance.getName());
assertEquals("clean ceiling", taskInstance.getTask().getName());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
-
+
public void testTaskComments() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='clean ceiling' />" +
- " <transition to='end' />" +
- " </task-node>" +
- " <end-state name='end' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='clean ceiling' />"
+ + " <transition to='end' />"
+ + " </task-node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
- processInstance = saveAndReload(processInstance);
- long tokenId = processInstance.getRootToken().getId();
- List taskInstances = taskMgmtSession.findTaskInstancesByToken(tokenId);
+ processInstance = saveAndReload(processInstance);
+ List<TaskInstance> taskInstances = taskMgmtSession.findTaskInstancesByToken(processInstance.getRootToken()
+ .getId());
assertEquals(1, taskInstances.size());
- TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
+ TaskInstance taskInstance = taskInstances.get(0);
taskInstance.addComment("please hurry!");
-
+
processInstance = saveAndReload(processInstance);
taskInstance = taskMgmtSession.loadTaskInstance(taskInstance.getId());
-
- List comments = taskInstance.getComments();
+
+ List<Comment> comments = taskInstance.getComments();
assertEquals(1, comments.size());
-
- Comment comment = (Comment) comments.get(0);
+
+ Comment comment = comments.get(0);
assertEquals("please hurry!", comment.getMessage());
assertSame(taskInstance, comment.getTaskInstance());
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
-
+
public void testBlockingTask() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <task-node name='a'>" +
- " <task name='laundry' blocking='true' />" +
- " <transition to='b' />" +
- " </task-node>" +
- " <state name='b' />" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <task-node name='a'>"
+ + " <task name='laundry' blocking='true' />"
+ + " <transition to='b' />"
+ + " </task-node>"
+ + " <state name='b' />"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
- processInstance.signal();
+ token.signal();
assertEquals("a", token.getNode().getName());
+
processInstance = saveAndReload(processInstance);
try {
processInstance.signal();
fail("expected exception");
- } catch (IllegalStateException e) {
+ }
+ catch (IllegalStateException e) {
// OK
}
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
public void testConditionalTasksOne() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='release' />" +
- " </start-state>" +
- " <task-node name='release'>" +
- " <task name='updateWebsite' condition='#{user.admin}' />" +
- " <task name='addNewsItem' />" +
- " <task name='publishRelease' condition='#{user.releaseManager}' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='release' />"
+ + " </start-state>"
+ + " <task-node name='release'>"
+ + " <task name='updateWebsite' condition='#{user.admin}' />"
+ + " <task name='addNewsItem' />"
+ + " <task name='publishRelease' condition='#{user.releaseManager}' />"
+ + " </task-node>"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("user", new User(true, false));
processInstance.signal();
processInstance = saveAndReload(processInstance);
- Collection taskInstances = processInstance.getTaskMgmtInstance().getTaskInstances();
- Set createdTasks = new HashSet();
- Iterator iter = taskInstances.iterator();
- while (iter.hasNext()) {
- TaskInstance taskInstance = (TaskInstance) iter.next();
- createdTasks.add(taskInstance.getName());
- }
+ Collection<TaskInstance> taskInstances = processInstance.getTaskMgmtInstance()
+ .getTaskInstances();
- Set expectedTasks = new HashSet();
- expectedTasks.add("updateWebsite");
- expectedTasks.add("addNewsItem");
-
- assertEquals(expectedTasks, createdTasks);
+ Set<String> taskNames = new HashSet<String>();
+ for (TaskInstance taskInstance : taskInstances) {
+ taskNames.add(taskInstance.getName());
+ }
+ assertEquals(2, taskNames.size());
+ assert taskNames.contains("updateWebsite") : taskNames;
+ assert taskNames.contains("addNewsItem") : taskNames;
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
public void testConditionalTasksTwo() {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition>" +
- " <start-state>" +
- " <transition to='release' />" +
- " </start-state>" +
- " <task-node name='release'>" +
- " <task name='updateWebsite' condition='#{user.admin}' />" +
- " <task name='addNewsItem' />" +
- " <task name='publishRelease' condition='#{user.releaseManager}' />" +
- " </task-node>" +
- "</process-definition>"
- );
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>"
+ + " <start-state>"
+ + " <transition to='release' />"
+ + " </start-state>"
+ + " <task-node name='release'>"
+ + " <task name='updateWebsite' condition='#{user.admin}' />"
+ + " <task name='addNewsItem' />"
+ + " <task name='publishRelease' condition='#{user.releaseManager}' />"
+ + " </task-node>"
+ + "</process-definition>");
processDefinition = saveAndReload(processDefinition);
- try
- {
+ try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("user", new User(false, true));
processInstance.signal();
processInstance = saveAndReload(processInstance);
- Collection taskInstances = processInstance.getTaskMgmtInstance().getTaskInstances();
- Set createdTasks = new HashSet();
- Iterator iter = taskInstances.iterator();
- while (iter.hasNext()) {
- TaskInstance taskInstance = (TaskInstance) iter.next();
- createdTasks.add(taskInstance.getName());
+ Collection<TaskInstance> taskInstances = processInstance.getTaskMgmtInstance()
+ .getTaskInstances();
+ Set<String> taskNames = new HashSet<String>();
+ for (TaskInstance taskInstance : taskInstances) {
+ taskNames.add(taskInstance.getName());
}
- Set expectedTasks = new HashSet();
- expectedTasks.add("addNewsItem");
- expectedTasks.add("publishRelease");
-
- assertEquals(expectedTasks, createdTasks);
+ assertEquals(2, taskNames.size());
+ assert taskNames.contains("addNewsItem") : taskNames;
+ assert taskNames.contains("publishRelease") : taskNames;
}
- finally
- {
+ finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
}
- public static class User implements Serializable
- {
+ public static class User implements Serializable {
private static final long serialVersionUID = 1L;
boolean isAdmin;
boolean isReleaseManager;
- public User(boolean isAdmin, boolean isReleaseManager)
- {
+ public User(boolean isAdmin, boolean isReleaseManager) {
this.isAdmin = isAdmin;
this.isReleaseManager = isReleaseManager;
}
- public boolean isAdmin()
- {
+ public boolean isAdmin() {
return isAdmin;
}
- public boolean isReleaseManager()
- {
+ public boolean isReleaseManager() {
return isReleaseManager;
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java 2009-02-17 20:07:30 UTC (rev 3908)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/log/TaskLogDbTest.java 2009-02-18 03:40:51 UTC (rev 3909)
@@ -24,66 +24,54 @@
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.taskmgmt.exe.TaskInstance;
-public class TaskLogDbTest extends AbstractDbTestCase
-{
+public class TaskLogDbTest extends AbstractDbTestCase {
- TaskInstance taskInstance = null;
+ TaskInstance taskInstance;
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
taskInstance = new TaskInstance();
session.save(taskInstance);
}
- protected void tearDown() throws Exception
- {
- taskInstance = null;
+ protected void tearDown() throws Exception {
+ session.delete(taskInstance);
super.tearDown();
}
- public void testTaskCreateLog()
- {
+ public void testTaskCreateLog() {
TaskCreateLog taskLog = new TaskCreateLog(taskInstance, "someone else");
session.save(taskLog);
newTransaction();
+ taskLog = (TaskCreateLog) session.load(TaskCreateLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
+ assertEquals("someone else", taskLog.getTaskActorId());
- taskLog = (TaskCreateLog)session.load(TaskCreateLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
- assertEquals("someone else", (taskLog.getTaskActorId()));
-
session.delete(taskLog);
}
- public void testTaskAssignLog()
- {
+ public void testTaskAssignLog() {
TaskAssignLog taskLog = new TaskAssignLog(taskInstance, "me", "toyou");
session.save(taskLog);
newTransaction();
+ taskLog = (TaskAssignLog) session.load(TaskAssignLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
+ assertEquals("me", taskLog.getTaskOldActorId());
+ assertEquals("toyou", taskLog.getTaskNewActorId());
- taskLog = (TaskAssignLog)session.load(TaskAssignLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
- assertEquals("me", (taskLog.getTaskOldActorId()));
- assertEquals("toyou", (taskLog.getTaskNewActorId()));
-
session.delete(taskLog);
-}
+ }
- public void testTaskEndLog()
- {
+ public void testTaskEndLog() {
TaskEndLog taskLog = new TaskEndLog(taskInstance);
session.save(taskLog);
newTransaction();
+ taskLog = (TaskEndLog) session.load(TaskEndLog.class, new Long(taskLog.getId()));
+ assertEquals(taskInstance.getId(), (taskInstance = taskLog.getTaskInstance()).getId());
- taskLog = (TaskEndLog)session.load(TaskEndLog.class, new Long(taskLog.getId()));
- assertNotNull(taskLog);
- assertNotNull(taskLog.getTaskInstance());
-
session.delete(taskLog);
}
}
More information about the jbpm-commits
mailing list