fix(modeling): convert to process when deleting last participant only

Related to #128
This commit is contained in:
Nico Rehwaldt 2015-04-28 10:52:21 +02:00
parent 6eceb0926b
commit 183a41cf26
4 changed files with 141 additions and 15 deletions

View File

@ -33,7 +33,7 @@ function RemoveBehavior(eventBus, modeling) {
var collaborationRoot = context.collaborationRoot;
if (collaborationRoot && collaborationRoot.businessObject.participants.length < 2) {
if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
// replace empty collaboration with process diagram
modeling.makeProcess();
}

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_P58jANhOEeSW1LwlVzMs4g" exporter="camunda modeler" exporterVersion="2.6.0" targetNamespace="http://activiti.org/bpmn">
<bpmn2:collaboration id="_Collaboration_2">
<bpmn2:participant id="_Participant_2" name="Participant" processRef="Process_1"/>
<bpmn2:collaboration id="Collaboration_1">
<bpmn2:participant id="Participant_2" name="Participant" processRef="Process_1"/>
<bpmn2:participant id="Participant_1" name="Pool" processRef="Process_2"/>
<bpmn2:messageFlow id="MessageFlow_1" name="" sourceRef="Task_1" targetRef="Participant_1"/>
<bpmn2:messageFlow id="MessageFlow_2" name="" sourceRef="Participant_1" targetRef="_Participant_2"/>
<bpmn2:messageFlow id="MessageFlow_3" name="" sourceRef="Task_2" targetRef="_Participant_2"/>
<bpmn2:messageFlow id="MessageFlow_2" name="" sourceRef="Participant_1" targetRef="Participant_2"/>
<bpmn2:messageFlow id="MessageFlow_3" name="" sourceRef="Task_2" targetRef="Participant_2"/>
</bpmn2:collaboration>
<bpmn2:process id="Process_1" isExecutable="false">
<bpmn2:subProcess id="SubProcess_1">
@ -28,7 +28,7 @@
</bpmn2:subProcess>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_2">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="174.0" y="155.0"/>
<bpmndi:BPMNLabel>
@ -61,7 +61,7 @@
<dc:Bounds height="6.0" width="6.0" x="516.0" y="173.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_Participant_2" bpmnElement="_Participant_2" isHorizontal="true">
<bpmndi:BPMNShape id="_BPMNShapeParticipant_2" bpmnElement="Participant_2" isHorizontal="true">
<dc:Bounds height="236.0" width="546.0" x="84.0" y="62.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Participant_3" bpmnElement="Participant_1" isHorizontal="true">
@ -77,11 +77,11 @@
<di:waypoint xsi:type="dc:Point" x="364.0" y="211.0"/>
<di:waypoint xsi:type="dc:Point" x="364.0" y="360.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_2" bpmnElement="MessageFlow_2" sourceElement="_BPMNShape_Participant_3" targetElement="_BPMNShape_Participant_2">
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_2" bpmnElement="MessageFlow_2" sourceElement="_BPMNShape_Participant_3" targetElement="_BPMNShapeParticipant_2">
<di:waypoint xsi:type="dc:Point" x="357.0" y="360.0"/>
<di:waypoint xsi:type="dc:Point" x="357.0" y="298.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_3" bpmnElement="MessageFlow_3" sourceElement="_BPMNShape_Task_3" targetElement="_BPMNShape_Participant_2">
<bpmndi:BPMNEdge id="BPMNEdge_MessageFlow_3" bpmnElement="MessageFlow_3" sourceElement="_BPMNShape_Task_3" targetElement="_BPMNShapeParticipant_2">
<di:waypoint xsi:type="dc:Point" x="518.0" y="408.0"/>
<di:waypoint xsi:type="dc:Point" x="518.0" y="298.0"/>
</bpmndi:BPMNEdge>

View File

@ -1,12 +1,12 @@
'use strict';
var TestHelper = require('../../../TestHelper');
var TestHelper = require('../../../../TestHelper');
/* global bootstrapModeler, inject */
var modelingModule = require('../../../../lib/features/modeling'),
coreModule = require('../../../../lib/core');
var modelingModule = require('../../../../../lib/features/modeling'),
coreModule = require('../../../../../lib/core');
describe('features/modeling - create participant', function() {
@ -18,7 +18,7 @@ describe('features/modeling - create participant', function() {
describe('should transform diagram into collaboration', function() {
var processDiagramXML = require('../../../fixtures/bpmn/collaboration/process-empty.bpmn');
var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/process-empty.bpmn');
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
@ -98,7 +98,7 @@ describe('features/modeling - create participant', function() {
describe('should wrap existing elements', function() {
var processDiagramXML = require('../../../fixtures/bpmn/collaboration/process.bpmn');
var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/process.bpmn');
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
@ -151,7 +151,7 @@ describe('features/modeling - create participant', function() {
describe('should add to collaboration', function() {
var collaborationDiagramXML = require('../../../fixtures/bpmn/collaboration/collaboration-participant.bpmn');
var collaborationDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-participant.bpmn');
beforeEach(bootstrapModeler(collaborationDiagramXML, { modules: testModules }));

View File

@ -0,0 +1,126 @@
'use strict';
var TestHelper = require('../../../../TestHelper');
/* global bootstrapModeler, inject */
var is = require('../../../../../lib/util/ModelUtil').is;
var modelingModule = require('../../../../../lib/features/modeling'),
coreModule = require('../../../../../lib/core');
describe('features/modeling - remove behavior', function() {
var testModules = [ coreModule, modelingModule ];
describe('when removing participant in collaboration', function() {
var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-message-flows.bpmn');
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
describe('retain collaboration', function() {
it('execute', inject(function(modeling, elementRegistry, canvas) {
// given
var participantShape = elementRegistry.get('Participant_2');
// when
modeling.removeShape(participantShape);
// then
var rootElement = canvas.getRootElement();
expect(is(rootElement, 'bpmn:Collaboration')).toBeTruthy();
}));
});
});
describe('when removing last remaining participant', function() {
var processDiagramXML = require('../../../../fixtures/bpmn/collaboration/collaboration-empty-participant.bpmn');
beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules }));
describe('should transform diagram into process diagram', function() {
it('execute', inject(function(modeling, elementRegistry, canvas) {
// given
var participantShape = elementRegistry.get('_Participant_2'),
participant = participantShape.businessObject,
participantDi = participant.di,
process = participant.processRef,
collaborationElement = participantShape.parent,
collaboration = collaborationElement.businessObject,
diPlane = collaboration.di,
bpmnDefinitions = collaboration.$parent;
// when
modeling.removeShape(participantShape);
// then
expect(participant.$parent).toBeFalsy();
var newRootShape = canvas.getRootElement(),
newRootBusinessObject = newRootShape.businessObject;
expect(newRootBusinessObject.$instanceOf('bpmn:Process')).toBe(true);
// collaboration DI is unwired
expect(participantDi.$parent).toBeFalsy();
expect(collaboration.di).toBeFalsy();
expect(bpmnDefinitions.rootElements).not.toContain(process);
expect(bpmnDefinitions.rootElements).not.toContain(collaboration);
// process DI is wired
expect(diPlane.bpmnElement).toBe(newRootBusinessObject);
expect(newRootBusinessObject.di).toBe(diPlane);
expect(bpmnDefinitions.rootElements).toContain(newRootBusinessObject);
}));
it('undo', inject(function(modeling, elementRegistry, canvas, commandStack) {
// given
var participantShape = elementRegistry.get('_Participant_2'),
participant = participantShape.businessObject,
originalRootElement = participantShape.parent,
originalRootElementBo = originalRootElement.businessObject,
bpmnDefinitions = originalRootElementBo.$parent,
participantDi = participant.di,
diPlane = participantDi.$parent;
modeling.removeShape(participantShape);
// when
commandStack.undo();
// then
expect(participant.$parent).toBe(originalRootElementBo);
expect(originalRootElementBo.$parent).toBe(bpmnDefinitions);
expect(canvas.getRootElement()).toBe(originalRootElement);
// di is unwired
expect(participantDi.$parent).toBe(originalRootElementBo.di);
// new di is wired
expect(diPlane.bpmnElement).toBe(originalRootElementBo);
}));
});
});
});