Skip to content

Commit

Permalink
feat(properties): mark variable source/target with whitespace as invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Apr 11, 2018
1 parent fd8dce1 commit dd163e6
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 52 deletions.
28 changes: 22 additions & 6 deletions lib/provider/camunda/parts/VariableMappingProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function getInOutType(mapping) {
var CAMUNDA_IN_EXTENSION_ELEMENT = 'camunda:In',
CAMUNDA_OUT_EXTENSION_ELEMENT = 'camunda:Out';

var WHITESPACE_REGEX = /\s/;


module.exports = function(group, element, bpmnFactory, translate) {
var signalEventDefinition = eventDefinitionHelper.getSignalEventDefinition(element);
Expand Down Expand Up @@ -133,7 +135,7 @@ module.exports = function(group, element, bpmnFactory, translate) {
var newElement = function(type) {
return function(element, extensionElements, value) {
var newElem = elementHelper.createElement(type, { source : '' }, extensionElements, bpmnFactory);

return cmdHelper.addElementsTolist(element, extensionElements, 'values', [ newElem ]);
};
};
Expand Down Expand Up @@ -186,18 +188,18 @@ module.exports = function(group, element, bpmnFactory, translate) {
prefix: 'Out',
idGeneration: false,
resizable: true,

createExtensionElement: newElement(CAMUNDA_OUT_EXTENSION_ELEMENT),
removeExtensionElement: removeElement(CAMUNDA_OUT_EXTENSION_ELEMENT),

getExtensionElements: function(element) {
return getVariableMappings(element, CAMUNDA_OUT_EXTENSION_ELEMENT);
},

onSelectionChange: function(element, node, event, scope) {
inEntry.deselect(element, node.parentNode);
},

setOptionLabelValue: setOptionLabelValue(CAMUNDA_OUT_EXTENSION_ELEMENT)
});
group.entries.push(outEntry);
Expand Down Expand Up @@ -310,7 +312,14 @@ module.exports = function(group, element, bpmnFactory, translate) {
var validation = {};
if (mapping) {
if (!values.source) {
validation.source = 'Mapping must have a ' + values.sourceLabel.toLowerCase() || 'value';
validation.source =
'Mapping must have a ' + (values.sourceLabel.toLowerCase() || 'value');
}

var inOutType = getInOutType(mapping);

if (WHITESPACE_REGEX.test(values.source) && inOutType !== 'sourceExpression') {
validation.source = values.sourceLabel + ' must not contain whitespace';
}
}

Expand Down Expand Up @@ -343,9 +352,16 @@ module.exports = function(group, element, bpmnFactory, translate) {
var validation = {};
if (mapping) {
var mappingType = getInOutType(mapping);

if (!values.target && mappingType !== 'variables') {
validation.target = 'Mapping must have a target';
}

if (values.target
&& WHITESPACE_REGEX.test(values.target)
&& mappingType !== 'variables') {
validation.target = 'Target must not contain whitespace';
}
}

return validation;
Expand Down
86 changes: 40 additions & 46 deletions test/spec/provider/camunda/CallActivityVariableMapping.bpmn
Original file line number Diff line number Diff line change
@@ -1,95 +1,89 @@
<?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:camunda="http://camunda.org/schema/1.0/bpmn"
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="_3ENCQCCrEeWkp5kiupH8Fw"
exporter="camunda modeler"
exporterVersion="2.7.0"
targetNamespace="http://activiti.org/bpmn">

<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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="_3ENCQCCrEeWkp5kiupH8Fw" targetNamespace="http://camunda.org/schema/1.0/bpmn" exporter="Camunda Modeler" exporterVersion="1.12.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:process id="Process_1" isExecutable="false">

<bpmn2:callActivity id="CallActivity_1" calledElement="asd" camunda:calledElementBinding="version" camunda:calledElementVersion="17">
<bpmn2:extensionElements>
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in variables="all" local="true"/>
<camunda:out variables="all" />
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in local="true" variables="all" />
<camunda:out variables="all" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_2" calledElement="asd">
<bpmn2:extensionElements>
<camunda:in source="myVar" target="myVar" />
<camunda:in source="foo" target="foo" />
<camunda:in source="mySource" target="myTarget" />
<camunda:in source="myVar" target="myVar" />
<camunda:in source="foo" target="foo" />
<camunda:in source="mySource" target="myTarget" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_3" calledElement="asd">
<bpmn2:extensionElements>
<camunda:in source=""/>
<camunda:out source="mySource" target="" />
<camunda:in source="" />
<camunda:out source="mySource" target="" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_4" calledElement="asd">
<bpmn2:extensionElements>
<camunda:in sourceExpression=""/>
<camunda:out sourceExpression="mySource" target="myTarget" />
<camunda:in sourceExpression="" />
<camunda:out sourceExpression="mySource" target="myTarget" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_5">
<bpmn2:extensionElements>
<camunda:in source="myVar" target="myVar" />
<camunda:in sourceExpression="#{foo}" target="#{foo}" />
<camunda:in source="" />
<camunda:in variables="all" />
<camunda:in businessKey="abc" />
<camunda:out source="myVar" target="myVar" />
<camunda:out sourceExpression="#{foo}" target="#{foo}" />
<camunda:in source="myVar" target="myVar" />
<camunda:in sourceExpression="#{foo}" target="#{foo}" />
<camunda:in source="" />
<camunda:in variables="all" />
<camunda:in businessKey="abc" />
<camunda:out source="myVar" target="myVar" />
<camunda:out sourceExpression="#{foo}" target="#{foo}" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_6" calledElement="mySubProcess">
<bpmn2:extensionElements>
<camunda:out source="myVar" target="myVar" />
<camunda:out source="foo" target="foo" />
<camunda:out source="mySource" target="myTarget" />
<camunda:out source="myVar" target="myVar" />
<camunda:out source="foo" target="foo" />
<camunda:out source="mySource" target="myTarget" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_7" camunda:caseRef="myCase">
<bpmn2:extensionElements>
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in businessKey="foo" />
<camunda:in variables="all" />
<camunda:in businessKey="abc" />
<camunda:in businessKey="#{execution.processBusinessKey}" />
<camunda:in businessKey="foo" />
<camunda:in variables="all" />
<camunda:in businessKey="abc" />
</bpmn2:extensionElements>
</bpmn2:callActivity>
<bpmn2:callActivity id="CallActivity_8">
<bpmn2:extensionElements>
<camunda:in sourceExpression="foo" target="bar" />
</bpmn2:extensionElements>
</bpmn2:callActivity>

</bpmn2:process>

<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_2" bpmnElement="CallActivity_1">
<dc:Bounds height="80.0" width="100.0" x="24.0" y="24.0"/>
<dc:Bounds x="24" y="24" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_3" bpmnElement="CallActivity_2">
<dc:Bounds height="80.0" width="100.0" x="24.0" y="180.0"/>
<dc:Bounds x="24" y="180" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_4" bpmnElement="CallActivity_3">
<dc:Bounds height="80.0" width="100.0" x="24.0" y="270.0"/>
<dc:Bounds x="24" y="270" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_5" bpmnElement="CallActivity_4">
<dc:Bounds height="80.0" width="100.0" x="24.0" y="360.0"/>
<dc:Bounds x="24" y="360" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_6" bpmnElement="CallActivity_5">
<dc:Bounds height="80.0" width="100.0" x="280.0" y="24.0"/>
<dc:Bounds x="280" y="24" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_7" bpmnElement="CallActivity_6">
<dc:Bounds height="80.0" width="100.0" x="280.0" y="180.0"/>
<dc:Bounds x="280" y="180" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_CallActivity_8" bpmnElement="CallActivity_7">
<dc:Bounds height="80.0" width="100.0" x="280.0" y="270.0"/>
<dc:Bounds x="280" y="270" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="CallActivity_0b6wmdt_di" bpmnElement="CallActivity_8">
<dc:Bounds x="280" y="360" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
Expand Down
103 changes: 103 additions & 0 deletions test/spec/provider/camunda/CallActivityVariableMappingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,72 @@ describe('CallActivity - variable mapping', function() {
}));


it('should mark source field of a camunda:in mapping of a call activity as invalid', inject(function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('CallActivity_3');
selection.select(shape);

var selectBox = domQuery('select[id=cam-extensionElements-variableMapping-in]', propertiesPanel._container),
typeSelectBox = domQuery('select[id=camunda-variableMapping-inOutType-select]', propertiesPanel._container),
sourceInput = domQuery('input[id=camunda-variableMapping-source]', propertiesPanel._container),
targetInput = domQuery('input[id="camunda-variableMapping-target"]', propertiesPanel._container),
businessObject = getBusinessObject(shape);

// given
expect(selectBox.options).to.have.length(1);

selectBox.options[0].selected = 'selected';
TestHelper.triggerEvent(selectBox, 'change');

expect(typeSelectBox.value).to.equal('source');
expect(sourceInput.className).to.equal('invalid');
expect(targetInput.value).to.be.empty;

// when
TestHelper.triggerValue(sourceInput, 'mySourceVal ', 'change');

// then
expect(sourceInput.value).to.equal('mySourceVal ');
expect(sourceInput.className).to.equal('invalid');

var variableMappings = getVariableMappings(businessObject.extensionElements, CAMUNDA_IN_EXTENSION_ELEMENT);
expect(variableMappings).to.have.length(1);
expect(variableMappings[0].source).to.equal('mySourceVal ');
}));


it('should NOT mark source expression field of a camunda:in mapping of a call activity as invalid', inject(function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('CallActivity_8');
selection.select(shape);

var selectBox = domQuery('select[id=cam-extensionElements-variableMapping-in]', propertiesPanel._container),
typeSelectBox = domQuery('select[id=camunda-variableMapping-inOutType-select]', propertiesPanel._container),
sourceInput = domQuery('input[id=camunda-variableMapping-source]', propertiesPanel._container),
businessObject = getBusinessObject(shape);

// given
expect(selectBox.options).to.have.length(1);

selectBox.options[0].selected = 'selected';
TestHelper.triggerEvent(selectBox, 'change');

expect(typeSelectBox.value).to.equal('sourceExpression');
expect(sourceInput.className).to.not.equal('invalid');

// when
TestHelper.triggerValue(sourceInput, 'mySourceVal ', 'change');

// then
expect(sourceInput.value).to.equal('mySourceVal ');
expect(sourceInput.className).to.not.equal('invalid');

var variableMappings = getVariableMappings(businessObject.extensionElements, CAMUNDA_IN_EXTENSION_ELEMENT);
expect(variableMappings).to.have.length(1);
expect(variableMappings[0].sourceExpression).to.equal('mySourceVal ');
}));


it('should change sourceExpression field of a camunda:in mapping of a call activity', inject(function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('CallActivity_4');
Expand Down Expand Up @@ -505,6 +571,43 @@ describe('CallActivity - variable mapping', function() {
}));


it('should mark target field of a camunda:out mapping of a call activity as invalid', inject(
function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('CallActivity_3');
selection.select(shape);

var selectBox = domQuery('select[id=cam-extensionElements-variableMapping-out]', propertiesPanel._container),
typeSelectBox = domQuery('select[id=camunda-variableMapping-inOutType-select]', propertiesPanel._container),
sourceInput = domQuery('input[id=camunda-variableMapping-source]', propertiesPanel._container),
targetInput = domQuery('input[id="camunda-variableMapping-target"]', propertiesPanel._container),
businessObject = getBusinessObject(shape);

// given
expect(selectBox.options).to.have.length(1);

selectBox.options[0].selected = 'selected';
TestHelper.triggerEvent(selectBox, 'change');

expect(typeSelectBox.value).to.equal('source');
expect(sourceInput.value).to.equal('mySource');
expect(targetInput.className).to.equal('invalid');

// when
TestHelper.triggerValue(targetInput, 'myTargetVal ', 'change');

// then
expect(targetInput.value).to.equal('myTargetVal ');
expect(targetInput.className).to.equal('invalid');

var variableMappings = getVariableMappings(businessObject.extensionElements, CAMUNDA_OUT_EXTENSION_ELEMENT);
expect(variableMappings).to.have.length(1);
expect(variableMappings[0].target).to.equal('myTargetVal ');

}
));


describe('should clear target field of a camunda:out mapping of a call activity', function() {

var targetInput,
Expand Down
35 changes: 35 additions & 0 deletions test/spec/provider/camunda/SignalEventVariableMappingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,41 @@ describe('SignalEvent - variable mapping', function() {
}));


it('should mark source field of a camunda:in mapping of a signal intermediate throw event as invalid', inject(function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('IntermediateThrowEvent_2');
selection.select(shape);

var selectBox = domQuery('select[id=cam-extensionElements-variableMapping-in]', propertiesPanel._container),
typeSelectBox = domQuery('select[id=camunda-variableMapping-inOutType-select]', propertiesPanel._container),
sourceInput = domQuery('input[id=camunda-variableMapping-source]', propertiesPanel._container),
targetInput = domQuery('input[id="camunda-variableMapping-target"]', propertiesPanel._container),
businessObject = getBusinessObject(shape),
signalEventDefinition = eventDefinitionHelper.getSignalEventDefinition(businessObject);

// given
expect(selectBox.options).to.have.length(1);

selectBox.options[0].selected = 'selected';
TestHelper.triggerEvent(selectBox, 'change');

expect(typeSelectBox.value).to.equal('source');
expect(sourceInput.className).to.equal('invalid');
expect(targetInput.value).to.be.empty;

// when
TestHelper.triggerValue(sourceInput, 'foo ', 'change');

// then
expect(sourceInput.value).to.equal('foo ');
expect(sourceInput.className).to.equal('invalid');

var variableMappings = getVariableMappings(signalEventDefinition.extensionElements, CAMUNDA_IN_EXTENSION_ELEMENT);
expect(variableMappings).to.have.length(1);
expect(variableMappings[0].source).to.equal('foo ');
}));


it('should change sourceExpression field of a camunda:in mapping of a signal intermediate throw event', inject(function(propertiesPanel, selection, elementRegistry) {

var shape = elementRegistry.get('IntermediateThrowEvent_3');
Expand Down

0 comments on commit dd163e6

Please sign in to comment.