JBoss JBPM SVN: r6384 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/activity/custom and 1 other directory.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-05-31 15:40:03 -0400 (Mon, 31 May 2010)
New Revision: 6384
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeActivityBehaviour.java
Log:
JBPM-2495: history for custom activities is now persisted.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeActivityBehaviour.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeActivityBehaviour.java 2010-05-31 08:21:34 UTC (rev 6383)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/usercode/UserCodeActivityBehaviour.java 2010-05-31 19:40:03 UTC (rev 6384)
@@ -26,6 +26,7 @@
import org.jbpm.api.activity.ActivityBehaviour;
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.activity.ExternalActivityBehaviour;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
/**
* @author Tom Baeyens
@@ -39,6 +40,7 @@
public void execute(ActivityExecution execution) throws Exception {
ActivityBehaviour activityBehaviour = (ActivityBehaviour) customActivityReference.getObject(execution);
activityBehaviour.execute(execution);
+ ((ExecutionImpl)execution).historyAutomatic();
}
public void signal(ActivityExecution execution, String signalName, Map<String, ? > parameters) throws Exception {
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/custom/CustomHistoryTest.java 2010-05-31 19:40:03 UTC (rev 6384)
@@ -0,0 +1,77 @@
+/*
+ * 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.activity.custom;
+
+import java.util.List;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.activity.ActivityBehaviour;
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.history.HistoryActivityInstance;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * @author Maciej Swiderski
+ *
+ */
+public class CustomHistoryTest extends JbpmTestCase {
+
+ public static class MyCustomAutomatic implements ActivityBehaviour {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.takeDefaultTransition();
+ }
+ }
+
+ public void testCustomAutomaticClass() {
+ deployJpdlXmlString(
+ "<process name='CustomClass'>" +
+ " <start>" +
+ " <transition to='c' />" +
+ " </start>" +
+ " <custom name='c' class='"+MyCustomAutomatic.class.getName()+"'>" +
+ " <transition to='wait' />" +
+ " </custom>" +
+ " <state name='wait'>" +
+ " <transition to='end' />" +
+ " </state>" +
+ " <end name='end'/>" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("CustomClass");
+
+ assertTrue(processInstance.findActiveActivityNames().contains("wait"));
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+
+ assertProcessInstanceEnded(processInstance);
+
+ List<HistoryActivityInstance> histActivities = historyService.createHistoryActivityInstanceQuery().processInstanceId(processInstance.getId()).list();
+
+ assertEquals(2, histActivities.size());
+ assertEquals("c", histActivities.get(0).getActivityName());
+ assertEquals("wait", histActivities.get(1).getActivityName());
+ }
+
+}
13 years, 11 months
JBoss JBPM SVN: r6383 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/parser and 9 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-05-31 04:21:34 -0400 (Mon, 31 May 2010)
New Revision: 6383
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TypesBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ClassDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/CollectionDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateConfigurationDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/BindingParser.java
Log:
JBPM-2875 using ReflectUtil.classForName() to do the find class job. this method comes from hibernate.
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Configuration.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -29,16 +29,16 @@
/**
* process engine configuration.
- *
+ *
* @author Tom Baeyens
*/
public class Configuration {
/** singletone instance */
private static ProcessEngine singleton;
-
+
transient Configuration impl;
-
+
/** default constructor */
public Configuration() {
impl = instantiate("org.jbpm.pvm.internal.cfg.ConfigurationImpl");
@@ -51,7 +51,12 @@
protected Configuration instantiate(String className) {
Configuration implementation;
try {
- Class<?> implementationClass = Class.forName(className, true, getClassLoader());
+ Class<?> implementationClass = null;
+ try {
+ implementationClass = Class.forName(className, true, getClassLoader());
+ } catch(ClassNotFoundException ex) {
+ implementationClass = Class.forName(className);
+ }
implementation = (Configuration) implementationClass.newInstance();
} catch (Exception e) {
throw new JbpmException("couldn't instantiate configuration of type "+className, e);
@@ -99,26 +104,26 @@
return impl;
}
- /** after specifying the configuration resources with the other methods, a
+ /** after specifying the configuration resources with the other methods, a
* process engine can be created. */
public ProcessEngine buildProcessEngine() {
return impl.buildProcessEngine();
}
-
+
/** provides the hibernate session factory programmatically.
- * The hibernateSessionFactory parameter is of type Object to
+ * The hibernateSessionFactory parameter is of type Object to
* prevent a dependency of the API on hibernate directly.*/
public Configuration setHibernateSessionFactory(Object hibernateSessionFactory){
return impl.setHibernateSessionFactory(hibernateSessionFactory);
}
-
- /** get the singleton ProcessEngine that is created from the default
+
+ /** get the singleton ProcessEngine that is created from the default
* configuration file 'jbpm.cfg.xml'. */
public static ProcessEngine getProcessEngine() {
if (singleton == null) {
synchronized (Configuration.class) {
if (singleton == null) {
- singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
+ singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
}
}
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -59,8 +59,7 @@
if (bindingClassName != null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class< ? > bindingClass = Class.forName(bindingClassName, true, classLoader);
+ Class<?> bindingClass = ReflectUtil.classForName(bindingClassName);
return (Binding) bindingClass.newInstance();
} catch (Exception e) {
parse.addProblem("couldn't instantiate activity binding " + bindingClassName, e);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaActivity.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -27,6 +27,7 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.model.OpenExecution;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireDefinition;
import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
@@ -49,7 +50,7 @@
protected String variableName;
protected String jndiName;
-
+
public void perform(OpenExecution execution) throws Exception {
Object target = null;
@@ -60,7 +61,7 @@
} else {
throw new JbpmException("no target specified");
}
-
+
Class<?> clazz;
// method invocation on object or static method invocation in case object is null
if (target!=null) {
@@ -68,18 +69,17 @@
} else {
ObjectDescriptor objectDescriptor = (ObjectDescriptor) invocationReference.getDescriptor();
String className = objectDescriptor.getClassName();
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- clazz = Class.forName(className, true, classLoader);
+ clazz = ReflectUtil.classForName(className);
}
-
+
WireContext wireContext = new WireContext(new WireDefinition());
Object returnValue = ObjectDescriptor.invokeMethod(methodName, argDescriptors, wireContext, target, clazz);
-
+
if (variableName!=null) {
execution.setVariable(variableName, returnValue);
}
}
-
+
public void setInvocationReference(UserCodeReference invocationReference) {
this.invocationReference = invocationReference;
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -22,6 +22,7 @@
package org.jbpm.jpdl.internal.xml;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.util.TagBinding;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Binding;
@@ -36,30 +37,29 @@
public class JpdlBindingsParser extends Parser {
private static final Log log = Log.getLog(JpdlBindingsParser.class.getName());
-
+
public Object parseDocumentElement(Element documentElement, Parse parse) {
Bindings bindings = (Bindings) parse.contextMapGet(Parse.CONTEXT_KEY_BINDINGS);
parse.setDocumentObject(bindings);
-
+
for (Element bindingElement : XmlUtil.elements(documentElement)) {
Binding binding = instantiateBinding(bindingElement, parse);
bindings.addBinding(binding);
}
-
+
return bindings;
}
protected Binding instantiateBinding(Element bindingElement, Parse parse) {
String bindingClassName = XmlUtil.attribute(bindingElement, "binding", true, parse);
-
+
log.trace("adding jpdl binding "+bindingClassName);
-
+
if (bindingClassName!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> bindingClass = Class.forName(bindingClassName, true, classLoader);
+ Class<?> bindingClass = ReflectUtil.classForName(bindingClassName);
TagBinding binding = (TagBinding) bindingClass.newInstance();
-
+
String tagLocalName = XmlUtil.getTagLocalName(bindingElement);
if ("activity".equals(tagLocalName)) {
binding.setCategory(JpdlParser.CATEGORY_ACTIVITY);
@@ -68,7 +68,7 @@
} else {
parse.addProblem("unrecognized binding tag: "+tagLocalName);
}
-
+
return binding;
} catch (Exception e) {
parse.addProblem("couldn't instantiate activity binding "+bindingClassName, e);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -34,16 +34,17 @@
import org.hibernate.usertype.ParameterizedType;
import org.jbpm.api.JbpmException;
import org.jbpm.pvm.internal.type.Converter;
+import org.jbpm.pvm.internal.util.ReflectUtil;
/**
* @author Tom Baeyens
*/
public class ConverterType extends ImmutableType implements ParameterizedType {
-
+
private static final long serialVersionUID = 1L;
private static Map<Class<?>, String> converterNames = null;
private static Map<String, Converter> converters = null;
-
+
public Object fromStringValue(String arg0) throws HibernateException {
return null;
}
@@ -77,21 +78,12 @@
public void setParameterValues(Properties properties) {
converterNames = new HashMap<Class<?>, String>();
converters = new HashMap<String, Converter>();
-
+
for(Object key : properties.keySet()) {
String converterClassName = (String) key;
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class< ? > converterClass = null;
- try {
- converterClass = Class.forName(converterClassName, true, classLoader);
- } catch (ClassNotFoundException e) {
- // when running jBPM from ant, the context classloader is not set properly
- // so the jBPM classloader is necessary as a fallback
- classLoader = getClass().getClassLoader();
- converterClass = Class.forName(converterClassName, true, classLoader);
- }
-
+ Class< ? > converterClass = ReflectUtil.classForName(converterClassName);
+
String converterName = properties.getProperty(converterClassName);
converterNames.put(converterClass, converterName);
Converter converter = (Converter) converterClass.newInstance();
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -26,9 +26,11 @@
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
+import org.jbpm.pvm.internal.util.ReflectUtil;
+
/**
* Helper class responsible for providing classes while deserializing variables.
- *
+ *
* @author Maciej Swiderski swiderski.maciej(a)gmail.com
*/
public class DeploymentObjectInputStream extends ObjectInputStream {
@@ -44,12 +46,12 @@
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
ClassNotFoundException {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
- return Class.forName(desc.getName(), false, contextClassLoader);
+ return ReflectUtil.classForName(desc.getName());
}
catch (ClassNotFoundException e) {
// trying to get it from deployment
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader deploymentClassLoader =
new DeploymentClassLoader(contextClassLoader, deploymentId);
return Class.forName(desc.getName(), false, deploymentClassLoader);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -51,6 +51,7 @@
import javax.script.SimpleBindings;
import org.jbpm.pvm.internal.env.ExecutionContext;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import de.odysseus.el.util.SimpleResolver;
@@ -155,7 +156,7 @@
}
};
-
+
ctx.setAttribute("elcontext", elContext, 100);
return elContext;
@@ -286,7 +287,7 @@
{
try
{
- clazz = Class.forName((String)obj);
+ clazz = ReflectUtil.classForName((String) obj);
}
catch (ClassNotFoundException cnfe)
{
@@ -340,7 +341,7 @@
private class ScriptContextFunctionMapper extends FunctionMapper
{
- private ScriptContext ctx;
+ private ScriptContext ctx;
ScriptContextFunctionMapper(ScriptContext ctx)
{
@@ -397,7 +398,7 @@
// to support null value for existing variables
Bindings b = this.ctx.getBindings(ScriptContext.ENGINE_SCOPE);
ExecutionContext execContext = (ExecutionContext) ((EnvironmentBindings) b).environment.getContext("execution");
- // if variable name exist then set value expression as null
+ // if variable name exist then set value expression as null
// since it was not discovered by attribute scope method
if (execContext.getExecution().getVariables().containsKey(variable)) {
return exprFactory.createValueExpression(null, Object.class);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -21,7 +21,7 @@
import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
public class ReflectUtil {
-
+
private ReflectUtil() {
// hide default constructor to prevent instantiation
}
@@ -66,7 +66,7 @@
throw new JbpmException("couldn't find field '"+original.getName()+"."+fieldName+"'", e);
}
}
-
+
return field;
}
@@ -77,10 +77,10 @@
private static Method getMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes, Class<?> original) {
Method method = null;
-
+
try {
method = clazz.getDeclaredMethod(methodName, parameterTypes);
-
+
if (log.isTraceEnabled()) log.trace("found method "+clazz.getName()+"."+methodName+"("+Arrays.toString(parameterTypes)+")");
} catch (SecurityException e) {
@@ -92,7 +92,7 @@
throw new JbpmException("couldn't find method '"+original.getName()+"."+methodName+"("+getParameterTypesText(parameterTypes)+")'", e);
}
}
-
+
return method;
}
@@ -118,7 +118,7 @@
public static <T> T newInstance(Constructor<T> constructor, Object[] args) {
return newInstance(null, constructor, args);
}
-
+
private static <T> T newInstance(Class<T> clazz, Constructor<T> constructor, Object[] args) {
if ( (clazz==null)
&& (constructor==null)
@@ -142,7 +142,7 @@
throw new JbpmException("couldn't construct new '"+clazz.getName()+"' with args "+Arrays.toString(args), t);
}
}
-
+
public static Object get(Field field, Object object) {
if (field==null) {
throw new NullPointerException("field is null");
@@ -171,7 +171,7 @@
throw new JbpmException("couldn't set '"+field.getName()+"' to '"+value+"'", e);
}
}
-
+
public static Object invoke(Method method, Object target, Object[] args) {
if (method==null) {
throw new JbpmException("method is null");
@@ -203,7 +203,7 @@
if (log.isTraceEnabled()) {
if (log.isTraceEnabled()) log.trace("found matching method "+clazz.getName()+"."+methodName);
}
-
+
return candidate;
}
}
@@ -226,15 +226,15 @@
public static boolean isArgumentMatch(Class<?>[] parameterTypes, List<ArgDescriptor> argDescriptors, Object[] args) {
int nbrOfArgs = args!=null ? args.length : 0;
int nbrOfParameterTypes = parameterTypes!=null ? parameterTypes.length : 0;
-
+
if (nbrOfArgs!=nbrOfParameterTypes) {
return false;
}
-
+
if (nbrOfArgs==0) {
return true;
}
-
+
for (int i=0; i<parameterTypes.length; i++) {
Class<?> parameterType = parameterTypes[i];
String argTypeName;
@@ -364,7 +364,7 @@
if ( (argDescriptor!=null)
&& (argDescriptor.getTypeName()!=null)
) {
- argType = argDescriptor.getTypeName();
+ argType = argDescriptor.getTypeName();
}
}
if ( (argType==null)
@@ -381,7 +381,7 @@
signature+=")";
return signature;
}
-
+
public static String getUnqualifiedClassName(Class<?> clazz) {
if (clazz==null) {
return null;
@@ -409,15 +409,15 @@
Thread currentThread = Thread.currentThread();
ClassLoader original = currentThread.getContextClassLoader();
- RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
+ RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
DeploymentClassLoader deploymentClassLoader = repositoryCache.getDeploymentClassLoader(deploymentId, original);
if (deploymentClassLoader==null) {
deploymentClassLoader = new DeploymentClassLoader(original, deploymentId);
repositoryCache.setDeploymentClassLoader(deploymentId, original, deploymentClassLoader);
}
-
+
currentThread.setContextClassLoader(deploymentClassLoader);
-
+
return original;
}
@@ -426,7 +426,7 @@
Thread.currentThread().setContextClassLoader(original);
}
}
-
+
public static Object instantiateUserCode(Descriptor descriptor, ProcessDefinitionImpl processDefinition, ScopeInstanceImpl scopeInstance) {
ClassLoader classLoader = ReflectUtil.installDeploymentClassLoader(processDefinition);
try {
@@ -435,4 +435,26 @@
ReflectUtil.uninstallDeploymentClassLoader(classLoader);
}
}
+
+ /**
+ * Perform resolution of a class name.
+ * <p/>
+ * Same as {@link #classForName(String, Class)} except that here we delegate to
+ * {@link Class#forName(String)} if the context classloader lookup is unsuccessful.
+ *
+ * @param name The class name
+ * @return The class reference.
+ * @throws ClassNotFoundException From {@link Class#forName(String)}.
+ */
+ public static Class classForName(String name) throws ClassNotFoundException {
+ try {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (contextClassLoader != null) {
+ return contextClassLoader.loadClass(name);
+ }
+ }
+ catch (Throwable ignore) {
+ }
+ return Class.forName(name);
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.descriptor.CollectionDescriptor;
@@ -19,19 +20,19 @@
public Object parse(Element element, Parse parse, Parser parser) {
CollectionDescriptor descriptor = createDescriptor();
-
+
String className = XmlUtil.attribute(element,"class");
-
+
// verify if the given classname is specified and implements the collection interface
if (verify(className, getCollectionInterface(), parse, parser)) {
descriptor.setClassName(className);
}
-
+
Boolean isSynchronized = XmlUtil.attributeBoolean(element, "synchronized", false, parse);
if (isSynchronized!=null) {
descriptor.setSynchronized(isSynchronized.booleanValue());
}
-
+
List<Descriptor> valueDescriptors = new ArrayList<Descriptor>();
List<Element> elements = XmlUtil.elements(element);
for (Element valueElement: elements) {
@@ -53,9 +54,8 @@
}
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> collectionClass = Class.forName(className, true, classLoader);
-
+ Class<?> collectionClass = ReflectUtil.classForName(className);
+
if (collectionInterface.isAssignableFrom(collectionClass)) {
return true;
} else {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ScriptManagerBinding.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -48,7 +48,7 @@
public Object parse(Element element, Parse parse, Parser parser) {
ObjectDescriptor descriptor = new ObjectDescriptor(ScriptManager.class);
-
+
if (element.hasAttribute("default-expression-language")) {
String defaultLanguage = element.getAttribute("default-expression-language");
descriptor.addInjection("defaultExpressionLanguage", new StringDescriptor(defaultLanguage));
@@ -74,13 +74,12 @@
} else {
parse.addProblem("'name' is a required attribute in element <script-language />", element);
}
-
+
if ( (languageName!=null)
&& (factoryClassName!=null)
) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> factoryClass = Class.forName(factoryClassName, true, classLoader);
+ Class<?> factoryClass = ReflectUtil.classForName(factoryClassName);
ScriptEngineFactory scriptEngineFactory = (ScriptEngineFactory) factoryClass.newInstance();
scriptEngineManager.registerEngineName(languageName, scriptEngineFactory);
} catch (Exception e) {
@@ -88,9 +87,9 @@
}
}
}
-
+
descriptor.addInjection("scriptEngineManager", new ProvidedObjectDescriptor(scriptEngineManager));
-
+
return descriptor;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TypesBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TypesBinding.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TypesBinding.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -37,6 +37,7 @@
import org.jbpm.pvm.internal.type.matcher.HibernateLongIdMatcher;
import org.jbpm.pvm.internal.type.matcher.HibernateStringIdMatcher;
import org.jbpm.pvm.internal.type.matcher.SerializableMatcher;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
@@ -46,13 +47,13 @@
import org.w3c.dom.Element;
/** parses a descriptor for Boolean.TRUE.
- *
+ *
* See schema docs for more details.
*
* @author Tom Baeyens
*/
public class TypesBinding extends WireDescriptorBinding {
-
+
public TypesBinding() {
super("types");
}
@@ -69,14 +70,14 @@
parse.addProblem("file "+fileName+" isn't a file", element);
}
}
-
+
if (element.hasAttribute("resource")) {
String resource = element.getAttribute("resource");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
streamSource = new ResourceStreamInput(resource, classLoader);
parser.importStream(streamSource, element, parse);
}
-
+
if (element.hasAttribute("url")) {
String urlText = element.getAttribute("url");
try {
@@ -87,9 +88,9 @@
parse.addProblem("couldn't open url "+urlText, e);
}
}
-
+
TypesDescriptor typesDescriptor = new TypesDescriptor();
-
+
List<Element> typeElements = XmlUtil.elements(element, "type");
for (Element typeElement: typeElements) {
TypeMapping typeMapping = parseTypeMapping(typeElement, parse, parser);
@@ -102,31 +103,31 @@
TypeMapping typeMapping = new TypeMapping();
Type type = new Type();
typeMapping.setType(type);
-
+
// type name
if (element.hasAttribute("name")) {
type.setName(element.getAttribute("name"));
}
-
+
String hibernateSessionFactoryName = XmlUtil.attribute(element, "hibernate-session-factory");
-
+
// first we get the matcher
Matcher matcher = null;
if (element.hasAttribute("class")) {
String className = element.getAttribute("class");
-
+
// if type="serializable"
if ("serializable".equals(className)) {
matcher = new SerializableMatcher();
-
+
// if type="hibernatable"
} else if ("hibernatable".equals(className)) {
if (element.hasAttribute("id-type")) {
String idType = element.getAttribute("id-type");
if ("long".equalsIgnoreCase(idType)) {
- matcher = new HibernateLongIdMatcher(hibernateSessionFactoryName);
+ matcher = new HibernateLongIdMatcher(hibernateSessionFactoryName);
} else if ("string".equalsIgnoreCase(idType)) {
- matcher = new HibernateStringIdMatcher(hibernateSessionFactoryName);
+ matcher = new HibernateStringIdMatcher(hibernateSessionFactoryName);
} else {
parse.addProblem("id-type was not 'long' or 'string': "+idType, element);
}
@@ -157,13 +158,12 @@
typeMapping.setMatcher(matcher);
- // parsing the converter
+ // parsing the converter
Converter converter = null;
if (element.hasAttribute("converter")) {
String converterClassName = element.getAttribute("converter");
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> converterClass = Class.forName(converterClassName, true, classLoader);
+ Class<?> converterClass = ReflectUtil.classForName(converterClassName);
converter = (Converter) converterClass.newInstance();
} catch (Exception e) {
parse.addProblem("couldn't instantiate converter "+converterClassName, element);
@@ -178,19 +178,18 @@
} catch (ClassCastException e) {
parse.addProblem("converter is not a "+Converter.class.getName()+": "+(converter!=null ? converter.getClass().getName() : "null"), element);
}
- }
+ }
}
type.setConverter(converter);
-
+
// parsing the variable class
-
+
Class<?> variableClass = null;
if (element.hasAttribute("variable-class")) {
- String variableClassName = element.getAttribute("variable-class");
+ String variableClassName = element.getAttribute("variable-class");
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- variableClass = Class.forName(variableClassName, true, classLoader);
+ variableClass = ReflectUtil.classForName(variableClassName);
} catch (Exception e) {
parse.addProblem("couldn't instantiate variable-class "+variableClassName, e);
}
@@ -199,7 +198,7 @@
}
type.setVariableClass(variableClass);
-
+
return typeMapping;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ClassDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ClassDescriptor.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ClassDescriptor.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -1,10 +1,11 @@
package org.jbpm.pvm.internal.wire.descriptor;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireException;
/** loads the class with the specified class name using the WireContext class loader.
- *
+ *
* @see WireContext#getClassLoader()
*
* @author Tom Baeyens
@@ -21,8 +22,7 @@
*/
public Object construct(WireContext wireContext) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- return Class.forName(text, true, classLoader);
+ return ReflectUtil.classForName(text);
} catch (Exception e) {
Throwable cause = (e.getCause()!=null ? e.getCause() : e);
throw new WireException("couldn't load class '"+text+"': "+cause.getMessage(), cause);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/CollectionDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/CollectionDescriptor.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/CollectionDescriptor.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -10,6 +10,7 @@
import java.util.SortedSet;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireException;
@@ -23,13 +24,13 @@
private static final long serialVersionUID = 1L;
private static Log log = Log.getLog(CollectionDescriptor.class.getName());
-
+
protected String className;
protected List<Descriptor> valueDescriptors;
protected boolean isSynchronized;
protected CollectionDescriptor() { }
-
+
public CollectionDescriptor(String defaultImplClassName) {
this.className = defaultImplClassName;
}
@@ -38,10 +39,9 @@
Object object = null;
try {
// instantiate
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = Class.forName(className, true, classLoader);
+ Class<?> clazz = ReflectUtil.classForName(className);
object = clazz.newInstance();
-
+
if (isSynchronized) {
if (object instanceof SortedSet) {
object = Collections.synchronizedSortedSet((SortedSet) object);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateConfigurationDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateConfigurationDescriptor.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/HibernateConfigurationDescriptor.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -57,8 +57,7 @@
if (className!=null) {
try {
log.trace("instantiating hibernate configuration class "+className);
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> configurationClass = Class.forName(className, true, classLoader);
+ Class<?> configurationClass = ReflectUtil.classForName(className);
configuration = (Configuration) ReflectUtil.newInstance(configurationClass);
} catch (Exception e) {
throw new JbpmException("couldn't instantiate hibernate configuration class "+className, e);
@@ -95,15 +94,14 @@
public Class<?> getType(WireDefinition wireDefinition) {
if (className!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- return Class.forName(className, true, classLoader);
+ return ReflectUtil.classForName(className);
} catch (Exception e) {
throw new WireException("couldn't create hibernate configuration '"+className+"': "+e.getMessage(), e.getCause());
}
}
return Configuration.class;
}
-
+
public void addCfgResource(String cfgResource) {
cfgOperations.add(new AddCfgResource(cfgResource));
}
@@ -231,8 +229,7 @@
public void apply(Object target, WireContext wireContext) {
Configuration configuration = (Configuration) target;
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> persistentClass = Class.forName(className, true, classLoader);
+ Class<?> persistentClass = ReflectUtil.classForName(className);
configuration.addClass(persistentClass);
} catch (Exception e) {
throw new JbpmException("couldn't add mapping for class "+className, e);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -97,7 +97,7 @@
String factoryObjectName = null;
protected Expression expression;
-
+
/** specifies the object on which to invoke the method.
* Either className, objectName or a descriptor has to be specified. */
protected Descriptor factoryDescriptor = null;
@@ -111,7 +111,7 @@
/** True if autowiring is enabled. */
protected boolean isAutoWireEnabled = false;
-
+
public ObjectDescriptor() {
}
@@ -138,8 +138,7 @@
if (className!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- clazz = Class.forName(className, true, classLoader);
+ clazz = ReflectUtil.classForName(className);
} catch (Exception e) {
throw new JbpmClassNotFoundException("couldn't load class "+className, e);
}
@@ -239,13 +238,12 @@
public Class<?> getType(WireDefinition wireDefinition) {
if (className!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- return Class.forName(className, true, classLoader);
+ return ReflectUtil.classForName(className);
} catch (Exception e) {
throw new WireException("couldn't load class '"+className+"'", e);
}
}
-
+
Descriptor descriptor = null;
if (factoryDescriptor!=null) {
descriptor = factoryDescriptor;
@@ -258,14 +256,14 @@
if (factoryClass!=null) {
Method method = ReflectUtil.findMethod(factoryClass, methodName, argDescriptors, null);
if (method!=null) {
- return method.getReturnType();
+ return method.getReturnType();
}
}
}
return null;
}
-
+
/**
* Auto wire object present in the context and the specified object's fields.
* @param object object on which auto-wiring is performed.
@@ -294,20 +292,20 @@
autoWireValue = wireContext.get(fieldName);
} else {
- autoWireValue = wireContext.get(fieldType);
+ autoWireValue = wireContext.get(fieldType);
}
- // if auto wire value has not been found in current context,
+ // if auto wire value has not been found in current context,
// search in environment
if (autoWireValue == null) {
EnvironmentImpl currentEnvironment = EnvironmentImpl.getCurrent();
if (currentEnvironment != null) {
- autoWireValue = currentEnvironment.get(fieldName);
+ autoWireValue = currentEnvironment.get(fieldName);
if (autoWireValue == null) {
autoWireValue = currentEnvironment.get(fieldType);
}
}
}
-
+
if (autoWireValue!=null) {
try {
if (log.isTraceEnabled()) log.trace("auto wiring field "+fieldName+" in "+name);
@@ -376,7 +374,7 @@
}
operations.add(operation);
}
-
+
/** convenience method to add a type based field injection */
public void addTypedInjection(String fieldName, Class<?> type) {
addInjection(fieldName, new EnvDescriptor(type));
@@ -401,7 +399,7 @@
// getters and setters //////////////////////////////////////////////////////
-
+
public String getClassName() {
return className;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ReferenceDescriptor.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -1,6 +1,7 @@
package org.jbpm.pvm.internal.wire.descriptor;
import org.jbpm.api.JbpmException;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
@@ -37,8 +38,7 @@
return wireContext.get(text, isDelayedInitializationAllowed());
} else if (type!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> clazz = Class.forName(type, true, classLoader);
+ Class<?> clazz = ReflectUtil.classForName(type);
return wireContext.get(clazz);
} catch (Exception e) {
throw new JbpmException("couldn't load "+type, e);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/BindingParser.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/BindingParser.java 2010-05-30 18:53:44 UTC (rev 6382)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/BindingParser.java 2010-05-31 08:21:34 UTC (rev 6383)
@@ -24,6 +24,7 @@
import java.util.List;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.util.ReflectUtil;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Binding;
import org.jbpm.pvm.internal.xml.Bindings;
@@ -32,21 +33,20 @@
import org.w3c.dom.Element;
public class BindingParser extends Parser {
-
+
private static final Log log = Log.getLog(BindingParser.class.getName());
public Object parseDocumentElement(Element documentElement, Parse parse) {
List<Element> elements = XmlUtil.elements(documentElement, "binding");
for (Element bindingElement : elements) {
String bindingClassName = XmlUtil.attribute(bindingElement, "class");
-
+
log.trace("adding wire binding for "+bindingClassName);
Binding binding = null;
if (bindingClassName!=null) {
try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- Class<?> bindingClass = Class.forName(bindingClassName, true, classLoader);
+ Class<?> bindingClass = ReflectUtil.classForName(bindingClassName);
binding = (Binding) bindingClass.newInstance();
} catch (Exception e) {
log.trace("couldn't instantiate binding "+bindingClassName);
@@ -54,13 +54,13 @@
} else {
parse.addProblem("class is a required attribute in a binding "+XmlUtil.toString(bindingElement), documentElement);
}
-
+
if (binding!=null) {
Bindings bindings = parse.contextStackFind(Bindings.class);
bindings.addBinding(binding);
}
}
-
+
return null;
}
}
13 years, 11 months
JBoss JBPM SVN: r6382 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/model and 1 other directories.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-05-30 14:53:44 -0400 (Sun, 30 May 2010)
New Revision: 6382
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessSignalTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
Log:
JBPM-2874: exposed subProcessInstance via Execution interface and ensure that signal cannot be mode on process instance that has active subprocess + test case
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2010-05-28 06:19:37 UTC (rev 6381)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/Execution.java 2010-05-30 18:53:44 UTC (rev 6382)
@@ -184,6 +184,12 @@
* structure</a>. Null will be returned in case this execution itself is the
* main execution path. */
Execution getProcessInstance();
+
+ /**
+ * the sub path of execution in the <a href="package-summary.html#basicexecutionstructure">execution
+ * structure</a>. Null will be returned in case there is no sub process execution.
+ */
+ Execution getSubProcessInstance();
/** the parent execution in the <a href="package-summary.html#basicexecutionstructure">execution
* structure</a>. Null will be returned in case this execution itself is the
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-05-28 06:19:37 UTC (rev 6381)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-05-30 18:53:44 UTC (rev 6382)
@@ -1069,6 +1069,9 @@
protected void checkActive() {
if (!isActive()) {
throw new JbpmException(toString()+" is not active: "+state);
+ } else if (this.subProcessInstance != null && !Execution.STATE_ENDED.equals(this.subProcessInstance.getState())) {
+ throw new JbpmException(toString() + " has running subprocess: "
+ + this.subProcessInstance.toString() + " in state " + this.subProcessInstance.getState());
}
}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessSignalTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessSignalTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessSignalTest.java 2010-05-30 18:53:44 UTC (rev 6382)
@@ -0,0 +1,125 @@
+/*
+ * 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.activity.subprocess;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * Test case for signal of subprocess state activities.
+ *
+ * @author Maciej Swiderski
+ */
+public class SubProcessSignalTest extends JbpmTestCase {
+
+
+
+ private static final String SUB_PROCESS_WITH_WAIT_STATE =
+ "<process name='SubProcessReview'>" +
+ " <start>" +
+ " <transition to='wait'/>" +
+ " </start>" +
+ " <state name='wait'>" +
+ " <transition name='wait2' to='wait2'/>" +
+ " </state>" +
+ " <state name='wait2'>" +
+ " <transition name='ok' to='ok'/>" +
+ " </state>" +
+ " <end name='ok' />" +
+ "</process>";
+
+
+
+ private static final String MAIN_PROCESS_SUB_EL_ID =
+ "<process name='mainProcess'>" +
+ " <!
start>" +
+ " <transition to='review' />" +
+ " </st!
art>" +
+ " <sub-process name='review' sub-process-id='#{dynamic_subprocess}'>" +
+ " <transition name='ok' to='next step'/>" +
+ " <transition name='nok' to='update'/>" +
+ " <transition name='reject' to='close'/>" +
+ " </sub-process>" +
+ " <state name='next step'>" +
+ " <transition name='close' to='close'/>" +
+ " </state>" +
+ " <state name='update'>" +
+ " <transition name='close' to='close'/>" +
+ " </state>" +
+ " <end name='close'/>" +
+ "</process>";
+
+
+ public void testSubProcessWithStateFailure() {
+ deployJpdlXmlString(SUB_PROCESS_WITH_WAIT_STATE);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL_ID);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("dynamic_subprocess", "SubProcessReview-1");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess", vars);
+
+ try {
+ processInstance = executionService.signalExecut!
ionById(processInstance.getId());
+
+ fail("Should fail since signal was made on a process with subprocess stil active");
+ } catch (Exception e) {
+
+ //expected exception since we are signaling main process while sub process is not finished
+ assertTrue(e.getMessage().indexOf("has running subprocess") != -1);
+
+ // clean up to let other tests execute
+ executionService.signalExecutionById(processInstance.getSubProcessInstance().getId());
+ executionService.signalExecutionById(processInstance.getSubProcessInstance().getId());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+
+ }
+
+ }
+
+ public void testSubProcessWithStateSuccess() {
+ deployJpdlXmlString(SUB_PROCESS_WITH_WAIT_STATE);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL_ID);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("dynamic_subprocess", "SubPr!
ocessReview-1");
+
+ ProcessInstance processInstance = e!
xecution
Service.startProcessInstanceByKey("mainProcess", vars);
+ String subId = processInstance.getSubProcessInstance().getId();
+ executionService.signalExecutionById(processInstance.getSubProcessInstance().getId());
+ executionService.signalExecutionById(processInstance.getSubProcessInstance().getId());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+
+ assertProcessInstanceEnded(processInstance);
+ ProcessInstance subProcessInstance = executionService.findProcessInstanceById(subId);
+ assertNull(subProcessInstance);
+
+ }
+
+}
13 years, 11 months
JBoss JBPM SVN: r6381 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/xml and 2 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-05-28 02:19:37 -0400 (Fri, 28 May 2010)
New Revision: 6381
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/stream/ResourceStreamInput.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java
Log:
JBPM-2875 enhance classloader for OSGi
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-05-28 06:09:45 UTC (rev 6380)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-05-28 06:19:37 UTC (rev 6381)
@@ -191,6 +191,10 @@
Enumeration<URL> resourceUrls;
try {
resourceUrls = classLoader.getResources(resourceName);
+
+ if (!resourceUrls.hasMoreElements()) {
+ resourceUrls = BpmnParser.class.getClassLoader().getResources(resourceName);
+ }
} catch (Exception e) {
throw new JbpmException("couldn't get resource urls for "+resourceName, e);
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-05-28 06:09:45 UTC (rev 6380)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-05-28 06:19:37 UTC (rev 6381)
@@ -140,6 +140,10 @@
Enumeration<URL> resourceUrls;
try {
resourceUrls = classLoader.getResources(resourceName);
+
+ if (!resourceUrls.hasMoreElements()) {
+ resourceUrls = JpdlParser.class.getClassLoader().getResources(resourceName);
+ }
} catch (Exception e) {
throw new JbpmException("couldn't get resource urls for "+resourceName, e);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/stream/ResourceStreamInput.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/stream/ResourceStreamInput.java 2010-05-28 06:09:45 UTC (rev 6380)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/stream/ResourceStreamInput.java 2010-05-28 06:19:37 UTC (rev 6381)
@@ -51,6 +51,11 @@
public InputStream openStream() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream(resource);
+
+ if (stream == null) {
+ stream = ResourceStreamInput.class.getClassLoader().getResourceAsStream(resource);
+ }
+
if (stream==null) {
throw new JbpmException("resource "+resource+" does not exist");
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java 2010-05-28 06:09:45 UTC (rev 6380)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/xml/WireParser.java 2010-05-28 06:19:37 UTC (rev 6381)
@@ -276,6 +276,10 @@
Enumeration<URL> resourceUrls;
try {
resourceUrls = classLoader.getResources(wireResource);
+
+ if (!resourceUrls.hasMoreElements()) {
+ resourceUrls = WireParser.class.getClassLoader().getResources(wireResource);
+ }
} catch (Exception e) {
throw new JbpmException("couldn't get resource urls for "+wireResource, e);
}
13 years, 11 months
JBoss JBPM SVN: r6380 - in jbpm4/trunk/modules: test-cfg/src/test/java/org/jbpm/test/spring and 3 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-05-28 02:09:45 -0400 (Fri, 28 May 2010)
New Revision: 6380
Added:
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/
jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml
jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java
Log:
JBPM-2710 solve Circular Reference error for spring integration
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java 2010-05-28 06:01:59 UTC (rev 6379)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/processengine/SpringProcessEngine.java 2010-05-28 06:09:45 UTC (rev 6380)
@@ -36,23 +36,23 @@
/**
* this environment factory will see only the singleton beans.
- *
+ *
* The created {@link SpringEnvironment}s will see the prototype beans and it
* will cache them.
- *
+ *
* @author Andries Inze
*/
public class SpringProcessEngine extends ProcessEngineImpl implements EnvironmentFactory, ProcessEngine {
private static final Log log = Log.getLog(SpringProcessEngine.class.getName());
-
+
private static final long serialVersionUID = 1L;
private ApplicationContext applicationContext;
public static ProcessEngine create(ConfigurationImpl configuration) {
SpringProcessEngine springProcessEngine = null;
-
+
ApplicationContext applicationContext = null;
if (configuration.isInstantiatedFromSpring()) {
applicationContext = (ApplicationContext) configuration.getApplicationContext();
@@ -66,7 +66,7 @@
springProcessEngine.processEngineWireContext
.getWireDefinition()
.addDescriptor(new ProvidedObjectDescriptor(hibernateConfiguration, true));
-
+
springProcessEngine.checkDb(configuration);
} else {
@@ -77,7 +77,7 @@
applicationContext = new ClassPathXmlApplicationContext(springCfg);
springProcessEngine = (SpringProcessEngine) applicationContext.getBean("processEngine");
}
-
+
return springProcessEngine;
}
@@ -99,18 +99,24 @@
@SuppressWarnings("unchecked")
@Override
public <T> T get(Class<T> type) {
+ T candidateComponent = super.get(type);
+
+ if (candidateComponent != null) {
+ return candidateComponent;
+ }
+
String[] names = applicationContext.getBeanNamesForType(type);
-
+
if (names.length >= 1) {
-
+
if (names.length > 1 && log.isWarnEnabled()) {
log.warn("Multiple beans for type " + type + " found. Returning the first result.");
}
-
+
return (T) applicationContext.getBean(names[0]);
}
- return super.get(type);
+ return null;
}
@Override
Added: jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/java/org/jbpm/test/spring/circularreference/CircularReferenceTest.java 2010-05-28 06:09:45 UTC (rev 6380)
@@ -0,0 +1,35 @@
+/*
+ * 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.spring.circularreference;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.AbstractTransactionalSpringJbpmTestCase;
+
+public class CircularReferenceTest extends AbstractTransactionalSpringJbpmTestCase {
+ public void testGetRepositoryService() {
+ assertNotNull(repositoryService);
+ }
+}
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/applicationContext.xml 2010-05-28 06:09:45 UTC (rev 6380)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
+
+ <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
+ <property name="jbpmCfg" value="org/jbpm/test/spring/circularreference/jbpm.cfg.xml" />
+ </bean>
+
+ <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
+
+ <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
+
+ <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
+ <property name="configLocation" value="classpath:org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
+ <property name="sessionFactory" ref="sessionFactory" />
+ <property name="dataSource" ref="dataSource" />
+ </bean>
+
+ <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:." />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </bean>
+</beans>
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.cfg.xml 2010-05-28 06:09:45 UTC (rev 6380)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <import resource="jbpm.default.cfg.xml" />
+ <import resource="jbpm.jpdl.cfg.xml" />
+ <import resource="jbpm.bpmn.cfg.xml" />
+ <import resource="jbpm.identity.cfg.xml" />
+ <import resource="jbpm.businesscalendar.cfg.xml" />
+ <import resource="jbpm.console.cfg.xml" />
+
+ <!-- Spring configuration -->
+ <import resource="jbpm.tx.spring.cfg.xml" />
+
+</jbpm-configuration>
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/jbpm.hibernate.cfg.xml 2010-05-28 06:09:45 UTC (rev 6380)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+
+ <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
+ <property name="hibernate.format_sql">true</property>
+
+ <property name="hibernate.hbm2ddl.auto">create-drop</property>
+
+ <mapping resource="jbpm.repository.hbm.xml" />
+ <mapping resource="jbpm.execution.hbm.xml" />
+ <mapping resource="jbpm.history.hbm.xml" />
+ <mapping resource="jbpm.task.hbm.xml" />
+ <mapping resource="jbpm.identity.hbm.xml" />
+
+ </session-factory>
+</hibernate-configuration>
Added: jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties
===================================================================
--- jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties (rev 0)
+++ jbpm4/trunk/modules/test-cfg/src/test/resources/org/jbpm/test/spring/circularreference/log4j.properties 2010-05-28 06:09:45 UTC (rev 6380)
@@ -0,0 +1,4 @@
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+log4j.rootLogger=info, stdout
13 years, 11 months
JBoss JBPM SVN: r6379 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/activity/subprocess and 1 other directory.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-05-28 02:01:59 -0400 (Fri, 28 May 2010)
New Revision: 6379
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/DynamicSubProcessTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessParameterOutTest.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessDeleteTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java
Log:
JBPM-2856 delete sub process instance when it ended, and do some refactor for subprocess testcase.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-05-28 05:53:35 UTC (rev 6378)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-05-28 06:01:59 UTC (rev 6379)
@@ -373,6 +373,9 @@
fire(Event.END, getProcessDefinition());
if (superProcessExecution!=null) {
+ if (dbSession!=null) {
+ dbSession.delete(this);
+ }
log.trace(toString()+" signals super process execution");
superProcessExecution.signal();
}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/DynamicSubProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/DynamicSubProcessTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/DynamicSubProcessTest.java 2010-05-28 06:01:59 UTC (rev 6379)
@@ -0,0 +1,168 @@
+/*
+ * 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.activity.subprocess;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.internal.compiler.ast.AssertStatement;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * Test case for different usages of the subprocess activity.
+ *
+ * @author Joram Barrez
+ */
+public class DynamicSubProcessTest extends JbpmTestCase {
+
+ private static final String SUB_PROCESS =
+ "<process name='SubProcessReview'>" +
+ " <start>" +
+ " <transition to='get approval'/>" +
+ " </start>" +
+ " <task name='get approval' assignee='johndoe'>" +
+ " <transition name='ok' to='ok'/>" +
+ " <transition name='nok' to='nok'/>" +
+ " <transition name='reject' to='reject'/>" +
+ " </task>" +
+ " <end name='ok' />" +
+ " <end name='nok' />" +
+ " <end name='reject' />" +
+ "</process>";
+
+ private static final String MAIN_PROCESS_SUB_EL =
+ "<process name='mainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-key='#{dynamic_subprocess}'>" +
+ " <transition name='ok' to='next step'/>" +
+ " <transition name='nok' to='update'/>" +
+ " <transition name='reject' to='close'/>" +
+ " </sub-process>" +
+ " <state name='next step'/>" +
+ " <state name='update'/>" +
+ " <end name='close'/>" +
+ "</process>";
+
+ private static final String MAIN_PROCESS_SUB_EL_ID =
+ "<process name='mainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-id='#{dynamic_subprocess}'>" +
+ " <transition name='ok' to='next step'/>" +
+ " <transition name='nok' to='update'/>" +
+ " <transition name='reject' to='close'/>" +
+ " </sub-process>" +
+ " <state name='next step'/>" +
+ " <state name='update'/>" +
+ " <end name='close'/>" +
+ "</process>";
+
+ private static final String MAIN_PROCESS_SUB_ID =
+ "<process name='mainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-id='SubProcessReview-1'>" +
+ " <transition name='ok' to='next step'/>" +
+ " <transition name='nok' to='update'/>" +
+ " <transition name='reject' to='close'/>" +
+ " </sub-process>" +
+ " <state name='next step'/>" +
+ " <state name='update'/>" +
+ " <end name='close'/>" +
+ "</process>";
+
+ public void testDynamicSubProcess() {
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("dynamic_subprocess", "SubProcessReview");
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
+ Task task = taskService.findPersonalTasks("johndoe").get(0);
+ taskService.completeTask(task.getId(), "reject");
+ assertProcessInstanceEnded(processInstance);
+ }
+
+ public void testDynamicSubProcessNotFound() {
+ String expectedError = "Subprocess 'DOES_NOT_EXIST' could not be found.";
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("dynamic_subprocess", "DOES_NOT_EXIST");
+ try {
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
+ fail("Should not happen, error expected: " + expectedError);
+ } catch (JbpmException je) {
+ assertEquals(expectedError, je.getMessage());
+ }
+ }
+
+ public void testDynamicSubProcessWrongProperty() {
+ String expectedError = "Subprocess key '#{dynamic_subprocess}' could not be resolved.";
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("WRONG_PROPERTY", "VALUE_DOES_NOT_MATTER");
+ try {
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
+ fail("Should not happen, error expected: " + expectedError);
+ } catch (JbpmException je) {
+ assertEquals(expectedError, je.getMessage());
+ }
+ }
+
+ public void testDynamicSubProcessWithId() {
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_EL_ID);
+
+ Map<String, String> vars = new HashMap<String, String>();
+ vars.put("dynamic_subprocess", "SubProcessReview-1");
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
+ Task task = taskService.findPersonalTasks("johndoe").get(0);
+ taskService.completeTask(task.getId(), "reject");
+ assertProcessInstanceEnded(processInstance);
+ }
+
+ public void testSubProcessWithId() {
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS_SUB_ID);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
+ Task task = taskService.findPersonalTasks("johndoe").get(0);
+ taskService.completeTask(task.getId(), "reject");
+ assertProcessInstanceEnded(processInstance);
+ }
+
+}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessDeleteTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessDeleteTest.java 2010-05-28 05:53:35 UTC (rev 6378)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessDeleteTest.java 2010-05-28 06:01:59 UTC (rev 6379)
@@ -41,21 +41,97 @@
" <state name='next step'/>" +
"</process>"
);
-
+
deployJpdlXmlString(
"<process name='SubProcessReview'>" +
" <start>" +
" <transition to='get approval'/>" +
" </start>" +
- " <state name='get approval'>" +
+ " <task name='get approval' assignee='johndoe'>" +
" <transition to='ok'/>" +
- " </state>" +
+ " </task>" +
" <end name='ok' />" +
- "</process>"
+ "</process>"
);
-
+
String pid = executionService.startProcessInstanceByKey("MainProcess").getId();
-
+
+ assertEquals(2, executionService.createProcessInstanceQuery().list().size());
+
executionService.deleteProcessInstance(pid);
+
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
+
+ assertEquals(0, taskService.createTaskQuery().list().size());
}
+
+ public void testMultipleSubProcess() {
+ deployJpdlXmlString(
+ "<process name='MainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-key='SubProcessReview'>" +
+ " <transition to='second sub process'/>" +
+ " </sub-process>" +
+ " <sub-process name='second sub process' sub-process-key='SubProcessReview'>" +
+ " <transition to='next step'/>" +
+ " </sub-process>" +
+ " <state name='next step'/>" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='SubProcessReview'>" +
+ " <start>" +
+ " <transition to='ok'/>" +
+ " </start>" +
+ " <end name='ok' />" +
+ "</process>"
+ );
+
+ String pid = executionService.startProcessInstanceByKey("MainProcess").getId();
+
+ assertEquals(1, executionService.createProcessInstanceQuery().list().size());
+
+ executionService.deleteProcessInstance(pid);
+
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
+ }
+
+ public void testSubProcessWithFork() {
+ deployJpdlXmlString(
+ "<process name='MainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-key='SubProcessReview'>" +
+ " <transition to='next step'/>" +
+ " </sub-process>" +
+ " <state name='next step'/>" +
+ "</process>"
+ );
+
+ deployJpdlXmlString(
+ "<process name='SubProcessReview'>" +
+ " <start>" +
+ " <transition to='fork'/>" +
+ " </start>" +
+ " <fork name='fork'>" +
+ " <transition to='ok'/>" +
+ " <transition to='wait'/>" +
+ " </fork>" +
+ " <state name='wait'/>" +
+ " <end name='ok' />" +
+ "</process>"
+ );
+
+ String pid = executionService.startProcessInstanceByKey("MainProcess").getId();
+
+ assertEquals(1, executionService.createProcessInstanceQuery().list().size());
+
+ executionService.deleteProcessInstance(pid);
+
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
+ }
}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessParameterOutTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessParameterOutTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessParameterOutTest.java 2010-05-28 06:01:59 UTC (rev 6379)
@@ -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.activity.subprocess;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * JBPM-2856.
+ *
+ * @author Huisheng Xu
+ */
+public class SubProcessParameterOutTest extends JbpmTestCase {
+
+ private static final String MAIN_PROCESS =
+ "<process name='mainProcess'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <sub-process name='review' sub-process-key='SubProcessReview'>" +
+ " <parameter-out var='reviewResult' subvar='result' />" +
+ " <transition name='ok' to='wait'/>" +
+ " </sub-process>" +
+ " <state name='wait'>" +
+ " <transition to='close'/>" +
+ " </state>" +
+ " <end name='close'/>" +
+ "</process>";
+
+ private static final String SUB_PROCESS =
+ "<process name='SubProcessReview'>" +
+ " <start>" +
+ " <transition to='script'/>" +
+ " </start>" +
+ " <script name='script' var='result' expr='#{\"result\"}'>" +
+ " <transition name='ok' to='ok'/>" +
+ " </script>" +
+ " <end name='ok' />" +
+ "</process>";
+
+
+ public void testSubProcessParameterOut() {
+ deployJpdlXmlString(SUB_PROCESS);
+ deployJpdlXmlString(MAIN_PROCESS);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
+ assertEquals(1, executionService.createProcessInstanceQuery().list().size());
+
+ assertEquals("result", executionService.getVariable(processInstance.getId(), "reviewResult"));
+ }
+}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java 2010-05-28 05:53:35 UTC (rev 6378)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/subprocess/SubProcessTest.java 2010-05-28 06:01:59 UTC (rev 6379)
@@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
- *
+ *
*/
package org.jbpm.test.activity.subprocess;
@@ -36,11 +36,11 @@
/**
* Test case for different usages of the subprocess activity.
- *
+ *
* @author Joram Barrez
*/
public class SubProcessTest extends JbpmTestCase {
-
+
private static final String MAIN_PROCESS =
"<process name='mainProcess'>" +
" <start>" +
@@ -52,10 +52,12 @@
" <transition name='reject' to='close'/>" +
" </sub-process>" +
" <state name='next step'/>" +
- " <state name='update'/>" +
+ " <state name='update'>" +
+ " <transition to='close'/>" +
+ " </state>" +
" <end name='close'/>" +
- "</process>";
-
+ "</process>";
+
private static final String SUB_PROCESS =
"<process name='SubProcessReview'>" +
" <start>" +
@@ -69,8 +71,8 @@
" <end name='ok' />" +
" <end name='nok' />" +
" <end name='reject' />" +
- "</process>";
-
+ "</process>";
+
private static final String MAIN_PROCESS_NO_WAIT_STATE =
"<process name='mainProcess'>" +
" <start>" +
@@ -80,153 +82,59 @@
" <transition to='theMainEnd'/>" +
" </sub-process>" +
" <end name='theMainEnd'/>" +
- "</process>";
-
+ "</process>";
+
private static final String SUB_PROCESS_NO_WAIT_STATE =
"<process name='SubProcessReview'>" +
" <start>" +
" <transition to='theEnd'/>" +
" </start>" +
" <end name='theEnd' />" +
- "</process>";
-
- private static final String MAIN_PROCESS_SUB_EL =
- "<process name='mainProcess'>" +
- " <start>" +
- " <transition to='review' />" +
- " </start>" +
- " <sub-process name='review' sub-process-key='#{dynamic_subprocess}'>" +
- " <transition name='ok' to='next step'/>" +
- " <transition name='nok' to='update'/>" +
- " <transition name='reject' to='close'/>" +
- " </sub-process>" +
- " <state name='next step'/>" +
- " <state name='update'/>" +
- " <end name='close'/>" +
- "</process>";
-
- private static final String MAIN_PROCESS_SUB_EL_ID =
- "<process name='mainProcess'>" +
- " <start>" +
- " <transition to='review' />" +
- " </start>" +
- " <sub-process name='review' sub-process-id='#{dynamic_subprocess}'>" +
- " <transition name='ok' to='next step'/>" +
- " <transition name='nok' to='update'/>" +
- " <transition name='reject' to='close'/>" +
- " </sub-process>" +
- " <state name='next step'/>" +
- " <state name='update'/>" +
- " <end name='close'/>" +
- "</process>";
-
- private static final String MAIN_PROCESS_SUB_ID =
- "<process name='mainProcess'>" +
- " <start>" +
- " <transition to='review' />" +
- " </start>" +
- " <sub-process name='review' sub-process-id='SubProcessReview-1'>" +
- " <transition name='ok' to='next step'/>" +
- " <transition name='nok' to='update'/>" +
- " <transition name='reject' to='close'/>" +
- " </sub-process>" +
- " <state name='next step'/>" +
- " <state name='update'/>" +
- " <end name='close'/>" +
- "</process>";
-
+ "</process>";
+
public void testSubProcessOutcomeToState() {
deployJpdlXmlString(SUB_PROCESS);
deployJpdlXmlString(MAIN_PROCESS);
-
+
ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
+
+ assertEquals(2, executionService.createProcessInstanceQuery().list().size());
+
Task task = taskService.findPersonalTasks("johndoe").get(0);
taskService.completeTask(task.getId(), "nok");
assertActivityActive(processInstance.getId(), "update");
- }
-
- public void testDynamicSubProcess() {
- deployJpdlXmlString(SUB_PROCESS);
- deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
-
- Map<String, String> vars = new HashMap<String, String>();
- vars.put("dynamic_subprocess", "SubProcessReview");
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
- Task task = taskService.findPersonalTasks("johndoe").get(0);
- taskService.completeTask(task.getId(), "reject");
- assertProcessInstanceEnded(processInstance);
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+
+ assertProcessInstanceEnded(processInstance);
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
}
-
- public void testDynamicSubProcessNotFound() {
- String expectedError = "Subprocess 'DOES_NOT_EXIST' could not be found.";
- deployJpdlXmlString(SUB_PROCESS);
- deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
-
- Map<String, String> vars = new HashMap<String, String>();
- vars.put("dynamic_subprocess", "DOES_NOT_EXIST");
- try {
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
- fail("Should not happen, error expected: " + expectedError);
- } catch (JbpmException je) {
- assertEquals(expectedError, je.getMessage());
- }
- }
-
- public void testDynamicSubProcessWrongProperty() {
- String expectedError = "Subprocess key '#{dynamic_subprocess}' could not be resolved.";
- deployJpdlXmlString(SUB_PROCESS);
- deployJpdlXmlString(MAIN_PROCESS_SUB_EL);
-
- Map<String, String> vars = new HashMap<String, String>();
- vars.put("WRONG_PROPERTY", "VALUE_DOES_NOT_MATTER");
- try {
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
- fail("Should not happen, error expected: " + expectedError);
- } catch (JbpmException je) {
- assertEquals(expectedError, je.getMessage());
- }
- }
-
+
public void testSubProcessOutcomeToEnd() {
deployJpdlXmlString(SUB_PROCESS);
deployJpdlXmlString(MAIN_PROCESS);
-
+
ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
+
+ assertEquals(2, executionService.createProcessInstanceQuery().list().size());
+
Task task = taskService.findPersonalTasks("johndoe").get(0);
taskService.completeTask(task.getId(), "reject");
- assertProcessInstanceEnded(processInstance);
+ assertProcessInstanceEnded(processInstance);
}
-
+
// Test for JBPM-2651
public void testSubProcessNoWaitStates() {
deployJpdlXmlString(SUB_PROCESS_NO_WAIT_STATE);
deployJpdlXmlString(MAIN_PROCESS_NO_WAIT_STATE);
-
+
executionService.startProcessInstanceByKey("mainProcess");
- }
-
- public void testDynamicSubProcessWithId() {
- deployJpdlXmlString(SUB_PROCESS);
- deployJpdlXmlString(MAIN_PROCESS_SUB_EL_ID);
-
- Map<String, String> vars = new HashMap<String, String>();
- vars.put("dynamic_subprocess", "SubProcessReview-1");
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess",vars);
- Task task = taskService.findPersonalTasks("johndoe").get(0);
- taskService.completeTask(task.getId(), "reject");
- assertProcessInstanceEnded(processInstance);
- }
-
- public void testSubProcessWithId() {
- deployJpdlXmlString(SUB_PROCESS);
- deployJpdlXmlString(MAIN_PROCESS_SUB_ID);
-
+
ProcessInstance processInstance = executionService.startProcessInstanceByKey("mainProcess");
- Task task = taskService.findPersonalTasks("johndoe").get(0);
- taskService.completeTask(task.getId(), "reject");
- assertProcessInstanceEnded(processInstance);
+ assertProcessInstanceEnded(processInstance);
+
+ assertEquals(0, executionService.createProcessInstanceQuery().list().size());
}
-
+
}
13 years, 11 months
JBoss JBPM SVN: r6378 - jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-05-28 01:53:35 -0400 (Fri, 28 May 2010)
New Revision: 6378
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java
Log:
JBPM-2832 update testcase for verify this issue has bean fixed.
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java 2010-05-26 01:22:01 UTC (rev 6377)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java 2010-05-28 05:53:35 UTC (rev 6378)
@@ -1,118 +1,167 @@
-/*
- * 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.activity.forkjoin;
-
-import org.jbpm.api.ProcessInstance;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.test.JbpmTestCase;
-
-import java.util.Set;
-
-public class ForkResultsInNullEndActivityTest extends JbpmTestCase {
- private String deploymentId;
-
- protected void setUp() throws Exception {
- super.setUp();
- final String jpdl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<process name=\"ForkTest\" xmlns=\"http://jbpm.org/4.3/jpdl\">\n" +
- " <start name=\"preparing test\">\n" +
- " <transition to=\"fork\"/>\n" +
- " </start>\n" +
- " <fork name=\"fork\">\n" +
- " <transition to=\"state1\"/>\n" +
- " <transition to=\"state2\"/>\n" +
- " <transition to=\"cancel\"/>\n" +
- " </fork>\n" +
- " <state name=\"cancel\">\n" +
- " <transition to=\"cancelled\"/>\n" +
- " </state>\n" +
- " <state name=\"state1\">\n" +
- " <transition to=\"states completed\"/>\n" +
- " </state>\n" +
- " <state name=\"state2\">\n" +
- " <transition to=\"states completed\"/>\n" +
- " </state>\n" +
- " <join multiplicity=\"2\" name=\"states completed\">\n" +
- " <transition to=\"completed\"/>\n" +
- " </join>\n" +
- " <end name=\"cancelled\"/>\n" +
- " <end name=\"completed\"/>\n" +
- "</process>";
-
- // Deploys the process
- deploymentId = repositoryService.createDeployment().
- addResourceFromString("ForkTest.jpdl.xml", jpdl).deploy();
- }
-
- protected void tearDown() throws Exception {
- repositoryService.deleteDeploymentCascade(deploymentId);
- super.tearDown();
- }
-
- private void verifyInitialActivities(ProcessInstance proc) {
- String[] expectedStartActivities = {"state1", "state2", "cancel"};
- Set<String> foundStartActivities = proc.findActiveActivityNames();
- for (String act : expectedStartActivities) {
- assertTrue(foundStartActivities.contains(act));
- }
- }
-
- public void testCompleteJoin() {
- ProcessInstance proc = executionService.startProcessInstanceByKey("ForkTest");
- verifyInitialActivities(proc);
-
- String state1Id = proc.findActiveExecutionIn("state1").getId();
- proc = executionService.signalExecutionById(state1Id);
-
- String state2Id = proc.findActiveExecutionIn("state2").getId();
- proc = executionService.signalExecutionById(state2Id);
-
- assertExecutionEnded(proc.getId());
-
- //the name of the end activity should now be set on the execution
- ExecutionImpl executionImpl = (ExecutionImpl) proc;
- assertEquals("completed", executionImpl.getActivityName());
-
- assertEquals("completed", historyService.createHistoryProcessInstanceQuery()
- .uniqueResult()
- .getEndActivityName());
- }
-
- public void testCancelWithoutJoin() {
- ProcessInstance proc = executionService.startProcessInstanceByKey("ForkTest");
- verifyInitialActivities(proc);
-
- String driveTruckExecutionId = proc.findActiveExecutionIn("cancel").getId();
- proc = executionService.signalExecutionById(driveTruckExecutionId);
-
- assertExecutionEnded(proc.getId());
-
- //the name of the end activity should now be set on the execution
- ExecutionImpl executionImpl = (ExecutionImpl) proc;
- assertEquals("cancelled", executionImpl.getActivityName());
-
- assertEquals("cancelled", historyService.createHistoryProcessInstanceQuery()
- .uniqueResult()
- .getEndActivityName());
- }
-
-}
+/*
+ * 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.activity.forkjoin;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.test.JbpmTestCase;
+
+import java.util.Set;
+
+/**
+ * JBPM-2832, JBPM-2833.
+ *
+ * @author Huisheng Xu
+ */
+public class ForkResultsInNullEndActivityTest extends JbpmTestCase {
+ public static final String XML_FORK_JOIN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<process name=\"ForkTest\" xmlns=\"http://jbpm.org/4.3/jpdl\">\n" +
+ " <start name=\"preparing test\">\n" +
+ " <on event='end'>" +
+ " <event-listener class='org.jbpm.test.activity.forkjoin.ForkResultsInNullEndActivityTest$StartEventListener'/>" +
+ " </on>" +
+ " <transition to=\"fork\"/>\n" +
+ " </start>\n" +
+ " <fork name=\"fork\">\n" +
+ " <transition to=\"state1\"/>\n" +
+ " <transition to=\"state2\"/>\n" +
+ " <transition to=\"cancel\"/>\n" +
+ " </fork>\n" +
+ " <state name=\"cancel\">\n" +
+ " <transition to=\"cancelled\"/>\n" +
+ " </state>\n" +
+ " <state name=\"state1\">\n" +
+ " <transition to=\"states completed\"/>\n" +
+ " </state>\n" +
+ " <state name=\"state2\">\n" +
+ " <transition to=\"states completed\"/>\n" +
+ " </state>\n" +
+ " <join multiplicity=\"2\" name=\"states completed\">\n" +
+ " <transition to=\"completed\"/>\n" +
+ " </join>\n" +
+ " <end name=\"cancelled\"/>\n" +
+ " <end name=\"completed\"/>\n" +
+ "</process>";
+
+ public static final String XML_SUB_PROCESS = "" +
+ "<process name='sub_process' xmlns='http://jbpm.org/4.3/jpdl'>" +
+ " <start>" +
+ " <transition to='sub'/>" +
+ " </start>" +
+ " <sub-process name='sub' sub-process-key='ForkTest' outcome='#{result}'>" +
+ " <transition name='to A' to='A'/>" +
+ " <transition name='to B' to='B'/>" +
+ " <transition name='to C' to='C'/>" +
+ " </sub-process>" +
+ " <state name='A'/>" +
+ " <state name='B'/>" +
+ " <state name='C'/>" +
+ "</process>";
+
+ private String deploymentId;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Deploys the process
+ deploymentId = repositoryService.createDeployment()
+ .addResourceFromString("ForkTest.jpdl.xml", XML_FORK_JOIN)
+ .addResourceFromString("sub_process.jpdl.xml", XML_SUB_PROCESS)
+ .deploy();
+ }
+
+ protected void tearDown() throws Exception {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ super.tearDown();
+ }
+
+ private void verifyInitialActivities(ProcessInstance proc) {
+ String[] expectedStartActivities = {"state1", "state2", "cancel"};
+ Set<String> foundStartActivities = proc.findActiveActivityNames();
+ for (String act : expectedStartActivities) {
+ assertTrue(foundStartActivities.contains(act));
+ }
+ }
+
+ public void t2estCompleteJoin() {
+ ProcessInstance proc = executionService.startProcessInstanceByKey("ForkTest");
+ verifyInitialActivities(proc);
+
+ String state1Id = proc.findActiveExecutionIn("state1").getId();
+ proc = executionService.signalExecutionById(state1Id);
+
+ String state2Id = proc.findActiveExecutionIn("state2").getId();
+ proc = executionService.signalExecutionById(state2Id);
+
+ assertExecutionEnded(proc.getId());
+
+ //the name of the end activity should now be set on the execution
+ ExecutionImpl executionImpl = (ExecutionImpl) proc;
+ assertEquals("completed", executionImpl.getActivityName());
+
+ assertEquals("completed", historyService.createHistoryProcessInstanceQuery()
+ .uniqueResult()
+ .getEndActivityName());
+ }
+
+ public void t2estCancelWithoutJoin() {
+ ProcessInstance proc = executionService.startProcessInstanceByKey("ForkTest");
+ verifyInitialActivities(proc);
+
+ String driveTruckExecutionId = proc.findActiveExecutionIn("cancel").getId();
+ proc = executionService.signalExecutionById(driveTruckExecutionId);
+
+ assertExecutionEnded(proc.getId());
+
+ //the name of the end activity should now be set on the execution
+ ExecutionImpl executionImpl = (ExecutionImpl) proc;
+ assertEquals("cancelled", executionImpl.getActivityName());
+
+ assertEquals("cancelled", historyService.createHistoryProcessInstanceQuery()
+ .uniqueResult()
+ .getEndActivityName());
+ }
+
+ public void testForkAndSubProcess() {
+ ProcessInstance mainProcess = executionService.startProcessInstanceByKey("sub_process");
+
+ ProcessInstance subProcess = executionService.createProcessInstanceQuery()
+ .orderDesc("dbid")
+ .page(0, 1)
+ .uniqueResult();
+
+ String driveTruckExecutionId = subProcess.findActiveExecutionIn("cancel").getId();
+ subProcess = executionService.signalExecutionById(driveTruckExecutionId);
+
+ mainProcess = executionService.findProcessInstanceById(mainProcess.getId());
+ assertEquals("A", mainProcess.findActiveActivityNames().iterator().next());
+ }
+
+ public static class StartEventListener implements EventListener {
+ public void notify(EventListenerExecution execution) {
+ execution.setVariable("result", "to A");
+ }
+ }
+
+}
13 years, 11 months
JBoss JBPM SVN: r6377 - in jbpm3/branches/jbpm-3.2-soa/modules/identity/src: main/java/org/jbpm/identity/xml and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-05-25 21:22:01 -0400 (Tue, 25 May 2010)
New Revision: 6377
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/ant/LoadIdentitiesTask.java
jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java
jbpm3/branches/jbpm-3.2-soa/modules/identity/src/test/java/org/jbpm/identity/xml/IdentityXmlParsingTest.java
Log:
clean up identity xml parsing
Modified: jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/ant/LoadIdentitiesTask.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/ant/LoadIdentitiesTask.java 2010-05-26 01:02:24 UTC (rev 6376)
+++ jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/ant/LoadIdentitiesTask.java 2010-05-26 01:22:01 UTC (rev 6377)
@@ -27,41 +27,45 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
-import org.hibernate.Session;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.ant.AntHelper;
import org.jbpm.identity.Entity;
+import org.jbpm.identity.hibernate.IdentitySession;
import org.jbpm.identity.xml.IdentityXmlParser;
public class LoadIdentitiesTask extends Task {
- private File file = null;
- private String jbpmCfg = null;
+ private File file;
+ private String jbpmCfg;
public void execute() throws BuildException {
// get the JbpmSessionFactory
JbpmConfiguration jbpmConfiguration = AntHelper.getJbpmConfiguration(jbpmCfg);
-
+
// if attribute file is set, deploy that file file
- if (file==null) throw new BuildException("no file specified in the loadidentities task");
+ if (file == null) throw new BuildException("no file specified in the loadidentities task");
- log( "loading identities from "+file+" ..." );
- FileInputStream fileInputStream = null;
+ log("loading identities from " + file + " ...");
+ FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(file);
- } catch (FileNotFoundException e) {
- throw new BuildException("identities file '"+file+"' not found");
}
+ catch (FileNotFoundException e) {
+ throw new BuildException("identities file '" + file + "' not found");
+ }
Entity[] entities = IdentityXmlParser.parseEntitiesResource(fileInputStream);
-
+
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
- Session session = jbpmContext.getSession();
- for (int i=0; i<entities.length; i++) {
- session.save(entities[i]);
+ IdentitySession identitySession = (IdentitySession) jbpmContext.getServices()
+ .getPersistenceService()
+ .getCustomSession(IdentitySession.class);
+ for (int i = 0; i < entities.length; i++) {
+ identitySession.saveEntity(entities[i]);
}
- } finally {
+ }
+ finally {
jbpmContext.close();
}
}
@@ -69,6 +73,7 @@
public void setFile(File file) {
this.file = file;
}
+
public void setJbpmCfg(String jbpmCfg) {
this.jbpmCfg = jbpmCfg;
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java 2010-05-26 01:02:24 UTC (rev 6376)
+++ jbpm3/branches/jbpm-3.2-soa/modules/identity/src/main/java/org/jbpm/identity/xml/IdentityXmlParser.java 2010-05-26 01:22:01 UTC (rev 6377)
@@ -22,6 +22,7 @@
package org.jbpm.identity.xml;
import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,6 +33,7 @@
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
+import org.jbpm.JbpmException;
import org.jbpm.identity.Entity;
import org.jbpm.identity.Group;
import org.jbpm.identity.Membership;
@@ -39,11 +41,11 @@
import org.jbpm.util.ClassLoaderUtil;
public class IdentityXmlParser {
-
- List entities = new ArrayList();
- Map users = new HashMap();
- Map groups = new HashMap();
+ private List entities = new ArrayList();
+ private Map users = new HashMap();
+ private Map groups = new HashMap();
+
public static Entity[] parseEntitiesResource(String resource) {
return new IdentityXmlParser().parse(resource);
}
@@ -53,34 +55,42 @@
}
public Entity[] parse(String resource) {
- return parse(ClassLoaderUtil.getStream(resource));
+ try {
+ URL resourceUrl = ClassLoaderUtil.getClassLoader().getResource(resource);
+ return parse(new SAXReader().read(resourceUrl));
+ }
+ catch (DocumentException e) {
+ throw new JbpmException("could not read identity resource: " + resource, e);
+ }
}
public Entity[] parse(InputStream inputStream) {
- Document document;
try {
- document = new SAXReader().read(inputStream);
- } catch (DocumentException e) {
- throw new RuntimeException("couldn't parse identities from stream '"+inputStream+"'");
+ return parse(new SAXReader().read(inputStream));
}
- Element identitiesRootElement = document.getRootElement();
-
- readUsers(identitiesRootElement.elements("user"));
- readGroups(identitiesRootElement.elements("group"));
- readParentGroups(identitiesRootElement.elements("group"));
- readMemberships(identitiesRootElement.elements("membership"));
+ catch (DocumentException e) {
+ throw new JbpmException("could not read identity document", e);
+ }
+ }
+ private Entity[] parse(Document document) {
+ Element identitiesElement = document.getRootElement();
+
+ readUsers(identitiesElement.elements("user"));
+ readGroups(identitiesElement.elements("group"));
+ readParentGroups(identitiesElement.elements("group"));
+ readMemberships(identitiesElement.elements("membership"));
+
return (Entity[]) entities.toArray(new Entity[entities.size()]);
}
private void readUsers(List userElements) {
- Iterator iter = userElements.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = userElements.iterator(); iter.hasNext();) {
Element userElement = (Element) iter.next();
String name = userElement.attributeValue("name");
String email = userElement.attributeValue("email");
String password = userElement.attributeValue("password");
-
+
User user = new User(name);
user.setEmail(email);
user.setPassword(password);
@@ -90,12 +100,11 @@
}
private void readGroups(List groupElements) {
- Iterator iter = groupElements.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = groupElements.iterator(); iter.hasNext();) {
Element groupElement = (Element) iter.next();
String name = groupElement.attributeValue("name");
String type = groupElement.attributeValue("type");
-
+
Group group = new Group(name);
group.setType(type);
entities.add(group);
@@ -104,39 +113,45 @@
}
private void readParentGroups(List groupElements) {
- Iterator iter = groupElements.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = groupElements.iterator(); iter.hasNext();) {
Element groupElement = (Element) iter.next();
String childName = groupElement.attributeValue("name");
String parentName = groupElement.attributeValue("parent");
-
- if (parentName!=null) {
+
+ if (parentName != null) {
Group parent = (Group) groups.get(parentName);
- if (parent==null) throw new RuntimeException("unexisting parent group '"+parentName+"'");
+ if (parent == null) {
+ throw new JbpmException("no such group: " + parentName);
+ }
+
Group child = (Group) groups.get(childName);
-
parent.addChild(child);
}
}
}
private void readMemberships(List membershipElements) {
- Iterator iter = membershipElements.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = membershipElements.iterator(); iter.hasNext();) {
Element membershipElement = (Element) iter.next();
+
String role = membershipElement.attributeValue("role");
+ Membership membership = new Membership();
+ membership.setRole(role);
+
String userName = membershipElement.attributeValue("user");
User user = (User) users.get(userName);
- if (user==null) throw new RuntimeException("unexisting membership user '"+userName+"'");
+ if (user == null) {
+ throw new JbpmException("no such user: " + userName);
+ }
+ user.addMembership(membership);
+
String groupName = membershipElement.attributeValue("group");
Group group = (Group) groups.get(groupName);
- if (group==null) throw new RuntimeException("unexisting membership group '"+groupName+"'");
-
- Membership membership = new Membership();
- membership.setRole(role);
+ if (group == null) {
+ throw new JbpmException("no such group: " + groupName);
+ }
group.addMembership(membership);
- user.addMembership(membership);
-
+
entities.add(membership);
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/identity/src/test/java/org/jbpm/identity/xml/IdentityXmlParsingTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/identity/src/test/java/org/jbpm/identity/xml/IdentityXmlParsingTest.java 2010-05-26 01:02:24 UTC (rev 6376)
+++ jbpm3/branches/jbpm-3.2-soa/modules/identity/src/test/java/org/jbpm/identity/xml/IdentityXmlParsingTest.java 2010-05-26 01:22:01 UTC (rev 6377)
@@ -21,50 +21,63 @@
*/
package org.jbpm.identity.xml;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
-import junit.framework.TestCase;
-
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.identity.Entity;
import org.jbpm.identity.Group;
import org.jbpm.identity.User;
-public class IdentityXmlParsingTest extends TestCase {
+public class IdentityXmlParsingTest extends AbstractJbpmTestCase {
- IdentityXmlParser identityXmlParser;
-
+ private Map users = new HashMap();
+ private Map groups = new HashMap();
+
public void setUp() {
- identityXmlParser = new IdentityXmlParser();
- identityXmlParser.parse("org/jbpm/identity/xml/identity.xml");
+ IdentityXmlParser identityXmlParser = new IdentityXmlParser();
+ Entity[] entities = identityXmlParser.parse("org/jbpm/identity/xml/identity.xml");
+ for (int i = 0; i < entities.length; i++) {
+ Entity entity = entities[i];
+ if (entity instanceof User) {
+ users.put(entity.getName(), entity);
+ }
+ else if (entity instanceof Group) {
+ groups.put(entity.getName(), entity);
+ }
+ }
}
public void testUser() {
- User sampleManager = (User) identityXmlParser.users.get("manager");
+ User sampleManager = (User) users.get("manager");
assertEquals("manager", sampleManager.getName());
assertEquals("sample.manager(a)sample.domain", sampleManager.getEmail());
assertEquals("manager", sampleManager.getPassword());
}
public void testGroup() {
- Group bananalovers = (Group) identityXmlParser.groups.get("bananalovers");
+ Group bananalovers = (Group) groups.get("bananalovers");
assertEquals("bananalovers", bananalovers.getName());
assertEquals("fruitpreference", bananalovers.getType());
}
public void testGroupParent() {
- Group residents = (Group) identityXmlParser.groups.get("residents");
- Group bananalovers = (Group) identityXmlParser.groups.get("bananalovers");
+ Group residents = (Group) groups.get("residents");
+ Group bananalovers = (Group) groups.get("bananalovers");
assertSame(residents, bananalovers.getParent());
assertEquals(1, residents.getChildren().size());
assertSame(bananalovers, residents.getChildren().iterator().next());
}
public void testUserMembership() {
- User sampleManager = (User) identityXmlParser.users.get("manager");
- Group bananalovers = (Group) identityXmlParser.groups.get("bananalovers");
+ User sampleManager = (User) users.get("manager");
+ Group bananalovers = (Group) groups.get("bananalovers");
Set sampleManagersMemberships = sampleManager.getMemberships();
assertEquals(1, sampleManagersMemberships.size());
Set bananaloversMemberships = bananalovers.getMemberships();
assertEquals(1, bananaloversMemberships.size());
- assertSame(bananaloversMemberships.iterator().next(), sampleManagersMemberships.iterator().next());
+ assertSame(bananaloversMemberships.iterator().next(), sampleManagersMemberships.iterator()
+ .next());
}
}
13 years, 11 months
JBoss JBPM SVN: r6376 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: main/java/org/jbpm/ant and 3 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-05-25 21:02:24 -0400 (Tue, 25 May 2010)
New Revision: 6376
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmContextTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmDefaultConfigTest.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java
Log:
JBPM-2630: review and improve warnings logged when closing context in unstructured manner or from another thread
check that unstructured context close succeeds despite the warning
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -543,61 +543,18 @@
}
static JbpmConfiguration getCurrentJbpmConfiguration() {
- JbpmConfiguration currentJbpmConfiguration = null;
List stack = getJbpmConfigurationStack();
- if (!stack.isEmpty()) {
- currentJbpmConfiguration = (JbpmConfiguration) stack.get(stack.size() - 1);
- }
- return currentJbpmConfiguration;
+ return stack.isEmpty() ? null : (JbpmConfiguration) stack.get(stack.size() - 1);
}
private static List getJbpmConfigurationStack() {
return (List) jbpmConfigurationStacks.get();
}
- static void clearJbpmConfigurationStack() {
- List configStack = getJbpmConfigurationStack();
- if (configStack != null) {
- JbpmConfiguration[] configs = (JbpmConfiguration[]) configStack.toArray(new JbpmConfiguration[configStack.size()]);
- for (int f = 0; f < configs.length; f++) {
- List contextStack = configs[f].getJbpmContextStack();
- if (contextStack != null) {
- JbpmContext[] contexts = (JbpmContext[]) contextStack.toArray(new JbpmContext[contextStack.size()]);
- for (int t = 0; t < contexts.length; t++) {
- contexts[t].close();
- }
- }
- assert contextStack.isEmpty() : contextStack;
- }
- assert configStack.isEmpty() : configStack;
- }
- }
-
static void clearInstances() {
instances.clear();
}
- private void pushJbpmConfiguration() {
- getJbpmConfigurationStack().add(this);
- }
-
- private void popJbpmConfiguration() {
- List stack = getJbpmConfigurationStack();
- int index = stack.lastIndexOf(this);
- if (index == -1) {
- log.warn(this + " was not found in thread-local stack;"
- + "do not access JbpmContext instances from multiple threads");
- }
- else {
- if (index != stack.size() - 1) {
- log.warn(this + " was not closed in reverse creation order;"
- + " check your try-finally clauses around JbpmContext blocks");
- }
- // prevent configuration from remaining in the stack, no matter what
- stack.remove(index);
- }
- }
-
public JbpmContext getCurrentJbpmContext() {
ensureOpen();
@@ -610,26 +567,52 @@
}
void pushJbpmContext(JbpmContext jbpmContext) {
- pushJbpmConfiguration();
+ // first push the configuration
+ getJbpmConfigurationStack().add(this);
+ // then push the context
getJbpmContextStack().add(jbpmContext);
}
void popJbpmContext(JbpmContext jbpmContext) {
- List stack = getJbpmContextStack();
- int index = stack.lastIndexOf(jbpmContext);
- if (index == -1) {
- log.warn(jbpmContext + " was not found in thread-local stack;"
- + " do not access JbpmContext instances from multiple threads");
+ boolean threadSafetyFlag = false;
+ boolean creationOrderFlag = false;
+
+ // first pop the context
+ List contextStack = getJbpmContextStack();
+ int contextIndex = contextStack.lastIndexOf(jbpmContext);
+ if (contextIndex == -1) {
+ threadSafetyFlag = true;
}
else {
- if (index != stack.size() - 1) {
- log.warn(jbpmContext + " was not closed in reverse creation order;"
- + " check your try-finally clauses around JbpmContext blocks");
+ if (contextIndex != contextStack.size() - 1) {
+ creationOrderFlag = true;
}
// prevent context from remaining in the stack, no matter what
- stack.remove(index);
+ contextStack.remove(contextIndex);
}
- popJbpmConfiguration();
+
+ // then pop the configuration
+ List configStack = getJbpmConfigurationStack();
+ int configIndex = configStack.lastIndexOf(this);
+ if (configIndex == -1) {
+ threadSafetyFlag = true;
+ }
+ else {
+ if (configIndex != configStack.size() - 1) {
+ creationOrderFlag = true;
+ }
+ // prevent configuration from remaining in the stack, no matter what
+ configStack.remove(configIndex);
+ }
+
+ if (threadSafetyFlag) {
+ log.warn(jbpmContext + " was not closed in the thread that created it;"
+ + " JbpmContext is not safe for access from multiple threads!");
+ }
+ else if (creationOrderFlag) {
+ log.warn(jbpmContext + " was not closed in a block-structured manner;"
+ + " check your try-finally clauses around JbpmContext blocks");
+ }
}
public void startJobExecutor() {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/ant/DeployProcessTask.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -68,8 +68,9 @@
for (int i = 0; i < includedFiles.length; i++) {
String fileName = includedFiles[i];
- if (!ArrayUtil.contains(excludedFiles, fileName))
+ if (!ArrayUtil.contains(excludedFiles, fileName)) {
handleProcessFile(jbpmConfiguration, new File(baseDir, fileName));
+ }
}
}
}
@@ -77,12 +78,12 @@
private void handleProcessFile(JbpmConfiguration jbpmConfiguration, File processFile) {
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
- log("parsing process archive " + processFile.getName());
+ log("parsing process archive: " + processFile);
ProcessDefinition processDefinition = parseProcessArchive(processFile);
deployProcessDefinition(processDefinition, jbpmContext);
}
catch (IOException e) {
- log("error reading process archive " + processFile.getName(), e, Project.MSG_ERR);
+ log("failed to read process archive: " + processFile, e, Project.MSG_ERR);
if (failOnError) throw new BuildException(e, getLocation());
}
finally {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -178,10 +178,11 @@
// evaluate the description
if (task != null) {
String description = task.getDescription();
- if ((description != null) && (description.indexOf("#{") != -1)) {
- Object result = JbpmExpressionEvaluator.evaluate(description, executionContext);
+ if (description != null) {
+ String result = (String) JbpmExpressionEvaluator
+ .evaluate(description, executionContext, String.class);
if (result != null) {
- taskInstance.setDescription(result.toString());
+ taskInstance.setDescription(result);
}
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmConfigurationTest.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -32,15 +32,17 @@
protected void setUp() throws Exception {
super.setUp();
- JbpmConfiguration.clearJbpmConfigurationStack();
JbpmConfiguration.clearInstances();
+ }
+
+ protected void tearDown() throws Exception {
JbpmConfiguration.setDefaultObjectFactory(null);
+ super.tearDown();
}
public void testSingleton() {
JbpmConfiguration.setDefaultObjectFactory(new ObjectFactoryImpl(null, null));
JbpmConfiguration instance = JbpmConfiguration.getInstance();
- assertNotNull(instance);
assertSame(instance, JbpmConfiguration.getInstance());
assertSame(instance, JbpmConfiguration.getInstance());
assertSame(instance, JbpmConfiguration.getInstance());
@@ -50,8 +52,13 @@
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
+ " <jbpm-context />"
+ "</jbpm-configuration>");
- assertNotNull(jbpmConfiguration);
- assertNotNull(jbpmConfiguration.createJbpmContext());
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try {
+ assertNotNull(jbpmContext);
+ }
+ finally {
+ jbpmContext.close();
+ }
}
public void testNonExistingContext() {
@@ -71,12 +78,20 @@
+ " <jbpm-context name='a' />"
+ " <jbpm-context name='b' />"
+ "</jbpm-configuration>");
- assertNotNull(jbpmConfiguration);
+
JbpmContext a = jbpmConfiguration.createJbpmContext("a");
- assertNotNull(a);
- JbpmContext b = jbpmConfiguration.createJbpmContext("b");
- assertNotNull(b);
- assertNotSame(a, b);
+ try {
+ JbpmContext b = jbpmConfiguration.createJbpmContext("b");
+ try {
+ assertNotSame(a, b);
+ }
+ finally {
+ b.close();
+ }
+ }
+ finally {
+ a.close();
+ }
}
public void testNonSingletonContextCreation() {
@@ -84,11 +99,20 @@
+ " <jbpm-context name='a' />"
+ "</jbpm-configuration>");
assertNotNull(jbpmConfiguration);
+
JbpmContext a = jbpmConfiguration.createJbpmContext("a");
- assertNotNull(a);
- JbpmContext a2 = jbpmConfiguration.createJbpmContext("a");
- assertNotNull(a2);
- assertNotSame(a, a2);
+ try {
+ JbpmContext a2 = jbpmConfiguration.createJbpmContext("a");
+ try {
+ assertNotSame(a, a2);
+ }
+ finally {
+ a2.close();
+ }
+ }
+ finally {
+ a.close();
+ }
}
public void testParseXmlFault() {
@@ -123,11 +147,7 @@
private static final long serialVersionUID = 1L;
public Object createObject(String name) {
- Object o = null;
- if ("myproperty".equals(name)) {
- o = "mycustomfactoriedvalue";
- }
- return o;
+ return "myproperty".equals(name) ? "mycustomfactoriedvalue" : null;
}
public boolean hasObject(String name) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmContextTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmContextTest.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmContextTest.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -35,36 +35,59 @@
protected void setUp() throws Exception {
super.setUp();
- JbpmConfiguration.clearJbpmConfigurationStack();
JbpmConfiguration.clearInstances();
+ }
+
+ protected void tearDown() throws Exception {
JbpmConfiguration.setDefaultObjectFactory(null);
+ super.tearDown();
}
public void testServices() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a' />"
- + "</jbpm-configuration>");
- assertNotNull(jbpmConfiguration);
- Services s = jbpmConfiguration.createJbpmContext("a").getServices();
- assertNotNull(s);
- Services s2 = jbpmConfiguration.createJbpmContext("a").getServices();
- assertNotNull(s2);
- assertNotSame(s, s2);
+ + " <jbpm-context name='a' />"
+ + "</jbpm-configuration>");
+
+ JbpmContext a = jbpmConfiguration.createJbpmContext("a");
+ try {
+ Services s = a.getServices();
+
+ JbpmContext a2 = jbpmConfiguration.createJbpmContext("a");
+ try {
+ Services s2 = a2.getServices();
+ assertNotSame(s, s2);
+ }
+ finally {
+ a2.close();
+ }
+ }
+ finally {
+ a.close();
+ }
}
public void testJbpmContext() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a' />"
- + "</jbpm-configuration>");
+ + " <jbpm-context name='a' />"
+ + "</jbpm-configuration>");
+
JbpmContext one = jbpmConfiguration.createJbpmContext("a");
- assertNotNull(one);
- JbpmContext two = jbpmConfiguration.createJbpmContext("a");
- assertNotNull(two);
- assertNotSame(one, two);
+ try {
+
+ JbpmContext two = jbpmConfiguration.createJbpmContext("a");
+ try {
+ assertNotSame(one, two);
+ }
+ finally {
+ two.close();
+ }
+ }
+ finally {
+ one.close();
+ }
}
public static class TestServiceFactory implements ServiceFactory {
-
private static final long serialVersionUID = 1L;
public Service openService() {
@@ -76,7 +99,6 @@
}
public static class TestService implements Service {
-
private static final long serialVersionUID = 1L;
public void close() {
@@ -85,48 +107,67 @@
public void testCustomService() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a'>"
- + " <service name='test' factory='org.jbpm.JbpmContextTest$TestServiceFactory' />"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
- Object service = jbpmConfiguration.createJbpmContext("a").getServices().getService("test");
- assertNotNull(service);
- assertEquals(TestService.class, service.getClass());
+ + " <jbpm-context name='a'>"
+ + " <service name='test' factory='org.jbpm.JbpmContextTest$TestServiceFactory' />"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext("a");
+ try {
+ Object service = jbpmContext.getServices().getService("test");
+ assertSame(TestService.class, service.getClass());
+ }
+ finally {
+ jbpmContext.close();
+ }
}
public void testServiceInFactoryElement() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a'>"
- + " <service name='test'>"
- + " <factory>"
- + " <bean class='org.jbpm.JbpmContextTest$TestServiceFactory' />"
- + " </factory>"
- + " </service>"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
- Object service = jbpmConfiguration.createJbpmContext("a").getServices().getService("test");
- assertNotNull(service);
- assertEquals(TestService.class, service.getClass());
+ + " <jbpm-context name='a'>"
+ + " <service name='test'>"
+ + " <factory>"
+ + " <bean class='org.jbpm.JbpmContextTest$TestServiceFactory' />"
+ + " </factory>"
+ + " </service>"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext("a");
+ try {
+ Object service = jbpmContext.getServices().getService("test");
+ assertSame(TestService.class, service.getClass());
+ }
+ finally {
+ jbpmContext.close();
+ }
}
public void testServiceCaching() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a'>"
- + " <service name='test' factory='org.jbpm.JbpmContextTest$TestServiceFactory' />"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext("a");
- TestService serviceOne = (TestService) jbpmContext.getServices().getService("test");
- assertNotNull(serviceOne);
- TestService serviceTwo = (TestService) jbpmContext.getServices().getService("test");
- assertNotNull(serviceTwo);
- assertSame(serviceOne, serviceTwo);
- jbpmContext = jbpmConfiguration.createJbpmContext("a");
- assertNotSame(serviceOne, jbpmContext.getServices().getService("test"));
+ + " <jbpm-context name='a'>"
+ + " <service name='test' factory='" + TestServiceFactory.class.getName() + "' />"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
+
+ JbpmContext a = jbpmConfiguration.createJbpmContext("a");
+ try {
+ TestService serviceOne = (TestService) a.getServices().getService("test");
+ TestService serviceTwo = (TestService) a.getServices().getService("test");
+ assertSame(serviceOne, serviceTwo);
+
+ JbpmContext a2 = jbpmConfiguration.createJbpmContext("a");
+ try {
+ assertNotSame(serviceOne, a2.getServices().getService("test"));
+ }
+ finally {
+ a2.close();
+ }
+ }
+ finally {
+ a.close();
+ }
}
public static class CustomLoggingServiceFactory implements ServiceFactory {
-
private static final long serialVersionUID = 1L;
public Service openService() {
@@ -138,8 +179,8 @@
}
public static class CustomLoggingService implements LoggingService {
+ private static final long serialVersionUID = 1L;
- private static final long serialVersionUID = 1L;
ProcessLog processLog;
int invocationCount = 0;
@@ -154,10 +195,10 @@
public void testCustomLoggingService() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='a'>"
- + " <service name='logging' factory='org.jbpm.JbpmContextTest$CustomLoggingServiceFactory' />"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
+ + " <jbpm-context name='a'>"
+ + " <service name='logging' factory='" + CustomLoggingServiceFactory.class.getName() + "' />"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
CustomLoggingService customLoggingService = null;
MessageLog messageLog = null;
@@ -165,6 +206,7 @@
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext("a");
try {
customLoggingService = (CustomLoggingService) jbpmContext.getServices().getLoggingService();
+
messageLog = new MessageLog("blablabla");
ProcessInstance processInstance = new ProcessInstance(new ProcessDefinition());
processInstance.getLoggingInstance().addLog(messageLog);
@@ -174,13 +216,13 @@
jbpmContext.close();
}
assertEquals(messageLog, customLoggingService.processLog);
- assertEquals(2, customLoggingService.invocationCount); // count process instance create log
+ assertEquals(2, customLoggingService.invocationCount);
}
public static class TestSaveOperation implements SaveOperation {
+ private static final long serialVersionUID = 1L;
static int invocationCount = 0;
- private static final long serialVersionUID = 1L;
public void save(ProcessInstance processInstance, JbpmContext jbpmContext) {
invocationCount++;
@@ -189,22 +231,20 @@
public void testSaveOperation() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='default.jbpm.context'>"
- + " <save-operations>"
- + " <save-operation class='org.jbpm.JbpmContextTest$TestSaveOperation' />"
- + " </save-operations>"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
+ + " <jbpm-context name='default.jbpm.context'>"
+ + " <save-operations>"
+ + " <save-operation class='" + TestSaveOperation.class.getName() + "' />"
+ + " </save-operations>"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
+ TestSaveOperation.invocationCount = 0;
- TestSaveOperation.invocationCount = 0;
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
try {
+ assertEquals(0, TestSaveOperation.invocationCount);
- assertEquals(0, TestSaveOperation.invocationCount);
jbpmContext.save(new ProcessInstance());
assertEquals(1, TestSaveOperation.invocationCount);
-
}
finally {
jbpmContext.close();
@@ -213,24 +253,22 @@
public void testSaveOperationInBeanElement() {
JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>"
- + " <jbpm-context name='default.jbpm.context'>"
- + " <save-operations>"
- + " <save-operation>"
- + " <bean class='org.jbpm.JbpmContextTest$TestSaveOperation' />"
- + " </save-operation>"
- + " </save-operations>"
- + " </jbpm-context>"
- + "</jbpm-configuration>");
+ + " <jbpm-context name='default.jbpm.context'>"
+ + " <save-operations>"
+ + " <save-operation>"
+ + " <bean class='" + TestSaveOperation.class.getName() + "' />"
+ + " </save-operation>"
+ + " </save-operations>"
+ + " </jbpm-context>"
+ + "</jbpm-configuration>");
+ TestSaveOperation.invocationCount = 0;
- TestSaveOperation.invocationCount = 0;
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-
try {
+ assertEquals(0, TestSaveOperation.invocationCount);
- assertEquals(0, TestSaveOperation.invocationCount);
jbpmContext.save(new ProcessInstance());
assertEquals(1, TestSaveOperation.invocationCount);
-
}
finally {
jbpmContext.close();
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmDefaultConfigTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmDefaultConfigTest.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/JbpmDefaultConfigTest.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -1,10 +1,8 @@
package org.jbpm;
-
public class JbpmDefaultConfigTest extends AbstractJbpmTestCase {
- // this test should be ran without jbpm.cfg.xml on the
- // classpath.
+ // this test should be run without jbpm.cfg.xml on the classpath
public void testWithoutJbpmCfgXml() {
JbpmConfiguration.getInstance().createJbpmContext().close();
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java 2010-05-25 16:18:06 UTC (rev 6375)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm2630/JBPM2630Test.java 2010-05-26 01:02:24 UTC (rev 6376)
@@ -50,7 +50,7 @@
super.tearDown();
}
- public void testPopJbpmConfiguration() {
+ public void testBlockStructuredContextClose() {
JbpmContext testContext1 = testConfiguration.createJbpmContext();
try {
JbpmContext noLogContext = noLogConfiguration.createJbpmContext();
@@ -75,4 +75,20 @@
testContext1.close();
}
}
+
+ public void testUnstructuredContextClose() {
+ JbpmContext testContext = testConfiguration.createJbpmContext();
+ assertSame(testConfiguration,
+ JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+
+ JbpmContext noLogContext = noLogConfiguration.createJbpmContext();
+ assertSame(noLogConfiguration,
+ JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+
+ // this will emit a block-structured warning, but still succeed
+ testContext.close();
+ noLogContext.close();
+
+ assertNull(JbpmConfigurationTestHelper.getCurrentJbpmConfiguration());
+ }
}
13 years, 11 months
JBoss JBPM SVN: r6375 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/activity/forkjoin and 1 other directory.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-05-25 12:18:06 -0400 (Tue, 25 May 2010)
New Revision: 6375
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
Log:
JBPM-2720: ends forked (but not joined) executions when multiplicity attribute on join activity is used, contains support for expression in multiplicity attribute of join node
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java 2010-05-25 03:45:03 UTC (rev 6374)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java 2010-05-25 16:18:06 UTC (rev 6375)
@@ -31,6 +31,7 @@
import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.model.Activity;
import org.jbpm.api.model.Transition;
+import org.jbpm.pvm.internal.el.Expression;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
@@ -44,6 +45,7 @@
int multiplicity = -1;
LockMode lockMode = LockMode.UPGRADE;
+ Expression multiplicityExpression;
public void execute(ActivityExecution execution) {
execute((ExecutionImpl)execution);
@@ -52,6 +54,15 @@
public void execute(ExecutionImpl execution) {
Activity activity = execution.getActivity();
+ // evaluate multiplicity expression
+ if (multiplicityExpression != null) {
+ try {
+ multiplicity = Integer.valueOf(multiplicityExpression.evaluate(execution).toString());
+ } catch (Exception e) {
+ throw new JbpmException("Problem while evaluating multiplicity attribute: " + e.getMessage());
+ }
+ }
+
// if this is a single, non concurrent root
if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
// just pass through
@@ -75,7 +86,19 @@
if (isComplete(joinedExecutions, activity)) {
endJoinedExecutions(joinedExecutions);
-
+
+ if (multiplicity != -1) {
+ // remove forked but not joined executions only when multiplicity attribute was used
+ List<ExecutionImpl> forkedExecutionsToRemove = new ArrayList<ExecutionImpl>();
+ for (ExecutionImpl concurrentExecution : concurrentRoot.getExecutions()) {
+ //collect all executions from the parent that are forked
+ if ( (Execution.STATE_ACTIVE_CONCURRENT.equals(concurrentExecution.getState()))) {
+ forkedExecutionsToRemove.add(concurrentExecution);
+ }
+ }
+ // end all of found forked (but not joined) executions
+ endJoinedExecutions(forkedExecutionsToRemove);
+ }
ExecutionImpl outgoingExecution = null;
if (concurrentRoot.getExecutions().size()==0) {
outgoingExecution = concurrentRoot;
@@ -125,10 +148,10 @@
}
}
- public void setMultiplicity(int multiplicity) {
- this.multiplicity = multiplicity;
- }
public void setLockMode(LockMode lockMode) {
this.lockMode = lockMode;
+ }
+ public void setMultiplicityExpression(Expression multiplicityExpression) {
+ this.multiplicityExpression = multiplicityExpression;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2010-05-25 03:45:03 UTC (rev 6374)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2010-05-25 16:18:06 UTC (rev 6375)
@@ -23,6 +23,7 @@
import org.hibernate.LockMode;
import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.el.Expression;
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;
@@ -45,12 +46,8 @@
if (element.hasAttribute(MULTIPLICITY)) {
String multiplicictyText = element.getAttribute(MULTIPLICITY);
- try {
- int multiplicity = Integer.parseInt(multiplicictyText);
- joinActivity.setMultiplicity(multiplicity);
- } catch (NumberFormatException e) {
- parse.addProblem(MULTIPLICITY + " " + multiplicictyText + " is not a valid integer", element);
- }
+ Expression expression = Expression.create(multiplicictyText, Expression.LANGUAGE_UEL_VALUE);
+ joinActivity.setMultiplicityExpression(expression);
}
if (element.hasAttribute(LOCKMODE)) {
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkJoinWithMutliplicityTest.java 2010-05-25 16:18:06 UTC (rev 6375)
@@ -0,0 +1,138 @@
+/*
+ * 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.activity.forkjoin;
+
+import java.util.HashMap;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * @author Maciej Swiderski
+ *
+ */
+public class ForkJoinWithMutliplicityTest extends JbpmTestCase {
+
+ public void testForkWithMultiplicityOne() {
+ deployJpdlXmlString(""
+ + "<process name='ForkJoingMultiplicity' xmlns='http://jbpm.org/4.3/jpdl'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to fork1' to='fork1'/>"
+ + " </start>"
+ + " <fork g='185,95,49,50' name='fork1' >"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " <transition name='right' to='task2' g='-44,-18'/>"
+ + " </fork>"
+ + " <task name='task1' g='90,177,73,44' assignee='mike'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task2' g='90,177,73,44' assignee='alex'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <join name='join1' g='192,511,57,44' multiplicity='1'>"
+ + " <transition name='to Big car' to='Big car' g='-42,-18'/>"
+ + " </join>"
+ + " <state name='Big car' > "
+ + " <transition name='to end1' to='end1' g='-43,-18'/>"
+ + " </state> "
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkJoingMultiplicity");
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+ executionService.signalExecutionById(processInstance.getId());
+
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForkWithMultiplicityAsExpression() {
+ deployJpdlXmlString(""
+ + "<process name='ForkJoingMultiplicity' xmlns='http://jbpm.org/4.3/jpdl'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to fork1' to='fork1'/>"
+ + " </start>"
+ + " <fork g='185,95,49,50' name='fork1' >"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " <transition name='right' to='task2' g='-44,-18'/>"
+ + " </fork>"
+ + " <task name='task1' g='90,177,73,44' assignee='mike'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task2' g='90,177,73,44' assignee='alex'>"
+ + " <transition name='to join1' to='join1' g='-43,-18'/>"
+ + " </task>"
+ + " <join name='join1' g='192,511,57,44' multiplicity='#{multiplicity}'>"
+ + " <transition name='to Big car' to='Big car' g='-42,-18'/>"
+ + " </join>"
+ + " <state name='Big car' > "
+ + " <transition name='to end1' to='end1' g='-43,-18'/>"
+ + " </state> "
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ HashMap<String, Integer> variables = new HashMap<String, Integer>();
+ variables.put("multiplicity", 1);
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForkJoingMultiplicity", variables);
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+ executionService.signalExecutionById(processInstance.getId());
+
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+}
13 years, 11 months