001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: ToolInvocation.java,v 1.5 2007/03/27 21:59:42 mlipp Exp $
021: *
022: * $Log: ToolInvocation.java,v $
023: * Revision 1.5 2007/03/27 21:59:42 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.4 2006/10/13 13:58:32 drmlipp
027: * Adapted to new environment.
028: *
029: * Revision 1.3 2006/10/07 20:41:34 mlipp
030: * Merged J2EE 1.4 adaptions from test branch.
031: *
032: * Revision 1.2 2006/09/29 12:32:10 drmlipp
033: * Consistently using WfMOpen as projct name now.
034: *
035: * Revision 1.1.1.3 2004/08/18 15:18:47 drmlipp
036: * Update to 1.2
037: *
038: * Revision 1.18 2004/01/27 11:45:33 lipp
039: * Preserve newlines when reading process definitions.
040: *
041: * Revision 1.17 2003/10/21 21:00:45 lipp
042: * Moved EJBClientTest to new junit sub-package.
043: *
044: * Revision 1.16 2003/10/08 11:52:55 huaiyang
045: * make test weblogic compatible.
046: *
047: * Revision 1.15 2003/09/19 13:12:29 lipp
048: * Adapted to closed.completed having a substate.
049: *
050: * Revision 1.14 2003/06/27 09:44:13 lipp
051: * Fixed copyright/license information.
052: *
053: * Revision 1.13 2003/04/26 16:46:55 lipp
054: * Made unittests and systemtests coexist in eclipse.
055: *
056: * Revision 1.12 2003/04/17 13:28:41 lipp
057: * Modification for analysis fixed problem. Magic.
058: *
059: * Revision 1.11 2003/04/16 19:25:04 lipp
060: * Adapted to jdk 1.4
061: *
062: * Revision 1.10 2003/02/25 17:08:27 lipp
063: * Reorganized requester implementation.
064: *
065: * Revision 1.9 2003/02/24 10:46:41 lipp
066: * Removed usage of System.out and .err.
067: *
068: * Revision 1.8 2003/02/19 08:35:12 lipp
069: * Added delay.
070: *
071: * Revision 1.7 2003/02/05 15:57:06 lipp
072: * Replaced DummyRequester with DefaultRequester.
073: *
074: * Revision 1.6 2002/11/19 15:14:52 lipp
075: * New transition manager.
076: *
077: * Revision 1.5 2002/10/23 11:36:47 lipp
078: * Got them running again.
079: *
080: * Revision 1.4 2002/10/23 07:29:15 lipp
081: * Adapted to state handling changes.
082: *
083: * Revision 1.3 2002/10/22 17:19:01 lipp
084: * Still adapting to state handling changes.
085: *
086: * Revision 1.2 2002/09/24 15:54:08 lipp
087: * Removed not needed import.
088: *
089: * Revision 1.1 2002/09/23 12:57:40 huaiyang
090: * Check the datafield.
091: *
092: *
093: */
094: package process;
095:
096: import java.io.BufferedReader;
097: import java.io.InputStream;
098: import java.io.InputStreamReader;
099: import java.util.Collection;
100: import java.util.Iterator;
101:
102: import junit.framework.Test;
103: import junit.framework.TestCase;
104: import junit.framework.TestSuite;
105:
106: import common.UTLoginContext;
107: import javax.security.auth.login.LoginException;
108:
109: import de.danet.an.util.EJBUtil;
110: import de.danet.an.util.junit.EJBClientTest;
111: import de.danet.an.workflow.api.DefaultRequester;
112: import de.danet.an.workflow.api.FactoryConfigurationError;
113: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
114: import de.danet.an.workflow.api.ProcessMgr;
115: import de.danet.an.workflow.api.WorkflowService;
116: import de.danet.an.workflow.api.WorkflowServiceFactory;
117: import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
118: import de.danet.an.workflow.omgcore.ProcessData;
119: import de.danet.an.workflow.omgcore.WfActivity;
120: import de.danet.an.workflow.omgcore.WfProcess;
121: import de.danet.an.workflow.omgcore.WfRequester;
122:
123: /**
124: * Test the life cycle of different processes.
125: */
126: public class ToolInvocation extends TestCase {
127: private static UTLoginContext plc = null;
128: static {
129: try {
130: plc = new UTLoginContext();
131: plc.login();
132: } catch (LoginException e) {
133: throw new IllegalStateException(e.getMessage());
134: }
135: }
136:
137: /**
138: * Constructor of this TestCase
139: */
140: public ToolInvocation(String name) {
141: super (name);
142: }
143:
144: /**
145: * Stellt diese TestSuite zusammen.
146: */
147: public static Test suite() {
148: TestSuite suite = new TestSuite();
149: suite.addTest(new ToolInvocation("importProcessDefinitions"));
150: suite.addTest(new ToolInvocation("processjutToolInvocation"));
151: return new EJBClientTest(plc, suite);
152: }
153:
154: private static WorkflowService wfsCache = null;
155:
156: private WorkflowService workflowService() {
157: if (wfsCache == null) {
158: try {
159: WorkflowServiceFactory wfsf = WorkflowServiceFactory
160: .newInstance();
161: wfsCache = wfsf.newWorkflowService();
162: } catch (FactoryConfigurationError e) {
163: throw new IllegalStateException(e.getMessage());
164: }
165: }
166: return wfsCache;
167: }
168:
169: /**
170: * Import the process definitions from a XPDL file
171: * unsing the ProcessDefinitionDirectory bean.
172: */
173: public void importProcessDefinitions() throws Exception {
174: // Create process definition directory bean
175: ProcessDefinitionDirectory pdd = workflowService()
176: .processDefinitionDirectory();
177:
178: InputStream is = getClass().getResourceAsStream(
179: "/process/testToolInvocation.xml");
180: assertTrue(is != null);
181: BufferedReader br = new BufferedReader(new InputStreamReader(
182: is, "ISO-8859-1"));
183: StringBuffer sb = new StringBuffer();
184: String st;
185: while ((st = br.readLine()) != null) {
186: sb.append(st + "\n");
187: }
188: pdd.importProcessDefinitions(sb.toString());
189: Collection processDefinitions = pdd.processDefinitions();
190: assertTrue(processDefinitions.size() > 0);
191: }
192:
193: private WfProcess createProcess(String pkgId, String prcId,
194: WfRequester req) throws Exception {
195: ProcessDefinitionDirectory procDir = null;
196: try {
197: procDir = workflowService().processDefinitionDirectory();
198: ProcessMgr pmgr = procDir.processMgr(pkgId, prcId);
199: return pmgr.createProcess(req);
200: } finally {
201: workflowService().release(procDir);
202: }
203: }
204:
205: /**
206: *
207: */
208: public void processjutToolInvocation() throws Exception {
209: WfRequester req = new DefaultRequester(workflowService());
210: // create the process
211: WfProcess process = createProcess("ut-process",
212: "jut_tool_invocation", req);
213: assertTrue(process.state().equals(
214: "open.not_running.not_started"));
215: // start the process
216: process.start();
217: Thread.sleep(1000);
218: assertTrue(process.state().startsWith("open.running"));
219: WfActivity act = actByName(process, "Account Antrag erstellen");
220: assertTrue(invoke(act));
221: act = actByName(process, "Account Antrag bearbeiten");
222: assertTrue(invoke(act));
223: Thread.sleep(1500);
224: assertTrue(actByName(process, "Account Antrag rückmelden")
225: .state().startsWith("closed.completed"));
226: assertTrue(process.state().startsWith("closed.completed"));
227: }
228:
229: private WfActivity actByName(WfProcess proc, String name)
230: throws Exception {
231: WfActivity a = null;
232: for (Iterator it = proc.steps().iterator(); it.hasNext();) {
233: WfActivity ai = (WfActivity) it.next();
234: if (ai.name().equals(name)) {
235: a = ai;
236: break;
237: }
238: }
239: return a;
240: }
241:
242: private boolean invoke(WfActivity a) throws Exception {
243: assertTrue(a.state() != null);
244: ProcessData processData = a.processContext();
245: // Check data field has been read correctly.
246: processData.containsKey("emailAddress");
247: processData.containsValue("account@bank.com");
248: a.complete();
249: Thread.sleep(1000);
250: return true;
251: }
252:
253: }
|