2017-01-11 07:12:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
require('../../TestHelper');
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
/* global bootstrapModeler, inject */
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var coreModule = require('../../../lib/core');
|
2017-12-07 22:12:00 +00:00
|
|
|
var modelingModule = require('../../../lib/features/modeling');
|
2017-01-11 07:12:34 +00:00
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var ModelCloneHelper = require('../../../lib/util/model/ModelCloneHelper');
|
|
|
|
|
|
|
|
var camundaPackage = require('../../fixtures/json/model/camunda');
|
2017-01-11 07:12:34 +00:00
|
|
|
|
2017-01-23 13:12:43 +00:00
|
|
|
var camundaModdleModule = require('./camunda-moddle');
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
function getProp(element, property) {
|
|
|
|
return element && element.$model.properties.get(element, property);
|
|
|
|
}
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
describe('util/ModelCloneHelper', function() {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
var testModules = [
|
|
|
|
camundaModdleModule,
|
|
|
|
coreModule,
|
|
|
|
modelingModule
|
|
|
|
];
|
2017-01-11 07:12:34 +00:00
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var basicXML = require('../../fixtures/bpmn/basic.bpmn');
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(basicXML, {
|
|
|
|
modules: testModules,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var helper;
|
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
beforeEach(inject(function(eventBus, bpmnFactory) {
|
|
|
|
helper = new ModelCloneHelper(eventBus, bpmnFactory);
|
2017-01-11 14:22:32 +00:00
|
|
|
}));
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
describe('simple', function() {
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
it('should pass property', inject(function(moddle) {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var userTask = moddle.create('bpmn:UserTask', {
|
|
|
|
asyncBefore: true
|
|
|
|
});
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var serviceTask = helper.clone(userTask, moddle.create('bpmn:ServiceTask'), [ 'camunda:asyncBefore' ]);
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
expect(getProp(serviceTask, 'camunda:asyncBefore')).to.be.true;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
it('should not pass property', inject(function(moddle) {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var userTask = moddle.create('bpmn:UserTask', {
|
|
|
|
assignee: 'foobar'
|
|
|
|
});
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var serviceTask = helper.clone(userTask, moddle.create('bpmn:ServiceTask'), []);
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
expect(getProp(serviceTask, 'camunda:assignee')).to.not.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-07 22:12:00 +00:00
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
describe('nested', function() {
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
it('should pass nested property - documentation', inject(function(moddle) {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
// given
|
2017-01-11 14:22:32 +00:00
|
|
|
var userTask = moddle.create('bpmn:UserTask');
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
var docs = userTask.get('documentation');
|
|
|
|
|
|
|
|
docs.push(moddle.create('bpmn:Documentation', { textFormat: 'xyz', text: 'FOO\nBAR' }));
|
|
|
|
docs.push(moddle.create('bpmn:Documentation', { text: '<some /><html></html>' }));
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var serviceTask = helper.clone(userTask, moddle.create('bpmn:ServiceTask'), [ 'bpmn:documentation' ]);
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
var serviceTaskDocs = getProp(serviceTask, 'bpmn:documentation'),
|
|
|
|
userTaskDocs = getProp(userTask, 'bpmn:documentation');
|
|
|
|
|
|
|
|
expect(userTaskDocs[0]).to.not.equal(serviceTaskDocs[0]);
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
expect(serviceTaskDocs[0].$parent).to.equal(serviceTask);
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(serviceTaskDocs[0].text).to.equal('FOO\nBAR');
|
|
|
|
expect(serviceTaskDocs[0].textFormat).to.equal('xyz');
|
|
|
|
|
|
|
|
expect(serviceTaskDocs[1].text).to.equal('<some /><html></html>');
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
it('should pass deeply nested property - executionListener', inject(function(moddle) {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var script = moddle.create('camunda:Script', {
|
|
|
|
scriptFormat: 'groovy',
|
|
|
|
value: 'foo = bar;'
|
|
|
|
});
|
|
|
|
|
|
|
|
var execListener = moddle.create('camunda:ExecutionListener', {
|
|
|
|
event: 'start',
|
|
|
|
script: script
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ execListener ] });
|
|
|
|
|
|
|
|
var userTask = moddle.create('bpmn:UserTask', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var serviceTask = helper.clone(userTask, moddle.create('bpmn:ServiceTask'), [
|
2017-01-11 07:12:34 +00:00
|
|
|
'bpmn:extensionElements',
|
|
|
|
'camunda:executionListener'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var executionListener = serviceTask.extensionElements.values[0];
|
|
|
|
|
|
|
|
// then
|
2017-01-19 15:13:31 +00:00
|
|
|
expect(executionListener).to.not.equal(userTask.extensionElements.values[0]);
|
|
|
|
expect(executionListener.$type).to.equal('camunda:ExecutionListener');
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(executionListener.$type).to.equal('camunda:ExecutionListener');
|
2017-01-11 14:22:32 +00:00
|
|
|
expect(executionListener.$parent).to.equal(serviceTask.extensionElements);
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(executionListener.event).to.equal('start');
|
|
|
|
|
|
|
|
expect(executionListener.script.$type).to.equal('camunda:Script');
|
2017-01-11 14:22:32 +00:00
|
|
|
expect(executionListener.script.$parent).to.equal(executionListener);
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(executionListener.script.scriptFormat).to.equal('groovy');
|
|
|
|
expect(executionListener.script.value).to.equal('foo = bar;');
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
it('should pass deeply nested property - inputOutput', inject(function(moddle) {
|
2017-01-11 07:12:34 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var outputParameter = moddle.create('camunda:OutputParameter', {
|
|
|
|
name: 'var1',
|
|
|
|
definition: moddle.create('camunda:List', {
|
|
|
|
items: [
|
|
|
|
moddle.create('camunda:Value', { value: '${1+1}' }),
|
|
|
|
moddle.create('camunda:Value', { value: '${1+2}' }),
|
|
|
|
moddle.create('camunda:Value', { value: '${1+3}' })
|
|
|
|
]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
var inputOutput = moddle.create('camunda:InputOutput', {
|
|
|
|
outputParameters: [ outputParameter ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ inputOutput ] });
|
|
|
|
|
|
|
|
var userTask = moddle.create('bpmn:UserTask', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
|
|
|
|
2017-02-01 14:52:24 +00:00
|
|
|
var subProcess = helper.clone(userTask, moddle.create('bpmn:SubProcess'), [
|
|
|
|
'bpmn:extensionElements'
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(subProcess.extensionElements.values[0].$type).to.equal('camunda:InputOutput');
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
var serviceTask = helper.clone(userTask, moddle.create('bpmn:ServiceTask'), [
|
2017-01-11 07:12:34 +00:00
|
|
|
'bpmn:extensionElements',
|
|
|
|
'camunda:inputOutput'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var executionListener = serviceTask.extensionElements.values[0];
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(executionListener.$type).to.equal('camunda:InputOutput');
|
|
|
|
|
|
|
|
var newOutParam = executionListener.outputParameters[0];
|
|
|
|
var oldOutParam = userTask.extensionElements.values[0].outputParameters[0];
|
|
|
|
|
|
|
|
expect(newOutParam).to.not.equal(oldOutParam);
|
2017-01-11 14:22:32 +00:00
|
|
|
|
|
|
|
expect(newOutParam.$parent).to.equal(executionListener);
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(newOutParam.definition).to.not.equal(oldOutParam.definition);
|
2017-01-11 14:22:32 +00:00
|
|
|
expect(newOutParam.definition.$parent).to.equal(newOutParam);
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(newOutParam.definition.items[0]).to.not.equal(oldOutParam.definition.items[0]);
|
|
|
|
|
2017-01-11 14:22:32 +00:00
|
|
|
expect(newOutParam.definition.items[0].$parent).to.not.equal(newOutParam.definition.$parent);
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
expect(newOutParam.$type).to.equal('camunda:OutputParameter');
|
|
|
|
expect(newOutParam.definition.$type).to.equal('camunda:List');
|
|
|
|
expect(newOutParam.definition.items[0].value).to.equal('${1+1}');
|
|
|
|
}));
|
|
|
|
|
2017-01-19 15:13:31 +00:00
|
|
|
|
|
|
|
it('should not pass disallowed deeply nested property - connector', inject(function(moddle) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var connector = moddle.create('camunda:Connector', {
|
|
|
|
connectorId: 'hello_connector'
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ connector ] });
|
|
|
|
|
|
|
|
var serviceTask = moddle.create('bpmn:UserTask', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
|
|
|
|
|
|
|
var userTask = helper.clone(serviceTask, moddle.create('bpmn:UserTask'), [
|
|
|
|
'bpmn:extensionElements'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var extElem = userTask.extensionElements;
|
|
|
|
|
|
|
|
// then
|
2017-02-01 09:42:49 +00:00
|
|
|
expect(extElem).to.not.exist;
|
2017-01-19 15:13:31 +00:00
|
|
|
}));
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
});
|
|
|
|
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
describe('special cases', function() {
|
|
|
|
|
|
|
|
it('failed job retry time cycle', inject(function(moddle) {
|
|
|
|
|
|
|
|
function createExtElems() {
|
|
|
|
var retryTimeCycle = moddle.create('camunda:FailedJobRetryTimeCycle', { body: 'foobar' });
|
|
|
|
|
|
|
|
return moddle.create('bpmn:ExtensionElements', { values: [ retryTimeCycle ] });
|
|
|
|
}
|
|
|
|
|
|
|
|
// given
|
|
|
|
var timerEvtDef = moddle.create('bpmn:TimerEventDefinition', {
|
|
|
|
timeDuration: 'foobar'
|
|
|
|
});
|
|
|
|
|
|
|
|
var signalEvtDef = moddle.create('bpmn:SignalEventDefinition', {
|
2017-02-01 09:42:49 +00:00
|
|
|
async: true
|
2017-01-23 13:12:43 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 09:42:49 +00:00
|
|
|
var multiInst = moddle.create('bpmn:MultiInstanceLoopCharacteristics', {
|
|
|
|
elementVariable: 'foobar'
|
|
|
|
});
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
var timerStartEvent = moddle.create('bpmn:StartEvent', {
|
|
|
|
extensionElements: createExtElems(),
|
|
|
|
eventDefinitions: [ timerEvtDef ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var signalStartEvt = moddle.create('bpmn:StartEvent', {
|
|
|
|
extensionElements: createExtElems(),
|
|
|
|
eventDefinitions: [ signalEvtDef ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var subProcess = moddle.create('bpmn:SubProcess', {
|
|
|
|
extensionElements: createExtElems(),
|
|
|
|
loopCharacteristics: multiInst
|
|
|
|
});
|
|
|
|
|
|
|
|
var intCatchEvt = helper.clone(timerStartEvent, moddle.create('bpmn:IntermediateCatchEvent'), [
|
|
|
|
'bpmn:extensionElements',
|
|
|
|
'bpmn:eventDefinitions'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var startEvt = helper.clone(signalStartEvt, moddle.create('bpmn:StartEvent'), [
|
|
|
|
'bpmn:extensionElements',
|
|
|
|
'bpmn:eventDefinitions'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var newSubProcess = helper.clone(subProcess, moddle.create('bpmn:SubProcess'), [
|
|
|
|
'bpmn:extensionElements',
|
|
|
|
'bpmn:loopCharacteristics'
|
|
|
|
]);
|
|
|
|
|
|
|
|
var intCatchEvtExtElems = intCatchEvt.extensionElements.values,
|
|
|
|
startEvtExtElems = startEvt.extensionElements.values,
|
|
|
|
newSubProcessExtElems = newSubProcess.extensionElements.values;
|
|
|
|
|
|
|
|
// then
|
2017-02-02 10:28:40 +00:00
|
|
|
expect(intCatchEvtExtElems[0].$type).to.equal('camunda:FailedJobRetryTimeCycle');
|
|
|
|
expect(intCatchEvtExtElems[0].body).to.equal('foobar');
|
2017-01-23 13:12:43 +00:00
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
expect(startEvtExtElems[0].$type).to.equal('camunda:FailedJobRetryTimeCycle');
|
|
|
|
expect(startEvtExtElems[0].body).to.equal('foobar');
|
2017-01-23 13:12:43 +00:00
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
expect(newSubProcessExtElems[0].$type).to.equal('camunda:FailedJobRetryTimeCycle');
|
|
|
|
expect(newSubProcessExtElems[0].body).to.equal('foobar');
|
2017-01-23 13:12:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('connector', inject(function(moddle) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var connector = moddle.create('camunda:Connector', {
|
|
|
|
connectorId: 'hello_connector'
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ connector ] });
|
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
var msgEvtDef = moddle.create('bpmn:MessageEventDefinition', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
var msgIntermThrowEvt = moddle.create('bpmn:IntermediateThrowEvent', {
|
|
|
|
eventDefinitions: [ msgEvtDef ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var clonedElement = helper.clone(msgIntermThrowEvt, moddle.create('bpmn:EndEvent'), [
|
|
|
|
'bpmn:extensionElements',
|
|
|
|
'bpmn:eventDefinitions'
|
|
|
|
]);
|
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
var extElems = clonedElement.eventDefinitions[0].extensionElements.values;
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(extElems[0].$type).to.equal('camunda:Connector');
|
|
|
|
expect(extElems[0].connectorId).to.equal('hello_connector');
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('field', inject(function(moddle) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var field = moddle.create('camunda:Field', {
|
|
|
|
name: 'hello_field'
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ field ] });
|
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
var msgEvtDef = moddle.create('bpmn:MessageEventDefinition', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
var msgIntermThrowEvt = moddle.create('bpmn:IntermediateThrowEvent', {
|
|
|
|
eventDefinitions: [ msgEvtDef ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var clonedElement = helper.clone(msgIntermThrowEvt, moddle.create('bpmn:EndEvent'), [
|
|
|
|
'bpmn:extensionElements',
|
|
|
|
'bpmn:eventDefinitions'
|
|
|
|
]);
|
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
var extElems = clonedElement.eventDefinitions[0].extensionElements.values;
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(extElems[0].$type).to.equal('camunda:Field');
|
|
|
|
expect(extElems[0].name).to.equal('hello_field');
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('not clone field', inject(function(moddle) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var field = moddle.create('camunda:Field', {
|
|
|
|
name: 'hello_field'
|
|
|
|
});
|
|
|
|
|
|
|
|
var extensionElements = moddle.create('bpmn:ExtensionElements', { values: [ field ] });
|
|
|
|
|
2017-02-02 10:28:40 +00:00
|
|
|
var msgEvtDef = moddle.create('bpmn:MessageEventDefinition', {
|
|
|
|
extensionElements: extensionElements
|
|
|
|
});
|
2017-01-23 13:12:43 +00:00
|
|
|
|
|
|
|
var msgIntermThrowEvt = moddle.create('bpmn:IntermediateThrowEvent', {
|
|
|
|
eventDefinitions: [ msgEvtDef ]
|
|
|
|
});
|
|
|
|
|
|
|
|
var clonedElement = helper.clone(msgIntermThrowEvt, moddle.create('bpmn:IntermediateThrowEvent'), [
|
|
|
|
'bpmn:extensionElements'
|
|
|
|
]);
|
|
|
|
|
2017-02-01 09:42:49 +00:00
|
|
|
var extElems = clonedElement.extensionElements;
|
|
|
|
|
2017-01-23 13:12:43 +00:00
|
|
|
// then
|
2017-02-01 09:42:49 +00:00
|
|
|
expect(extElems).to.not.exist;
|
2017-01-23 13:12:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-01-11 07:12:34 +00:00
|
|
|
});
|