Source Code Cross Referenced for Create.java in  » Workflow-Engines » wfmopen-2.1.1 » procdef » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » wfmopen 2.1.1 » procdef 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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: Create.java,v 1.3 2007/03/27 21:59:42 mlipp Exp $
021:         *
022:         * $Log: Create.java,v $
023:         * Revision 1.3  2007/03/27 21:59:42  mlipp
024:         * Fixed lots of checkstyle warnings.
025:         *
026:         * Revision 1.2  2006/09/29 12:32:09  drmlipp
027:         * Consistently using WfMOpen as projct name now.
028:         *
029:         * Revision 1.1.1.2  2003/12/19 13:01:45  drmlipp
030:         * Updated to 1.1rc1
031:         *
032:         * Revision 1.14  2003/10/27 15:32:05  huaiyang
033:         * use wrappedProcess/Activity.
034:         *
035:         * Revision 1.13  2003/10/21 21:00:45  lipp
036:         * Moved EJBClientTest to new junit sub-package.
037:         *
038:         * Revision 1.12  2003/10/08 12:39:40  huaiyang
039:         * make test weblogic compatible.
040:         *
041:         * Revision 1.11  2003/06/27 09:44:03  lipp
042:         * Fixed copyright/license information.
043:         *
044:         * Revision 1.10  2003/06/02 15:25:19  lipp
045:         * Activated IPR38 check.
046:         *
047:         * Revision 1.9  2003/05/31 18:29:59  lipp
048:         * Fixed test case.
049:         *
050:         * Revision 1.8  2003/05/22 11:39:57  lipp
051:         * Fixed test case.
052:         *
053:         * Revision 1.7  2003/05/14 12:02:26  schlue
054:         * Import of process descriptions changed due to modified import behaviour.
055:         *
056:         * Revision 1.6  2003/05/14 09:30:27  schlue
057:         * Package names for minimal and full changed due to modified import behaviour.
058:         *
059:         * Revision 1.5  2003/05/07 09:55:21  schlue
060:         * Redefinable header with version info added.
061:         *
062:         * Revision 1.4  2003/04/26 16:12:22  lipp
063:         * Moved some classes to reduce package dependencies.
064:         *
065:         * Revision 1.3  2003/04/16 14:06:26  schlue
066:         * Some renames.
067:         *
068:         * Revision 1.2  2003/04/15 14:17:22  schlue
069:         * Cleanup added.
070:         *
071:         * Revision 1.1  2003/04/15 12:57:25  schlue
072:         * Static tests of process and activity (definitions) moved to directory process.
073:         * More test cases for block activities added.
074:         *
075:         * Revision 1.3  2003/04/11 14:39:56  schlue
076:         * System tests for activitites added.
077:         *
078:         * Revision 1.2  2003/04/10 09:44:08  schlue
079:         * Test cases for process data added.
080:         *
081:         * Revision 1.1  2003/03/21 10:00:59  schlue
082:         * Initial version.
083:         *
084:         *
085:         *
086:         */
087:        package procdef;
088:
089:        import java.io.BufferedReader;
090:        import java.io.InputStream;
091:        import java.io.InputStreamReader;
092:
093:        import java.util.ArrayList;
094:        import java.util.Collection;
095:        import java.util.HashSet;
096:        import java.util.Iterator;
097:        import java.util.LinkedList;
098:        import java.util.List;
099:        import java.util.Set;
100:
101:        import java.rmi.RemoteException;
102:
103:        import de.danet.an.workflow.omgcore.InvalidPriorityException;
104:        import de.danet.an.workflow.omgcore.NotEnabledException;
105:        import de.danet.an.workflow.omgcore.WfExecutionObject;
106:        import de.danet.an.workflow.omgcore.WfProcess;
107:        import de.danet.an.workflow.omgcore.WfProcessMgr;
108:        import de.danet.an.workflow.omgcore.WfRequester;
109:
110:        import de.danet.an.util.junit.EJBClientTest;
111:        import de.danet.an.workflow.api.Activity;
112:        import de.danet.an.workflow.api.DefaultRequester;
113:        import de.danet.an.workflow.api.ImportException;
114:        import de.danet.an.workflow.api.InvalidKeyException;
115:        import de.danet.an.workflow.api.PrioritizedMessage;
116:        import de.danet.an.workflow.api.Process;
117:        import de.danet.an.workflow.api.ProcessDefinitionDirectory;
118:        import de.danet.an.workflow.api.ProcessDirectory;
119:        import de.danet.an.workflow.api.ProcessMgr;
120:        import de.danet.an.workflow.api.WorkflowService;
121:        import de.danet.an.workflow.api.WorkflowServiceFactory;
122:
123:        import junit.framework.Test;
124:        import junit.framework.TestSuite;
125:        import process.WfMOpenTestCase;
126:        import process.EventWatch;
127:        import common.WrappedProcess;
128:        import common.WrappedActivity;
129:        import common.WrappedProcessDefinitionDirectory;
130:
131:        /**
132:         * Test creation of processes.
133:         * After completion, all previously imported process descriptions
134:         * and created processes are cleared.
135:         * @author <a href="mailto:schlueter@danet.de">Holger Schlueter</a>
136:         * @version 1.0
137:         */
138:        public class Create extends WfMOpenTestCase {
139:
140:            private static Collection createdProcs = new ArrayList();
141:
142:            /**
143:             * Access to process definition directory (singleton)
144:             */
145:            private WrappedProcessDefinitionDirectory defDir = null;
146:
147:            /**
148:             * Access to process directory (singleton)
149:             */
150:            private ProcessDirectory procDir = null;
151:
152:            /**
153:             * Access to default requester (singleton)
154:             */
155:            private WfRequester requester = null;
156:
157:            /**
158:             * Constructor of this TestCase
159:             * @param name a <code>String</code> value
160:             */
161:            public Create(String name) {
162:                super (name);
163:            }
164:
165:            /**
166:             * Construct this test suite.
167:             * @return a <code>Test</code> value
168:             */
169:            public static Test suite() {
170:                TestSuite suite = new TestSuite();
171:                suite.addTest(new Create("testEnabled"));
172:                suite.addTest(new Create("createMinimal"));
173:                suite.addTest(new Create("testProcAttributes"));
174:                suite.addTest(new Create("testActivities"));
175:                suite.addTest(new Create("testActivitiesBlock1"));
176:                suite.addTest(new Create("testActivitiesBlock2"));
177:                suite.addTest(new Create("removeProcesses"));
178:                suite.addTest(new Create("cleanup"));
179:                suite.addTest(new Create("testActivitiesBlock2"));
180:                suite.addTest(new Create("removeProcesses"));
181:                return new EJBClientTest(plc, suite);
182:            }
183:
184:            /**
185:             * Test enable flag on creation of a process.
186:             * @exception Exception if an error occurs
187:             */
188:            public void testEnabled() throws Exception {
189:                boolean gotException = false;
190:                // test default setting
191:                assertTrue(defDir.isEnabled("SystemTest_minimal", "minimal"));
192:                defDir.setEnabled("SystemTest_minimal", "minimal", false);
193:                ProcessMgr mgr = defDir.processMgr("SystemTest_minimal",
194:                        "minimal");
195:                int noprocs = mgr.processes().size();
196:                //WfProcess proc = null;
197:                WrappedProcess proc = null;
198:                // Make sure that default is "disabled"
199:                assertTrue(mgr.processMgrState() == WfProcessMgr.DISABLED);
200:                // Test that process creation is not possible
201:                try {
202:                    //proc = mgr.createProcess(requester);
203:                    proc = new WrappedProcess(mgr.createProcess(requester));
204:                } catch (NotEnabledException exc) {
205:                    gotException = true;
206:                }
207:                assertTrue(gotException);
208:                // Enable now and make sure that process can be created
209:                mgr.setProcessMgrState(WfProcessMgr.ENABLED);
210:                assertTrue(mgr.processes().size() == noprocs);
211:                proc = new WrappedProcess(mgr.createProcess(requester));
212:                createdProcs.add(proc);
213:                assertTrue(mgr.processes().size() == noprocs + 1);
214:            }
215:
216:            /**
217:             * Test creation of a process with minimal process definition. 
218:             * @exception Exception if an error occurs
219:             */
220:            public void createMinimal() throws Exception {
221:                boolean gotException = false;
222:                // Try invald packageId
223:                try {
224:                    defDir.processMgr("Systemtest", "minimal");
225:                } catch (InvalidKeyException exc) {
226:                    gotException = true;
227:                }
228:                assertTrue(gotException);
229:                // Try invald processId
230:                gotException = false;
231:                try {
232:                    defDir.processMgr("SystemTest_minimal", "Minimal");
233:                } catch (InvalidKeyException exc) {
234:                    gotException = true;
235:                }
236:                assertTrue(gotException);
237:                // Try correct identifier
238:                ProcessMgr mgr = defDir.processMgr("SystemTest_minimal",
239:                        "minimal");
240:                int noprocs = mgr.processes().size();
241:                //WfProcess proc = mgr.createProcess(requester);
242:                WrappedProcess proc = new WrappedProcess(mgr
243:                        .createProcess(requester));
244:                assertTrue(mgr.processes().size() == noprocs + 1);
245:                createdProcs.add(proc);
246:            }
247:
248:            /**
249:             * Test removal of all previously created processes.
250:             * @exception Exception if an error occurs
251:             */
252:            public void removeProcesses() throws Exception {
253:                int noprocs = procDir.processes().size();
254:                Iterator procs = createdProcs.iterator();
255:                while (procs.hasNext()) {
256:                    //WfProcess proc = (Process)procs.next();
257:                    WrappedProcess proc = (WrappedProcess) procs.next();
258:                    procDir.removeProcess(proc.getWfProcess());
259:                }
260:                assertTrue(procDir.processes().size() == noprocs
261:                        - createdProcs.size());
262:                createdProcs.clear();
263:            }
264:
265:            /**
266:             * Remove all imported process definitions.
267:             * @exception Exception if an error occurs
268:             */
269:            public void cleanup() throws Exception {
270:                defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
271:                boolean procdefRemoved = false;
272:                try {
273:                    defDir.processMgr("SystemTest_minimal", "minimal");
274:                } catch (InvalidKeyException exc) {
275:                    procdefRemoved = true;
276:                }
277:                assertTrue(procdefRemoved);
278:                defDir.removeProcessDefinition("SystemTest_full", "full");
279:                procdefRemoved = false;
280:                try {
281:                    defDir.processMgr("SystemTest_full", "full");
282:                } catch (InvalidKeyException exc) {
283:                    procdefRemoved = true;
284:                }
285:                assertTrue(procdefRemoved);
286:                defDir.removeProcessDefinition("SystemTest", "block_diamond");
287:                procdefRemoved = false;
288:                try {
289:                    defDir.processMgr("SystemTest", "block_diamond");
290:                } catch (InvalidKeyException exc) {
291:                    procdefRemoved = true;
292:                }
293:                assertTrue(procdefRemoved);
294:                defDir
295:                        .removeProcessDefinition("SystemTest",
296:                                "block_2_in_2_out");
297:                procdefRemoved = false;
298:                try {
299:                    defDir.processMgr("SystemTest", "block_2_in_2_out");
300:                } catch (InvalidKeyException exc) {
301:                    procdefRemoved = true;
302:                }
303:                assertTrue(procdefRemoved);
304:            }
305:
306:            /**
307:             * Test all accessible attributes of process manager and process
308:             * (except process data and process context information).
309:             * @exception Exception if an error occurs
310:             */
311:            public void testProcAttributes() throws Exception {
312:                ProcessMgr mgrMin = defDir.processMgr("SystemTest_minimal",
313:                        "minimal");
314:                ProcessMgr mgrFull = defDir.processMgr("SystemTest_full",
315:                        "full");
316:
317:                // Test attributes of process manager
318:                assertTrue(mgrMin.category() == null);
319:                assertTrue(mgrMin.description() == null);
320:                assertTrue(mgrMin.version() == null);
321:                assertTrue(mgrMin.name().equals("SystemTest_minimal/minimal"));
322:                assertTrue(mgrFull.category().equals("System Test (procdef)"));
323:                assertTrue(mgrFull.description().equals(
324:                        "Description for test of all accessible attributes"));
325:
326:                assertTrue(mgrFull.version().equals("beta 1"));
327:                assertTrue(mgrFull.name().equals("SystemTest_full/full"));
328:
329:                // 	WfProcess proc1 = mgrMin.createProcess(requester);
330:                // 	WfProcess proc2 = mgrFull.createProcess(requester);
331:                // 	WfProcess proc3 = mgrFull.createProcess(requester);
332:                WrappedProcess proc1 = new WrappedProcess(mgrMin
333:                        .createProcess(requester));
334:                WrappedProcess proc2 = new WrappedProcess(mgrFull
335:                        .createProcess(requester));
336:                WrappedProcess proc3 = new WrappedProcess(mgrFull
337:                        .createProcess(requester));
338:                // Test attributes of processes without existing process definition
339:                defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
340:                defDir.removeProcessDefinition("SystemTest_full", "full");
341:                boolean procdefRemoved = false;
342:                try {
343:                    mgrMin = defDir.processMgr("SystemTest_minimal", "minimal");
344:                } catch (InvalidKeyException exc) {
345:                    procdefRemoved = true;
346:                }
347:                assertTrue(procdefRemoved);
348:                procdefRemoved = false;
349:                try {
350:                    mgrFull = defDir.processMgr("SystemTest_full", "full");
351:                } catch (InvalidKeyException exc) {
352:                    procdefRemoved = true;
353:                }
354:                assertTrue(procdefRemoved);
355:
356:                assertTrue(proc1.name() == null);
357:                proc1.setName("minimal Process");
358:                assertTrue(proc2.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
359:                assertTrue(proc3.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
360:                proc2.setName(null);
361:                assertTrue(proc1.name().equals("minimal Process"));
362:                assertTrue(proc2.name() == null);
363:                assertTrue(proc3.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
364:                assertTrue(!proc2.key().equals(proc3.key()));
365:                assertTrue(proc1.description() == null);
366:                assertTrue(proc2.description().equals(
367:                        "Description for test of all accessible attributes"));
368:                assertTrue(proc3.description().equals(
369:                        "Description for test of all accessible attributes"));
370:                proc3.setDescription("full");
371:                assertTrue(proc2.description().equals(
372:                        "Description for test of all accessible attributes"));
373:                assertTrue(proc3.description().equals("full"));
374:                assertTrue(proc1.priority() == 3); // default priority
375:                assertTrue(proc2.priority() == 5);
376:                boolean gotException = false;
377:                try {
378:                    proc1.setPriority(0);
379:                } catch (InvalidPriorityException exc) {
380:                    gotException = true;
381:                }
382:                assertTrue(gotException);
383:                proc1.setPriority(1);
384:                gotException = false;
385:                try {
386:                    proc2.setPriority(6);
387:                } catch (InvalidPriorityException exc) {
388:                    gotException = true;
389:                }
390:                assertTrue(gotException);
391:                proc2.setPriority(4);
392:                assertTrue(proc1.priority() == 1);
393:                assertTrue(proc2.priority() == 4);
394:
395:                /* Make sure that process attributes are no longer
396:                   accessible after removal of process */
397:                procDir.removeProcess(proc1.getWfProcess());
398:                procDir.removeProcess(proc2.getWfProcess());
399:                procDir.removeProcess(proc3.getWfProcess());
400:                boolean processNotAccessible = false;
401:                try {
402:                    int dummy = proc1.priority();
403:                } catch (RemoteException exc) {
404:                    processNotAccessible = true;
405:                }
406:                assertTrue(processNotAccessible);
407:            }
408:
409:            /**
410:             * Test activitiy information for minimal and full description.
411:             * @exception Exception if an error occurs
412:             */
413:            public void testActivities() throws Exception {
414:                ProcessMgr mgrMin = defDir.processMgr("SystemTest_minimal",
415:                        "minimal");
416:                ProcessMgr mgrFull = defDir.processMgr("SystemTest_full",
417:                        "full");
418:                // 	WfProcess proc1 = mgrMin.createProcess(requester);
419:                // 	WfProcess proc2 = mgrFull.createProcess(requester);
420:                // 	WfProcess proc3 = mgrFull.createProcess(requester);
421:                WrappedProcess proc1 = new WrappedProcess(mgrMin
422:                        .createProcess(requester));
423:                WrappedProcess proc2 = new WrappedProcess(mgrFull
424:                        .createProcess(requester));
425:                WrappedProcess proc3 = new WrappedProcess(mgrFull
426:                        .createProcess(requester));
427:
428:                // Test activity of process 1
429:                assertTrue(proc1.steps().size() == 1);
430:                WrappedActivity act = (WrappedActivity) proc1.steps().toArray()[0];
431:                assertTrue(act.assignments().size() == 0);
432:                assertTrue(act.name() == null);
433:                assertTrue(act.priority() == 3); // Default priority
434:                assertTrue(act.container().key().equals(proc1.key()));
435:                assertTrue(act.nextActivities().size() == 0);
436:
437:                // Test activities of processes 2 and 3
438:                assertTrue(proc2.steps().size() == 3);
439:                assertTrue(proc3.steps().size() == 3);
440:                Iterator it = proc2.steps().iterator();
441:                List acts = new LinkedList();
442:                while (it.hasNext()) {
443:                    act = (WrappedActivity) it.next();
444:                    acts.clear();
445:                    if (act.name().equals("ACT1")) {
446:                        assertTrue(act.priority() == 1);
447:                        assertTrue(act.description().equals(
448:                                "Activity with dummy implementation"));
449:                        assertTrue(act.assignments().size() == 0);
450:                        assertTrue(act.container().equals(proc2));
451:                        assertTrue(act.nextActivities().size() == 1);
452:                        acts.add("SET1");
453:                        assertTrue(activitiesIncluded(act.nextActivities(),
454:                                acts));
455:                    } else if (act.name().equals("ACT2")) {
456:                        assertTrue(act.priority() == 2);
457:                        assertTrue(act.description() == null);
458:                        assertTrue(act.assignments().size() == 0);
459:                        assertTrue(act.nextActivities().size() == 1);
460:                        acts.add("SET1");
461:                        assertTrue(activitiesIncluded(act.nextActivities(),
462:                                acts));
463:                    } else if (act.name().equals("SET1")) {
464:                        assertTrue(act.priority() == 3); // default priority
465:                        assertTrue(act.description() == null);
466:                        assertTrue(act.assignments().size() == 0);
467:                        assertTrue(act.nextActivities().size() == 0);
468:                    } else {
469:                        assertTrue("Invalid activity " + act.name(), false);
470:                    }
471:                }
472:                it = proc3.steps().iterator();
473:                Set step3Keys = new HashSet();
474:                while (it.hasNext()) {
475:                    step3Keys.add(((WrappedActivity) it.next()).key());
476:                }
477:                it = proc3.activitiesInState("open.not_running.not_started")
478:                        .iterator();
479:                Set state3NSKeys = new HashSet();
480:                while (it.hasNext()) {
481:                    state3NSKeys.add(((WrappedActivity) it.next()).key());
482:                }
483:                it = proc3.activitiesInState("open.not_running.not_started")
484:                        .iterator();
485:                Set state3NRKeys = new HashSet();
486:                while (it.hasNext()) {
487:                    state3NRKeys.add(((WrappedActivity) it.next()).key());
488:                }
489:                it = proc2.activitiesInState("open.not_running").iterator();
490:                Set state2Keys = new HashSet();
491:                while (it.hasNext()) {
492:                    state2Keys.add(((WrappedActivity) it.next()).key());
493:                }
494:                // Make sure that all activities are in state 
495:                // "open.not_running.not_started" and differ between process
496:                // instances.
497:                assertTrue(step3Keys.equals(state3NSKeys));
498:                assertTrue(step3Keys.equals(state3NRKeys));
499:                assertTrue(!step3Keys.equals(state2Keys));
500:                assertTrue(proc3
501:                        .activitiesInState("open.not_running.suspended").size() == 0);
502:                assertTrue(proc3.steps().size() == proc3.activitiesInState(
503:                        "open").size());
504:                assertTrue(proc3.activitiesInState("closed").size() == 0);
505:
506:                assertTrue(proc1.workflowState() == WfExecutionObject.State.OPEN);
507:                assertTrue(proc2.workflowState() == WfExecutionObject.State.OPEN);
508:                assertTrue(proc3.workflowState() == WfExecutionObject.State.OPEN);
509:
510:                procDir.removeProcess(proc1.getWfProcess());
511:                procDir.removeProcess(proc2.getWfProcess());
512:                procDir.removeProcess(proc3.getWfProcess());
513:            }
514:
515:            /**
516:             * Test activitiy information for second block activity
517:             * @exception Exception if an error occurs
518:             */
519:            public void testActivitiesBlock1() throws Exception {
520:                ProcessMgr mgr = defDir.processMgr("SystemTest",
521:                        "block_2_in_2_out");
522:                //WfProcess proc = mgr.createProcess(requester);
523:                WrappedProcess proc = new WrappedProcess(mgr
524:                        .createProcess(requester));
525:
526:                // Test activities of process
527:                assertTrue(proc.steps().size() == 9);
528:                Iterator it = proc.steps().iterator();
529:                List acts = new LinkedList();
530:                while (it.hasNext()) {
531:                    WrappedActivity act = (WrappedActivity) it.next();
532:                    acts.clear();
533:                    if (act.name().equals("ACT1")) {
534:                        assertTrue(act.priority() == 1);
535:                        assertTrue(act.description().equals(
536:                                "Activity with dummy implementation"));
537:                        assertTrue(act.assignments().size() == 0);
538:                        assertTrue(act.container().key().equals(proc.key()));
539:                        assertTrue(act.nextActivities().size() == 2);
540:                        acts.add("B1");
541:                        acts.add("B2");
542:                        assertTrue(activitiesIncluded(act.nextActivities(),
543:                                acts));
544:                    } else if (act.name().equals("ACT2")) {
545:                        assertTrue(act.priority() == 2);
546:                        assertTrue(act.description() == null);
547:                        assertTrue(act.assignments().size() == 0);
548:                        assertTrue(act.nextActivities().size() == 2);
549:                        acts.add("B1");
550:                        acts.add("B2");
551:                        assertTrue(activitiesIncluded(act.nextActivities(),
552:                                acts));
553:                    } else if (act.name().equals("ACT3")) {
554:                        assertTrue(act.priority() == 3);
555:                        assertTrue(act.description() == null);
556:                        assertTrue(act.assignments().size() == 0);
557:                        assertTrue(act.nextActivities().size() == 0);
558:                    } else if (act.name().equals("ACT4")) {
559:                        assertTrue(act.priority() == 4);
560:                        assertTrue(act.description() == null);
561:                        assertTrue(act.assignments().size() == 0);
562:                        assertTrue(act.nextActivities().size() == 0);
563:                    } else if (act.name().equals("B0")) {
564:                        assertTrue(act.priority() == 3); // default priority
565:                        assertTrue(act.description() == null);
566:                        assertTrue(act.assignments().size() == 0);
567:                        assertTrue(act.nextActivities().size() == 2);
568:                        acts.add("B3");
569:                        acts.add("B4");
570:                        assertTrue(activitiesIncluded(act.nextActivities(),
571:                                acts));
572:                    } else if (act.name().equals("B1")) {
573:                        assertTrue(act.priority() == 3); // default priority
574:                        assertTrue(act.description() == null);
575:                        assertTrue(act.assignments().size() == 0);
576:                        assertTrue(act.nextActivities().size() == 1);
577:                        acts.add("B0");
578:                        assertTrue(activitiesIncluded(act.nextActivities(),
579:                                acts));
580:                    } else if (act.name().equals("B2")) {
581:                        assertTrue(act.priority() == 3); // default priority
582:                        assertTrue(act.description() == null);
583:                        assertTrue(act.assignments().size() == 0);
584:                        assertTrue(act.nextActivities().size() == 1);
585:                        acts.add("B0");
586:                        assertTrue(activitiesIncluded(act.nextActivities(),
587:                                acts));
588:                    } else if (act.name().equals("B3")) {
589:                        assertTrue(act.priority() == 5);
590:                        assertTrue(act.description() == null);
591:                        assertTrue(act.assignments().size() == 0);
592:                        assertTrue(act.nextActivities().size() == 2);
593:                        acts.add("ACT3");
594:                        acts.add("ACT4");
595:                        assertTrue(activitiesIncluded(act.nextActivities(),
596:                                acts));
597:                    } else if (act.name().equals("B4")) {
598:                        assertTrue(act.priority() == 3); // default priority
599:                        assertTrue(act.description() == null);
600:                        assertTrue(act.assignments().size() == 0);
601:                        assertTrue(act.nextActivities().size() == 2);
602:                        acts.add("ACT3");
603:                        acts.add("ACT4");
604:                        assertTrue(activitiesIncluded(act.nextActivities(),
605:                                acts));
606:                    } else {
607:                        assertTrue("Invalid activity " + act.name(), false);
608:                    }
609:                }
610:                procDir.removeProcess(proc.getWfProcess());
611:            }
612:
613:            /**
614:             * Test activitiy information for second block activity
615:             * @exception Exception if an error occurs
616:             */
617:            public void testActivitiesBlock2() throws Exception {
618:                ProcessMgr mgr = defDir.processMgr("SystemTest",
619:                        "block_diamond");
620:                //	WfProcess proc = mgr.createProcess(requester);
621:                WrappedProcess proc = new WrappedProcess(mgr
622:                        .createProcess(requester));
623:                // Test activities of process
624:                assertTrue(proc.steps().size() == 15);
625:                Iterator it = proc.steps().iterator();
626:                List acts = new LinkedList();
627:                while (it.hasNext()) {
628:                    WrappedActivity act = (WrappedActivity) it.next();
629:                    acts.clear();
630:                    if (act.name().equals("S1A1")) {
631:                        assertTrue(act.nextActivities().size() == 2);
632:                        acts.add("S1A3");
633:                        acts.add("S1A4");
634:                        assertTrue(activitiesIncluded(act.nextActivities(),
635:                                acts));
636:                    } else if (act.name().equals("S1A2")) {
637:                        assertTrue(act.nextActivities().size() == 2);
638:                        acts.add("S1A3");
639:                        acts.add("S1A4");
640:                        assertTrue(activitiesIncluded(act.nextActivities(),
641:                                acts));
642:                    } else if (act.name().equals("S1A3")) {
643:                        assertTrue(act.nextActivities().size() == 3);
644:                        acts.add("S2A1");
645:                        acts.add("S3A1");
646:                        acts.add("S3A2");
647:                        assertTrue(activitiesIncluded(act.nextActivities(),
648:                                acts));
649:                    } else if (act.name().equals("S1A4")) {
650:                        assertTrue(act.nextActivities().size() == 3);
651:                        acts.add("S2A1");
652:                        acts.add("S3A1");
653:                        acts.add("S3A2");
654:                        assertTrue(activitiesIncluded(act.nextActivities(),
655:                                acts));
656:                    } else if (act.name().equals("S2A1")) {
657:                        assertTrue(act.nextActivities().size() == 3);
658:                        acts.add("S2A2");
659:                        acts.add("S2A3");
660:                        acts.add("S2A4");
661:                        assertTrue(activitiesIncluded(act.nextActivities(),
662:                                acts));
663:                    } else if (act.name().equals("S2A2")) {
664:                        assertTrue(act.nextActivities().size() == 3);
665:                        acts.add("S4A1");
666:                        acts.add("S4A2");
667:                        acts.add("S4A3");
668:                        assertTrue(activitiesIncluded(act.nextActivities(),
669:                                acts));
670:                    } else if (act.name().equals("S2A3")) {
671:                        assertTrue(act.nextActivities().size() == 3);
672:                        acts.add("S4A1");
673:                        acts.add("S4A2");
674:                        acts.add("S4A3");
675:                        assertTrue(activitiesIncluded(act.nextActivities(),
676:                                acts));
677:                    } else if (act.name().equals("S2A4")) {
678:                        assertTrue(act.nextActivities().size() == 3);
679:                        acts.add("S4A1");
680:                        acts.add("S4A2");
681:                        acts.add("S4A3");
682:                        assertTrue(activitiesIncluded(act.nextActivities(),
683:                                acts));
684:                    } else if (act.name().equals("S3A1")) {
685:                        assertTrue(act.nextActivities().size() == 1);
686:                        acts.add("S3A3");
687:                        assertTrue(activitiesIncluded(act.nextActivities(),
688:                                acts));
689:                    } else if (act.name().equals("S3A2")) {
690:                        assertTrue(act.nextActivities().size() == 1);
691:                        acts.add("S3A3");
692:                        assertTrue(activitiesIncluded(act.nextActivities(),
693:                                acts));
694:                    } else if (act.name().equals("S3A3")) {
695:                        assertTrue(act.nextActivities().size() == 3);
696:                        acts.add("S4A1");
697:                        acts.add("S4A2");
698:                        acts.add("S4A3");
699:                        assertTrue(activitiesIncluded(act.nextActivities(),
700:                                acts));
701:                    } else if (act.name().equals("S4A1")) {
702:                        assertTrue(act.nextActivities().size() == 1);
703:                        acts.add("S4A4");
704:                        assertTrue(activitiesIncluded(act.nextActivities(),
705:                                acts));
706:                    } else if (act.name().equals("S4A2")) {
707:                        assertTrue(act.nextActivities().size() == 1);
708:                        acts.add("S4A4");
709:                        assertTrue(activitiesIncluded(act.nextActivities(),
710:                                acts));
711:                    } else if (act.name().equals("S4A3")) {
712:                        assertTrue(act.nextActivities().size() == 1);
713:                        acts.add("S4A4");
714:                        assertTrue(activitiesIncluded(act.nextActivities(),
715:                                acts));
716:                    } else if (act.name().equals("S4A4")) {
717:                        assertTrue(act.nextActivities().size() == 0);
718:                    } else {
719:                        assertTrue("Invalid activity " + act.name(), false);
720:                    }
721:                }
722:                procDir.removeProcess(proc.getWfProcess());
723:            }
724:
725:            /**
726:             * Initialisation.
727:             * The <code>setUp</code> method defines the way a state change is 
728:             * realized. Override this method to change this way.
729:             * @exception Exception if an error occurs
730:             */
731:            protected void setUp() throws Exception {
732:                super .setUp();
733:                WorkflowService wfs = WorkflowServiceFactory.newInstance()
734:                        .newWorkflowService();
735:                try {
736:                    defDir = new WrappedProcessDefinitionDirectory(wfs
737:                            .processDefinitionDirectory());
738:                } catch (RemoteException exc) {
739:                    System.err
740:                            .println("Process definition directory not accessible: "
741:                                    + exc.getMessage());
742:                    System.exit(-1);
743:                }
744:
745:                // Read process definitions
746:                importProcessDefinition("/procdef/full.xml");
747:                importProcessDefinition("/procdef/minimal.xml");
748:                importProcessDefinition("/procdef/blockActivities.xml");
749:                procDir = wfs.processDirectory();
750:                requester = new DefaultRequester(wfs);
751:            }
752:
753:            private static boolean activitiesIncluded(List activities,
754:                    List names) throws Exception {
755:                List acts = new LinkedList();
756:                Iterator it = activities.iterator();
757:                while (it.hasNext()) {
758:                    acts.add(((WrappedActivity) it.next()).name());
759:                }
760:                return acts.containsAll(names) && (acts.size() == names.size());
761:            }
762:
763:            private void importProcessDefinition(String name) throws Exception {
764:                StringBuffer processDefinition = new StringBuffer();
765:                InputStream is = getClass().getResourceAsStream(name);
766:                BufferedReader in = new BufferedReader(new InputStreamReader(
767:                        is, "ISO-8859-1"));
768:                String line = null;
769:                while ((line = in.readLine()) != null) {
770:                    processDefinition.append(line + "\n");
771:                }
772:                try {
773:                    defDir.importProcessDefinitions(processDefinition
774:                            .toString());
775:                } catch (ImportException exc) {
776:                    Iterator msg = exc.messages().iterator();
777:                    while (msg.hasNext()) {
778:                        System.out.println(((PrioritizedMessage) msg.next())
779:                                .message());
780:                    }
781:                }
782:            }
783:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.