[jbpm-commits] JBoss JBPM SVN: r2705 - in jbpm4/trunk/modules: test-base and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 31 12:07:13 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-10-31 12:07:13 -0400 (Fri, 31 Oct 2008)
New Revision: 2705
Added:
jbpm4/trunk/modules/test-base/
jbpm4/trunk/modules/test-base/pom.xml
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
Removed:
jbpm4/trunk/modules/test-base/pom.xml
Log:
unification api proposals
Copied: jbpm4/trunk/modules/test-base (from rev 2701, jbpm4/trunk/modules/test)
Property changes on: jbpm4/trunk/modules/test-base
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: jbpm4/trunk/modules/test-base/pom.xml
===================================================================
--- jbpm4/trunk/modules/test/pom.xml 2008-10-31 10:28:46 UTC (rev 2701)
+++ jbpm4/trunk/modules/test-base/pom.xml 2008-10-31 16:07:13 UTC (rev 2705)
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!-- ====================================================================== -->
-<!-- -->
-<!-- JBoss, the OpenSource J2EE webOS -->
-<!-- -->
-<!-- Distributable under LGPL license. -->
-<!-- See terms of license at http://www.gnu.org. -->
-<!-- -->
-<!-- ====================================================================== -->
-
-<!-- $Id$ -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <name>jBPM 4 - Test</name>
- <groupId>org.jbpm.jbpm4</groupId>
- <artifactId>jbpm-test</artifactId>
- <packaging>jar</packaging>
-
- <!-- Parent -->
- <parent>
- <groupId>org.jbpm.jbpm4</groupId>
- <artifactId>jbpm</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <!-- Dependencies -->
- <dependencies>
- <dependency>
- <groupId>org.jbpm.jbpm4</groupId>
- <artifactId>jbpm-api</artifactId>
- <version>${version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate</artifactId>
- </dependency>
- </dependencies>
-
- <!-- Plugins -->
- <build>
- <plugins>
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
Copied: jbpm4/trunk/modules/test-base/pom.xml (from rev 2702, jbpm4/trunk/modules/test/pom.xml)
===================================================================
--- jbpm4/trunk/modules/test-base/pom.xml (rev 0)
+++ jbpm4/trunk/modules/test-base/pom.xml 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ====================================================================== -->
+<!-- -->
+<!-- JBoss, the OpenSource J2EE webOS -->
+<!-- -->
+<!-- Distributable under LGPL license. -->
+<!-- See terms of license at http://www.gnu.org. -->
+<!-- -->
+<!-- ====================================================================== -->
+
+<!-- $Id$ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <name>jBPM 4 - Test</name>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-test-base</artifactId>
+ <packaging>jar</packaging>
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <!-- Dependencies -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-api</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-log</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ </dependency>
+ </dependencies>
+
+ <!-- Plugins -->
+ <build>
+ <plugins>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/Db.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.MySQLDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.mapping.ForeignKey;
+import org.hibernate.mapping.Table;
+import org.jbpm.pvm.env.EnvironmentFactory;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class Db {
+
+ private static final String CLEAN_SQL_KEY = "cleanSql";
+
+ public static void clean(EnvironmentFactory environmentFactory) {
+ SessionFactory sessionFactory = environmentFactory.get(SessionFactory.class);
+ String[] cleanSql = (String[]) environmentFactory.get(CLEAN_SQL_KEY);
+
+ if (cleanSql == null) {
+ Configuration configuration = environmentFactory.get(Configuration.class);
+
+ SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
+ Dialect dialect = sessionFactoryImplementor.getDialect();
+
+ // loop over all foreign key constraints
+ List<String> dropForeignKeysSql = new ArrayList<String>();
+ List<String> createForeignKeysSql = new ArrayList<String>();
+ Iterator<Table> iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ String catalog = table.getCatalog();
+ String schema = table.getSchema();
+ Iterator<ForeignKey> subIter = table.getForeignKeyIterator();
+ while (subIter.hasNext()) {
+ ForeignKey fk = (ForeignKey) subIter.next();
+ if (fk.isPhysicalConstraint()) {
+ // collect the drop foreign key constraint sql
+ dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema));
+ // MySQLDialect creates an index for each foreign key.
+ // see
+ // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155
+ // This index should be dropped or an error will be thrown during
+ // the creation phase
+ if (dialect instanceof MySQLDialect) {
+ dropForeignKeysSql.add("alter table " + table.getName() + " drop key " + fk.getName());
+ }
+ // and collect the create foreign key constraint sql
+ createForeignKeysSql.add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema));
+ }
+ }
+ }
+ }
+
+ List<String> deleteSql = new ArrayList<String>();
+ iter = configuration.getTableMappings();
+ while (iter.hasNext()) {
+ Table table = (Table) iter.next();
+ if (table.isPhysicalTable()) {
+ 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
+ List<String> cleanSqlList = new ArrayList<String>();
+ cleanSqlList.addAll(dropForeignKeysSql);
+ cleanSqlList.addAll(deleteSql);
+ cleanSqlList.addAll(createForeignKeysSql);
+
+ cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]);
+
+ environmentFactory.set(CLEAN_SQL_KEY, cleanSql);
+ }
+
+ Session session = sessionFactory.openSession();
+ try {
+ for (String query : cleanSql) {
+ session.createSQLQuery(query).executeUpdate();
+ }
+ } finally {
+ session.close();
+ }
+ }
+
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/DbTestCase.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import org.jbpm.ExecutionService;
+import org.jbpm.ManagementService;
+import org.jbpm.ProcessService;
+import org.jbpm.cmd.CommandService;
+
+
+/** for tests that use persistence through a command service.
+ *
+ * The DB is cleaned inbetween tests. No environment is created.
+ *
+ * @author Tom Baeyens
+ */
+public abstract class DbTestCase extends EnvironmentFactoryTestCase {
+
+ protected CommandService commandService;
+ protected ProcessService processService;
+ protected ExecutionService executionService;
+ protected ManagementService managementService;
+
+ public DbTestCase() {
+ super();
+ }
+
+ public DbTestCase(String configResource) {
+ super(configResource);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ if (isEnvironmentFactoryCached()) {
+ Db.clean(getEnvironmentFactory());
+ }
+
+ commandService = getEnvironmentFactory().get(CommandService.class);
+ processService = getEnvironmentFactory().get(ProcessService.class);
+ executionService = getEnvironmentFactory().get(ExecutionService.class);
+ managementService = getEnvironmentFactory().get(ManagementService.class);
+ }
+
+ public void tearDown() throws Exception {
+ commandService = null;
+ processService = null;
+ executionService = null;
+ managementService = null;
+ super.tearDown();
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import java.lang.reflect.Field;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.jbpm.Execution;
+import org.jbpm.pvm.model.OpenProcessDefinition;
+import org.jbpm.pvm.session.DbSession;
+import org.jbpm.pvm.session.PvmDbSession;
+
+
+/** for tests that use persistence inside environment blocks.
+ *
+ * An environment is opened in the setUp and closed in the tearDown.
+ * DB is cleaned inbetween tests. Extra convenience methods for usage
+ * inside an environment block are provided.
+ *
+ * @author Tom Baeyens
+ */
+public class EnvironmentDbTestCase extends EnvironmentTestCase {
+
+ Transaction transaction = null;
+
+ public EnvironmentDbTestCase() {
+ }
+
+ public EnvironmentDbTestCase(String configResource) {
+ super(configResource);
+ }
+
+ public void setUp() throws Exception {
+ if (isEnvironmentFactoryCached()) {
+ Db.clean(getEnvironmentFactory());
+ }
+ super.setUp();
+ beginTransaction();
+ }
+
+ public void tearDown() throws Exception {
+ commitTransaction();
+ super.tearDown();
+ }
+
+ void beginTransaction() {
+ Session session = environment.get(Session.class);
+ transaction = session.beginTransaction();
+ }
+
+ void commitTransaction() {
+ transaction.commit();
+ transaction = null;
+ }
+
+ void rollbackTransaction() {
+ transaction.rollback();
+ transaction = null;
+ }
+
+ public DbSession getDbSession() {
+ return environment.get(DbSession.class);
+ }
+
+ public void rollbackAndBeginNewTransaction() {
+ rollbackTransaction();
+ closeEnvironment();
+ openEnvironment();
+ beginTransaction();
+ }
+
+ public void newTransaction() {
+ try {
+ commitTransaction();
+ closeEnvironment();
+ } finally {
+ openEnvironment();
+ beginTransaction();
+ }
+ }
+
+ public void beginCacheTest() {
+ SessionFactory sessionFactory = environment.get(SessionFactory.class);
+ if (sessionFactory != null) {
+ log.debug("=================================================================");
+ log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test");
+ log.debug("=================================================================");
+
+ sessionFactory.getStatistics().clear();
+ sessionFactory.getStatistics().setStatisticsEnabled(true);
+ }
+ }
+
+ public void endCacheTest() {
+ SessionFactory sessionFactory = environment.get(SessionFactory.class);
+ if (sessionFactory != null) {
+ assertEquals(0, sessionFactory.getStatistics().getEntityLoadCount());
+ assertEquals(0, sessionFactory.getStatistics().getCollectionLoadCount());
+ }
+ }
+
+ public <T> T reload(T object, Class<T> persistentClass) {
+ environment.get(DbSession.class).save(object);
+ newTransaction();
+
+ Long dbid = null;
+ try {
+ Field dbidField = persistentClass.getDeclaredField("dbid");
+ dbidField.setAccessible(true);
+ dbid = (Long) dbidField.get(object);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ new RuntimeException(e);
+ }
+
+ return environment.get(DbSession.class).get(persistentClass, dbid);
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.PvmException;
+import org.jbpm.pvm.env.EnvironmentFactory;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class EnvironmentFactoryTestCase extends JbpmTestCase {
+
+ String configResource;
+
+ static Map<String, EnvironmentFactory> environmentFactories = new HashMap<String, EnvironmentFactory>();
+
+ public EnvironmentFactoryTestCase() {
+ this("environment.cfg.xml");
+ }
+
+ public EnvironmentFactoryTestCase(String configResource) {
+ this.configResource = configResource;
+ }
+
+ public EnvironmentFactory getEnvironmentFactory() {
+ if (isEnvironmentFactoryCached()) {
+ return environmentFactories.get(configResource);
+ }
+ return createEnvironmentFactory();
+ }
+
+ boolean isEnvironmentFactoryCached() {
+ return environmentFactories.containsKey(configResource);
+ }
+
+ EnvironmentFactory createEnvironmentFactory() {
+ return createEnvironmentFactory(configResource);
+ }
+
+ static EnvironmentFactory createEnvironmentFactory(String configResource) {
+ try {
+ log.debug("creating environment factory for ["+configResource+"]");
+ EnvironmentFactory newEnvironmentFactory = new PvmEnvironmentFactory(configResource);
+ environmentFactories.put(configResource, newEnvironmentFactory);
+ return newEnvironmentFactory;
+ } catch (Exception e) {
+ throw new PvmException("Exception during creation of environment factory for "+configResource, e);
+ }
+ }
+
+ static void closeEnvironmentFactory(String configResource) {
+ EnvironmentFactory environmentFactory = environmentFactories.remove(configResource);
+ if (environmentFactory!=null) {
+ log.debug("closing environment factory for ["+configResource+"]");
+ environmentFactory.close();
+ }
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2007 Bull S. A. S.
+ * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
+ * This library is free software; you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Foundation
+ * version 2.1 of the License.
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301, USA.
+ **/
+package org.jbpm.test;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Guillaume Porcher
+ *
+ */
+public class EnvironmentFactoryTestSetup extends TestSetup
+{
+ private String configResource;
+
+ public EnvironmentFactoryTestSetup(Test test)
+ {
+ this(test, "environment.cfg.xml");
+ }
+
+ public EnvironmentFactoryTestSetup(Class<?> testClass)
+ {
+ this(new TestSuite(testClass), "environment.cfg.xml");
+ }
+
+ public EnvironmentFactoryTestSetup(Test test, String configResource)
+ {
+ super(test);
+ this.configResource = configResource;
+ }
+
+ public EnvironmentFactoryTestSetup(Class<?> testClass, String configResource)
+ {
+ super(new TestSuite(testClass));
+ this.configResource = configResource;
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ EnvironmentFactoryTestCase.createEnvironmentFactory(configResource);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ EnvironmentFactoryTestCase.closeEnvironmentFactory(configResource);
+ super.tearDown();
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/EnvironmentTestCase.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import org.jbpm.pvm.env.Environment;
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class EnvironmentTestCase extends EnvironmentFactoryTestCase {
+
+ protected Environment environment;
+
+ public EnvironmentTestCase() {
+ }
+
+ public EnvironmentTestCase(String configResource) {
+ super(configResource);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ openEnvironment();
+ }
+
+ public void tearDown() throws Exception {
+ closeEnvironment();
+ super.tearDown();
+ }
+
+ void closeEnvironment() {
+ environment.close();
+ environment = null;
+ }
+
+ void openEnvironment() {
+ environment = getEnvironmentFactory().openEnvironment();
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java (from rev 2701, jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/test/JbpmTestCase.java)
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java (rev 0)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java 2008-10-31 16:07:13 UTC (rev 2705)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.test;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.jbpm.log.Jdk14LogFactory;
+import org.jbpm.log.Log;
+import org.jbpm.log.LogFormatter;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.EnvironmentFactory;
+import org.jbpm.pvm.env.PvmEnvironmentFactory;
+
+public abstract class JbpmTestCase extends TestCase {
+
+ static {
+ Jdk14LogFactory.initializeJdk14Logging();
+ }
+
+ static protected Log log = Log.getLog(JbpmTestCase.class.getName());
+
+ public void setUp() throws Exception {
+ assertNull(Environment.getCurrent());
+ LogFormatter.resetIndentation();
+ log.info("=== starting "+getName()+" =============================");
+ }
+
+ public void tearDown() throws Exception {
+ log.info("=== ending "+getName()+" =============================\n");
+ assertNull(Environment.getCurrent());
+ }
+
+ public void assertTextPresent(String expected, String value) {
+ if ( (value==null)
+ || (value.indexOf(expected)==-1)
+ ) {
+ throw new AssertionFailedError("expected presence of '"+expected+"' but was '"+value+"'");
+ }
+ }
+
+ public static Environment openEnvironment(String xmlString) {
+ EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(xmlString);
+ return environmentFactory.openEnvironment();
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ super.runTest();
+ } catch (AssertionFailedError e) {
+ log.error("");
+ log.error("ASSERTION FAILURE: "+e.getMessage());
+ log.error("");
+ throw e;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ throw t;
+ }
+ }
+}
Property changes on: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
___________________________________________________________________
Name: svn:mergeinfo
+
More information about the jbpm-commits
mailing list