Hey
so building from the covo in #28 and #31, i have put together a alternati…ve to the current coverage implementation:
![sock-bpmn-coverage-digitalstate](https://user-images.githubusercontent.com/1994838/41068841-5dce8f14-69b9-11e8-93b1-63c3cf7f6a7d.png)
This is a spock framework report that integrates BPMN-js and the coverage results.
I am iteratively adding features to be feature equivalent to the current workarounds that bpmnCoverage implements:
so far i have setups for:
1. Activity Events, including Sequence flows
1. Aync configs for all elements
1. and user tasks listing.
```
Executed Activity Events:
[SequenceFlow_19totff, SequenceFlow_19ak290, SequenceFlow_1uq2whs, SequenceFlow_1rvhomr, SequenceFlow_1v7gx3u, SequenceFlow_152lh88, SequenceFlow_0qsbc3h, StartEvent_07ulwup, Task_1vbilbk, SubProcess_0nx9ieb, StartEvent_0bpfm61, Task_0dm0rll, EndEvent_03b850y, ExclusiveGateway_0jlwph2, Task_0qacez5, EndEvent_02dwqrb]
Async Element Configs:
[[id:Task_0dm0rll, asyncBefore:false, asyncAfter:false, exclusive:true], [id:Task_1vbilbk, asyncBefore:false, asyncAfter:false, exclusive:true], [id:SubProcess_0nx9ieb, asyncBefore:false, asyncAfter:false, exclusive:true], [id:ExclusiveGateway_0jlwph2, asyncBefore:false, asyncAfter:false, exclusive:true], [id:EndEvent_02dwqrb, asyncBefore:false, asyncAfter:false, exclusive:true], [id:EndEvent_03b850y, asyncBefore:false, asyncAfter:false, exclusive:true], [id:Task_0qacez5, asyncBefore:false, asyncAfter:false, exclusive:true], [id:StartEvent_07ulwup, asyncBefore:false, asyncAfter:false, exclusive:true], [id:StartEvent_0bpfm61, asyncBefore:false, asyncAfter:false, exclusive:true]]
User Tasks:
[Task_0qacez5]
```
The sequence flow is added currently using a Script that is added into the BPMN before the BPMN is loaded into the engine:
```groovy
def addExecutionListener(model, elementId, scriptResource, scriptFormat){
// @TODO NOTE: The estLis had to be new for every instance
CamundaExecutionListener extLis = model.newInstance(CamundaExecutionListener.class);
CamundaScript camScript = model.newInstance(CamundaScript.class);
camScript.setCamundaResource(scriptResource)
camScript.setCamundaScriptFormat(scriptFormat)
extLis.setCamundaEvent('take')
extLis.setCamundaScript(camScript)
def newModel = model.getModelElementById(elementId).builder().addExtensionElement(extLis).done()
return newModel
}
def setupSequenceFlowListeners(model, scriptResource, scriptFormat){
def sequenceFlows = model.getModelElementsByType(org.camunda.bpm.model.bpmn.instance.SequenceFlow.class).collect {it.getId()}
def newModel = model
sequenceFlows.each {
newModel = addExecutionListener(newModel, it, scriptResource, scriptFormat)
}
return newModel
}
```
and the script being:
```js
var Date = Java.type("java.util.Date")
// https://docs.camunda.org/javadoc/camunda-bpm-platform/7.9/org/camunda/bpm/engine/impl/history/event/HistoricActivityInstanceEventEntity.html
var HistoricActivityInstanceEventEntity = Java.type('org.camunda.bpm.engine.impl.history.event.HistoricActivityInstanceEventEntity')
var historicActivityInstance = new HistoricActivityInstanceEventEntity()
historicActivityInstance.setActivityId(execution.getCurrentTransitionId())
historicActivityInstance.setExecutionId(execution.getId())
historicActivityInstance.setActivityType('sequenceFlow')
historicActivityInstance.setStartTime(new Date())
historicActivityInstance.setEndTime(new Date())
historicActivityInstance.setDurationInMillis(0)
historicActivityInstance.setProcessDefinitionId(execution.getProcessDefinitionId())
historicActivityInstance.setProcessInstanceId(execution.getProcessInstanceId())
// https://docs.camunda.org/javadoc/camunda-bpm-platform/7.9/org/camunda/bpm/engine/impl/history/handler/DbHistoryEventHandler.html
var historyHandler = Java.type('org.camunda.bpm.engine.impl.history.handler.DbHistoryEventHandler');
(new historyHandler).handleEvent(historicActivityInstance)
```
this script is going to be rebuilt as a Groovy script to align with Spock.
will also be making updates as per @ThorbenLindhauer discussions on: https://forum.camunda.org/t/execution-listener-on-sequence-flow-generate-history-event/7586/2
The goal of the coverage reporting is to provide a more script based reporting solution for Coverage; and make is very easy for typical technical business users to update reports with additional queries as they see fit.
We are also looking to only use built in camunda services and not modify the engine (so far so good / not needed, but it's not a hard "no"; just preferable) so we can easily add the unit testing to any implementation.