提交 c4e454c9 编写于 作者: J Joram Barrez

Added simple deployment test to verify transactional behavior in Spring

上级 286de021
/* 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.spring.test.transaction;
import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
/**
* @author Joram Barrez
*/
public class DeployBean {
@Autowired
protected RepositoryService repositoryService;
@Transactional
public void deployProcesses() {
repositoryService.createDeployment().addString("process01.bpmn20.xml",
"<definitions xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' targetNamespace='http://activiti.org/BPMN20'>"
+ "<process id='process01' name='Insurance Damage Report' /></definitions>")
.deploy();
repositoryService.createDeployment().addString("process01.bpmn20.xml",
"<definitions xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' targetNamespace='http://activiti.org/BPMN20'>"
+ "<process id='process01' name='Insurance Damage Report' this_should='fail' /></definitions>")
.deploy();
}
public RepositoryService getRepositoryService() {
return repositoryService;
}
public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
}
......@@ -15,6 +15,7 @@ package org.activiti.spring.test.transaction;
import javax.sql.DataSource;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.Deployment;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
......@@ -32,6 +33,9 @@ public class SpringTransactionIntegrationTest extends SpringActivitiTestCase {
@Autowired
protected UserBean userBean;
@Autowired
protected DeployBean deployBean;
@Autowired
protected DataSource dataSource;
......@@ -69,5 +73,17 @@ public class SpringTransactionIntegrationTest extends SpringActivitiTestCase {
jdbcTemplate.execute("drop table MY_TABLE if exists;");
}
public void testRollBackOnDeployment() {
// The second process should fail. None of the processes should be deployed, the first one should be rolled back
assertEquals(0, repositoryService.createProcessDefinitionQuery().count());
try {
deployBean.deployProcesses();
fail();
} catch (ActivitiException e) {
// Parse exception should happen
}
assertEquals(0, repositoryService.createProcessDefinitionQuery().count());
}
}
......@@ -43,6 +43,10 @@
<property name="taskService" ref="taskService" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="deployBean" class="org.activiti.spring.test.transaction.DeployBean">
<property name="repositoryService" ref="repositoryService" />
</bean>
<bean id="printer" class="org.activiti.spring.test.transaction.Printer" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册