Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
daisuke-yoshimoto committed Dec 23, 2018
1 parent 8386e83 commit f9d0daa
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ protected boolean validateModel(Resource resource, final RepositoryService repos
BpmnModel bpmnModel = converter.convertToBpmnModel(new InputStreamSource(resource.getInputStream()), true,
false);
List<ValidationError> validationErrors = repositoryService.validateProcess(bpmnModel);
if (validationErrors == null || validationErrors.isEmpty()) {
return true;
} else {
if ( validationErrors != null && !validationErrors.isEmpty() ) {
StringBuilder warningBuilder = new StringBuilder();
StringBuilder errorBuilder = new StringBuilder();

for (ValidationError error : validationErrors) {
if (error.isWarning()) {
if ( error.isWarning() ) {
warningBuilder.append(error.toString());
warningBuilder.append("\n");
} else {
Expand All @@ -96,23 +94,21 @@ protected boolean validateModel(Resource resource, final RepositoryService repos
}

// Write out warnings (if any)
if (warningBuilder.length() > 0) {
if ( warningBuilder.length() > 0 ) {
LOGGER.warn("Following warnings encountered during process validation: "
+ warningBuilder.toString());
}

if (errorBuilder.length() > 0) {
if ( errorBuilder.length() > 0 ) {
LOGGER.warn("Errors while parsing:\n" + errorBuilder.toString());
return false;
} else {
return true;
}
}
}
} catch (Exception e) {
} catch ( Exception e ) {
LOGGER.warn("Error parsing XML", e);
return false;
}
return false;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.activiti.spring.test.autodeployment;

import java.util.List;

import org.activiti.engine.ActivitiException;
import org.activiti.spring.autodeployment.FailOnNoProcessAutoDeploymentStrategy;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration("classpath:org/activiti/spring/test/autodeployment/errorHandling/spring-context.xml")
public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTestCase {

private final String nameHint = "FailOnNoProcessAutoDeploymentStrategyTest";

private final String validName1 = "org/activiti/spring/test/autodeployment/errorHandling/valid.bpmn20.xml";
private final String invalidName1 = "org/activiti/spring/test/autodeployment/errorHandling/parsing-error.bpmn20.xml";
private final String invalidName2 = "org/activiti/spring/test/autodeployment/errorHandling/validation-error.bpmn20.xml";

private void cleanUp() {
List<org.activiti.engine.repository.Deployment> deployments = repositoryService.createDeploymentQuery().list();
for (org.activiti.engine.repository.Deployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}

@Test
public void testValidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testInvalidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1), new ClassPathResource(invalidName2)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testWithParsingErrorResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testWithValidationErrorResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName2)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testOnlyInvalidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(invalidName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
try {
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
} catch (ActivitiException e) {
assertEquals("No process definition was deployed.", e.getMessage());
assertEquals(0, repositoryService.createDeploymentQuery().count());
cleanUp();
return;
}
fail();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.activiti.spring.test.autodeployment;

import java.util.List;

import org.activiti.spring.autodeployment.NeverFailAutoDeploymentStrategy;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration("classpath:org/activiti/spring/test/autodeployment/errorHandling/spring-context.xml")
public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase {

private final String nameHint = "NeverFailAutoDeploymentStrategyTest";

private final String validName1 = "org/activiti/spring/test/autodeployment/errorHandling/valid.bpmn20.xml";
private final String invalidName1 = "org/activiti/spring/test/autodeployment/errorHandling/parsing-error.bpmn20.xml";
private final String invalidName2 = "org/activiti/spring/test/autodeployment/errorHandling/validation-error.bpmn20.xml";

private void cleanUp() {
List<org.activiti.engine.repository.Deployment> deployments = repositoryService.createDeploymentQuery().list();
for (org.activiti.engine.repository.Deployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}

@Test
public void testValidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testInvalidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1), new ClassPathResource(invalidName2)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testWithParsingErrorResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testWithValidationErrorResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName2)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
cleanUp();
}

@Test
public void testOnlyInvalidResources() {
cleanUp();
final Resource[] resources = new Resource[]{new ClassPathResource(invalidName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(0, repositoryService.createDeploymentQuery().count());
cleanUp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aaa
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true"/>
<property name="deploymentResources"
value="classpath*:/org/activiti/spring/test/autodeployment/autodeploy.*.bpmn20.xml"/>
</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"/>
</bean>

<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
targetNamespace="http://www.activiti.org/test">

<process id="a">

<startEvent id="start"/>
<sequenceFlow id="flow1" sourceRef="start" targetRef="end"/>

<endEvent id="end"/>

</process>

<bpmndi:BPMNDiagram id="BPMNDiagram_MyProcess">
<bpmndi:BPMNPlane bpmnElement="a" id="BPMNPlane_MyProcess">
<bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
<omgdc:Bounds height="35" width="35" x="130" y="180"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
<omgdc:Bounds height="35" width="35" x="250" y="180"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="165" y="197"></omgdi:waypoint>
<omgdi:waypoint x="250" y="197"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

</definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions expressionLanguage="http://www.w3.org/1999/XPath"
id="definitions" targetNamespace="testapp"
typeLanguage="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="testProcess1" name="test process">
<property id="processVariable" itemSubjectRef="xsd:string" name="processVariable"/>
<startEvent activiti:async="true" id="start" name="Start">
<extensionElements>
<activiti:formProperty id="task1Variable1"
name="task1 Variable1" required="false" type="string"/>
<activiti:formProperty id="task1Variable2"
name="task1 Variable2" required="false" type="string"/>
</extensionElements>
</startEvent>
<serviceTask id="task1" name="Task 1">
<extensionElements>
<activiti:field name="variableNames">
<activiti:string> task1Variable1, task1Variable2 </activiti:string>
</activiti:field>
</extensionElements>
</serviceTask>
<endEvent id="end" name="End"/>
<sequenceFlow id="flow1" sourceRef="start" targetRef="task1"/>
<sequenceFlow id="flow2" sourceRef="task1" targetRef="end"/>
</process>
</definitions>

0 comments on commit f9d0daa

Please sign in to comment.