cancel
Showing results for 
Search instead for 
Did you mean: 

Need some guidance on BPMN implementation

robojeff
Champ in-the-making
Champ in-the-making
Some questions for the experts:

I'm using Script Tasks (in Groovy) to call out to external services via REST.  I'd like to be able to fake out these external dependencies so I can write unit tests that can put a workflow through all of its paths without the need to stand these external services up.  I don't know how to inject mocks into my Script Tasks.  Is this even possible?

I'd like to eliminate the need for my Script Tasks to rely on external Java "helper" classes.  In our case, we may have to frequently re-deploy updates to a BPMN xml file.  The big problem I see with having logic reside outside the XML file is that the Activiti Engine has to be shut down in order to deploy new or updated Java classes.  But, without externalizing a lot of this common logic, I'd have to duplicate it in many of my Script Tasks.  Is there a reasonable solution to this dilemma?

Is it a reasonable requirement that a workflow implementation be responsible for enforcing business logic pertaining to application roles and permissions? We are not using Activiti users and groups.  We're assigning user ids (UUIDs) as candidate users to a task.  We have a wrapper micro-service around Activiti that enforces authentication and tenant management (this is a generic "workflow" service that purposely knows nothing application specific so it can support multiple BPMNs for different applications).  I've got a requirement that the workflow somehow has to prevent a user from doing something at the application level (for example, edit a document when the state of the workflow is in the certification step).   Isn't this kind of business logic best left enforced at the application level?

Quite often, the users of an application move in and out of their "groups".  Prior to entering a user task, we have a script task that calls out to an external service to find out which users belong to specific groups.  We then assign these UUIDs to a process instance variable that is then used to set the candidate users of the user task that follows the script task.  But once we enter the user task, membership in these groups can change hands.  We're trying to think of a reasonable way to notify the workflow that it needs to update the task's candidate user list.  Any suggestions?

I appreciate any time the experts can devote to thinking on these issues and making recommendations.

Thanks!
4 REPLIES 4

warper
Star Contributor
Star Contributor
Is this even possible?
In Spring environment with bean function calls it works well enough. You can switch any particular component for mock for unit testing.

Is there a reasonable solution to this dilemma?
Camel/Mule integration and countless lines of code/params in your scripts for every piece of rest call? I don't think it's reasonable, but it's doable. Also, you can make simple helpers that call arbitrary rest service, in this case mock unit testing looks easier.

Is it a reasonable requirement
More or less it's part of business logic, but if you get requirement that something should not happen, then ask back what should process do in this case. Most restrictions like this in ruins clear business logic if they are left outside of process - most obvious outcome would be stuck process, because user is already selected, but he/she can't move process forward. You have to have plan B for every case, and it will make processes look like x-mas tree…

We're trying to think of a reasonable way to notify the workflow that it needs to update the task's candidate user list.
You can make signal/message catching events or receive tasks in parallel execution to handle this situation.
But why bother to notify workflow? In general case process is stored in DB waiting for user task/timer/event. You can simply update task properties outside of process - engine doesn't require you to be inside process to make changes.

robojeff
Champ in-the-making
Champ in-the-making
Can anyone point me to an example of how to inject mock objects into a groovy script? I'm trying to get my head around how a Spring Application would even know to scan for things to @Inject into a snippet of groovy code.  When you @ComponentScan you need to tell Spring about packages to scan for.  How does it know to go look for something embedded in an XML file?

I'd really prefer we were able to keep all of our implementation embedded within the BPMN file, as it alleviates us of having to take down Activiti in order to deploy updated or new Java helper classes.  I don't see much out there in the Googlesphere about doing this.  Any advice on that subject?

Thanks!

Hi,

I would propose to use spring beans in the groovy script. You can mock spring beans easily in the spring context.

Regards
Martin

warper
Star Contributor
Star Contributor
How does it know to go look for something embedded in an XML file?
It does not know, it loads everything you mention in bean definitions and annotated component-scan classes. Everything you need should be already defined in spring context.
Unit test loads proper context (here with mocks):
@ContextConfiguration({ "classpath:META-INF/spring/test-mock-context.xml", "classpath:META-INF/spring/test-context.xml" })

public class getRegionMockTest extends SpringActivitiTestCase {