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: WfMOpenTestCase.java,v 1.1 2006/09/29 12:32:07 drmlipp Exp $
021: *
022: * $Log: WfMOpenTestCase.java,v $
023: * Revision 1.1 2006/09/29 12:32:07 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.3 2004/08/18 15:17:39 drmlipp
027: * Update to 1.2
028: *
029: * Revision 1.14 2004/02/21 12:50:29 lipp
030: * Made tests a bit more robust.
031: *
032: * Revision 1.13 2004/01/27 11:45:32 lipp
033: * Preserve newlines when reading process definitions.
034: *
035: * Revision 1.12 2003/10/21 21:00:45 lipp
036: * Moved EJBClientTest to new junit sub-package.
037: *
038: * Revision 1.11 2003/10/20 10:31:19 barzik
039: * - separated process creation prerequisites from proper process creation
040: * - execute prerequisites and first creation separately
041: *
042: * Revision 1.10 2003/10/08 12:39:40 huaiyang
043: * make test weblogic compatible.
044: *
045: * Revision 1.9 2003/06/27 09:44:03 lipp
046: * Fixed copyright/license information.
047: *
048: * Revision 1.8 2003/04/26 16:46:55 lipp
049: * Made unittests and systemtests coexist in eclipse.
050: *
051: * Revision 1.7 2003/04/16 19:58:49 lipp
052: * Adapted to jdk 1.4
053: *
054: * Revision 1.6 2003/03/21 14:21:43 montag
055: * New system test for wsif invocation.
056: *
057: * Revision 1.5 2003/02/25 17:08:18 lipp
058: * Reorganized requester implementation.
059: *
060: * Revision 1.4 2003/02/14 14:03:03 lipp
061: * Reactivated process removal.
062: *
063: * Revision 1.3 2003/02/12 16:14:43 lipp
064: * Delays now based on events.
065: *
066: * Revision 1.2 2002/11/25 17:27:19 weidauer
067: * completed documentation
068: *
069: * Revision 1.1 2002/11/25 17:22:42 weidauer
070: * refactored with WfMOpenTestCase as base test case and cleaned up classes
071: *
072: */
073:
074: package process;
075:
076: import java.io.BufferedReader;
077: import java.io.InputStream;
078: import java.io.InputStreamReader;
079: import java.rmi.RemoteException;
080: import java.util.Collection;
081:
082: import junit.framework.TestCase;
083:
084: import common.STProjectLoginContext;
085:
086: import javax.security.auth.login.LoginException;
087:
088: import de.danet.an.util.junit.EJBClientTest;
089: import de.danet.an.workflow.api.DefaultRequester;
090: import de.danet.an.workflow.api.FactoryConfigurationError;
091: import de.danet.an.workflow.api.Process;
092: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
093: import de.danet.an.workflow.api.ProcessDirectory;
094: import de.danet.an.workflow.api.ProcessMgr;
095: import de.danet.an.workflow.api.WorkflowService;
096: import de.danet.an.workflow.api.WorkflowServiceFactory;
097: import de.danet.an.workflow.omgcore.WfActivity;
098: import de.danet.an.workflow.omgcore.WfProcess;
099: import de.danet.an.workflow.omgcore.WfRequester;
100:
101: /**
102: * Base test case for WfMOpen test cases.
103: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
104: * @version 1.0
105: */
106: public class WfMOpenTestCase extends TestCase {
107: protected static STProjectLoginContext plc = null;
108: static {
109: try {
110: plc = new STProjectLoginContext();
111: plc.login();
112: } catch (LoginException e) {
113: throw new IllegalStateException(e.getMessage());
114: }
115: }
116:
117: /**
118: * Describe variable <code>xpdlFile</code> here.
119: *
120: */
121: protected String xpdlFile;
122:
123: /**
124: * <code>setStateDirectly</code> defines how a state transition is caused.
125: *
126: */
127: protected boolean setStateDirectly = false;
128:
129: /**
130: * Describe <code>setSetStateDirectly</code> method here.
131: *
132: * @param setStateDirectly a <code>boolean</code> value
133: */
134: protected void setSetStateDirectly(boolean setStateDirectly) {
135: this .setStateDirectly = setStateDirectly;
136: }
137:
138: /**
139: * Constructor of this TestCase
140: * @param name a <code>String</code> value
141: */
142: public WfMOpenTestCase(String name) {
143: super (name);
144: }
145:
146: /**
147: * Describe constant <code>RUNNING</code> here.
148: *
149: */
150: protected static final String RUNNING = "open.running";
151: /**
152: * Describe constant <code>SUSPENDED</code> here.
153: *
154: */
155: protected static final String SUSPENDED = "open.not_running.suspended";
156: /**
157: * Describe constant <code>NOT_STARTED</code> here.
158: *
159: */
160: protected static final String NOT_STARTED = "open.not_running.not_started";
161: /**
162: * Describe constant <code>COMPLETED</code> here.
163: *
164: */
165: protected static final String COMPLETED = "closed.completed";
166: /**
167: * Describe constant <code>TERMINATED</code> here.
168: *
169: */
170: protected static final String TERMINATED = "closed.terminated";
171: /**
172: * Describe constant <code>ABORTED</code> here.
173: *
174: */
175: protected static final String ABORTED = "closed.aborted";
176:
177: private static WorkflowService wfsCache = null;
178:
179: protected WorkflowService workflowService() {
180: if (wfsCache == null) {
181: try {
182: WorkflowServiceFactory wfsf = WorkflowServiceFactory
183: .newInstance();
184: wfsCache = wfsf.newWorkflowService();
185: } catch (FactoryConfigurationError e) {
186: throw new IllegalStateException(e.getMessage());
187: }
188: }
189: return wfsCache;
190: }
191:
192: private static WfRequester defReqCache = null;
193:
194: protected WfRequester defaultRequester() throws RemoteException {
195: if (defReqCache == null) {
196: defReqCache = new DefaultRequester(workflowService());
197: }
198: return defReqCache;
199: }
200:
201: /**
202: * Import the process definitions from a XPDL file
203: * using the ProcessDefinitionDirectory bean.
204: * @exception Exception if an error occurs
205: */
206: public void importProcessDefinitions() throws Exception {
207: ProcessDefinitionDirectory pdd = workflowService()
208: .processDefinitionDirectory();
209: InputStream is = getClass().getResourceAsStream(xpdlFile);
210: assertTrue(is != null);
211: BufferedReader br = new BufferedReader(new InputStreamReader(
212: is, "ISO-8859-1"));
213: StringBuffer sb = new StringBuffer();
214: String st;
215: while ((st = br.readLine()) != null) {
216: sb.append(st + "\n");
217: }
218: pdd.importProcessDefinitions(sb.toString());
219: Collection processDefinitions = pdd.processDefinitions();
220: assertTrue(processDefinitions.size() > 0);
221: }
222:
223: /**
224: * remove the process definition
225: * using the ProcessDefinitionDirectory bean.
226: * @param packageId Id attribute of the process package.
227: * @param processId Id attribute of the process.
228: * @exception Exception if an error occurs
229: */
230: public void removeProcessDefinition(String packageId,
231: String processId) throws Exception {
232: ProcessDefinitionDirectory pdd = workflowService()
233: .processDefinitionDirectory();
234: pdd.removeProcessDefinition(packageId, processId);
235: }
236:
237: /**
238: * Describe <code>createProcess</code> method here.
239: *
240: * @param pkgId a <code>String</code> value
241: * @param prcId a <code>String</code> value
242: * @param req a <code>WfRequester</code> value
243: * @return a <code>SmartWfProcess</code> value
244: * @exception Exception if an error occurs
245: */
246: protected SmartWfProcess createProcess(String pkgId, String prcId)
247: throws Exception {
248: ProcessDefinitionDirectory pdd = workflowService()
249: .processDefinitionDirectory();
250: ProcessMgr pmgr = pdd.processMgr(pkgId, prcId);
251: return smart(pmgr.createProcess(defaultRequester()));
252: }
253:
254: /**
255: *
256: */
257: private static ProcessMgr processManager = null;
258:
259: /**
260: * Prepares the creation of a process.
261: *
262: * @param pkgId a <code>String</code> value
263: * @param prcId a <code>String</code> value
264: * @exception Exception if an error occurs
265: */
266: protected void prepareCreateProcess(String pkgId, String prcId) {
267: try {
268: ProcessDefinitionDirectory pdd = workflowService()
269: .processDefinitionDirectory();
270: processManager = pdd.processMgr(pkgId, prcId);
271: defReqCache = defaultRequester();
272: } catch (Exception e) {
273: e.printStackTrace();
274: }
275: }
276:
277: /**
278: * Creates a smart process using its process manager and default
279: * requester.
280: *
281: * @return a <code>SmartWfProcess</code> value
282: * @exception Exception if an error occurs
283: */
284: protected SmartWfProcess createProcess() throws Exception {
285: return smart(processManager.createProcess(defReqCache));
286: }
287:
288: /**
289: * Describe <code>removeProcess</code> method here.
290: *
291: * @param process a <code>SmartWfProcess</code> value
292: * @exception Exception if an error occurs
293: */
294: protected void removeProcess(SmartWfProcess process)
295: throws Exception {
296: ProcessDirectory pd = workflowService().processDirectory();
297: pd.removeProcess((Process) process.getWfProcess());
298: }
299:
300: /**
301: * Describe <code>smart</code> method here.
302: *
303: * @param activity a <code>WfActivity</code> value
304: * @return a <code>SmartWfActivity</code> value
305: */
306: protected SmartWfActivity smart(WfActivity activity)
307: throws Exception {
308: return new SmartWfActivity(activity, setStateDirectly);
309: }
310:
311: /**
312: * Describe <code>smart</code> method here.
313: *
314: * @param process a <code>WfProcess</code> value
315: * @return a <code>SmartWfProcess</code> value
316: */
317: protected SmartWfProcess smart(WfProcess process) throws Exception {
318: return new SmartWfProcess(process, setStateDirectly);
319: }
320:
321: protected void assertState(SmartWfExecutionObject obj, String state) {
322: for (int i = 0; i < 15; i++) {
323: if (obj.hasState(state)) {
324: return;
325: }
326: try {
327: Thread.sleep(1000);
328: } catch (InterruptedException e) {
329: }
330: }
331: assertTrue(obj.toString() + " should have state " + state
332: + ", has " + obj.state(), obj.hasState(state));
333: }
334: }
|