Source Code Cross Referenced for ApplDirTests.java in  » Workflow-Engines » wfmopen-2.1.1 » tools » 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 » tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2004 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: ApplDirTests.java,v 1.4 2006/12/12 10:54:38 drmlipp Exp $
021:         *
022:         * $Log: ApplDirTests.java,v $
023:         * Revision 1.4  2006/12/12 10:54:38  drmlipp
024:         * Added method for retrieving infos by application.
025:         *
026:         * Revision 1.3  2006/10/26 13:25:33  drmlipp
027:         * Updated.
028:         *
029:         * Revision 1.2  2006/10/26 09:18:48  drmlipp
030:         * Added explicit cleanup of directory.
031:         *
032:         * Revision 1.1  2006/10/25 21:43:39  mlipp
033:         * Added unittest for simple application directory.
034:         *
035:         * Revision 1.5  2006/10/19 12:20:53  drmlipp
036:         * Fixed test.
037:         *
038:         * Revision 1.4  2006/10/19 11:47:52  drmlipp
039:         * Added suspended test.
040:         *
041:         * Revision 1.3  2006/09/29 12:32:07  drmlipp
042:         * Consistently using WfMOpen as projct name now.
043:         *
044:         * Revision 1.2  2005/08/25 13:24:22  drmlipp
045:         * Synchronized with 1.3.1p6.
046:         *
047:         * Revision 1.1.2.1  2005/08/24 20:41:08  drmlipp
048:         * Added exception mapping tests.
049:         *
050:         * Revision 1.1  2004/12/22 19:28:11  mlipp
051:         * Added jelly tool.
052:         *
053:         */
054:        package tools;
055:
056:        import java.io.BufferedReader;
057:        import java.io.InputStream;
058:        import java.io.InputStreamReader;
059:
060:        import java.util.Collection;
061:        import java.util.Iterator;
062:
063:        import javax.security.auth.login.LoginException;
064:
065:        import de.danet.an.util.junit.EJBClientTest;
066:
067:        import de.danet.an.workflow.omgcore.WfActivity;
068:        import de.danet.an.workflow.omgcore.WfProcess;
069:        import de.danet.an.workflow.omgcore.WfRequester;
070:        import de.danet.an.workflow.tools.util.SimpleApplicationDirectory;
071:        import de.danet.an.workflow.tools.util.SimpleApplicationDirectoryLookup;
072:        import de.danet.an.workflow.tools.util.SimpleApplicationInfo;
073:
074:        import de.danet.an.workflow.api.Activity;
075:        import de.danet.an.workflow.api.DefaultRequester;
076:        import de.danet.an.workflow.api.FactoryConfigurationError;
077:        import de.danet.an.workflow.api.Process;
078:        import de.danet.an.workflow.api.ProcessDefinitionDirectory;
079:        import de.danet.an.workflow.api.ProcessDirectory;
080:        import de.danet.an.workflow.api.ProcessMgr;
081:        import de.danet.an.workflow.api.WorkflowService;
082:        import de.danet.an.workflow.api.WorkflowServiceFactory;
083:
084:        import common.UTLoginContext;
085:        import junit.framework.Test;
086:        import junit.framework.TestCase;
087:        import junit.framework.TestSuite;
088:
089:        /**
090:         * Test exception mapping
091:         */
092:        public class ApplDirTests extends TestCase {
093:            private static UTLoginContext plc = null;
094:            static {
095:                try {
096:                    plc = new UTLoginContext();
097:                    plc.login();
098:                } catch (LoginException e) {
099:                    throw new IllegalStateException(e.getMessage());
100:                }
101:            }
102:
103:            /**
104:             * A process directory reference.
105:             */
106:            private ProcessDirectory pdd = null;
107:
108:            /**
109:             * Constructor of this TestCase
110:             */
111:            public ApplDirTests(String name) {
112:                super (name);
113:            }
114:
115:            /**
116:             * Stellt diese TestSuite zusammen.
117:             */
118:            public static Test suite() {
119:                TestSuite suite = new TestSuite();
120:                suite.addTest(new ApplDirTests("importProcessDefinitions"));
121:                suite.addTest(new ApplDirTests("findByKey"));
122:                return new EJBClientTest(plc, suite);
123:            }
124:
125:            private WorkflowService workflowService = null;
126:
127:            /**
128:             * Initialisierung.
129:             */
130:            protected void setUp() throws Exception {
131:                try {
132:                    WorkflowServiceFactory wfsf = WorkflowServiceFactory
133:                            .newInstance();
134:                    workflowService = wfsf.newWorkflowService();
135:                } catch (FactoryConfigurationError e) {
136:                    throw new IllegalStateException(e.getMessage());
137:                }
138:            }
139:
140:            protected void tearDown() throws Exception {
141:                workflowService.release(workflowService);
142:                workflowService = null;
143:            }
144:
145:            /**
146:             * Import the process definitions from a XPDL file
147:             * unsing the ProcessDefinitionDirectory bean.
148:             */
149:            public void importProcessDefinitions() throws Exception {
150:                // Create process definition directory bean
151:                ProcessDefinitionDirectory pdd = workflowService
152:                        .processDefinitionDirectory();
153:
154:                InputStream is = getClass().getResourceAsStream(
155:                        "/tools/simpleApplDirTest.xml");
156:                assertTrue(is != null);
157:                BufferedReader br = new BufferedReader(new InputStreamReader(
158:                        is, "ISO-8859-1"));
159:                StringBuffer sb = new StringBuffer();
160:                String st;
161:                while ((st = br.readLine()) != null) {
162:                    sb.append(st + "\n");
163:                }
164:                pdd.importProcessDefinitions(sb.toString());
165:                Collection processDefinitions = pdd.processDefinitions();
166:                assertTrue(processDefinitions.size() > 0);
167:            }
168:
169:            /**
170:             * Test.
171:             */
172:            public void findByKey() throws Exception {
173:                ProcessDefinitionDirectory procDefDir = null;
174:                ProcessDirectory procDir = null;
175:                try {
176:                    SimpleApplicationDirectory ad = (SimpleApplicationDirectory) workflowService
177:                            .executeBatch(new SimpleApplicationDirectoryLookup());
178:                    assertTrue(ad.infosByKey("unittests.Test1", "ToolTest")
179:                            .size() == 0);
180:                    procDefDir = workflowService.processDefinitionDirectory();
181:                    procDir = workflowService.processDirectory();
182:                    ProcessMgr pmgr = procDefDir.processMgr(
183:                            "simpleApplDirTests", "test1");
184:                    WfProcess process = pmgr
185:                            .createProcess(new DefaultRequester(workflowService));
186:                    process.start();
187:                    WfActivity act = null;
188:                    for (Iterator i = process.steps().iterator(); i.hasNext();) {
189:                        act = (WfActivity) i.next();
190:                        if (act.name().equals("invokeTool")) {
191:                            break;
192:                        }
193:                    }
194:                    assertTrue(act != null);
195:                    assertTrue(stateReached(act, "open.running"));
196:                    Thread.sleep(1000);
197:
198:                    assertTrue(ad.infosByApplication("unittests.Test1").size() == 1);
199:                    Collection infos = ad.infosByKey("unittests.Test1",
200:                            "ToolTest");
201:                    assertTrue(infos.size() == 1);
202:                    SimpleApplicationInfo info = (SimpleApplicationInfo) infos
203:                            .iterator().next();
204:                    assertTrue(info.state() instanceof  Object[]);
205:                    WfActivity actFound = workflowService.processDirectory()
206:                            .lookupActivity(info.activityUniqueKey());
207:                    actFound.complete();
208:                    ad.removeInstance(info.id());
209:
210:                    assertTrue(stateReached(process, "closed.completed"));
211:                    procDir.removeProcess(process);
212:                } finally {
213:                    workflowService.release(procDefDir);
214:                    workflowService.release(procDir);
215:                }
216:            }
217:
218:            private WfProcess createProcess(String pkgId, String prcId,
219:                    WfRequester req) throws Exception {
220:                ProcessDefinitionDirectory procDir = null;
221:                try {
222:                    procDir = workflowService.processDefinitionDirectory();
223:                    ProcessMgr pmgr = procDir.processMgr(pkgId, prcId);
224:                    return pmgr.createProcess(req);
225:                } finally {
226:                    workflowService.release(procDir);
227:                }
228:            }
229:
230:            private boolean stateReached(WfProcess proc, String procState)
231:                    throws Exception {
232:                boolean test = true;
233:                boolean stateReached = false;
234:                int maxRetries = 100;
235:                while (test) {
236:                    if (maxRetries-- > 0) {
237:                        if (proc.state().startsWith(procState)) {
238:                            stateReached = true;
239:                            test = false;
240:                        } else {
241:                            Thread.sleep(500);
242:                        }
243:                    } else {
244:                        test = false;
245:                    }
246:                }
247:                return stateReached;
248:            }
249:
250:            private boolean stateReached(WfActivity act, String actState)
251:                    throws Exception {
252:                boolean test = true;
253:                boolean stateReached = false;
254:                int maxRetries = 100;
255:                while (test) {
256:                    if (maxRetries-- > 0) {
257:                        if (act.state().startsWith(actState)) {
258:                            stateReached = true;
259:                            test = false;
260:                        } else {
261:                            Thread.sleep(500);
262:                        }
263:                    } else {
264:                        test = false;
265:                    }
266:                }
267:                return stateReached;
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.