Skip to content

Commit

Permalink
CDN/Local, Class Folder Names, Groovy dep compile, version bumb
Browse files Browse the repository at this point in the history
- Add folder generation based on class name,
- add local and CDN support for bpmn.js
- Update tests to show the new usage.
- Update version to 0.7
- Fixed typo in documentation for the artifact name in the How to Install section.
  • Loading branch information
StephenOTT committed Aug 29, 2018
1 parent 5dde5e5 commit dafe0c1
Show file tree
Hide file tree
Showing 7 changed files with 15,574 additions and 12 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Each coverage item can have its look-and-feel modified through a change in the r
|`getSequenceFlowListenerScript()` | Returns a InputStream of the Listener Script that can then be added into the deployment. See the Spock Framework example. | |
|`addSequenceFlowListeners('some/path/to/file.bpmn')` | Processes a BPMN file to add Listeners to each sequence flow, and returns a Model Instance to be used in the deployment | See the Spock Framework Example. |
|`coverageSnapshot(processInstance, 'Coverage Title')` | Generates a coverage snapshot: this will query the Process Instance's BPMN Model and the Camunda DB for all relevant data required to generate the Coverage Data. This method can be called multiple times during a test, allow coverage generation throughout the process lifecycle. | Only the process instance is required. The Title is optional and only used to set a custom file name of the .html file generated by `saveCoverageSnapshots()` |
|`saveCoverageSnapshots()` | Generates BPMNJS .html coverage files for each Coverage Snapshot. Saves to the defined output directory; typically: `target/bpmn-converage` | The snapshots will be saved in the order they were generated with file names formats of: If coverageName was provided: `[index]_[coverageName].html` or if no coverage name was provided: `[index].html`. Examples: 0_snap.html, 1_anotherSnap.html, 2.html. Notice how you can use titles and no-titles as you see fit. See the Spock Framework Example.|
|`saveCoverageSnapshots()` | Generates BPMN.js .html coverage files for each Coverage Snapshot. Saves to the defined output directory; typically: `target/bpmn-converage/[fully.qualified.class.name]/`. | The snapshots will be saved in the order they were generated with file names formats of: If coverageName was provided: `[index]_[coverageName].html` or if no coverage name was provided: `[index].html`. Examples: 0_snap.html, 1_anotherSnap.html, 2.html. Notice how you can use titles and no-titles as you see fit. See the Spock Framework Example.|


The coverage generation tool using Groovy Traits to inject the functions. Within your Groovy class of your Unit Test add the following traits `CoverageBuilder` and `SequenceFlowHistory`
Expand All @@ -92,7 +92,18 @@ CallActivitySingleFeatureSpec extends Specification implements CoverageBuilder,
```

# Offline Usage (BPMN.js CDN vs Local bpmn.js file)

By default the bpmn.js library from [bpmn.io](http://bpmn.io) is loaded from a CDN. This is done for easy compartmentalization
and 'no worry' setup. But in some environments this may not be optimal:

For build/test environment that do not have access to the internet, a local bpmn.js is provided.

When using the `saveCoverageSnapshots()` method you can provide a boolean value to override the default/globally set CDN configuration.
By default the CDN is used. If you use `saveCoverageSnapshots(false)`, this will instruct the coverage builder to use the local bpmn.js file,
and it will save that file into `${buildDir}/bpmn-coverage/bpmnjs/[bpmnjsFile]`, typically this means something like: `target/bpmn-coverage/bpmnjs/bpmn-navigated-viewer.development-2.1.0.js`.

See the TemplateGeneration.groovy file for further methods on how to override the location of the CDN URL and the local bpmnjs file.

# How to install

Expand Down Expand Up @@ -120,8 +131,8 @@ Then add the following dependency:
...
<dependency>
<groupId>com.github.digitalstate</groupId>
<artifactId>camunda-coverage-genertion-groovy</artifactId>
<version>v0.6</version>
<artifactId>camunda-coverage-generation-groovy</artifactId>
<version>v0.7</version>
<scope>test</scope>
</dependency>
```
Expand Down Expand Up @@ -321,6 +332,7 @@ public class SimpleTestCase {
complete(task(processInstance));
// Then the process instance should be ended
assertThat(processInstance).isEnded();

coverageBuilder.coverageSnapshot(processInstance);
coverageBuilder.saveCoverageSnapshots();

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.digitalstate</groupId>
<artifactId>camunda-coverage-genertion-groovy</artifactId>
<version>v0.6</version>
<version>v0.7</version>
<packaging>jar</packaging>
<name>Camunda Converage Generation Groovy</name>

Expand Down Expand Up @@ -114,8 +114,8 @@
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.10</version>
<scope>provided</scope>
<version>2.4.15</version>
<scope>compile</scope>
</dependency>

<!-- camunda process engine -->
Expand Down Expand Up @@ -149,7 +149,7 @@
<dependency>
<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-assert</artifactId>
<scope>provided</scope>
<scope>compile</scope>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import org.camunda.bpm.model.bpmn.instance.IntermediateCatchEvent
import org.camunda.bpm.model.bpmn.instance.ReceiveTask
import org.camunda.bpm.model.bpmn.instance.ServiceTask
import org.camunda.bpm.model.bpmn.instance.UserTask
import org.codehaus.groovy.reflection.ReflectionUtils

import java.nio.file.Paths

import static groovy.json.JsonOutput.toJson
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.historyService
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.repositoryService
Expand All @@ -24,9 +28,32 @@ trait CoverageBuilder implements TemplateGeneration{
coverageSnapshots.put(coverageDataName, coverageData)
}

void saveCoverageSnapshots(HashMap<String, CoverageData> data = coverageSnapshots, String buildDir = 'target') {
void saveCoverageSnapshots(Boolean useCdn = getBpmnViewerCdnUseState(), HashMap<String, CoverageData> data = coverageSnapshots, String buildDir = 'target') {
FileTreeBuilder treeBuilder = new FileTreeBuilder()

// @TODO review use cases of reflection and how it gets used in practice. Using the #2 as the depth for the calling class is not really a "sure bet"
// generate a folder name based on the calling class (the Test class name) - fully qualified
String folderName = ReflectionUtils.getCallingClass(2).getName()

// @TODO implement lots of cleanup around how CDN vs local file generation is implemented in this method and the coveragebulder/templateGeneration traits
if (!useCdn) {
setUseBpmnViewerCdn(false)
InputStream bpmnJsPath = resourceStream(getLocalBpmnViewerPath())
String bpmnJsFileName = Paths.get(getLocalBpmnViewerPath()).getFileName()

treeBuilder {
"${buildDir}" {
"bpmn-coverage" {
"${folderName}" {
"bpmnjs" {
file(bpmnJsFileName, bpmnJsPath.getText('UTF-8'))
}
}
}
}
}
}

data.eachWithIndex { key, value, index ->
// Generate the compiled template using the CoverageData
String output = compileTemplate(value)
Expand All @@ -51,7 +78,9 @@ trait CoverageBuilder implements TemplateGeneration{
treeBuilder {
"${buildDir}" {
"bpmn-coverage" {
file(fileName(), output)
"${folderName}" {
file(fileName(), output)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import io.digitalstate.camunda.coverage.bpmn.Helpers
trait TemplateGeneration implements Helpers{

String templateDir = 'templates'
String bpmnViewerUrl = 'https://unpkg.com/bpmn-js@2.1.0/dist/bpmn-navigated-viewer.development.js'
Boolean useBpmnViewerCdn = true
String localBpmnViewerPath = './bpmnjs/bpmn-navigated-viewer.development-2.1.0.js'

/**
*
Expand All @@ -19,6 +22,31 @@ trait TemplateGeneration implements Helpers{
return this.templateDir
}

void setBpmnViewerUrl(String url){
this.bpmnViewerUrl = url
}

String getBpmnViewerUrl(){
return this.bpmnViewerUrl
}

void setLocalBpmnViewerPath(String path){
this.localBpmnViewerPath = path
}

String getLocalBpmnViewerPath(){
return this.localBpmnViewerPath
}

void useBpmnViewerCdn(Boolean useCdn){
this.useBpmnViewerCdn = useCdn
}

Boolean getBpmnViewerCdnUseState(){
return this.useBpmnViewerCdn
}


def generateTemplateHead(String file = 'head.html'){
return resourceStream("${getTemplateDir()}/${file}").getText()
}
Expand All @@ -27,6 +55,14 @@ trait TemplateGeneration implements Helpers{
return resourceStream("${getTemplateDir()}/${file}").getText()
}

String getBpmnViewer(){
if (this.useBpmnViewerCdn){
return this.bpmnViewerUrl
} else {
return this.localBpmnViewerPath
}
}

def generateTemplateBody( String featureName = '',
String xml = '',
userTasks = [],
Expand All @@ -51,7 +87,8 @@ trait TemplateGeneration implements Helpers{
'externalTasks': externalTasks,
'intermediateCatchEvents': intermediateCatchEvents,
'activityInstancesStillActive': activityInstancesStillActive,
'activityInstanceVariableMapping':activityInstanceVariableMapping
'activityInstanceVariableMapping':activityInstanceVariableMapping,
'bpmnViewer': getBpmnViewer()
]

String template = resourceStream("${getTemplateDir()}/${file}").getText()
Expand Down
Loading

0 comments on commit dafe0c1

Please sign in to comment.