Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deploymenttests #81

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/run-npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ on:
jobs:
run-test:
runs-on: ubuntu-latest

services:
workflow-test-engine:
image: planqk/workflow-engine-test:latest
ports:
- 8090:8090

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function dispatchWorkflowEvent(type, workflowXml, workflowName) {
},
cancelable: true
});
return modelerComponent.dispatchEvent(newEvent);
return modelerComponent?.dispatchEvent?.(newEvent)??true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ export async function deployWorkflowToCamunda(workflowName, workflowXml, viewMap
};
} else {
console.error('Deployment of workflow returned invalid status code: %s', response.status);
return { status: 'failed' };
return { status: 'failed', message: 'Deployment of workflow returned invalid response: ' + response };
}
} catch (error) {
console.error('Error while executing post to deploy workflow: ' + error);
return { status: 'failed' };
return { status: 'failed', message: 'Error while executing post to deploy workflow: ' + error };
}
}

Expand Down
10 changes: 0 additions & 10 deletions components/bpmn-q/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,8 @@
}
}
]
// const divContainer = document.getElementById('modeler-container');
// divContainer.append(modelerComponent);

modelerComponent.pluginConfigs = pluginConfigs;

// const exampleWorkflow = '<?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" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> <bpmn2:process id="Process_1" isExecutable="false"> <bpmn2:startEvent id="StartEvent_1"> <bpmn2:outgoing>Flow_1kcmptx</bpmn2:outgoing> </bpmn2:startEvent> <bpmn2:task id="Activity_0ahfq1y"> <bpmn2:incoming>Flow_1kcmptx</bpmn2:incoming> <bpmn2:outgoing>Flow_0d4z11j</bpmn2:outgoing> </bpmn2:task> <bpmn2:sequenceFlow id="Flow_1kcmptx" sourceRef="StartEvent_1" targetRef="Activity_0ahfq1y" /> <bpmn2:endEvent id="Event_0qqpbb9"> <bpmn2:incoming>Flow_0d4z11j</bpmn2:incoming> </bpmn2:endEvent> <bpmn2:sequenceFlow id="Flow_0d4z11j" sourceRef="Activity_0ahfq1y" targetRef="Event_0qqpbb9" /> </bpmn2:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1"> <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> <dc:Bounds x="412" y="240" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Activity_0ahfq1y_di" bpmnElement="Activity_0ahfq1y"> <dc:Bounds x="500" y="218" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Event_0qqpbb9_di" bpmnElement="Event_0qqpbb9"> <dc:Bounds x="652" y="240" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="Flow_1kcmptx_di" bpmnElement="Flow_1kcmptx"> <di:waypoint x="448" y="258" /> <di:waypoint x="500" y="258" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_0d4z11j_di" bpmnElement="Flow_0d4z11j"> <di:waypoint x="600" y="258" /> <di:waypoint x="652" y="258" /> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn2:definitions> ';
//
// function loadWorkflow() {
// modelerComponent.loadWorkflowDiagram(exampleWorkflow);
// }
// setTimeout(loadWorkflow, 8000);

</script>

</body>
Expand Down
92 changes: 14 additions & 78 deletions components/bpmn-q/test/tests/quantme/quantme-transformation.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const { setPluginConfig, resetConfig } = require("../../../modeler-component/editor/plugin/PluginConfigHandler");
const { setPluginConfig } = require("../../../modeler-component/editor/plugin/PluginConfigHandler");
const { deployWorkflowToCamunda } = require("../../../modeler-component/editor/util/IoUtilities");
const { updateQRMs, resetQRMs } = require("../../../modeler-component/extensions/quantme/qrm-manager");
const { getFoldersInRepository } = require("../../../modeler-component/extensions/quantme/qrm-manager/git-handler");
const { startQuantmeReplacementProcess } = require("../../../modeler-component/extensions/quantme/replacement/QuantMETransformator");
const { validQuantMEDiagram, validQuantMESubprocessDiagram } = require("../helpers/DiagramHelper");
const config = require("../../../modeler-component/extensions/quantme/framework-config/config-manager");
const camundaConfig = require("../../../modeler-component/editor/config/EditorConfigManager");
const chai = require("chai");
const {createTempModeler} = require("../../../modeler-component/editor/ModelerHandler");
describe('Test the QuantMETransformator of the QuantME extension.', function () {

describe('Transformation of QuantME extensions', function () {

it('should create a valid native workflow model after two transformations', async function () {
const modeler = createTempModeler();
setPluginConfig([{ name: 'dataflow' },
{
name: 'quantme',
Expand All @@ -34,43 +36,28 @@ describe('Test the QuantMETransformator of the QuantME extension.', function ()
chai.expect(qrmMaxCut.length).to.equal(1);
let allQrms = qrms.concat(qrmMaxCut);

// remove the optimization QRM
let qrmsFirstTransformation = qrms.slice(0, 5).concat(qrms.slice(6)).concat(qrmMaxCut);
let expectedExpandedAttributes = [];
for (let i = 0; i < qrmsFirstTransformation.length; i++) {
let expandedAttributes = extractIsExpandedAttribute(qrmsFirstTransformation[i].replacement);
expectedExpandedAttributes = expectedExpandedAttributes.concat(expandedAttributes);
}
const result = await startQuantmeReplacementProcess(validQuantMESubprocessDiagram, qrmsFirstTransformation, {
const firstTransformationResult = await startQuantmeReplacementProcess(validQuantMESubprocessDiagram, allQrms, {
nisqAnalyzerEndpoint: config.getNisqAnalyzerEndpoint(),
transformationFrameworkEndpoint: config.getTransformationFrameworkEndpoint(),
camundaEndpoint: camundaConfig.getCamundaEndpoint()
});

chai.expect(result.status).to.equal('transformed');
let expandedFirstTransformation = extractIsExpandedAttribute(result.xml);
chai.expect(expandedFirstTransformation).to.deep.equal(expectedExpandedAttributes);
chai.expect(firstTransformationResult.status).to.equal('transformed');

chai.expect(result.status).to.equal('transformed');
expectedExpandedAttributes = [];
allQrms = allQrms.concat(qrms.slice(5, 6));
for (let i = 0; i < allQrms.length; i++) {
let expandedAttributes = extractIsExpandedAttribute(allQrms[i].replacement);
expectedExpandedAttributes = expectedExpandedAttributes.concat(expandedAttributes);
}

const transformationResult = await startQuantmeReplacementProcess(result.xml, allQrms, {
const secondTransformationResult = await startQuantmeReplacementProcess(firstTransformationResult.xml, allQrms, {
nisqAnalyzerEndpoint: config.getNisqAnalyzerEndpoint(),
transformationFrameworkEndpoint: config.getTransformationFrameworkEndpoint(),
camundaEndpoint: camundaConfig.getCamundaEndpoint()
});

chai.expect(transformationResult.status).to.equal('transformed');
let expandedSecondTransformation = extractIsExpandedAttribute(transformationResult.xml);
chai.expect(expandedSecondTransformation).to.deep.equal(expectedExpandedAttributes);
chai.expect(secondTransformationResult.status).to.equal('transformed');

// check that all extension elements are replaced
chai.expect(transformationResult.xml).to.not.contain('<quantme:');
chai.expect(secondTransformationResult.xml).to.not.contain('<quantme:');

const deployment = await deployWorkflowToCamunda('testworkflow.bpmn',secondTransformationResult.xml, {});
console.log(deployment);
chai.expect(deployment.status).to.equal('deployed');

//clean up
resetQRMs();
Expand All @@ -93,55 +80,4 @@ describe('Test the QuantMETransformator of the QuantME extension.', function ()
chai.expect(result.cause).to.contain('by suited QRM!');
});
});
});

function extractIsExpandedAttribute(xmlString) {

// Create a DOMParser instance
const parser = new DOMParser();

// Parse the XML string and extract all subprocesses
const xmlDoc = parser.parseFromString(xmlString, "application/xml");
const regexPattern = /\<\w+:subProcess[^>]*>/g;
const matches = xmlString.match(regexPattern);

let expanded = [];

// Regular expression pattern to extract bpmndi:BPMNShape elements
const shapeRegexPattern = /<bpmndi:BPMNShape[^>]*>/g;

// Regular expression pattern to extract isExpanded attribute value
const isExpandedRegexPattern = /isExpanded="([^"]+)"/;

// Extract the bpmndi:BPMNShape elements using the regular expression
const shapeMatches = xmlString.match(shapeRegexPattern);

// Loop through the shape matches and extract the isExpanded attribute
for (let i = 0; i < shapeMatches.length; i++) {
const shapeMatch = shapeMatches[i];

// Extract the bpmnElement attribute value
const bpmnElementMatch = shapeMatch.match(/bpmnElement="([^"]+)"/);
if (bpmnElementMatch && bpmnElementMatch.length > 1) {
const bpmnElement = bpmnElementMatch[1];

// Extract the isExpanded attribute value
const isExpandedMatch = shapeMatch.match(isExpandedRegexPattern);
let positionCircuitCutting = xmlString.search('circuitCuttingSubprocess id="' + bpmnElement + '"');
let positionSubProcess = xmlString.search('subProcess id="' + bpmnElement + '"');

if (positionCircuitCutting > -1 || positionSubProcess > -1) {
if (isExpandedMatch && isExpandedMatch.length > 1) {
const isExpanded = isExpandedMatch[1];

if (isExpanded !== undefined) {
expanded.push(isExpanded);
}
} else {
expanded.push('false');
}
}
}
}
return expanded;
}
});