Hi,
I have provided a sample class to run scheduler test without using the
servlet. Maybe this could help you (i have not included import classes). This
is a very crude way of testing but it helped me understand the activities
inside.
This is the ActionHandler class. package is br.com.glr.jbpm.handlers
| public class MailActionHandler implements ActionHandler {
|
| String message;
| String to;
| String from;
| String subject;
|
| public void execute(ExecutionContext executionContext) throws Exception
{
| System.out.println( "MAILING MESSAGE " + subject + "; to->" +
to + "; from->" + from + "; message->" + message);
| }
|
| }
And this is my test class
| public class TestDeployer {
|
| public static void deployTest() throws Exception{
| ProcessDefinition def = ProcessDefinition.parseXmlString(
| "<process-definition name='test-timer-process'>" +
| "<start-state name='start-test'>" +
| "<transition to='state1'/>" +
| "</start-state>" +
| "<state name='state1'>" +
| "<timer name='test-timer' duedate='20
seconds' repeat='10 seconds'>" +
| "<action
name='test-timer-action' class='br.com.glr.jbpm.handlers.MailActionHandler'>" +
| "<from>[EMAIL
PROTECTED]</from>" +
|
"<message>timer</message>" +
|
"<subject>timer</subject>" +
| "<to>[EMAIL
PROTECTED]</to>" +
| "</action>" +
| "</timer>" +
| "<transition to='end-test'/>" +
| "</state>" +
| "<end-state name='end-test'/>" +
| "</process-definition>"
| );
| JbpmSession session =
JbpmSessionFactory.getInstance().openJbpmSession();
| session.beginTransaction();
| session.getGraphSession().saveProcessDefinition(def);
| session.commitTransactionAndClose();
| System.out.println( "FINISH DEPLOYMENT" );
| }
|
| public static void createProcessInstance() throws Exception{
| JbpmSession session =
JbpmSessionFactory.getInstance().openJbpmSession();
| ProcessDefinition def =
session.getGraphSession().findLatestProcessDefinition("test-timer-process");
| ProcessInstance proc = new ProcessInstance(def);
|
| //System.out.println( proc.getRootToken().getNode().getName()
);
| session.beginTransaction();
| session.getGraphSession().saveProcessInstance(proc);
| session.commitTransactionAndClose();
| System.out.println( "YOUR PROCESS INSTANCE ID " + proc.getId());
| }
|
| public static void runFirstState(long id) throws Exception {
| JbpmSession session =
JbpmSessionFactory.getInstance().openJbpmSession();
| ProcessInstance proc =
session.getGraphSession().loadProcessInstance(id);
| proc.signal();
| session.beginTransaction();
| session.getGraphSession().saveProcessInstance(proc);
| session.commitTransactionAndClose();
| System.out.println( "your state name is " +
proc.getRootToken().getNode().getName());
| }
|
| public static void runScheduler() throws Exception{
| JbpmSession session =
JbpmSessionFactory.getInstance().openJbpmSession();
| SchedulerThread th = new SchedulerThread();
| th.start();
| }
|
| public static void endState(long id) throws Exception {
| JbpmSession session =
JbpmSessionFactory.getInstance().openJbpmSession();
| ProcessInstance proc =
session.getGraphSession().loadProcessInstance(id);
| proc.signal();
| session.beginTransaction();
| session.getGraphSession().saveProcessInstance(proc);
| session.commitTransactionAndClose();
| }
|
| public static void main(String[] args) throws Exception {
| //test
| }
|
| }
You must run these codes one at a time and observe the databse (I suggest you
have a clean database):
1. deployProcess();
TABLES AFFECTED: JBPM_PROCESSDEFINITION,
JBPM_NODE,JBPM_TRANSITION,JBPM_NODE,JBPM_EVENT,JBPM_ACTION,JBPM_DELEGATION,JBPM_MODULEDEFINITION
2. createProcessInstance();
TABLE AFFECTED: JBPM_TOKEN, JBPM_PROCESSINSTANCE, JBPM_MODULEINSTANCE,
JBPM_LOG, JBPM_TOKEN
NOTE: This will create a process instance number. You must remember this
instance for our next method. Special take note of JBPM_PROCESSINSTANCE.
3. runFirstState( processId ) //processId is the id in #2
TABLES AFFECTED: JBPM_LOG, JBPM_TIMER, JBPM_TOKEN
NOTE: The JBPM_TIMER is populated at this point. At this node state, this
means the timer is activated. However, you cannot see the effects until
you run the SchedulerThread.
4. runScheduler()
NOTE: This will run the thread that looks up the JBPM_TIMER. Our
ActionHandler will be executed in this step. If not, you must check that
your classes are referenced properly otherwise an error occurs.
5. endState( processId );
TABLES AFFECTED: JBPM_LOG, JBPM_TIMER, JBPM_TOKEN, JBPM_PROCESSINSTANCE
NOTE: At this point, the JBPM_TIMER entry will be removed. If you try to
run SchedulerThread, there will be no more actions to invoke.
Anyway, I hope this will help you in your testing. If this doesn't work just
notify me. Good luck!
Regards,
Elmo
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3913057#3913057
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3913057
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user