提交 70abe677 编写于 作者: T tombaeyens

ACT-60 fixing spring integration and added resource name to process definition

上级 d8512805
......@@ -12,51 +12,36 @@
*/
package org.activiti.test.cfg.spring;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import org.activiti.engine.ProcessInstance;
import org.activiti.engine.Task;
import org.activiti.engine.test.ProcessEngineTestCase;
/**
* @author Tom Baeyens
* @author Dave Syer
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringTest {
public class SpringTest extends ProcessEngineTestCase {
public SpringTest() {
setSpringApplicationContextConfigurationResource("org/activiti/test/cfg/spring/SpringTest-context.xml");
}
public void testProcessExecutionWithTaskAssignedFromExpression() {
// UserBean userBean = (UserBean) getSpringBean("userBean");
int before = processEngine.getTaskService().findAssignedTasks("kermit").size();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeExpressionProcess");
List<String> activeActivityIds = runtimeService.findActiveActivityIds(processInstance.getId());
assertEquals("[theTask]", activeActivityIds.toString());
List<Task> tasks = processEngine.getTaskService().findAssignedTasks("kermit");
assertEquals(1, tasks.size());
}
// @Autowired
// private ProcessEngine processEngine;
//
// @Autowired
// private UserBean userBean;
//
// @Autowired
// private PlatformTransactionManager transactionManager;
//
// @Rule
// public ExpectedException exception = ExpectedException.none();
//
// static {
// LogUtil.readJavaUtilLoggingConfigFromClasspath();
// }
//
// @Test
// public void testProcessExecutionWithTaskAssignedFromExpression() {
//
// int before = processEngine.getTaskService().findAssignedTasks("kermit").size();
// ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("taskAssigneeExpressionProcess");
// assertEquals("[theTask]", processInstance.findActivityIds().toString());
// ProcessInstanceEntity processInstanceEntity = (ProcessInstanceEntity) processInstance;
// ActivityInstanceImpl activityInstance = processInstanceEntity.getActivityInstances().iterator().next();
// assertEquals("${user}", ((TaskDefinition) ReflectionTestUtils.getField(((ActivityImpl) activityInstance.getActivity()).getActivityBehavior(),
// "taskDefinition")).getAssignee());
// List<Task> tasks = processEngine.getTaskService().findAssignedTasks("kermit");
// assertEquals(before + 1, tasks.size());
//
// processEngine.getRuntimeService().endProcessInstance(processInstance.getId());
//
// }
//
// @Test
// public void testJavaServiceDelegation() {
// RuntimeService runtimeService = processEngine.getRuntimeService();
......
......@@ -86,7 +86,7 @@ public class ProcessEngineInitializationTest extends PvmTestCase {
fail("expected exception");
} catch (ActivitiWrongDbException e) {
assertTextPresent("version mismatch", e.getMessage());
assertEquals(25.7, e.getDbVersion());
assertEquals("25.7", e.getDbVersion());
assertEquals(ProcessEngine.VERSION, e.getLibraryVersion());
}
......
......@@ -12,6 +12,7 @@
*/
package org.activiti.engine;
import java.util.List;
import java.util.Map;
......@@ -43,6 +44,10 @@ public interface RuntimeService {
ExecutionQuery createExecutionQuery();
Execution findExecutionById(String executionId);
/** the activity ids for all executions that are waiting in activities.
* This is a list because a single activity can be active multiple times.*/
List<String> findActiveActivityIds(String executionId);
ProcessInstanceQuery createProcessInstanceQuery();
......
......@@ -13,6 +13,7 @@
package org.activiti.engine.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.Execution;
......@@ -21,6 +22,7 @@ import org.activiti.engine.ProcessInstance;
import org.activiti.engine.ProcessInstanceQuery;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.cmd.DeleteProcessInstanceCmd;
import org.activiti.engine.impl.cmd.FindActiveActivityIdsCmd;
import org.activiti.engine.impl.cmd.GetVariableCmd;
import org.activiti.engine.impl.cmd.GetVariablesCmd;
import org.activiti.engine.impl.cmd.SetVariablesCmd;
......@@ -91,4 +93,8 @@ public class RuntimeServiceImpl extends ServiceImpl implements RuntimeService {
.executionId(executionId)
.singleResult();
}
public List<String> findActiveActivityIds(String executionId) {
return commandExecutor.execute(new FindActiveActivityIdsCmd(executionId));
}
}
......@@ -72,7 +72,7 @@ public class UserTaskActivity extends TaskActivity {
}
protected String evaluateExpression(String expr, ActivityExecution execution) {
// TODO move parsing of value expression to bpmn parser and only keep evaluation here
// TODO http://jira.codehaus.org/browse/ACT-84 move parsing of value expression to bpmn parser and only keep evaluation here
return (String) expressionManager.createValueExpression(expr).getValue(execution);
}
......
......@@ -62,7 +62,10 @@ public class BpmnDeployer implements Deployer, ProcessEngineConfigurationAware {
.name(resourceName)
.execute();
processDefinitions.addAll(bpmnParse.getProcessDefinitions());
for (ProcessDefinitionEntity processDefinition: bpmnParse.getProcessDefinitions()) {
processDefinition.setResourceName(resourceName);
processDefinitions.add(processDefinition);
}
}
}
......
......@@ -11,41 +11,36 @@
* limitations under the License.
*/
package org.activiti.engine.test;
package org.activiti.engine.impl.cmd;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.pvm.impl.util.LogUtil.ThreadLogMode;
import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.runtime.ExecutionEntity;
/** JUnit 3 style base class that also exposes selected implementation
* aspects of the engine like the CommandExecutor.
*
/**
* @author Tom Baeyens
*/
public class ProcessEngineImplTestCase extends ProcessEngineTestCase {
public class FindActiveActivityIdsCmd implements Command<List<String>> {
protected ProcessEngineConfiguration processEngineConfiguration;
protected String executionId;
public ProcessEngineImplTestCase() {
super();
}
public ProcessEngineImplTestCase(String configurationResource, ThreadLogMode threadRenderingMode) {
super(configurationResource, threadRenderingMode);
}
public ProcessEngineImplTestCase(String configurationResource) {
super(configurationResource);
}
public ProcessEngineImplTestCase(ThreadLogMode threadRenderingMode) {
super(threadRenderingMode);
public FindActiveActivityIdsCmd(String executionId) {
this.executionId = executionId;
}
@Override
void initializeServices() {
super.initializeServices();
processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
public List<String> execute(CommandContext commandContext) {
ExecutionEntity execution = commandContext
.getRuntimeSession()
.findExecutionById(executionId);
if (execution==null) {
throw new ActivitiException("execution with id "+executionId+" was not found");
}
return execution.findActiveActivityIds();
}
}
......@@ -18,6 +18,8 @@ import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationAware;
import org.activiti.engine.impl.persistence.runtime.ExecutionEntity;
import org.activiti.pvm.impl.runtime.ExecutionImpl;
......@@ -34,9 +36,6 @@ import org.activiti.pvm.impl.runtime.ExecutionImpl;
* expressions.
* </p>
* <p>
* The main extension point is the {@link #setElResolver(ELResolver)}.
* </p>
* <p>
* Using this class, also the runtime engine doesn't create a hard dependency on
* the javax.el library as long as you don't use expressions.
* </p>
......@@ -44,7 +43,7 @@ import org.activiti.pvm.impl.runtime.ExecutionImpl;
* @author Tom Baeyens
* @author Dave Syer
*/
public class ExpressionManager {
public class ExpressionManager implements ProcessEngineConfigurationAware {
public static final String UEL_VALUE = "uel-value";
public static final String UEL_METHOD = "uel-method";
......@@ -62,8 +61,9 @@ public class ExpressionManager {
* of global variables in a static engine wide scope. Defaults to null (so no
* custom variables).
*/
public void setElResolver(ELResolver elResolver) {
this.elResolver = elResolver;
public void configurationCompleted(ProcessEngineConfiguration processEngineConfiguration) {
this.elResolver = processEngineConfiguration.getElResolver();
}
public ActivitiValueExpression createValueExpression(String expression) {
......
......@@ -144,8 +144,13 @@ public class DbRepositorySession implements Session, RepositorySession {
return (List<DeploymentEntity>) dbSqlSession.selectList("selectDeployments");
};
@SuppressWarnings("unchecked")
public DeploymentEntity findLatestDeploymentByName(String deploymentName) {
return (DeploymentEntity) dbSqlSession.selectOne("selectLatestDeploymentByName", deploymentName);
List list = dbSqlSession.selectList("selectDeploymentsByName", deploymentName, new Page(0, 1));
if (list!=null && !list.isEmpty()) {
return (DeploymentEntity) list.get(0);
}
return null;
}
@SuppressWarnings("unchecked")
......
......@@ -34,6 +34,7 @@ public class ProcessDefinitionEntity extends ProcessDefinitionImpl implements Pr
protected String name;
protected int version;
protected String deploymentId;
protected String resourceName;
public ProcessDefinitionEntity() {
super(null);
......@@ -112,4 +113,12 @@ public class ProcessDefinitionEntity extends ProcessDefinitionImpl implements Pr
public void setId(String id) {
this.id = id;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
}
......@@ -39,6 +39,7 @@ import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.bpmn.deployer.BpmnDeployer;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.jobexecutor.JobExecutor;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.pvm.impl.util.ClassNameUtil;
......@@ -64,9 +65,14 @@ public class ProcessEngineTestCase extends PvmTestCase {
protected ThreadLogMode threadRenderingMode;
protected String configurationResource;
protected String springApplicationContextConfigurationResource;
// detyped storage of the application context is done to prevent a hard dependency of spring classes
// on the classpath in case spring is not actually used.
protected Object springApplicationContext;
protected List<String> deploymentsToDeleteAfterTestMethod = new ArrayList<String>();
protected Throwable exception;
protected ProcessEngineConfiguration processEngineConfiguration;
protected ProcessEngine processEngine;
protected RepositoryService repositoryService;
protected RuntimeService runtimeService;
......@@ -111,11 +117,7 @@ public class ProcessEngineTestCase extends PvmTestCase {
if (processEngine==null) {
processEngine = processEngines.get(configurationResource);
if (processEngine==null) {
log.fine("==== BUILDING PROCESS ENGINE ========================================================================");
processEngine = new ProcessEngineBuilder()
.configureFromPropertiesResource(configurationResource)
.buildProcessEngine();
log.fine("==== PROCESS ENGINE CREATED =========================================================================");
initializeProcessEngine();
processEngines.put(configurationResource, processEngine);
}
initializeServices();
......@@ -148,11 +150,19 @@ public class ProcessEngineTestCase extends PvmTestCase {
}
}
private void initializeProcessEngine() {
log.fine("==== BUILDING PROCESS ENGINE ========================================================================");
processEngine = new ProcessEngineBuilder()
.configureFromPropertiesResource(configurationResource)
.buildProcessEngine();
log.fine("==== PROCESS ENGINE CREATED =========================================================================");
}
/** Each test is assumed to clean up all DB content it entered.
* After a test method executed, this method scans all tables to see if the DB is completely clean.
* It throws AssertionFailed in case the DB is not clean.
* If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb() throws Throwable {
private void assertAndEnsureCleanDb() throws Throwable {
log.fine("verifying that db is clean after test");
Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
StringBuilder outputMessage = new StringBuilder();
......@@ -183,7 +193,7 @@ public class ProcessEngineTestCase extends PvmTestCase {
}
}
void annotationDeploymentBefore() {
private void annotationDeploymentBefore() {
Method method = null;
try {
method = getClass().getDeclaredMethod(getName(), (Class<?>[])null);
......@@ -223,7 +233,7 @@ public class ProcessEngineTestCase extends PvmTestCase {
return type.getName().replace('.', '/') + "." + name + "." + BpmnDeployer.BPMN_RESOURCE_SUFFIX;
}
protected void annotationDeploymentAfter() {
private void annotationDeploymentAfter() {
for (String deploymentId: deploymentsToDeleteAfterTestMethod) {
log.fine("annotation @Deployment deletes deployment for "+ClassNameUtil.getClassNameWithoutPackage(this)+"."+getName());
repositoryService.deleteDeploymentCascade(deploymentId);
......@@ -231,7 +241,8 @@ public class ProcessEngineTestCase extends PvmTestCase {
}
void initializeServices() {
private void initializeServices() {
processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
repositoryService = processEngine.getRepositoryService();
runtimeService = processEngine.getRuntimeService();
taskService = processEngine.getTaskService();
......@@ -267,11 +278,11 @@ public class ProcessEngineTestCase extends PvmTestCase {
}
}
protected boolean areJobsAvailable() {
public boolean areJobsAvailable() {
return !managementService.createJobQuery().list().isEmpty();
}
protected static class InteruptTask extends TimerTask {
private static class InteruptTask extends TimerTask {
protected boolean timeLimitExceeded = false;
protected Thread thread;
public InteruptTask(Thread thread) {
......@@ -292,4 +303,8 @@ public class ProcessEngineTestCase extends PvmTestCase {
}
processEngines.clear();
}
public void setSpringApplicationContextConfigurationResource(String springApplicationContextConfigurationResource) {
this.springApplicationContextConfigurationResource = springApplicationContextConfigurationResource;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test;
/**
* @author Tom Baeyens
*/
public class SpringProcessEngineTestCase extends ProcessEngineTestCase {
// private void initializeProcessEngineFromSpringConfigurationResource() {
// log.fine("==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE =========================================");
//
// ApplicationContext applicationContext = new ClassPathXmlApplicationContext(springApplicationContextConfigurationResource);
// Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class);
// if ( (beansOfType==null)
// || (beansOfType.isEmpty())
// ) {
// throw new ActivitiException("no "+ProcessEngine.class.getName()+" defined in the application context "+springApplicationContextConfigurationResource);
// }
//
// this.springApplicationContext = applicationContext;
//
// processEngine = beansOfType.values().iterator().next();
// log.fine("==== SPRING PROCESS ENGINE CREATED ==================================================================");
// }
// protected Object getSpringBean(String springBeanName) {
// // detyped storage of the application context and casting here is done to prevent a hard dependency of spring classes
// // on the classpath in case spring is not actually used.
// return ((ApplicationContext)springApplicationContext).getBean(springBeanName);
// }
}
......@@ -89,6 +89,7 @@ create table ACT_PROCESSDEFINITION (
KEY_ varchar(255),
VERSION_ integer,
DEPLOYMENT_ID_ varchar(255),
RESOURCE_NAME_ varchar(255),
primary key (ID_)
);
......
......@@ -90,12 +90,13 @@
<!-- PROCESSDEFINITION INSERT -->
<insert id="insertProcessDefinition" parameterType="org.activiti.engine.impl.persistence.repository.ProcessDefinitionEntity">
insert into ACT_PROCESSDEFINITION(ID_, NAME_, KEY_, VERSION_, DEPLOYMENT_ID_)
insert into ACT_PROCESSDEFINITION(ID_, NAME_, KEY_, VERSION_, DEPLOYMENT_ID_, RESOURCE_NAME_)
values (#{id, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{key, jdbcType=VARCHAR},
#{version, jdbcType=INTEGER},
#{deploymentId, jdbcType=VARCHAR})
#{deploymentId, jdbcType=VARCHAR},
#{resourceName, jdbcType=VARCHAR})
</insert>
<!-- PROCESSDEFINITION UPDATE -->
......@@ -114,6 +115,7 @@
<result property="key" column="KEY_" jdbcType="VARCHAR" />
<result property="version" column="VERSION_" jdbcType="INTEGER"/>
<result property="deploymentId" column="DEPLOYMENT_ID_" jdbcType="VARCHAR"/>
<result property="resourceName" column="RESOURCE_NAME_" jdbcType="VARCHAR"/>
</resultMap>
<!-- PROCESSDEFINITION SELECT -->
......
......@@ -21,12 +21,12 @@ import org.activiti.engine.Task;
import org.activiti.engine.TaskQuery;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.test.Deployment;
import org.activiti.engine.test.ProcessEngineImplTestCase;
import org.activiti.engine.test.ProcessEngineTestCase;
/**
* @author Joram Barrez
*/
public class CallActivityAdvancedTest extends ProcessEngineImplTestCase {
public class CallActivityAdvancedTest extends ProcessEngineTestCase {
@Deployment(resources = {
"org/activiti/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcess.bpmn20.xml",
......
......@@ -15,13 +15,13 @@ package org.activiti.impl.interceptor;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.test.ProcessEngineImplTestCase;
import org.activiti.engine.test.ProcessEngineTestCase;
/**
* @author Tom Baeyens
*/
public class CommandContextTest extends ProcessEngineImplTestCase {
public class CommandContextTest extends ProcessEngineTestCase {
public void testCommandContextGetCurrentAfterException() {
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册