001: /*
002: * Danet GmbH
003: * Beratung und Software-Entwicklung
004: * Geschäftstelle AN
005: *
006: * $Id: Basic.java,v 1.6 2007/05/03 21:58:24 mlipp Exp $
007: *
008: * $Log: Basic.java,v $
009: * Revision 1.6 2007/05/03 21:58:24 mlipp
010: * Internal refactoring for making better use of local EJBs.
011: *
012: * Revision 1.5 2006/10/13 13:58:32 drmlipp
013: * Adapted to new environment.
014: *
015: * Revision 1.4 2006/10/07 20:41:34 mlipp
016: * Merged J2EE 1.4 adaptions from test branch.
017: *
018: * Revision 1.3 2005/04/22 15:11:07 drmlipp
019: * Merged changes from 1.3 branch up to 1.3p15.
020: *
021: * Revision 1.2.2.1 2005/04/21 12:51:38 drmlipp
022: * Fixed test.
023: *
024: * Revision 1.2 2004/12/30 12:10:23 mlipp
025: * Adadpted to JNDI name changes.
026: *
027: * Revision 1.1.1.3 2004/08/18 15:18:47 drmlipp
028: * Update to 1.2
029: *
030: * Revision 1.39 2004/06/14 19:37:20 lipp
031: * Fixed assignment functions and cleaned up assignment related
032: * interfaces.
033: *
034: * Revision 1.38 2004/03/03 17:23:14 lipp
035: * Implemented setAssignee and cleaned up code a bit.
036: *
037: * Revision 1.37 2004/02/21 21:31:01 lipp
038: * Some more refactoring to resolve cyclic dependencies.
039: *
040: * Revision 1.36 2004/01/27 11:45:33 lipp
041: * Preserve newlines when reading process definitions.
042: *
043: * Revision 1.35 2003/10/21 21:00:45 lipp
044: * Moved EJBClientTest to new junit sub-package.
045: *
046: * Revision 1.34 2003/10/08 11:52:55 huaiyang
047: * make test weblogic compatible.
048: *
049: * Revision 1.33 2003/05/02 14:55:58 lipp
050: * Resolved some more package dependencies.
051: *
052: * Revision 1.32 2003/04/26 16:46:55 lipp
053: * Made unittests and systemtests coexist in eclipse.
054: *
055: * Revision 1.31 2003/04/16 19:25:04 lipp
056: * Adapted to jdk 1.4
057: *
058: * Revision 1.30 2003/02/25 17:08:27 lipp
059: * Reorganized requester implementation.
060: *
061: * Revision 1.29 2003/02/05 15:57:06 lipp
062: * Replaced DummyRequester with DefaultRequester.
063: *
064: * Revision 1.28 2003/01/13 20:29:42 lipp
065: * Classpath fixes.
066: *
067: * Revision 1.27 2002/12/19 21:37:42 lipp
068: * Reorganized interfaces.
069: *
070: * Revision 1.26 2002/12/05 10:20:39 lipp
071: * Adapted unittests to assignment changes.
072: *
073: * Revision 1.25 2002/12/04 16:05:08 lipp
074: * Reorganized assignment handling.
075: *
076: * Revision 1.24 2002/10/23 11:36:47 lipp
077: * Got them running again.
078: *
079: * Revision 1.23 2002/09/18 21:26:51 lipp
080: * Removed SAXFacade (integrated with WorkflowEngine).
081: *
082: * Revision 1.22 2002/09/18 20:48:21 lipp
083: * Cleanly separated workflow engine and service.
084: *
085: * Revision 1.21 2002/09/18 13:00:26 lipp
086: * Renamed WorkflowEngine to WorkflowService and introduced
087: * WorkflowServiceFactory.
088: *
089: * Revision 1.20 2002/09/08 18:49:18 lipp
090: * Proper use of packageId and processId.
091: *
092: * Revision 1.19 2002/09/04 20:50:44 lipp
093: * Adapted to new process manager name schema.
094: *
095: * Revision 1.18 2002/08/30 21:32:07 lipp
096: * Finished transition to WorkflowEngine.
097: *
098: * Revision 1.17 2002/08/30 13:37:05 lipp
099: * Using Workflow engine facade now.
100: *
101: * Revision 1.16 2002/08/26 20:23:14 lipp
102: * Lots of method renames.
103: *
104: * Revision 1.15 2002/08/21 22:06:48 lipp
105: * Finished transition to ProcessMgrStub.
106: *
107: * Revision 1.14 2002/06/27 10:48:36 lipp
108: * Adapted to change in RAS/RMS interface.
109: *
110: * Revision 1.13 2002/02/04 15:18:55 lipp
111: * Made ActivityFinderAndKey visible in EJB Remote interface.
112: *
113: * Revision 1.12 2002/02/03 21:41:42 lipp
114: * Cleaned up unittests.
115: *
116: * Revision 1.11 2002/01/23 14:09:57 huaiyang
117: * Adapted to API changed and new test case.
118: *
119: * Revision 1.10 2002/01/09 14:00:01 lipp
120: * Cleaned up relation between wfcore, resource assignment and resource
121: * management service.
122: *
123: * Revision 1.9 2001/12/19 09:06:15 lipp
124: * Added some comments.
125: *
126: * Revision 1.8 2001/12/18 22:16:53 lipp
127: * Restructured DOM generation, implemented "assignments" method from ras.
128: *
129: * Revision 1.7 2001/12/18 15:35:11 lipp
130: * Implemented workItems and isMemberOfWorkItem.
131: *
132: * Revision 1.6 2001/12/17 15:52:12 lipp
133: * New version.
134: *
135: * Revision 1.5 2001/12/17 12:14:04 lipp
136: * Adapted to configurable ResourceManagement/AssignmentServices.
137: *
138: * Revision 1.4 2001/12/16 21:48:57 lipp
139: * addAssignment implemented.
140: *
141: * Revision 1.3 2001/12/16 10:37:35 lipp
142: * Assignment service implemented.
143: *
144: * Revision 1.2 2001/12/15 18:04:28 lipp
145: * Fixed client class packing.
146: *
147: * Revision 1.1 2001/12/15 15:52:01 lipp
148: * Implementation of ActivityFinder completed.
149: *
150: */
151: package ras;
152:
153: import java.io.BufferedReader;
154: import java.io.InputStream;
155: import java.io.InputStreamReader;
156:
157: import java.util.Collection;
158: import java.util.Iterator;
159:
160: import javax.security.auth.login.LoginException;
161:
162: import de.danet.an.util.EJBUtil;
163: import de.danet.an.util.junit.EJBClientTest;
164:
165: import de.danet.an.workflow.omgcore.WfAssignment;
166: import de.danet.an.workflow.omgcore.WfAssignmentAuditEvent;
167: import de.danet.an.workflow.omgcore.WfAuditEvent;
168: import de.danet.an.workflow.omgcore.WfExecutionObject.State;
169: import de.danet.an.workflow.omgcore.WfProcess;
170: import de.danet.an.workflow.omgcore.WfProcessMgr;
171: import de.danet.an.workflow.omgcore.WfResource;
172:
173: import de.danet.an.workflow.api.Activity;
174: import de.danet.an.workflow.api.DefaultRequester;
175: import de.danet.an.workflow.api.FactoryConfigurationError;
176: import de.danet.an.workflow.api.ProcessDefinitionDirectory;
177: import de.danet.an.workflow.api.WorkflowService;
178: import de.danet.an.workflow.api.WorkflowServiceFactory;
179:
180: import de.danet.an.workflow.apix.ExtActivity;
181: import de.danet.an.workflow.ejbs.WorkflowEngine;
182: import de.danet.an.workflow.ejbs.WorkflowEngineHome;
183: import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
184: import de.danet.an.workflow.spis.ras.ActivityFinder;
185: import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
186: import de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory;
187: import de.danet.an.workflow.spis.rms.ResourceManagementService;
188: import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;
189:
190: import common.UTLoginContext;
191: import junit.framework.Test;
192: import junit.framework.TestCase;
193: import junit.framework.TestSuite;
194:
195: /**
196: * Zusammenstellung aller RasObjectTests.
197: */
198: public class Basic extends TestCase {
199: private static UTLoginContext plc = null;
200: static {
201: try {
202: plc = new UTLoginContext();
203: plc.login();
204: } catch (LoginException e) {
205: throw new IllegalStateException(e.getMessage());
206: }
207: }
208:
209: /**
210: * Konstruktor zum Erzeugen eines TestCase
211: */
212: public Basic(String name) {
213: super (name);
214: }
215:
216: /**
217: * Stellt diese TestSuite zusammen.
218: */
219: public static Test suite() {
220: TestSuite suite = new TestSuite();
221: suite.addTest(new Basic("getAFinder"));
222: suite.addTest(new Basic("changeAssignment"));
223: suite.addTest(new Basic("removeAssignment"));
224: return new EJBClientTest(plc, suite);
225: }
226:
227: private static WorkflowService wfsCache = null;
228:
229: private WorkflowService workflowService() {
230: if (wfsCache == null) {
231: try {
232: WorkflowServiceFactory wfsf = WorkflowServiceFactory
233: .newInstance();
234: wfsCache = wfsf.newWorkflowService();
235: } catch (FactoryConfigurationError e) {
236: throw new IllegalStateException(e.getMessage());
237: }
238: }
239: return wfsCache;
240: }
241:
242: private static WfProcess testProc = null;
243:
244: /**
245: * "Simply" try to get a finder.
246: */
247: public void getAFinder() throws Exception {
248: importProcessDefinition();
249: // To get a finder, we need a process.
250: testProc = createProcess("ut-ras", "ras_test");
251: testProc.start();
252: while (testProc.workflowState() != State.OPEN) {
253: Thread.sleep(100);
254: }
255: assertTrue(testProc != null);
256: Collection acts = testProc.steps();
257: assertTrue(acts.size() > 0);
258: Iterator i = acts.iterator();
259: ExtActivity act = (ExtActivity) i.next();
260: assertTrue(act != null);
261: // ActivityFinder af = act.activityFinder();
262: // Activity restored = (Activity)af.find(act.key());
263: // assertTrue (act.key().equals(restored.key()));
264: }
265:
266: private static ResourceAssignmentService ras = null;
267:
268: /**
269: * Change an assignment
270: */
271: public void changeAssignment() throws Exception {
272: // find predefined resource "Test, JUnit" and "Lipp, Michael"
273: WfResource resOP = null;
274: WfResource resMLipp = null;
275: Collection resList = workflowService().knownResources();
276: for (Iterator i = resList.iterator(); i.hasNext();) {
277: WfResource resource = (WfResource) i.next();
278: if (resource.resourceName().equals("ML")) {
279: resMLipp = resource;
280: }
281: if (resource.resourceName().equals("Order Processing")) {
282: resOP = resource;
283: }
284: }
285: assertTrue(resOP != null);
286: assertTrue(resMLipp != null);
287: // get current number of work items
288: ExtActivity act = null;
289: for (Iterator i = testProc.steps().iterator(); i.hasNext();) {
290: act = (ExtActivity) i.next();
291: if (act.name().equals("RAS Test A1")) {
292: break;
293: }
294: }
295: assertTrue(act.name().equals("RAS Test A1"));
296: // assign
297: Collection assmnts = act.assignments();
298: WfAssignment amnt = (WfAssignment) assmnts.iterator().next();
299: assertTrue(resMLipp.resourceKey(), amnt.assignee()
300: .resourceKey().equals(resMLipp.resourceKey()));
301: amnt.setAssignee(resOP);
302: assertTrue(amnt.assignee().resourceKey().equals(
303: resOP.resourceKey()));
304: // re-get assignment to make sure
305: assmnts = act.assignments();
306: assertTrue(assmnts.size() == 1);
307: Iterator i = assmnts.iterator();
308: WfAssignment assmnt = (WfAssignment) i.next();
309: assertTrue(assmnt.assignee().resourceKey().equals(
310: resOP.resourceKey()));
311: }
312:
313: /**
314: * Remove an assignment
315: */
316: public void removeAssignment() throws Exception {
317: // get current number of work items
318: ExtActivity act = null;
319: for (Iterator i = testProc.steps().iterator(); i.hasNext();) {
320: act = (ExtActivity) i.next();
321: if (act.name().equals("RAS Test A1")) {
322: break;
323: }
324: }
325: assertTrue(act.name().equals("RAS Test A1"));
326: // release
327: Collection assmnts = act.assignments();
328: WfAssignment amnt = (WfAssignment) assmnts.iterator().next();
329: amnt.assignee().release(amnt, "");
330: assmnts = act.assignments();
331: assertTrue(assmnts.size() == 0);
332: // check events
333: Thread.sleep(500);
334: boolean noneToJ = false;
335: boolean jToM = false;
336: boolean mToNone = false;
337: for (Iterator i = act.history().iterator(); i.hasNext();) {
338: WfAuditEvent evt = (WfAuditEvent) i.next();
339: if (evt instanceof WfAssignmentAuditEvent) {
340: WfAssignmentAuditEvent ae = (WfAssignmentAuditEvent) evt;
341: if (ae.oldResourceName() == null
342: && ae.newResourceName().equals("ML")
343: && !noneToJ) {
344: noneToJ = true;
345: } else if (ae.oldResourceName().equals("ML")
346: && ae.newResourceName().equals(
347: "Order Processing") && !jToM) {
348: jToM = true;
349: } else if (ae.oldResourceName().equals(
350: "Order Processing")
351: && ae.newResourceName() == null && !mToNone) {
352: mToNone = true;
353: } else {
354: assertTrue(false);
355: }
356: }
357: }
358: assertTrue(noneToJ);
359: assertTrue(jToM);
360: assertTrue(mToNone);
361: }
362:
363: /**
364: * Uploading the XPDL file and saving the process definitions in the
365: * database.
366: */
367: private void importProcessDefinition() throws Exception {
368: // now read input
369: InputStream is = getClass().getResourceAsStream(
370: "/ras/rasTestXPDL.xml");
371: if (is == null) {
372: return;
373: }
374: BufferedReader br = null;
375: br = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
376:
377: StringBuffer toParse = new StringBuffer();
378: String st;
379: while ((st = br.readLine()) != null) {
380: toParse.append(st + "\n");
381: }
382:
383: ProcessDefinitionDirectory pdd = workflowService()
384: .processDefinitionDirectory();
385: if (!pdd.processDefinitionExists("ut-ras", "ras_test")) {
386: pdd.importProcessDefinitions(toParse.toString());
387: }
388: }
389:
390: /**
391: * Try to create the process identified by the id
392: */
393: public WfProcess createProcess(String pkgId, String prcId)
394: throws Exception {
395: ProcessDefinitionDirectory pdd = null;
396: try {
397: pdd = workflowService().processDefinitionDirectory();
398: WfProcessMgr pmgr = pdd.processMgr(pkgId, prcId);
399: return pmgr.createProcess(new DefaultRequester(
400: workflowService()));
401: } finally {
402: workflowService().release(pdd);
403: }
404: }
405:
406: }
|