/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU TEL.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: InvokeProcess.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.3 2006/09/29 12:32:13 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.2 2005/04/22 15:11:06 drmlipp
* Merged changes from 1.3 branch up to 1.3p15.
*
* Revision 1.1.2.1 2005/04/18 13:06:09 drmlipp
* Invoke a single process.
*
*/
package load;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.security.auth.login.LoginException;
import de.danet.an.util.junit.EJBClientTest;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfRequester;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.FactoryConfigurationError;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import common.UTLoginContext;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* This class provides ...
*
* @author <a href="mailto:mnl@mnl.de">Michael N. Lipp</a>
* @version $Revision: 2326 $
*/
public class InvokeProcess extends TestCase {
private static UTLoginContext plc = null;
static {
try {
plc = new UTLoginContext();
plc.login();
} catch (LoginException e) {
throw new IllegalStateException (e.getMessage ());
}
}
private static WorkflowService wfsCache = null;
/**
* Creates an instance of <code>InvokeProcess</code>
* with all attributes initialized to default values.
*/
public InvokeProcess (String name) {
super (name);
}
/**
* Make this test suite.
*/
public static Test suite() {
TestSuite rootSuite = new TestSuite();
// rootSuite.addTest(new InvokeProcess("importProcessDefinitions"));
rootSuite.addTest(new InvokeProcess("runTest"));
return new EJBClientTest (plc, rootSuite);
}
private WorkflowService workflowService() {
if (wfsCache == null) {
try {
WorkflowServiceFactory wfsf
= WorkflowServiceFactory.newInstance ();
wfsCache = wfsf.newWorkflowService();
} catch (FactoryConfigurationError e) {
throw new IllegalStateException (e.getMessage());
}
}
return wfsCache;
}
/**
* Import the process definitions from a XPDL file
* unsing the ProcessDefinitionDirectory bean.
*/
public void importProcessDefinitions() throws Exception {
WorkflowServiceFactory wsf = WorkflowServiceFactory.newInstance();
WorkflowService ws = workflowService();
ProcessDefinitionDirectory pdd = ws.processDefinitionDirectory();
InputStream is = getClass()
.getResourceAsStream("/load/testByAudit2.xml");
assertTrue (is != null);
BufferedReader br = new BufferedReader
(new InputStreamReader(is, "ISO-8859-1"));
StringBuffer sb = new StringBuffer();
String st;
while ((st = br.readLine()) != null) {
sb.append(st + "\n");
}
pdd.importProcessDefinitions(sb.toString());
}
public void runTest () throws Exception {
WfRequester req = new DefaultRequester (workflowService());
WfProcess process = createProcess
("testByAudit2", "testByAudit_emptySeq_na", req);
assertTrue(process!=null);
process.start ();
assertTrue (stateReached (process, "closed"));
}
/**
* Creates the process
* using the ProcessDefinitionDirectory bean.
*/
private WfProcess createProcess
(String pkgId, String prcId, WfRequester req)
throws Exception {
ProcessDefinitionDirectory procDir = null;
try {
procDir = workflowService().processDefinitionDirectory ();
ProcessMgr pmgr = procDir.processMgr(pkgId, prcId);
return pmgr.createProcess (req);
} finally {
workflowService().release (procDir);
}
}
private boolean stateReached(WfProcess proc, String procState)
throws Exception {
int maxRetries = 30;
while (true){
if (proc.state().startsWith(procState)) {
return true;
}
if (maxRetries-- <= 0) {
return false;
}
Thread.sleep(1000);
}
}
}