-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2c1b0d
commit 9d58e0e
Showing
5 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/camunda/bpm/extension/mockito/process/SubProcessMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.camunda.bpm.extension.mockito.process; | ||
|
||
import org.camunda.bpm.engine.repository.ProcessDefinition; | ||
import org.camunda.bpm.engine.test.ProcessEngineRule; | ||
import org.camunda.bpm.model.bpmn.Bpmn; | ||
import org.camunda.bpm.model.bpmn.BpmnModelInstance; | ||
|
||
public class SubProcessMock extends ProcessMock { | ||
|
||
private final ProcessEngineRule rule; | ||
private final String processDefinitionKey; | ||
|
||
public SubProcessMock(final ProcessEngineRule rule, final String processDefinitionKey, final String subProcessModelId) { | ||
super(processDefinitionKey); | ||
this.rule = rule; | ||
this.processDefinitionKey = processDefinitionKey; | ||
|
||
this.extendGivenProcess(subProcessModelId); | ||
} | ||
|
||
private void extendGivenProcess(String subProcessModelId) { | ||
final ProcessDefinition processDefinition = this.rule.getRepositoryService() | ||
.createProcessDefinitionQuery() | ||
.processDefinitionKey(processDefinitionKey) | ||
.latestVersion().singleResult(); | ||
|
||
final BpmnModelInstance bpmnModelInstance = this.rule.getRepositoryService() | ||
.getBpmnModelInstance(processDefinition.getId()); | ||
|
||
System.out.println(Bpmn.convertToString(bpmnModelInstance)); | ||
|
||
flowNodeBuilder = bpmnModelInstance.getModelElementById(subProcessModelId); | ||
|
||
|
||
// bpmnModelInstance. | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/org/camunda/bpm/extension/mockito/EmbeddedSubprocessMockExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.camunda.bpm.extension.mockito; | ||
|
||
import org.camunda.bpm.engine.runtime.ProcessInstance; | ||
import org.camunda.bpm.engine.test.ProcessEngineRule; | ||
import org.camunda.bpm.extension.mockito.function.DeployProcess; | ||
import org.camunda.bpm.model.bpmn.Bpmn; | ||
import org.camunda.bpm.model.bpmn.BpmnModelInstance; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; | ||
import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.runtimeService; | ||
import static org.camunda.bpm.extension.mockito.MostUsefulProcessEngineConfiguration.mostUsefulProcessEngineConfiguration; | ||
import static org.camunda.bpm.extension.mockito.ProcessExpressions.registerEmbeddedSubProcessMock; | ||
|
||
public class EmbeddedSubprocessMockExample { | ||
|
||
public static final String PROCESS_ID = "myProcess"; | ||
public static final String SUB_PROCESS_ID = "mySubProcess"; | ||
public static final String SUB_PROCESS2_ID = "mySubProcess2"; | ||
|
||
@Rule | ||
public final ProcessEngineRule rule = new ProcessEngineRule(mostUsefulProcessEngineConfiguration().buildProcessEngine()); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final BpmnModelInstance processWithSubProcess = Bpmn.createExecutableProcess(PROCESS_ID) | ||
.startEvent("start") | ||
.subProcess(SUB_PROCESS_ID) | ||
.embeddedSubProcess() | ||
.startEvent() | ||
.endEvent() | ||
.subProcessDone() | ||
.userTask("user_task") | ||
.endEvent("end") | ||
.done(); | ||
|
||
DeployProcess.INSTANCE.apply(rule, processWithSubProcess, PROCESS_ID); | ||
} | ||
|
||
@Test | ||
public void register_embedded_subprocess_mock_addVar() throws Exception { | ||
registerEmbeddedSubProcessMock(rule, PROCESS_ID, SUB_PROCESS_ID) | ||
.onExecutionAddVariable("foo", "bar") | ||
.deploy(rule); | ||
|
||
final ProcessInstance processInstance = startProcess(PROCESS_ID); | ||
assertThat(processInstance).isWaitingAt("user_task"); | ||
//TODO doesn't work with current camunda-bpm-assert version (1.*) and our assertj version (3.*) | ||
//assertThat(processInstance).hasVariables("foo", "bar"); | ||
final Map<String, Object> variables = runtimeService().getVariables(processInstance.getId()); | ||
assertThat(variables).hasSize(1); | ||
assertThat(variables).containsEntry("foo", "bar"); | ||
} | ||
|
||
private ProcessInstance startProcess(final String key) { | ||
return rule.getRuntimeService().startProcessInstanceByKey(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters