Source Code Cross Referenced for WorklistTest.java in  » Workflow-Engines » osbl-1_0 » org » concern » controller » 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 » osbl 1_0 » org.concern.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: WorklistTest.java 847 2007-02-08 20:03:35Z hengels $
003:         * (c) Copyright 2004 con:cern development team.
004:         *
005:         * This file is part of con:cern (http://concern.org).
006:         *
007:         * con:cern is free software; you can redistribute it and/or modify
008:         * it under the terms of the GNU Lesser General Public License
009:         * as published by the Free Software Foundation; either version 2.1
010:         * of the License, or (at your option) any later version.
011:         *
012:         * Please see COPYING for the complete licence.
013:         */
014:        package org.concern.controller;
015:
016:        import junit.framework.TestCase;
017:        import org.hibernate.*;
018:        import org.hibernate.cfg.Configuration;
019:        import org.concern.*;
020:
021:        import java.util.*;
022:        import java.sql.Timestamp;
023:
024:        /**
025:         * @author hengels
026:         * @version $Revision: 847 $
027:         */
028:        public class WorklistTest extends TestCase {
029:            private SessionFactory sessionFactory;
030:            private Worklist worklist;
031:
032:            public WorklistTest(String name) {
033:                super (name);
034:            }
035:
036:            protected void setUp() throws Exception {
037:                Configuration configuration = new Configuration();
038:                configuration
039:                        .setNamingStrategy(new org.concern.controller.Configuration.PrefixNamingStrategy(
040:                                "WT"));
041:                configuration.configure("/controller-hibernate.cfg.xml");
042:                configuration.addResource("Controller.hbm.xml");
043:                sessionFactory = configuration.buildSessionFactory();
044:
045:                worklist = new Worklist();
046:                worklist.setSessionFactory(sessionFactory);
047:
048:                Session session = sessionFactory.openSession();
049:                Transaction transaction = session.beginTransaction();
050:                Query query = session
051:                        .createQuery("FROM org.concern.controller.Subject subject");
052:                List list = query.list();
053:                for (Iterator iterator = list.iterator(); iterator.hasNext();) {
054:                    Subject subject = (Subject) iterator.next();
055:                    System.out.println("deleting subject = " + subject);
056:                    session.delete(subject);
057:                }
058:                transaction.commit();
059:                session.close();
060:            }
061:
062:            public void testWorklist() throws Exception {
063:                Subject subject1 = new Subject("subject1");
064:                subject1.setProcess("WorklistTest");
065:                subject1.setSubjectLines(new HashSet(Arrays
066:                        .asList(new SubjectLine[] {
067:                                new SubjectLine("de", "hallo1"),
068:                                new SubjectLine("en", "hello1"), })));
069:                Enlistment enlistment11 = new Enlistment("TIMEOUT", "robot",
070:                        System.currentTimeMillis() + 10000);
071:                enlistment11.setAssignments(Collections
072:                        .singleton(new Assignment("you")));
073:                subject1.getEnlistments().add(enlistment11);
074:                Enlistment enlistment12 = new Enlistment("TIMEOUT", "boss",
075:                        System.currentTimeMillis() + 10000);
076:                enlistment12.setAssignments(Collections
077:                        .singleton(new Assignment("me")));
078:                subject1.getEnlistments().add(enlistment12);
079:                Enlistment enlistment13 = new Enlistment("TIMEOUT", "kill",
080:                        Long.MAX_VALUE);
081:                enlistment13.setAssignments(Collections
082:                        .singleton(new Assignment("me")));
083:                subject1.getEnlistments().add(enlistment13);
084:                Enlistment enlistment14 = new Enlistment("TIMEOUT", "help",
085:                        Long.MAX_VALUE);
086:                enlistment14.setAssignments(Collections
087:                        .singleton(new Assignment("me")));
088:                subject1.getEnlistments().add(enlistment14);
089:
090:                Subject subject2 = new Subject("subject2");
091:                subject2.setProcess("WorklistTest");
092:                subject2.setSubjectLines(new HashSet(Arrays
093:                        .asList(new SubjectLine[] {
094:                                new SubjectLine("de", "hallo2"),
095:                                new SubjectLine("en", "hello2"), })));
096:                Enlistment enlistment21 = new Enlistment("TIMEOUT", "robot",
097:                        System.currentTimeMillis() + 10000);
098:                enlistment21.setAssignments(Collections
099:                        .singleton(new Assignment("you")));
100:                subject2.getEnlistments().add(enlistment21);
101:                Enlistment enlistment22 = new Enlistment("TIMEOUT", "boss",
102:                        System.currentTimeMillis() + 10000);
103:                enlistment22.setAssignments(Collections
104:                        .singleton(new Assignment("me")));
105:                subject2.getEnlistments().add(enlistment22);
106:                Enlistment enlistment23 = new Enlistment("TIMEOUT", "kill",
107:                        Long.MAX_VALUE);
108:                enlistment23.setAssignments(Collections
109:                        .singleton(new Assignment("me")));
110:                subject2.getEnlistments().add(enlistment23);
111:                Enlistment enlistment24 = new Enlistment("TIMEOUT", "help",
112:                        Long.MAX_VALUE);
113:                enlistment24.setAssignments(Collections
114:                        .singleton(new Assignment("me")));
115:                subject2.getEnlistments().add(enlistment24);
116:
117:                Subject subject3 = new Subject("subject3");
118:                subject3.setProcess("WorklistTest");
119:                subject3.setSubjectLines(new HashSet(Arrays
120:                        .asList(new SubjectLine[] {
121:                                new SubjectLine("de", "hallo3"),
122:                                new SubjectLine("en", "hello3"), })));
123:                Enlistment enlistment31 = new Enlistment("TIMEOUT", "robot",
124:                        System.currentTimeMillis() + 10000);
125:                enlistment31.setAssignments(Collections
126:                        .singleton(new Assignment("you")));
127:                subject3.getEnlistments().add(enlistment31);
128:                Enlistment enlistment32 = new Enlistment("TIMEOUT", "boss",
129:                        System.currentTimeMillis() + 10000);
130:                enlistment32.setAssignments(Collections
131:                        .singleton(new Assignment("me")));
132:                subject3.getEnlistments().add(enlistment32);
133:
134:                Session session = sessionFactory.openSession();
135:                Transaction transaction = session.beginTransaction();
136:                session.save(subject1);
137:                session.save(subject2);
138:                session.save(subject3);
139:                transaction.commit();
140:                session.close();
141:
142:                List list = worklist.listWork(new String[] { "me" }, "de", 10);
143:                printWork(list);
144:                assertEquals(3, list.size());
145:
146:                list = worklist.listWork(new String[] { "me" },
147:                        new String[] { "WorklistTest" },
148:                        new String[] { "boss" },
149:                        new String[] { "h", "+l", "-c" }, null, "en", 10);
150:                printWork(list);
151:                assertEquals(3, list.size());
152:
153:                list = worklist.listSubjects(new String[] { "me" }, null, null,
154:                        null, Controller.STATE_RUNNING, null, "en", 10);
155:                printSubject(list);
156:                assertEquals(3, list.size());
157:
158:                session = sessionFactory.openSession();
159:                transaction = session.beginTransaction();
160:                session.delete(subject1);
161:                session.delete(subject2);
162:                session.delete(subject3);
163:                transaction.commit();
164:                session.close();
165:            }
166:
167:            public void testArchive() throws Exception {
168:                ArchiveSubject subject1 = new ArchiveSubject("subject1");
169:                subject1.setProcess("WorklistTest");
170:                subject1.setSubjectLines(new HashSet(Arrays
171:                        .asList(new ArchiveSubjectLine[] {
172:                                new ArchiveSubjectLine("de", "hallo1"),
173:                                new ArchiveSubjectLine("en", "hello1"), })));
174:
175:                ArchiveSubject subject2 = new ArchiveSubject("subject2");
176:                subject2.setProcess("WorklistTest");
177:                subject2.setSubjectLines(new HashSet(Arrays
178:                        .asList(new ArchiveSubjectLine[] {
179:                                new ArchiveSubjectLine("de", "hallo2"),
180:                                new ArchiveSubjectLine("en", "hello2"), })));
181:
182:                Session session = sessionFactory.openSession();
183:                Transaction transaction = session.beginTransaction();
184:                session.save(subject1);
185:                session.save(subject2);
186:                transaction.commit();
187:                session.close();
188:
189:                List list = worklist.listArchivedSubjects(null, null, null,
190:                        null, "en", 10);
191:                printSubject(list);
192:                assertEquals(2, list.size());
193:
194:                session = sessionFactory.openSession();
195:                transaction = session.beginTransaction();
196:                session.delete(subject1);
197:                session.delete(subject2);
198:                transaction.commit();
199:                session.close();
200:            }
201:
202:            public void testLocking() throws Exception {
203:                Subject subject1 = new Subject("subject1");
204:                subject1.setProcess("WorklistTest");
205:                subject1.setSubjectLines(new HashSet(Arrays
206:                        .asList(new SubjectLine[] {
207:                                new SubjectLine("de", "hallo1"),
208:                                new SubjectLine("en", "hello1"), })));
209:                Enlistment enlistment11 = new Enlistment("TIMEOUT", "robot",
210:                        System.currentTimeMillis() + 10000);
211:                enlistment11.setAssignments(Collections
212:                        .singleton(new Assignment("you")));
213:                subject1.getEnlistments().add(enlistment11);
214:                Enlistment enlistment12 = new Enlistment("TIMEOUT", "boss",
215:                        System.currentTimeMillis() + 10000);
216:                enlistment12.setAssignments(Collections
217:                        .singleton(new Assignment("me")));
218:                subject1.getEnlistments().add(enlistment12);
219:                Enlistment enlistment13 = new Enlistment("TIMEOUT", "kill",
220:                        Long.MAX_VALUE);
221:                enlistment13.setAssignments(Collections
222:                        .singleton(new Assignment("me")));
223:                subject1.getEnlistments().add(enlistment13);
224:                Enlistment enlistment14 = new Enlistment("TIMEOUT", "help",
225:                        Long.MAX_VALUE);
226:                enlistment14.setAssignments(Collections
227:                        .singleton(new Assignment("me")));
228:                subject1.getEnlistments().add(enlistment14);
229:
230:                Timestamp until = new Timestamp(
231:                        System.currentTimeMillis() + 10000);
232:
233:                Session session = sessionFactory.openSession();
234:                Transaction transaction = session.beginTransaction();
235:                session.save(subject1);
236:                transaction.commit();
237:                session.close();
238:
239:                session = sessionFactory.openSession();
240:                transaction = session.beginTransaction();
241:                List list = worklist.listWork(new String[] { "me" },
242:                        new String[] { "WorklistTest" },
243:                        new String[] { "boss" },
244:                        new String[] { "h", "+l", "-c" }, null, "en", 10);
245:                assertEquals(1, list.size());
246:                Work work = (Work) list.get(0);
247:                assertNull(work.getLockedBy());
248:                assertNull(work.getLockedUntil());
249:                boolean locked = worklist.lock(work, "me", until);
250:                assertTrue(locked);
251:                transaction.commit();
252:                session.close();
253:
254:                session = sessionFactory.openSession();
255:                transaction = session.beginTransaction();
256:                list = worklist.listWork(new String[] { "me" },
257:                        new String[] { "WorklistTest" },
258:                        new String[] { "boss" },
259:                        new String[] { "h", "+l", "-c" }, null, "en", 10);
260:                assertEquals(1, list.size());
261:                work = (Work) list.get(0);
262:                locked = worklist.lock(work, "you", until);
263:                assertFalse(locked);
264:                assertEquals("me", work.getLockedBy());
265:                assertEquals(until, work.getLockedUntil());
266:                boolean unlocked = worklist.unlock(work, "me");
267:                assertTrue(unlocked);
268:                transaction.commit();
269:                session.close();
270:
271:                session = sessionFactory.openSession();
272:                transaction = session.beginTransaction();
273:                list = worklist.listWork(new String[] { "me" },
274:                        new String[] { "WorklistTest" },
275:                        new String[] { "boss" },
276:                        new String[] { "h", "+l", "-c" }, null, "en", 10);
277:                assertEquals(1, list.size());
278:                work = (Work) list.get(0);
279:                unlocked = worklist.unlock(work, "me");
280:                assertFalse(unlocked);
281:                assertNull(work.getLockedBy());
282:                assertNull(work.getLockedUntil());
283:                transaction.commit();
284:                session.close();
285:            }
286:
287:            public void testAssignmentListener() throws Exception {
288:                final List assigned = new LinkedList();
289:                final List unassigned = new LinkedList();
290:                worklist.addAssignmentListener(new AssignmentListener() {
291:                    public void assigned(AssignmentEvent event) {
292:                        assigned.add(event);
293:                    }
294:
295:                    public void unassigned(AssignmentEvent event) {
296:                        unassigned.add(event);
297:                    }
298:                });
299:
300:                Subject subject = new Subject("subject");
301:                subject.setProcess("WorklistTest");
302:                subject.setSubjectLines(new HashSet(Arrays
303:                        .asList(new SubjectLine[] {
304:                                new SubjectLine("de", "hallo"),
305:                                new SubjectLine("en", "hello"), })));
306:
307:                Session session = sessionFactory.openSession();
308:                Transaction transaction = session.beginTransaction();
309:                session.save(subject);
310:                transaction.commit();
311:                session.close();
312:
313:                session = sessionFactory.openSession();
314:                transaction = session.beginTransaction();
315:                subject = (Subject) session
316:                        .load(Subject.class, subject.getId());
317:                Enlistment enlistment1 = new Enlistment("TIMEOUT", "robot",
318:                        System.currentTimeMillis() + 10000);
319:                enlistment1.setAssignments(Collections
320:                        .singleton(new Assignment("you")));
321:                subject.getEnlistments().add(enlistment1);
322:                Enlistment enlistment2 = new Enlistment("TIMEOUT", "boss",
323:                        System.currentTimeMillis() + 10000);
324:                enlistment2.setAssignments(Collections
325:                        .singleton(new Assignment("me")));
326:                subject.getEnlistments().add(enlistment2);
327:                transaction.commit();
328:                session.close();
329:
330:                worklist.timeout();
331:
332:                assertTrue(assigned.contains(new AssignmentEvent(worklist,
333:                        subject.getProcess(), "robot", "subject", "you", 0)));
334:                assertTrue(assigned.contains(new AssignmentEvent(worklist,
335:                        subject.getProcess(), "boss", "subject", "me", 0)));
336:
337:                session = sessionFactory.openSession();
338:                transaction = session.beginTransaction();
339:                subject = (Subject) session
340:                        .load(Subject.class, subject.getId());
341:                subject.getEnlistments().clear();
342:                transaction.commit();
343:                session.close();
344:
345:                worklist.timeout();
346:
347:                assertTrue(unassigned.contains(new AssignmentEvent(worklist,
348:                        subject.getProcess(), "robot", "subject", "you", 0)));
349:                assertTrue(unassigned.contains(new AssignmentEvent(worklist,
350:                        subject.getProcess(), "boss", "subject", "me", 0)));
351:            }
352:
353:            private void printWork(List works) {
354:                System.out.println("concern:");
355:                for (Iterator iterator = works.iterator(); iterator.hasNext();) {
356:                    Work work = (Work) iterator.next();
357:                    System.out.print(work.getProcess());
358:                    System.out.print("\t");
359:                    System.out.print(work.getActivity());
360:                    System.out.print("\t");
361:                    System.out.print(work.getSubjectId());
362:                    System.out.print("\t");
363:                    System.out.print(work.getSubjectLine());
364:                    System.out.print("\t");
365:                    System.out.print(work.getOriginator());
366:                    System.out.print("\t");
367:                    System.out.print(work.getDue());
368:                    System.out.print("\t");
369:                    System.out.print(work.getLockedBy());
370:                    System.out.print("\t");
371:                    System.out.print(work.getLockedUntil());
372:                    System.out.print("\n");
373:                }
374:            }
375:
376:            private void printSubject(List subjects) {
377:                System.out.println("subject:");
378:                for (Iterator iterator = subjects.iterator(); iterator
379:                        .hasNext();) {
380:                    org.concern.Subject subject = (org.concern.Subject) iterator
381:                            .next();
382:                    System.out.print(subject.getProcess());
383:                    System.out.print("\t");
384:                    System.out.print(subject.getSubjectId());
385:                    System.out.print("\t");
386:                    System.out.print(subject.getSubjectLine());
387:                    System.out.print("\t");
388:                    System.out.print(subject.getOriginator());
389:                    System.out.print("\t");
390:                    System.out.print(subject.getOptions());
391:                    System.out.print("\n");
392:                }
393:            }
394:        }
395:
396:        /*
397:         drop table worklisttest_enlistments;
398:         drop table worklisttest_log_annotations ;
399:         drop table worklisttest_logs ;
400:         drop table worklisttest_archive_annotations ;
401:         drop table worklisttest_archive ;
402:         drop table worklisttest_subject_assignments ;
403:         drop table worklisttest_subject_lines ;
404:         drop table worklisttest_subject ;
405:         commit
406:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.