Execute a single activity in a given process definition


#1

For testing purposes i would like to execute a single activity in a given/deployed process definiton.
I have already found the “Start Instructions” parameter to start a processinstance at the beginning of an activity.

runtimeService.createProcessInstanceModification(processInstance.getId())
.startBeforeActivity(“contactCustomer”)
.execute();

But if my process does not get into a wait state (directly after the activity execution) how can i suspend/terminate the process instance after it has passed the given activity.


#2

runtimeService.createProcessInstanceModification(processInstance.getId())
.startBeforeActivity(“contactCustomer”)
.execute();

But if my process does not get into a wait state how can i suspend/terminate the process instance after it has passed the given activity.


#3

@tim_kraeuter Can you test this using unit tests? You can set your activity to a Async After configuration, and then do a assertion based on the executed activity. The Job to execute the following activity would not occur until you manually execute the job.


#4

@StephenOTT Thanks for your answer. I dont want to edit my process definiton and i am not sure if i can/should do that at runtime.
In my company the developers have already tested their programmed activitys with unit tests by executing the delegate behind the activity. What I am trying to achieve is a service which can execute any activity of a deployed process definition in a running camunda instance (input would be activity name, process definition id and process variables).
As a result our Testers could easily test an activity isolated from the whole process. We have already wrapped the camunda rest api so we can write automated process tests by starting process instances and asserting their variables to our expected values (SOAP-UI Test suits).


#5

Hi @tim_kraeuter

You could mock the parts executed after your tested activity .

Use class Mocks for this.

Mocks.register(“delegateBeanName”, mockInstance);


#6

@Markus
That does not sound bad. Thanks for your answer.
I just have to ensure that “normal” process instances are not using the mocked classes, since I do not have a separated environment for whole process testing and just activity testing.


#7

Hi @tim_kraeuter

setUp your Mocks in
@Before of your concrete JUnit Test class

In @After you could use
Mocks.reset()
to reset (delete) all Mocks


#8

@Markus
I do not want to execute a single activity in Unit-Tests. The developers have already tested their activity.
I want to execute an activity in a running camunda instance.


#9

So it sounds like you are more making a sort of command execution flow? Where you are executing only the specific activity that was provided in the start context?


#10

@StephenOTT
Basically yes. I would have a webservice with the specified input data (process definiton id, activity name and prozessvariables + process engine name if there are multiple engines). Then i want to execute the given activity outside of the process definition in isolation preferably threw the camunda API and record its variable changes.


#11

Can you do something like this?

diagram_1

When you start your process through the api you provide a variable that tells the bpmn which path to follow. he path is the specific activity you want to execute.

If this does not work, can you explain why you have a overall “process” (that is followed in order sometimes?), and then you have scenarios where you just want to execute a single activity in the BPMN.


#12

In general all my processes should just follow their execution flow as specified in the bpmn. But for testing outside of unit tests i was looking for an easy way to execute an activity from any of my deployed process definitons in isolation. In this case i just want this activity to get executed and nothing else in the process. In every other case the activity is triggered by a process instance it should not stop after the execution.

I thought it would be helpful to test an activity in isolation so i can see if it works as specified (even outside of unit tests) with a running process engine.

Thank you very much @StephenOTT and @Markus for your answers. Great community here!


#13

If this is really required (you should really just write a unit test, you can do with with a few lines using scripting), you could also convert your BPMN have some Call activities for each of the tasks you would be trying to test. Then add the actual task into other bpmn files which are called by the Call activity tasks.

This essentially creates a level of abstraction. Then your parent process runs as expected. And when you want to execute your standalone activities would would start the other bpmn processes which are normally called by the call activities.


#14

I will stick to writing Unit-Tests. Thanks for your help @StephenOTT