Injecting class in (JAVA) serviceTask manually for testing

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2010 06:59 AM
Is it possible to inject manually in the service task the class for testing purposes?
As I read, the JavaDelegate object is injected in the process definition first time the process is instanced.
The problem is that I would like to inject a RuntimeService component (the runtimeService from the ActivitiRule test) before.
I've found a topic related
http://forums.activiti.org/en/viewtopic.php?f=3&t=249&hilit=runtimeservice+servicetask).
I tried in the test to use:
So I understand that the only way is using Spring Injection (http://forums.activiti.org/en/viewtopic.php?f=3&t=249&hilit=runtimeservice+servicetask).
Is there other way of testing a process without the use of Spring ?
The idea in the test should be:
1. Deploy process.
2. Inject all java beans in the several JAVA service tasks of the process. Initialize within the test these beans.
3. Run the test.
As I read, the JavaDelegate object is injected in the process definition first time the process is instanced.
The problem is that I would like to inject a RuntimeService component (the runtimeService from the ActivitiRule test) before.
I've found a topic related

I tried in the test to use:
ProcessEngineImpl engine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
for accesing to the current runtimeService of the test but it creates a new engine. I think that it is due to the fact that I'm using an in-memory database so it creates a new database in other memory location.So I understand that the only way is using Spring Injection (http://forums.activiti.org/en/viewtopic.php?f=3&t=249&hilit=runtimeservice+servicetask).
Is there other way of testing a process without the use of Spring ?
The idea in the test should be:
1. Deploy process.
2. Inject all java beans in the several JAVA service tasks of the process. Initialize within the test these beans.
3. Run the test.
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2010 08:58 AM
Hi,
If your goal is to use the RuntimeService from within your JavaDelegate implementation, then you should rethink this
The API is created to be used outside of the process-context. When you will try to use a service (eg. runtimeService) in the JavaDelegate, transactions an command-context will be messed up.
If your goal is to use the RuntimeService from within your JavaDelegate implementation, then you should rethink this

The API is created to be used outside of the process-context. When you will try to use a service (eg. runtimeService) in the JavaDelegate, transactions an command-context will be messed up.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2010 02:40 AM
I agree that a rule of thumb should be
I didn't want to change flow using runtimeService. I only wanted to access to parent process variables within a subprocess using ProcessInstanceQueries.
Execution class should access to parent variables or a best solution: access to parent execution. Currently I can not.
I only try to find a temporary solution to:
http://jira.codehaus.org/browse/ACT-313
http://jira.codehaus.org/browse/ACT-354
:cry: Excuse me, maybe the question shall be in other topic:
If you want I open a new topic with this issue.
Don't change process flow with code, use only process variables.
I didn't want to change flow using runtimeService. I only wanted to access to parent process variables within a subprocess using ProcessInstanceQueries.
Execution class should access to parent variables or a best solution: access to parent execution. Currently I can not.
I only try to find a temporary solution to:
http://jira.codehaus.org/browse/ACT-313
http://jira.codehaus.org/browse/ACT-354
:cry: Excuse me, maybe the question shall be in other topic:
Access to parent variables within a sub-process with code.
If you want I open a new topic with this issue.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2010 09:02 AM
Ah, now I see. A workaround could be to use the activiti-sessions instead of API to get execution-variables from parent, eg:
Since this is not part of the public API, we can't guarantee that the method-signature (or method itself) will remain the same over time. Also note that this code will only work when invoked from within a process-context (eg. taskListener or JavaDelegation).
CommandContext
.getCurrentSession(RuntimeSession.class)
.findVariableInstancesByExecutionId(parentExecutionId);
or
CommandContext
.getCurrentSession(RuntimeSession.class)
.findExecutionById(parentExecutionId);
Since this is not part of the public API, we can't guarantee that the method-signature (or method itself) will remain the same over time. Also note that this code will only work when invoked from within a process-context (eg. taskListener or JavaDelegation).
