Source Code Cross Referenced for IterationTests.java in  » Workflow-Engines » bonita-v3.1 » hero » client » test » 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 » bonita v3.1 » hero.client.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package hero.client.test;
0002:
0003:        /**
0004:         *
0005:         * Bonita
0006:         * Copyright (C) 1999 Bull S.A.
0007:         * Bull 68 route de versailles  78434 Louveciennes Cedex France
0008:         * Further information: bonita@objectweb.org
0009:         *
0010:         * This library is free software; you can redistribute it and/or
0011:         * modify it under the terms of the GNU Lesser General Public
0012:         * License as published by the Free Software Foundation; either
0013:         * version 2.1 of the License, or any later version.
0014:         *
0015:         * This library is distributed in the hope that it will be useful,
0016:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018:         * Lesser General Public License for more details.
0019:         *
0020:         * You should have received a copy of the GNU Lesser General Public
0021:         * License along with this library; if not, write to the Free Software
0022:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
0023:         * USA
0024:         *
0025:         *
0026:         --------------------------------------------------------------------------
0027:         * $Id: IterationTests.java,v 1.7 2006/08/17 15:30:53 mvaldes Exp $
0028:         *
0029:         --------------------------------------------------------------------------
0030:         */
0031:
0032:        import hero.interfaces.BnNodePropertyValue;
0033:        import hero.interfaces.Constants;
0034:        import hero.interfaces.ProjectSession;
0035:        import hero.interfaces.ProjectSessionHome;
0036:        import hero.interfaces.ProjectSessionUtil;
0037:        import hero.interfaces.UserSession;
0038:        import hero.interfaces.UserSessionHome;
0039:        import hero.interfaces.UserSessionUtil;
0040:
0041:        import java.util.Collection;
0042:        import java.util.Iterator;
0043:
0044:        import junit.framework.TestCase;
0045:        import junit.framework.TestSuite;
0046:
0047:        public class IterationTests extends TestCase {
0048:            public IterationTests(String testname) {
0049:                super (testname);
0050:            }
0051:
0052:            public static TestSuite suite() {
0053:                return new TestSuite(IterationTests.class);
0054:            }
0055:
0056:            public void setUp() throws Exception {
0057:            }
0058:
0059:            /**
0060:             * Tests the correct exit from the iterations 
0061:             * Uses: Automatic and Non automatic anticipable activities
0062:             * 
0063:             * @throws Exception
0064:             */
0065:            public void testLeaveIteration() throws Exception {
0066:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0067:                        .getHome();
0068:                ProjectSession ps = projectSessionh.create();
0069:                ps.initModel("LeaveIteration");
0070:
0071:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
0072:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
0073:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
0074:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
0075:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
0076:                ps.addNode("node5", Constants.Nd.AND_JOIN_NODE);
0077:                ps.addNode("node6", Constants.Nd.AND_JOIN_NODE);
0078:                ps.addNode("node7", Constants.Nd.AND_JOIN_NODE);
0079:                ps.addNode("node8", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0080:                ps.setNodeTraditional("node8");
0081:                ps.addNode("node9", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0082:                ps.setNodeTraditional("node9");
0083:
0084:                ps.addEdge("node0", "node1");
0085:                ps.addEdge("node1", "node3");
0086:                ps.addEdge("node1", "node4");
0087:                ps.addEdge("node1", "node5");
0088:                String from3to6 = ps.addEdge("node3", "node6");
0089:                String from3to8 = ps.addEdge("node3", "node8");
0090:                String from4to2 = ps.addEdge("node4", "node2");
0091:                String from4to6 = ps.addEdge("node4", "node6");
0092:                ps.addEdge("node5", "node4");
0093:                ps.addEdge("node5", "node6");
0094:                String from6to7 = ps.addEdge("node6", "node7");
0095:                ps.addEdge("node8", "node9");
0096:
0097:                ps.setProperty("iterate", "true");
0098:
0099:                // set conditions to exit from the iteration (they are mandatory)
0100:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
0101:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
0102:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
0103:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
0104:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
0105:
0106:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
0107:
0108:                ps.checkModelDefinition();
0109:
0110:                // ******************************   MAIN   ******************************
0111:                ps.setUserRole("admin", "InitialRole");
0112:                String project = ps.instantiateProject("LeaveIteration");
0113:                UserSessionHome usersh = UserSessionUtil.getHome();
0114:                UserSession usr = usersh.create();
0115:
0116:                usr.startActivity(project, "node0");
0117:                assertTrue(
0118:                        "Error in LeaveIteration, startActivity node0: node0 failed",
0119:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
0120:                assertTrue(
0121:                        "Error in LeaveIteration, startActivity node0: node1 failed",
0122:                        ps.getNodeValue("node1").getState() == Constants.Nd.ANTICIPABLE);
0123:
0124:                usr.terminateActivity(project, "node0");
0125:                assertTrue(
0126:                        "Error in LeaveIteration, terminateActivity node0: node0 failed",
0127:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0128:                assertTrue(
0129:                        "Error in LeaveIteration, terminateActivity node0: node1 failed",
0130:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0131:
0132:                int index = 0;
0133:                while (index < 2) {
0134:                    usr.startActivity(project, "node1");
0135:                    assertTrue(
0136:                            "Error in LeaveIteration, startActivity node1: node1 failed",
0137:                            ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0138:                    assertTrue(
0139:                            "Error in LeaveIteration, startActivity node1: node3 failed",
0140:                            ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0141:                    assertTrue(
0142:                            "Error in LeaveIteration, startActivity node1: node4 failed",
0143:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0144:                    assertTrue(
0145:                            "Error in LeaveIteration, startActivity node1: node5 failed",
0146:                            ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0147:
0148:                    usr.terminateActivity(project, "node1");
0149:                    assertTrue(
0150:                            "Error in LeaveIteration, terminateActivity node1: node1 failed",
0151:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0152:                    assertTrue(
0153:                            "Error in LeaveIteration, terminateActivity node1: node3 failed",
0154:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0155:                    assertTrue(
0156:                            "Error in LeaveIteration, terminateActivity node1: node4 failed",
0157:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0158:                    assertTrue(
0159:                            "Error in LeaveIteration, terminateActivity node1: node5 failed",
0160:                            ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0161:
0162:                    usr.startActivity(project, "node3");
0163:                    usr.startActivity(project, "node5");
0164:                    usr.startActivity(project, "node4");
0165:
0166:                    if (index == 0) {
0167:                        assertTrue(
0168:                                "Error in LeaveIteration, startActivity node2: node2 failed",
0169:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPABLE);
0170:                        usr.startActivity(project, "node2");
0171:                        assertTrue(
0172:                                "Error in LeaveIteration, startActivity node2: node2 failed",
0173:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPATING);
0174:                    }
0175:
0176:                    usr.terminateActivity(project, "node3");
0177:                    usr.terminateActivity(project, "node5");
0178:                    usr.terminateActivity(project, "node4");
0179:                    assertTrue(
0180:                            "Error in LeaveIteration, terminateActivity node3: node8 failed",
0181:                            ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
0182:                    assertTrue(
0183:                            "Error in LeaveIteration, terminateActivity node3: node9 failed",
0184:                            ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
0185:                    assertTrue(
0186:                            "Error in LeaveIteration, terminateActivity node4: node2 failed",
0187:                            ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
0188:
0189:                    usr.startActivity(project, "node6");
0190:                    usr.terminateActivity(project, "node6");
0191:                    assertTrue(
0192:                            "Error in LeaveIteration, terminateActivity node6: node0 failed",
0193:                            ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0194:                    assertTrue(
0195:                            "Error in LeaveIteration, terminateActivity node6: node1 failed",
0196:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0197:                    assertTrue(
0198:                            "Error in LeaveIteration, terminateActivity node6: node2 failed",
0199:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
0200:                    assertTrue(
0201:                            "Error in LeaveIteration, terminateActivity node6: node3 failed",
0202:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
0203:                    assertTrue(
0204:                            "Error in LeaveIteration, terminateActivity node6: node4 failed",
0205:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0206:                    assertTrue(
0207:                            "Error in LeaveIteration, terminateActivity node6: node5 failed",
0208:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
0209:                    assertTrue(
0210:                            "Error in LeaveIteration, terminateActivity node6: node6 failed",
0211:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
0212:                    assertTrue(
0213:                            "Error in LeaveIteration, terminateActivity node6: node7 failed",
0214:                            ps.getNodeValue("node7").getState() == Constants.Nd.INITIAL);
0215:                    assertTrue(
0216:                            "Error in LeaveIteration, terminateActivity node6: node8 failed",
0217:                            ps.getNodeValue("node8").getState() == Constants.Nd.INITIAL);
0218:                    assertTrue(
0219:                            "Error in LeaveIteration, terminateActivity node6: node9 failed",
0220:                            ps.getNodeValue("node9").getState() == Constants.Nd.INITIAL);
0221:                    index++;
0222:                }
0223:
0224:                usr.startActivity(project, "node1");
0225:                assertTrue(
0226:                        "Error in LeaveIteration, startActivity node1: node1 failed",
0227:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0228:                assertTrue(
0229:                        "Error in LeaveIteration, startActivity node1: node3 failed",
0230:                        ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0231:                assertTrue(
0232:                        "Error in LeaveIteration, startActivity node1: node4 failed",
0233:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0234:                assertTrue(
0235:                        "Error in LeaveIteration, startActivity node1: node5 failed",
0236:                        ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0237:
0238:                usr.terminateActivity(project, "node1");
0239:                assertTrue(
0240:                        "Error in LeaveIteration, terminateActivity node1: node1 failed",
0241:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0242:                assertTrue(
0243:                        "Error in LeaveIteration, terminateActivity node1: node3 failed",
0244:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0245:                assertTrue(
0246:                        "Error in LeaveIteration, terminateActivity node1: node4 failed",
0247:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0248:                assertTrue(
0249:                        "Error in LeaveIteration, terminateActivity node1: node5 failed",
0250:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0251:
0252:                usr.startActivity(project, "node3");
0253:                usr.startActivity(project, "node5");
0254:                usr.startActivity(project, "node4");
0255:
0256:                // Finally, it will leave throw node2 and node8 activities. node6 and node7 will become DEAD
0257:                ps.setProperty("iterate", "false");
0258:
0259:                usr.terminateActivity(project, "node3");
0260:                usr.terminateActivity(project, "node5");
0261:                usr.terminateActivity(project, "node4");
0262:
0263:                assertTrue(
0264:                        "Error in LeaveIteration, terminateActivity node3 | node4, after iterate: node6 failed",
0265:                        ps.getNodeValue("node6").getState() == Constants.Nd.DEAD);
0266:                assertTrue(
0267:                        "Error in LeaveIteration, terminateActivity node3 | node4, after iterate: node7 failed",
0268:                        ps.getNodeValue("node7").getState() == Constants.Nd.DEAD);
0269:
0270:                assertTrue(
0271:                        "Error in LeaveIteration, terminateActivity node3, after iterate: node8 failed",
0272:                        ps.getNodeValue("node8").getState() == Constants.Nd.TERMINATED);
0273:                assertTrue(
0274:                        "Error in LeaveIteration, terminateActivity node3, after iterate: node9 failed",
0275:                        ps.getNodeValue("node9").getState() == Constants.Nd.TERMINATED);
0276:
0277:                assertTrue(
0278:                        "Error in LeaveIteration, terminateActivity node6, after iterate: node2 failed",
0279:                        ps.getNodeValue("node2").getState() == Constants.Nd.READY);
0280:
0281:                usr.startActivity(project, "node2");
0282:                assertTrue(
0283:                        "Error in LeaveIteration, startActivity node2, after iterate: node2 failed",
0284:                        ps.getNodeValue("node2").getState() == Constants.Nd.EXECUTING);
0285:
0286:                usr.terminateActivity(project, "node2");
0287:            }
0288:
0289:            /**
0290:             * Tests that the iteration finalizes correctly (based on testLeaveIteration)
0291:             * Uses: Automatic and Non automatic anticipable activities
0292:             * 
0293:             * @throws Exception
0294:             */
0295:            public void testFinalizeIteration() throws Exception {
0296:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0297:                        .getHome();
0298:                ProjectSession ps = projectSessionh.create();
0299:                ps.initModel("FinalizeIteration");
0300:
0301:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
0302:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
0303:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
0304:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
0305:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
0306:                ps.addNode("node5", Constants.Nd.AND_JOIN_NODE);
0307:                ps.addNode("node6", Constants.Nd.AND_JOIN_NODE);
0308:                ps.addNode("node7", Constants.Nd.AND_JOIN_NODE);
0309:                ps.addNode("node8", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0310:                ps.setNodeTraditional("node8");
0311:                ps.addNode("node9", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0312:                ps.setNodeTraditional("node9");
0313:
0314:                ps.addEdge("node0", "node1");
0315:                ps.addEdge("node1", "node3");
0316:                ps.addEdge("node1", "node4");
0317:                ps.addEdge("node1", "node5");
0318:                String from3to6 = ps.addEdge("node3", "node6");
0319:                String from3to8 = ps.addEdge("node3", "node8");
0320:                String from4to2 = ps.addEdge("node4", "node2");
0321:                String from4to6 = ps.addEdge("node4", "node6");
0322:                ps.addEdge("node5", "node4");
0323:                ps.addEdge("node5", "node6");
0324:                String from6to7 = ps.addEdge("node6", "node7");
0325:                ps.addEdge("node8", "node9");
0326:
0327:                ps.setProperty("iterate", "true");
0328:
0329:                // set conditions to exit from the iteration (they are mandatory)
0330:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
0331:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
0332:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
0333:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
0334:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
0335:
0336:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
0337:
0338:                ps.checkModelDefinition();
0339:
0340:                // ******************************   MAIN   ******************************
0341:                ps.setUserRole("admin", "InitialRole");
0342:                String project = ps.instantiateProject("FinalizeIteration");
0343:                UserSessionHome usersh = UserSessionUtil.getHome();
0344:                UserSession usr = usersh.create();
0345:
0346:                usr.startActivity(project, "node0");
0347:                assertTrue(
0348:                        "Error in FinalizeIteration, startActivity node0: node0 failed",
0349:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
0350:                assertTrue(
0351:                        "Error in FinalizeIteration, startActivity node0: node1 failed",
0352:                        ps.getNodeValue("node1").getState() == Constants.Nd.ANTICIPABLE);
0353:
0354:                usr.terminateActivity(project, "node0");
0355:                assertTrue(
0356:                        "Error in FinalizeIteration, terminateActivity node0: node0 failed",
0357:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0358:                assertTrue(
0359:                        "Error in FinalizeIteration, terminateActivity node0: node1 failed",
0360:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0361:
0362:                int index = 0;
0363:                while (index < 2) {
0364:                    usr.startActivity(project, "node1");
0365:                    assertTrue(
0366:                            "Error in FinalizeIteration, startActivity node1: node1 failed",
0367:                            ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0368:                    assertTrue(
0369:                            "Error in FinalizeIteration, startActivity node1: node3 failed",
0370:                            ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0371:                    assertTrue(
0372:                            "Error in FinalizeIteration, startActivity node1: node4 failed",
0373:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0374:                    assertTrue(
0375:                            "Error in FinalizeIteration, startActivity node1: node5 failed",
0376:                            ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0377:
0378:                    usr.terminateActivity(project, "node1");
0379:                    assertTrue(
0380:                            "Error in FinalizeIteration, terminateActivity node1: node1 failed",
0381:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0382:                    assertTrue(
0383:                            "Error in FinalizeIteration, terminateActivity node1: node3 failed",
0384:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0385:                    assertTrue(
0386:                            "Error in FinalizeIteration, terminateActivity node1: node4 failed",
0387:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0388:                    assertTrue(
0389:                            "Error in FinalizeIteration, terminateActivity node1: node5 failed",
0390:                            ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0391:
0392:                    usr.startActivity(project, "node3");
0393:                    usr.startActivity(project, "node5");
0394:                    usr.startActivity(project, "node4");
0395:
0396:                    if (index == 0) {
0397:                        assertTrue(
0398:                                "Error in FinalizeIteration, startActivity node2: node2 failed",
0399:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPABLE);
0400:                        usr.startActivity(project, "node2");
0401:                        assertTrue(
0402:                                "Error in FinalizeIteration, startActivity node2: node2 failed",
0403:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPATING);
0404:                    }
0405:
0406:                    usr.terminateActivity(project, "node3");
0407:                    usr.terminateActivity(project, "node5");
0408:                    usr.terminateActivity(project, "node4");
0409:                    assertTrue(
0410:                            "Error in FinalizeIteration, terminateActivity node3: node8 failed",
0411:                            ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
0412:                    assertTrue(
0413:                            "Error in FinalizeIteration, terminateActivity node3: node9 failed",
0414:                            ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
0415:                    assertTrue(
0416:                            "Error in FinalizeIteration, terminateActivity node4: node2 failed",
0417:                            ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
0418:
0419:                    usr.startActivity(project, "node6");
0420:                    usr.terminateActivity(project, "node6");
0421:                    assertTrue(
0422:                            "Error in FinalizeIteration, terminateActivity node6: node0 failed",
0423:                            ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0424:                    assertTrue(
0425:                            "Error in FinalizeIteration, terminateActivity node6: node1 failed",
0426:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0427:                    assertTrue(
0428:                            "Error in FinalizeIteration, terminateActivity node6: node2 failed",
0429:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
0430:                    assertTrue(
0431:                            "Error in FinalizeIteration, terminateActivity node6: node3 failed",
0432:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
0433:                    assertTrue(
0434:                            "Error in FinalizeIteration, terminateActivity node6: node4 failed",
0435:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0436:                    assertTrue(
0437:                            "Error in FinalizeIteration, terminateActivity node6: node5 failed",
0438:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
0439:                    assertTrue(
0440:                            "Error in FinalizeIteration, terminateActivity node6: node6 failed",
0441:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
0442:                    assertTrue(
0443:                            "Error in FinalizeIteration, terminateActivity node6: node7 failed",
0444:                            ps.getNodeValue("node7").getState() == Constants.Nd.INITIAL);
0445:                    assertTrue(
0446:                            "Error in FinalizeIteration, terminateActivity node6: node8 failed",
0447:                            ps.getNodeValue("node8").getState() == Constants.Nd.INITIAL);
0448:                    assertTrue(
0449:                            "Error in FinalizeIteration, terminateActivity node6: node9 failed",
0450:                            ps.getNodeValue("node9").getState() == Constants.Nd.INITIAL);
0451:                    index++;
0452:                }
0453:
0454:                usr.startActivity(project, "node1");
0455:                assertTrue(
0456:                        "Error in FinalizeIteration, startActivity node1: node1 failed",
0457:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0458:                assertTrue(
0459:                        "Error in FinalizeIteration, startActivity node1: node3 failed",
0460:                        ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0461:                assertTrue(
0462:                        "Error in FinalizeIteration, startActivity node1: node4 failed",
0463:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0464:                assertTrue(
0465:                        "Error in FinalizeIteration, startActivity node1: node5 failed",
0466:                        ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0467:
0468:                usr.terminateActivity(project, "node1");
0469:                assertTrue(
0470:                        "Error in FinalizeIteration, terminateActivity node1: node1 failed",
0471:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0472:                assertTrue(
0473:                        "Error in FinalizeIteration, terminateActivity node1: node3 failed",
0474:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0475:                assertTrue(
0476:                        "Error in FinalizeIteration, terminateActivity node1: node4 failed",
0477:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0478:                assertTrue(
0479:                        "Error in FinalizeIteration, terminateActivity node1: node5 failed",
0480:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0481:
0482:                usr.startActivity(project, "node3");
0483:                usr.startActivity(project, "node5");
0484:                usr.startActivity(project, "node4");
0485:                usr.terminateActivity(project, "node3");
0486:                usr.terminateActivity(project, "node5");
0487:                usr.terminateActivity(project, "node4");
0488:                assertTrue(
0489:                        "Error in FinalizeIteration, terminateActivity node3, after iterate: node8 failed",
0490:                        ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
0491:                assertTrue(
0492:                        "Error in FinalizeIteration, terminateActivity node3, after iterate: node9 failed",
0493:                        ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
0494:                assertTrue(
0495:                        "Error in FinalizeIteration, terminateActivity node4, after iterate: node2 failed",
0496:                        ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
0497:
0498:                // Finally, it will finalize throw node7.  Node2, node8 and node9 will become DEAD
0499:                ps.setProperty("iterate", "false");
0500:
0501:                usr.startActivity(project, "node6");
0502:                usr.terminateActivity(project, "node6");
0503:                assertTrue(
0504:                        "Error in FinalizeIteration, terminateActivity node6, after iterate: node6 failed",
0505:                        ps.getNodeValue("node6").getState() == Constants.Nd.TERMINATED);
0506:                assertTrue(
0507:                        "Error in FinalizeIteration, terminateActivity node6, after iterate: node7 failed",
0508:                        ps.getNodeValue("node7").getState() == Constants.Nd.READY);
0509:
0510:                usr.startActivity(project, "node7");
0511:                usr.terminateActivity(project, "node7");
0512:            }
0513:
0514:            /**
0515:             * Tests that the iteration finalizes correctly with OR activities (based on testFinalizeIteration)
0516:             * Uses: Automatic and Non automatic anticipable activities
0517:             * 
0518:             * @throws Exception
0519:             */
0520:            public void testFinalizeIterationORjoin() throws Exception {
0521:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0522:                        .getHome();
0523:                ProjectSession ps = projectSessionh.create();
0524:                ps.initModel("FinalizeIterationORjoin");
0525:
0526:                ps.addNode("node0", Constants.Nd.OR_JOIN_NODE);
0527:                ps.addNode("node1", Constants.Nd.OR_JOIN_NODE);
0528:                ps.addNode("node2", Constants.Nd.OR_JOIN_NODE);
0529:                ps.addNode("node3", Constants.Nd.OR_JOIN_NODE);
0530:                ps.addNode("node4", Constants.Nd.OR_JOIN_NODE);
0531:                ps.addNode("node5", Constants.Nd.OR_JOIN_NODE);
0532:                ps.addNode("node6", Constants.Nd.OR_JOIN_NODE);
0533:                ps.addNode("node7", Constants.Nd.OR_JOIN_NODE);
0534:                ps.addNode("node8", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
0535:                ps.setNodeTraditional("node8");
0536:                ps.addNode("node9", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
0537:                ps.setNodeTraditional("node9");
0538:
0539:                ps.addEdge("node0", "node1");
0540:                ps.addEdge("node1", "node3");
0541:                ps.addEdge("node1", "node4");
0542:                ps.addEdge("node1", "node5");
0543:                String from3to6 = ps.addEdge("node3", "node6");
0544:                String from3to8 = ps.addEdge("node3", "node8");
0545:                String from4to2 = ps.addEdge("node4", "node2");
0546:                String from4to6 = ps.addEdge("node4", "node6");
0547:                ps.addEdge("node5", "node4");
0548:                ps.addEdge("node5", "node6");
0549:                String from6to7 = ps.addEdge("node6", "node7");
0550:                ps.addEdge("node8", "node9");
0551:
0552:                ps.setProperty("iterate", "true");
0553:
0554:                // set conditions to exit from the iteration (they are mandatory)
0555:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
0556:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
0557:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
0558:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
0559:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
0560:
0561:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
0562:
0563:                ps.checkModelDefinition();
0564:
0565:                // ******************************   MAIN   ******************************
0566:                ps.setUserRole("admin", "InitialRole");
0567:                String project = ps
0568:                        .instantiateProject("FinalizeIterationORjoin");
0569:                UserSessionHome usersh = UserSessionUtil.getHome();
0570:                UserSession usr = usersh.create();
0571:
0572:                usr.startActivity(project, "node0");
0573:                assertTrue(
0574:                        "Error in FinalizeIteration, startActivity node0: node0 failed",
0575:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
0576:                assertTrue(
0577:                        "Error in FinalizeIteration, startActivity node0: node1 failed",
0578:                        ps.getNodeValue("node1").getState() == Constants.Nd.ANTICIPABLE);
0579:
0580:                usr.terminateActivity(project, "node0");
0581:                assertTrue(
0582:                        "Error in FinalizeIteration, terminateActivity node0: node0 failed",
0583:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0584:                assertTrue(
0585:                        "Error in FinalizeIteration, terminateActivity node0: node1 failed",
0586:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0587:
0588:                int index = 0;
0589:                while (index < 2) {
0590:                    usr.startActivity(project, "node1");
0591:                    assertTrue(
0592:                            "Error in FinalizeIteration, startActivity node1: node1 failed",
0593:                            ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0594:                    assertTrue(
0595:                            "Error in FinalizeIteration, startActivity node1: node3 failed",
0596:                            ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0597:                    assertTrue(
0598:                            "Error in FinalizeIteration, startActivity node1: node4 failed",
0599:                            ps.getNodeValue("node4").getState() == Constants.Nd.ANTICIPABLE);
0600:                    assertTrue(
0601:                            "Error in FinalizeIteration, startActivity node1: node5 failed",
0602:                            ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0603:
0604:                    usr.terminateActivity(project, "node1");
0605:                    assertTrue(
0606:                            "Error in FinalizeIteration, terminateActivity node1: node1 failed",
0607:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0608:                    assertTrue(
0609:                            "Error in FinalizeIteration, terminateActivity node1: node3 failed",
0610:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0611:                    assertTrue(
0612:                            "Error in FinalizeIteration, terminateActivity node1: node4 failed",
0613:                            ps.getNodeValue("node4").getState() == Constants.Nd.READY);
0614:                    assertTrue(
0615:                            "Error in FinalizeIteration, terminateActivity node1: node5 failed",
0616:                            ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0617:
0618:                    usr.startActivity(project, "node3");
0619:                    usr.startActivity(project, "node5");
0620:                    usr.startActivity(project, "node4");
0621:
0622:                    if (index == 0) {
0623:                        assertTrue(
0624:                                "Error in FinalizeIteration, startActivity node2: node2 failed",
0625:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPABLE);
0626:                        usr.startActivity(project, "node2");
0627:                        assertTrue(
0628:                                "Error in FinalizeIteration, startActivity node2: node2 failed",
0629:                                ps.getNodeValue("node2").getState() == Constants.Nd.ANTICIPATING);
0630:                    }
0631:
0632:                    usr.terminateActivity(project, "node3");
0633:                    assertTrue(
0634:                            "Error in FinalizeIteration, terminateActivity node3: node8 failed",
0635:                            ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
0636:                    assertTrue(
0637:                            "Error in FinalizeIteration, terminateActivity node3: node9 failed",
0638:                            ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
0639:                    assertTrue(
0640:                            "Error in FinalizeIteration, terminateActivity node3: node6 failed",
0641:                            ps.getNodeValue("node6").getState() == Constants.Nd.READY);
0642:
0643:                    usr.startActivity(project, "node6");
0644:                    usr.terminateActivity(project, "node6");
0645:                    assertTrue(
0646:                            "Error in FinalizeIteration, terminateActivity node6: node0 failed",
0647:                            ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
0648:                    assertTrue(
0649:                            "Error in FinalizeIteration, terminateActivity node6: node1 failed",
0650:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
0651:                    assertTrue(
0652:                            "Error in FinalizeIteration, terminateActivity node6: node2 failed",
0653:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
0654:                    assertTrue(
0655:                            "Error in FinalizeIteration, terminateActivity node6: node3 failed",
0656:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
0657:                    assertTrue(
0658:                            "Error in FinalizeIteration, terminateActivity node6: node4 failed",
0659:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
0660:                    assertTrue(
0661:                            "Error in FinalizeIteration, terminateActivity node6: node5 failed",
0662:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
0663:                    assertTrue(
0664:                            "Error in FinalizeIteration, terminateActivity node6: node6 failed",
0665:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
0666:                    assertTrue(
0667:                            "Error in FinalizeIteration, terminateActivity node6: node7 failed",
0668:                            ps.getNodeValue("node7").getState() == Constants.Nd.INITIAL);
0669:                    assertTrue(
0670:                            "Error in FinalizeIteration, terminateActivity node6: node8 failed",
0671:                            ps.getNodeValue("node8").getState() == Constants.Nd.INITIAL);
0672:                    assertTrue(
0673:                            "Error in FinalizeIteration, terminateActivity node6: node9 failed",
0674:                            ps.getNodeValue("node9").getState() == Constants.Nd.INITIAL);
0675:                    index++;
0676:                }
0677:
0678:                usr.startActivity(project, "node1");
0679:                assertTrue(
0680:                        "Error in FinalizeIteration, startActivity node1: node1 failed",
0681:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
0682:                assertTrue(
0683:                        "Error in FinalizeIteration, startActivity node1: node3 failed",
0684:                        ps.getNodeValue("node3").getState() == Constants.Nd.ANTICIPABLE);
0685:                assertTrue(
0686:                        "Error in FinalizeIteration, startActivity node1: node4 failed",
0687:                        ps.getNodeValue("node4").getState() == Constants.Nd.ANTICIPABLE);
0688:                assertTrue(
0689:                        "Error in FinalizeIteration, startActivity node1: node5 failed",
0690:                        ps.getNodeValue("node5").getState() == Constants.Nd.ANTICIPABLE);
0691:
0692:                usr.terminateActivity(project, "node1");
0693:                assertTrue(
0694:                        "Error in FinalizeIteration, terminateActivity node1: node1 failed",
0695:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
0696:                assertTrue(
0697:                        "Error in FinalizeIteration, terminateActivity node1: node3 failed",
0698:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
0699:                assertTrue(
0700:                        "Error in FinalizeIteration, terminateActivity node1: node4 failed",
0701:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
0702:                assertTrue(
0703:                        "Error in FinalizeIteration, terminateActivity node1: node5 failed",
0704:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
0705:
0706:                usr.startActivity(project, "node3");
0707:                usr.terminateActivity(project, "node3");
0708:                assertTrue(
0709:                        "Error in FinalizeIteration, terminateActivity node3, after iterate: node8 failed",
0710:                        ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
0711:                assertTrue(
0712:                        "Error in FinalizeIteration, terminateActivity node3, after iterate: node9 failed",
0713:                        ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
0714:
0715:                usr.startActivity(project, "node4");
0716:                usr.terminateActivity(project, "node4");
0717:                assertTrue(
0718:                        "Error in FinalizeIteration, terminateActivity node4, after iterate: node2 failed",
0719:                        ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
0720:                assertTrue(
0721:                        "Error in FinalizeIteration, terminateActivity node4, after iterate: node6 failed",
0722:                        ps.getNodeValue("node6").getState() == Constants.Nd.READY);
0723:
0724:                // Finally, it will finalize throw node7.  Node2, node8 and node9 are DEAD
0725:                ps.setProperty("iterate", "false");
0726:
0727:                usr.startActivity(project, "node6");
0728:                usr.terminateActivity(project, "node6");
0729:                assertTrue(
0730:                        "Error in FinalizeIteration, terminateActivity node6, after iterate: node6 failed",
0731:                        ps.getNodeValue("node6").getState() == Constants.Nd.TERMINATED);
0732:                assertTrue(
0733:                        "Error in FinalizeIteration, terminateActivity node6, after iterate: node7 failed",
0734:                        ps.getNodeValue("node7").getState() == Constants.Nd.READY);
0735:
0736:                usr.startActivity(project, "node7");
0737:                usr.terminateActivity(project, "node7");
0738:            }
0739:
0740:            /**
0741:             * Tests a iteration over the same activity
0742:             * Uses: Non automatic traditional activities
0743:             * 
0744:             * @throws Exception
0745:             */
0746:            public void testRepeatActivity() throws Exception {
0747:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0748:                        .getHome();
0749:                ProjectSession ps = projectSessionh.create();
0750:                ps.initModel("RepeatActivity");
0751:
0752:                ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0753:                ps.addNode("B", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0754:                ps.addNode("C", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0755:
0756:                ps.setNodeTraditional("A");
0757:                ps.setNodeTraditional("B");
0758:                ps.setNodeTraditional("C");
0759:
0760:                ps.setProperty("repeat", "true");
0761:                ps.setProperty("repetitions", "3");
0762:
0763:                ps.addEdge("A", "B");
0764:                String fromBtoC = ps.addEdge("B", "C");
0765:                ps.setEdgeCondition(fromBtoC, "repeat.equals(\"false\")");
0766:
0767:                String repeatScript = "import hero.interfaces.*;\n"
0768:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
0769:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
0770:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
0771:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
0772:                        + "  BnProjectPropertyValue repetitionsProp = prjSession.getProperty(\"repetitions\"); \n"
0773:                        + "  int repetitions = Integer.parseInt(repetitionsProp.getTheValue()); \n"
0774:                        + "  if (repetitions == 0) { \n"
0775:                        + "    prjSession.setProperty(\"repeat\", \"false\"); \n"
0776:                        + "  } else { \n "
0777:                        + "    repetitions--; \n"
0778:                        + "    prjSession.setProperty(\"repetitions\", Integer.toString(repetitions)); \n"
0779:                        + "  } \n" + "} \n";
0780:                ps.addNodeInterHook("B", "Repeat hook",
0781:                        Constants.Nd.BEFORETERMINATE,
0782:                        Constants.Hook.BSINTERACTIVE, repeatScript);
0783:
0784:                ps.addIteration("B", "B", "repeat.equals(\"true\")");
0785:
0786:                ps.checkModelDefinition();
0787:
0788:                // ******************************   MAIN   ******************************
0789:                ps.setUserRole("admin", "InitialRole");
0790:                String project = ps.instantiateProject("RepeatActivity");
0791:                UserSessionHome usersh = UserSessionUtil.getHome();
0792:                UserSession usr = usersh.create();
0793:
0794:                usr.startActivity(project, "A");
0795:                usr.terminateActivity(project, "A");
0796:                assertTrue(
0797:                        "Error in RepeatActivity, terminateActivity 'A': 'A' failed",
0798:                        ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
0799:                assertTrue(
0800:                        "Error in RepeatActivity, terminateActivity 'A': 'B' failed",
0801:                        ps.getNodeValue("B").getState() == Constants.Nd.READY);
0802:
0803:                int repetitions = 0;
0804:                while (repetitions < 3) {
0805:                    usr.startActivity(project, "B");
0806:                    usr.terminateActivity(project, "B");
0807:                    assertTrue(
0808:                            "Error in RepeatActivity, terminateActivity 'B': 'B' failed",
0809:                            ps.getNodeValue("B").getState() == Constants.Nd.READY);
0810:                    assertTrue(
0811:                            "Error in RepeatActivity, terminateActivity 'B': 'C' failed",
0812:                            ps.getNodeValue("C").getState() == Constants.Nd.INITIAL);
0813:                    repetitions++;
0814:                }
0815:                usr.startActivity(project, "B");
0816:                usr.terminateActivity(project, "B");
0817:                assertTrue(
0818:                        "Error in RepeatActivity, terminateActivity 'B': 'B' failed",
0819:                        ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
0820:                assertTrue(
0821:                        "Error in RepeatActivity, terminateActivity 'B': 'C' failed",
0822:                        ps.getNodeValue("C").getState() == Constants.Nd.READY);
0823:
0824:                usr.startActivity(project, "C");
0825:                usr.terminateActivity(project, "C");
0826:            }
0827:
0828:            /**
0829:             * Tests a iteration inside another iteration
0830:             * Uses: Non automatic traditional activities
0831:             * 
0832:             * @throws Exception
0833:             */
0834:            public void testIterationInsideIteration() throws Exception {
0835:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0836:                        .getHome();
0837:                ProjectSession ps = projectSessionh.create();
0838:                ps.initModel("IterationInsideIteration");
0839:
0840:                ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0841:                ps.addNode("B", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0842:                ps.addNode("C", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0843:                ps.addNode("D", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0844:
0845:                ps.setNodeTraditional("A");
0846:                ps.setNodeTraditional("B");
0847:                ps.setNodeTraditional("C");
0848:                ps.setNodeTraditional("D");
0849:
0850:                ps.setProperty("condition1", "true");
0851:                ps.setProperty("condition2", "true");
0852:                ps.setProperty("repetitions1", "3");
0853:                ps.setProperty("repetitions2", "3");
0854:
0855:                ps.addEdge("A", "B");
0856:                String fromBtoC = ps.addEdge("B", "C");
0857:                String fromCtoD = ps.addEdge("C", "D");
0858:                ps.setEdgeCondition(fromBtoC, "condition1.equals(\"false\")");
0859:                ps.setEdgeCondition(fromCtoD, "condition2.equals(\"false\")");
0860:
0861:                String repeat1Script = "import hero.interfaces.*;\n"
0862:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
0863:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
0864:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
0865:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
0866:                        + "  BnProjectPropertyValue repetitions1Prop = prjSession.getProperty(\"repetitions1\"); \n"
0867:                        + "  int repetitions1 = Integer.parseInt(repetitions1Prop.getTheValue()); \n"
0868:                        + "  repetitions1--; \n"
0869:                        + "  if (repetitions1 == 0) { \n"
0870:                        + "    prjSession.setProperty(\"repetitions1\", \"3\"); \n"
0871:                        + "    prjSession.setProperty(\"condition1\", \"false\"); \n"
0872:                        + "  } else { \n "
0873:                        + "    prjSession.setProperty(\"repetitions1\", Integer.toString(repetitions1)); \n"
0874:                        + "  } \n" + "} \n";
0875:                ps.addNodeInterHook("B", "Repeat1 hook",
0876:                        Constants.Nd.BEFORETERMINATE,
0877:                        Constants.Hook.BSINTERACTIVE, repeat1Script);
0878:                ps.addIteration("B", "B", "condition1.equals(\"true\")");
0879:
0880:                String repeat2Script = "import hero.interfaces.*;\n"
0881:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
0882:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
0883:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
0884:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
0885:                        + "  BnProjectPropertyValue repetitions2Prop = prjSession.getProperty(\"repetitions2\"); \n"
0886:                        + "  int repetitions2 = Integer.parseInt(repetitions2Prop.getTheValue()); \n"
0887:                        + "  repetitions2--; \n"
0888:                        + "  if (repetitions2 == 0) { \n"
0889:                        + "    prjSession.setProperty(\"condition2\", \"false\"); \n"
0890:                        + "  } else { \n "
0891:                        + "    prjSession.setProperty(\"repetitions2\", Integer.toString(repetitions2)); \n"
0892:                        + "    prjSession.setProperty(\"condition1\", \"true\"); \n"
0893:                        + "  } \n" + "} \n";
0894:                ps.addNodeInterHook("C", "Repeat2 hook",
0895:                        Constants.Nd.BEFORETERMINATE,
0896:                        Constants.Hook.BSINTERACTIVE, repeat2Script);
0897:                ps.addIteration("C", "A", "condition2.equals(\"true\")");
0898:
0899:                ps.checkModelDefinition();
0900:
0901:                // ******************************   MAIN   ******************************
0902:                ps.setUserRole("admin", "InitialRole");
0903:                String project = ps
0904:                        .instantiateProject("IterationInsideIteration");
0905:                UserSessionHome usersh = UserSessionUtil.getHome();
0906:                UserSession usr = usersh.create();
0907:
0908:                int repetitions1 = 0;
0909:                int repetitions2 = 0;
0910:                while (repetitions2 < 3) {
0911:                    usr.startActivity(project, "A");
0912:                    usr.terminateActivity(project, "A");
0913:                    assertTrue(
0914:                            "Error in IterationInsideIteration, terminateActivity 'A': 'A' failed",
0915:                            ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
0916:                    assertTrue(
0917:                            "Error in IterationInsideIteration, terminateActivity 'A': 'B' failed",
0918:                            ps.getNodeValue("B").getState() == Constants.Nd.READY);
0919:
0920:                    repetitions1 = 0;
0921:                    while (repetitions1 < 2) {
0922:                        usr.startActivity(project, "B");
0923:                        usr.terminateActivity(project, "B");
0924:                        assertTrue(
0925:                                "Error in IterationInsideIteration, terminateActivity 'B': 'B' failed",
0926:                                ps.getNodeValue("B").getState() == Constants.Nd.READY);
0927:                        assertTrue(
0928:                                "Error in IterationInsideIteration, terminateActivity 'B': 'C' failed",
0929:                                ps.getNodeValue("C").getState() == Constants.Nd.INITIAL);
0930:                        repetitions1++;
0931:                    }
0932:                    usr.startActivity(project, "B");
0933:                    usr.terminateActivity(project, "B");
0934:                    assertTrue(
0935:                            "Error in IterationInsideIteration, terminateActivity 'B': 'B' failed",
0936:                            ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
0937:                    assertTrue(
0938:                            "Error in IterationInsideIteration, terminateActivity 'B': 'C' failed",
0939:                            ps.getNodeValue("C").getState() == Constants.Nd.READY);
0940:                    assertTrue(
0941:                            "Error in IterationInsideIteration, terminateActivity 'B': 'D' failed",
0942:                            ps.getNodeValue("D").getState() == Constants.Nd.INITIAL);
0943:
0944:                    usr.startActivity(project, "C");
0945:                    usr.terminateActivity(project, "C");
0946:                    repetitions2++;
0947:                }
0948:                assertTrue(
0949:                        "Error in IterationInsideIteration, terminateActivity 'C': 'A' failed",
0950:                        ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
0951:                assertTrue(
0952:                        "Error in IterationInsideIteration, terminateActivity 'C': 'B' failed",
0953:                        ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
0954:                assertTrue(
0955:                        "Error in IterationInsideIteration, terminateActivity 'C': 'C' failed",
0956:                        ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
0957:                assertTrue(
0958:                        "Error in IterationInsideIteration, terminateActivity 'C': 'D' failed",
0959:                        ps.getNodeValue("D").getState() == Constants.Nd.READY);
0960:
0961:                usr.startActivity(project, "D");
0962:                usr.terminateActivity(project, "D");
0963:            }
0964:
0965:            /**
0966:             * Tests that we can loop throw two crossed iterations as we want
0967:             * Uses: Non automatic traditional activities
0968:             * 
0969:             * @throws Exception
0970:             */
0971:            public void testManualArbitraryCycles() throws Exception {
0972:                ProjectSessionHome projectSessionh = ProjectSessionUtil
0973:                        .getHome();
0974:                ProjectSession ps = projectSessionh.create();
0975:                ps.initModel("ManualArbitraryCycles");
0976:
0977:                ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0978:                ps.addNode("B", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0979:                ps.addNode("C", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0980:                ps.addNode("D", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0981:                ps.addNode("E", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0982:                ps.addNode("F", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
0983:
0984:                ps.setNodeTraditional("A");
0985:                ps.setNodeTraditional("B");
0986:                ps.setNodeTraditional("C");
0987:                ps.setNodeTraditional("D");
0988:                ps.setNodeTraditional("E");
0989:                ps.setNodeTraditional("F");
0990:
0991:                ps.setProperty("condition1", "true"); // first condition			
0992:                ps.setProperty("condition2", "true"); // second iteration
0993:                ps.setProperty("iterations", "2"); // number of iterations
0994:
0995:                ps.addEdge("A", "B");
0996:                ps.addEdge("B", "C");
0997:                ps.addEdge("C", "D");
0998:                String fromDtoE = ps.addEdge("D", "E");
0999:                String fromEtoF = ps.addEdge("E", "F");
1000:
1001:                ps.setEdgeCondition(fromDtoE, "condition1.equals(\"false\")");
1002:                ps.setEdgeCondition(fromEtoF, "condition2.equals(\"false\")");
1003:
1004:                String dScript = "import hero.interfaces.*;\n"
1005:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
1006:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
1007:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
1008:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
1009:                        + "  BnProjectPropertyValue condition1Prop = prjSession.getProperty(\"condition1\"); \n"
1010:                        + "  String condition1 = condition1Prop.getTheValue(); \n"
1011:                        + "  if (condition1.equals(\"true\")) { \n"
1012:                        + "    prjSession.setProperty(\"condition1\", \"false\"); \n"
1013:                        + "  } else { \n "
1014:                        + "    prjSession.setProperty(\"condition1\", \"true\"); \n"
1015:                        + "  } \n" + "} \n";
1016:                ps.addNodeInterHook("D", "D script",
1017:                        Constants.Nd.BEFORETERMINATE,
1018:                        Constants.Hook.BSINTERACTIVE, dScript);
1019:
1020:                String eScript = "import hero.interfaces.*;\n"
1021:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
1022:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
1023:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
1024:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
1025:                        + "  BnProjectPropertyValue iterationsProp = prjSession.getProperty(\"iterations\"); \n"
1026:                        + "  int iterations = Integer.parseInt(iterationsProp.getTheValue()); \n"
1027:                        + "  if (iterations == 0) { \n"
1028:                        + "    prjSession.setProperty(\"condition2\", \"false\"); \n"
1029:                        + "  } else { \n "
1030:                        + "    iterations--; \n"
1031:                        + "    prjSession.setProperty(\"iterations\", Integer.toString(iterations)); \n"
1032:                        + "  } \n" + "} \n";
1033:                ps.addNodeInterHook("E", "E script",
1034:                        Constants.Nd.BEFORETERMINATE,
1035:                        Constants.Hook.BSINTERACTIVE, eScript);
1036:
1037:                ps.addIteration("D", "B", "condition1.equals(\"true\")");
1038:                ps.addIteration("E", "C", "condition2.equals(\"true\")");
1039:
1040:                ps.checkModelDefinition();
1041:
1042:                // ******************************   MAIN   ******************************
1043:                ps.setUserRole("admin", "InitialRole");
1044:                String project = ps.instantiateProject("ManualArbitraryCycles");
1045:                UserSessionHome usersh = UserSessionUtil.getHome();
1046:                UserSession usr = usersh.create();
1047:
1048:                usr.startActivity(project, "A");
1049:                usr.terminateActivity(project, "A");
1050:                assertTrue(
1051:                        "Error in ArbitraryCycles, terminateActivity 'A': 'A' failed",
1052:                        ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
1053:                assertTrue(
1054:                        "Error in ArbitraryCycles, terminateActivity 'A': 'B' failed",
1055:                        ps.getNodeValue("B").getState() == Constants.Nd.READY);
1056:
1057:                usr.startActivity(project, "B");
1058:                usr.terminateActivity(project, "B");
1059:                assertTrue(
1060:                        "Error in ArbitraryCycles, terminateActivity 'B': 'B' failed",
1061:                        ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
1062:                assertTrue(
1063:                        "Error in ArbitraryCycles, terminateActivity 'B': 'C' failed",
1064:                        ps.getNodeValue("C").getState() == Constants.Nd.READY);
1065:
1066:                usr.startActivity(project, "C");
1067:                usr.terminateActivity(project, "C");
1068:                assertTrue(
1069:                        "Error in ArbitraryCycles, terminateActivity 'C': 'C' failed",
1070:                        ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
1071:                assertTrue(
1072:                        "Error in ArbitraryCycles, terminateActivity 'C': 'D' failed",
1073:                        ps.getNodeValue("D").getState() == Constants.Nd.READY);
1074:
1075:                int iterations = 0;
1076:                while (iterations < 2) {
1077:                    usr.startActivity(project, "D");
1078:                    usr.terminateActivity(project, "D");
1079:                    assertTrue(
1080:                            "Error in ArbitraryCycles, terminateActivity 'D': 'D' failed",
1081:                            ps.getNodeValue("D").getState() == Constants.Nd.TERMINATED);
1082:                    assertTrue(
1083:                            "Error in ArbitraryCycles, terminateActivity 'D': 'E' failed",
1084:                            ps.getNodeValue("E").getState() == Constants.Nd.READY);
1085:
1086:                    usr.startActivity(project, "E");
1087:                    usr.terminateActivity(project, "E");
1088:                    assertTrue(
1089:                            "Error in ArbitraryCycles, terminateActivity 'E': 'C' failed",
1090:                            ps.getNodeValue("C").getState() == Constants.Nd.READY);
1091:                    assertTrue(
1092:                            "Error in ArbitraryCycles, terminateActivity 'E': 'D' failed",
1093:                            ps.getNodeValue("D").getState() == Constants.Nd.INITIAL);
1094:                    assertTrue(
1095:                            "Error in ArbitraryCycles, terminateActivity 'E': 'E' failed",
1096:                            ps.getNodeValue("E").getState() == Constants.Nd.INITIAL);
1097:                    assertTrue(
1098:                            "Error in ArbitraryCycles, terminateActivity 'E': 'F' failed",
1099:                            ps.getNodeValue("F").getState() == Constants.Nd.INITIAL);
1100:
1101:                    usr.startActivity(project, "C");
1102:                    usr.terminateActivity(project, "C");
1103:                    assertTrue(
1104:                            "Error in ArbitraryCycles, terminateActivity 'C': 'C' failed",
1105:                            ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
1106:                    assertTrue(
1107:                            "Error in ArbitraryCycles, terminateActivity 'C': 'D' failed",
1108:                            ps.getNodeValue("D").getState() == Constants.Nd.READY);
1109:
1110:                    usr.startActivity(project, "D");
1111:                    usr.terminateActivity(project, "D");
1112:                    assertTrue(
1113:                            "Error in ArbitraryCycles, terminateActivity 'D': 'B' failed",
1114:                            ps.getNodeValue("B").getState() == Constants.Nd.READY);
1115:                    assertTrue(
1116:                            "Error in ArbitraryCycles, terminateActivity 'D': 'C' failed",
1117:                            ps.getNodeValue("C").getState() == Constants.Nd.INITIAL);
1118:                    assertTrue(
1119:                            "Error in ArbitraryCycles, terminateActivity 'D': 'D' failed",
1120:                            ps.getNodeValue("D").getState() == Constants.Nd.INITIAL);
1121:                    assertTrue(
1122:                            "Error in ArbitraryCycles, terminateActivity 'D': 'E' failed",
1123:                            ps.getNodeValue("E").getState() == Constants.Nd.INITIAL);
1124:
1125:                    usr.startActivity(project, "B");
1126:                    usr.terminateActivity(project, "B");
1127:                    assertTrue(
1128:                            "Error in ArbitraryCycles, terminateActivity 'B': 'B' failed",
1129:                            ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
1130:                    assertTrue(
1131:                            "Error in ArbitraryCycles, terminateActivity 'B': 'C' failed",
1132:                            ps.getNodeValue("C").getState() == Constants.Nd.READY);
1133:
1134:                    usr.startActivity(project, "C");
1135:                    usr.terminateActivity(project, "C");
1136:                    assertTrue(
1137:                            "Error in ArbitraryCycles, terminateActivity 'C': 'C' failed",
1138:                            ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
1139:                    assertTrue(
1140:                            "Error in ArbitraryCycles, terminateActivity 'C': 'D' failed",
1141:                            ps.getNodeValue("D").getState() == Constants.Nd.READY);
1142:
1143:                    iterations++;
1144:                }
1145:                usr.startActivity(project, "D");
1146:                usr.terminateActivity(project, "D");
1147:
1148:                usr.startActivity(project, "E");
1149:                usr.terminateActivity(project, "E");
1150:
1151:                assertTrue(
1152:                        "Error in ArbitraryCycles, terminateActivity 'E': 'A' failed",
1153:                        ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
1154:                assertTrue(
1155:                        "Error in ArbitraryCycles, terminateActivity 'E': 'B' failed",
1156:                        ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
1157:                assertTrue(
1158:                        "Error in ArbitraryCycles, terminateActivity 'E': 'C' failed",
1159:                        ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
1160:                assertTrue(
1161:                        "Error in ArbitraryCycles, terminateActivity 'E': 'D' failed",
1162:                        ps.getNodeValue("D").getState() == Constants.Nd.TERMINATED);
1163:                assertTrue(
1164:                        "Error in ArbitraryCycles, terminateActivity 'E': 'E' failed",
1165:                        ps.getNodeValue("E").getState() == Constants.Nd.TERMINATED);
1166:
1167:                usr.startActivity(project, "F");
1168:                usr.terminateActivity(project, "F");
1169:            }
1170:
1171:            /**
1172:             * Tests arbitrary cycles with automatic activities using random values to evaluate the conditions
1173:             * Uses: Automaticand non automatic traditional activities
1174:             * 
1175:             * @throws Exception
1176:             */
1177:            public void testAutomaticArbitraryCycles() throws Exception {
1178:                ProjectSessionHome projectSessionh = ProjectSessionUtil
1179:                        .getHome();
1180:                ProjectSession ps = projectSessionh.create();
1181:                ps.initModel("AutomaticArbitraryCycles");
1182:
1183:                ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1184:                ps.addNode("B",
1185:                        hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
1186:                ps.addNode("C",
1187:                        hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
1188:                ps.addNode("D",
1189:                        hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
1190:                ps.addNode("E",
1191:                        hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
1192:                ps.addNode("F", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1193:
1194:                ps.setNodeTraditional("A");
1195:                ps.setNodeTraditional("B");
1196:                ps.setNodeTraditional("C");
1197:                ps.setNodeTraditional("D");
1198:                ps.setNodeTraditional("E");
1199:                ps.setNodeTraditional("F");
1200:
1201:                ps.setProperty("condition1", "50"); // % to do 1st iteration			
1202:                ps.setProperty("condition2", "50"); // % to do 2nd iteration
1203:                ps.setProperty("randomNum", "0"); // random number who decides if we iterate or not
1204:
1205:                ps.addEdge("A", "B");
1206:                ps.addEdge("B", "C");
1207:                ps.addEdge("C", "D");
1208:                String fromDtoE = ps.addEdge("D", "E");
1209:                String fromEtoF = ps.addEdge("E", "F");
1210:
1211:                ps
1212:                        .setEdgeCondition(fromDtoE,
1213:                                "(new Integer(randomNum).intValue() >= new Integer(condition1).intValue())");
1214:                ps
1215:                        .setEdgeCondition(fromEtoF,
1216:                                "(new Integer(randomNum).intValue() >= new Integer(condition2).intValue())");
1217:                String generateRandomScript = "import hero.interfaces.*;\n"
1218:                        + "import java.util.Random; \n"
1219:                        + "beforeTerminate(Object b,Object n) {\n\n\n"
1220:                        + "  hero.interfaces.ProjectSessionHome pHome = (hero.interfaces.ProjectSessionHome) hero.interfaces.ProjectSessionUtil.getHome(); \n"
1221:                        + "  hero.interfaces.ProjectSession prjSession = pHome.create(); \n"
1222:                        + "  prjSession.initModel(n.getBnProject().getName()); \n"
1223:                        + "  Random generator = new Random(System.currentTimeMillis()); \n"
1224:                        + "  int newRnd = generator.nextInt(100); \n"
1225:                        + "  prjSession.setProperty(\"randomNum\", Integer.toString(newRnd)); \n"
1226:                        + "} \n";
1227:                ps
1228:                        .addNodeInterHook(
1229:                                "D",
1230:                                "Generates random number and saves it in 'randomNum' var",
1231:                                Constants.Nd.BEFORETERMINATE,
1232:                                Constants.Hook.BSINTERACTIVE,
1233:                                generateRandomScript);
1234:                ps
1235:                        .addNodeInterHook(
1236:                                "E",
1237:                                "Generates random number and saves it in 'randomNum' var",
1238:                                Constants.Nd.BEFORETERMINATE,
1239:                                Constants.Hook.BSINTERACTIVE,
1240:                                generateRandomScript);
1241:
1242:                ps
1243:                        .addIteration("D", "B",
1244:                                "(new Integer(randomNum).intValue() < new Integer(condition1).intValue())");
1245:                ps
1246:                        .addIteration("E", "C",
1247:                                "(new Integer(randomNum).intValue() < new Integer(condition2).intValue())");
1248:
1249:                ps.checkModelDefinition();
1250:
1251:                // ******************************   MAIN   ******************************
1252:                ps.setUserRole("admin", "InitialRole");
1253:                String project = ps
1254:                        .instantiateProject("AutomaticArbitraryCycles");
1255:                UserSessionHome usersh = UserSessionUtil.getHome();
1256:                UserSession usr = usersh.create();
1257:
1258:                usr.startActivity(project, "A");
1259:                usr.terminateActivity(project, "A");
1260:                assertTrue(
1261:                        "Error in ArbitraryCycles, terminateActivity 'A': 'A' failed",
1262:                        ps.getNodeValue("A").getState() == Constants.Nd.TERMINATED);
1263:                assertTrue(
1264:                        "Error in ArbitraryCycles, terminateActivity 'A': 'B' failed",
1265:                        ps.getNodeValue("B").getState() == Constants.Nd.TERMINATED);
1266:                assertTrue(
1267:                        "Error in ArbitraryCycles, terminateActivity 'A': 'C' failed",
1268:                        ps.getNodeValue("C").getState() == Constants.Nd.TERMINATED);
1269:                assertTrue(
1270:                        "Error in ArbitraryCycles, terminateActivity 'A': 'D' failed",
1271:                        ps.getNodeValue("D").getState() == Constants.Nd.TERMINATED);
1272:                assertTrue(
1273:                        "Error in ArbitraryCycles, terminateActivity 'A': 'E' failed",
1274:                        ps.getNodeValue("E").getState() == Constants.Nd.TERMINATED);
1275:
1276:                usr.startActivity(project, "F");
1277:                usr.terminateActivity(project, "F");
1278:            }
1279:
1280:            /** 
1281:             * Tests all constrains related with iteration definition model <br>
1282:             * All restrictions defined in hero.session.ProjectSessionBean checkModelDefinition() and related with iterations should be tested here <br>
1283:             * To do that, it forces to throw all the possible Exceptions<br>
1284:             * <br>
1285:             * 		****  MultiIterationsLeaving  ****<br>
1286:             *      *                                *<br>
1287:             *      *          path=A                *<br>
1288:             *      *     - - - - - - - -            *<br>
1289:             *      *     |       path=B |           *<br>
1290:             *      *     |      - - - - |           *<br>
1291:             *      *     |      |      ||path=D     *<br>
1292:             *      *     A----->B----->C----->D     *<br>
1293:             *      *                  |_|           *<br>
1294:             *      *                 path=C         *<br>
1295:             *      *                                *<br>
1296:             *      **********************************<br>
1297:             * <br>     
1298:             * Uses: Non automatic traditional activities<br>
1299:             *      
1300:             * @throws Exception
1301:             */
1302:            public void testIterationsConstrains() throws Exception {
1303:                ProjectSessionHome projectSessionh = ProjectSessionUtil
1304:                        .getHome();
1305:                ProjectSession ps = projectSessionh.create();
1306:                ps.initModel("MultiIterationsLeaving");
1307:
1308:                ps.addNode("A", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1309:                ps.addNode("B", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1310:                ps.addNode("C", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1311:                ps.addNode("D", hero.interfaces.Constants.Nd.AND_JOIN_NODE);
1312:
1313:                ps.setNodeTraditional("A");
1314:                ps.setNodeTraditional("B");
1315:                ps.setNodeTraditional("C");
1316:                ps.setNodeTraditional("D");
1317:
1318:                ps.setProperty("path", "A"); // Decides which iteration we have to take			
1319:
1320:                // ----- hero.session.ProjectSessionBean.addIteration checks: -----
1321:                // - checks if fromIteration node is reachable from toIteration node
1322:                ps.addEdge("A", "B");
1323:                //ps.addEdge("B", "C"); // We don't add this edge to force the Exception
1324:                String fromCtoD = ps.addEdge("C", "D");
1325:                ps.setEdgeCondition(fromCtoD, "path.equals(\"D\")");
1326:                try {
1327:                    ps.addIteration("C", "A", "path.equals(\"A\")");
1328:                    assertTrue(
1329:                            "Error in testIterationsConstrains, it's imposible to have and iteration here",
1330:                            false);
1331:                } catch (Exception e) { // Expected execution
1332:                    System.out.println(e);
1333:                }
1334:
1335:                ps.addEdge("B", "C"); // We don't add this edge to force the Exception
1336:                ps.addIteration("C", "A", "path.equals(\"A\")");
1337:
1338:                // - checks that there is not another iteration between from-->to nodes. (we cannot define 2 iterations over the same nodes)
1339:                try {
1340:                    ps.addIteration("C", "A", "path.equals(\"B\")");
1341:                    assertTrue(
1342:                            "Error in testIterationsConstrains, we cannot define 2 iterations over the same nodes",
1343:                            false);
1344:                } catch (Exception e) { // Expected execution
1345:                    System.out.println(e);
1346:                }
1347:                ps.addIteration("C", "B", "path.equals(\"B\")");
1348:                ps.addIteration("C", "C", "path.equals(\"C\")");
1349:
1350:                ps.checkModelDefinition();
1351:
1352:                // - tests with nodes that doesn't exist
1353:                try {
1354:                    ps.addIteration("D", "zzz", "true");
1355:                    assertTrue(
1356:                            "Error in testIterationsConstrains, cannot create an iteration with nodes that doesn't exit",
1357:                            false);
1358:                } catch (Exception e) { // Expected execution
1359:                    System.out.println(e);
1360:                }
1361:                try {
1362:                    ps.addIteration("zzz", "D", "true");
1363:                    assertTrue(
1364:                            "Error in testIterationsConstrains, cannot create an iteration with nodes that doesn't exit",
1365:                            false);
1366:                } catch (Exception e) { // Expected execution
1367:                    System.out.println(e);
1368:                }
1369:                // ----- end addIteration checks ------
1370:
1371:                // ----- hero.session.ProjectSessionBean.addEdge checks: -----
1372:                // - checks if the new edge creates a new cycle (we cannot put an edge from D to A because it creates a cycle)
1373:                try {
1374:                    ps.addEdge("C", "D");
1375:                    assertTrue(
1376:                            "Error in testIterationsConstrains, this edge creates a cycle",
1377:                            false);
1378:                } catch (Exception e) { // Expected execution
1379:                    System.out.println(e);
1380:                }
1381:                // ----- end addEdge checks ------
1382:
1383:                // ----- hero.session.ProjectSessionBean.checkModelDefinition checks: -----
1384:                // - checkIterationConstrains
1385:                // 		· checks if iteration's conditions are not empty (ex1: cond2.equals(""))
1386:                try {
1387:                    ps.addIteration("D", "D", "");
1388:                    ps.checkModelDefinition();
1389:                    assertTrue(
1390:                            "Error in testIterationsConstrains, iteration's condition cannot be \"\" (empty)",
1391:                            false);
1392:                } catch (Exception e) { // Expected execution
1393:                    System.out.println(e);
1394:                    ps.deleteIteration("D", "D");
1395:                }
1396:
1397:                //		· (NOTE: it is allowed to have "true" as condition -> in order to have an infinite process)
1398:                try {
1399:                    ps.addIteration("D", "D", "\"true\"");
1400:                    ps.checkModelDefinition();
1401:                    assertTrue(
1402:                            "Error in testIterationsConstrains, it is posible to have an iteration condition = \"true\"",
1403:                            true);
1404:                    ps.deleteIteration("D", "D");
1405:                } catch (Exception e) { // NOT Expected execution
1406:                    System.out.println(e);
1407:                }
1408:
1409:                //		· checks if exists a path between from--->to
1410:                try {
1411:                    ps.addIteration("D", "C", "\"true\"");
1412:                    ps.deleteEdge(fromCtoD); // delete the edge to force the error (we don't have path from C to D) 
1413:                    ps.checkModelDefinition();
1414:                    assertTrue(
1415:                            "Error in testIterationsConstrains, it's impossible to have a iteration because these nodes are not connected",
1416:                            false);
1417:                } catch (Exception e) { // Expected execution
1418:                    System.out.println(e);
1419:                    ps.deleteIteration("D", "C");
1420:                    fromCtoD = ps.addEdge("C", "D");
1421:                    ps.setEdgeCondition(fromCtoD, "path.equals(\"D\")");
1422:                }
1423:
1424:                //		· if we have more than one iteration starting in the same node -> checks that the iterations conditions are different (ex: new path condition != path1 condition)
1425:                try {
1426:                    ps.addIteration("D", "A", "path.equals(\"A\")");
1427:                    ps.addIteration("D", "B", "path.equals(\"A\")");
1428:                    ps.checkModelDefinition();
1429:                    assertTrue(
1430:                            "Error in testIterationsConstrains, iterations conditions must be different",
1431:                            false);
1432:                } catch (Exception e) { // Expected execution
1433:                    System.out.println(e);
1434:                    ps.deleteIteration("D", "A");
1435:                    ps.deleteIteration("D", "B");
1436:                }
1437:
1438:                // - checkMandatoryIterationConditions
1439:                // 		· checks mandatory conditions over the out edges of the nodes that create and extra exit point from the iteration (ex: condition in edge C--->D)
1440:                // 			throws an HeroException if these edges don't have a condition
1441:                try {
1442:                    ps.deleteEdge(fromCtoD); // delete the edge to delete the condition
1443:                    fromCtoD = ps.addEdge("C", "D");
1444:                    ps.checkModelDefinition();
1445:                    assertTrue(
1446:                            "Error in testIterationsConstrains, condition in edge C--->D has to exist",
1447:                            false);
1448:                } catch (Exception e) { // Expected execution
1449:                    System.out.println(e);
1450:                }
1451:
1452:                // 			throws an HeroException if the condition is empty (equals("")) 
1453:                try {
1454:                    ps.setEdgeCondition(fromCtoD, "");
1455:                    ps.checkModelDefinition();
1456:                    assertTrue(
1457:                            "Error in testIterationsConstrains, condition in edge C--->D cannot be \"\" (empty)",
1458:                            false);
1459:                } catch (Exception e) { // Expected execution
1460:                    System.out.println(e);
1461:                }
1462:
1463:                // 			throws an HeroException if the condition is "true" (equals("true"))
1464:                try {
1465:                    ps.deleteEdge(fromCtoD);
1466:                    fromCtoD = ps.addEdge("C", "D");
1467:                    ps.setEdgeCondition(fromCtoD, "true");
1468:                    ps.checkModelDefinition();
1469:                    assertTrue(
1470:                            "Error in testIterationsConstrains, condition in edge C--->D cannot be \"true\"",
1471:                            false);
1472:                } catch (Exception e) { // Expected execution
1473:                    System.out.println(e);
1474:                }
1475:
1476:                //		· checks if mandatory conditions over the out edges from the node that starts the iteration are different from the iteration's condition (ex: condition in edge C--->D & condition of iteration C--->A)
1477:                // 			throws an HeroException if the iteration's condition and out edge's condition are equal 
1478:                try {
1479:                    ps.deleteEdge(fromCtoD);
1480:                    fromCtoD = ps.addEdge("C", "D");
1481:                    ps.setEdgeCondition(fromCtoD, "path.equals(\"A\")");
1482:                    ps.checkModelDefinition();
1483:                    assertTrue(
1484:                            "Error in testIterationsConstrains, condition in edge C--->D cannot be equal to another iteration condition",
1485:                            false);
1486:                } catch (Exception e) { // Expected execution
1487:                    System.out.println(e);
1488:                }
1489:                // ----- end checkModelDefinition checks ------
1490:            }
1491:
1492:            /**
1493:             * It tests extra entry points incoming to an iteration<br>
1494:             * Uses: node2 = AND_JOIN and true conditions<br>
1495:             * 
1496:             * @throws Exception
1497:             */
1498:            public void testExtraEntryPointsSimple1() throws Exception {
1499:                ProjectSessionHome projectSessionh = ProjectSessionUtil
1500:                        .getHome();
1501:                ProjectSession ps = projectSessionh.create();
1502:                ps.initModel("ExtraEntryPointsSimple1");
1503:
1504:                // Properties
1505:                ps.setProperty("condA", "true");
1506:                ps.setProperty("condB", "true");
1507:                ps.setProperty("condC", "true");
1508:                ps.setProperty("iterate", "true");
1509:
1510:                // add Nodes
1511:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
1512:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
1513:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
1514:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
1515:                // extra entry points
1516:                ps.addNode("extraA", Constants.Nd.AND_JOIN_NODE);
1517:                ps.addNode("extraB", Constants.Nd.AND_JOIN_NODE);
1518:                ps.addNode("extraC", Constants.Nd.AND_JOIN_NODE);
1519:
1520:                ps.setNodeTraditional("node1");
1521:                ps.setNodeTraditional("node2");
1522:                ps.setNodeTraditional("node3");
1523:                ps.setNodeTraditional("node4");
1524:                ps.setNodeTraditional("extraA");
1525:                ps.setNodeTraditional("extraB");
1526:                ps.setNodeTraditional("extraC");
1527:
1528:                // add Edges
1529:                ps.addEdge("node1", "node2");
1530:                ps.addEdge("node2", "node3");
1531:                String from3to4 = ps.addEdge("node3", "node4");
1532:
1533:                String fromAto2 = ps.addEdge("extraA", "node2");
1534:                String fromBto2 = ps.addEdge("extraB", "node2");
1535:                String fromCto2 = ps.addEdge("extraC", "node2");
1536:
1537:                ps.setEdgeCondition(from3to4, "iterate.equals(\"false\")");
1538:                ps.setEdgeCondition(fromAto2, "condA.equals(\"true\")");
1539:                ps.setEdgeCondition(fromBto2, "condB.equals(\"true\")");
1540:                ps.setEdgeCondition(fromCto2, "condC.equals(\"true\")");
1541:
1542:                // set Iteration
1543:                ps.addIteration("node3", "node1", "iterate.equals(\"true\")");
1544:
1545:                // checks if model is defined correctly
1546:                ps.checkModelDefinition();
1547:
1548:                // ******************************   MAIN   ******************************
1549:                ps.setUserRole("admin", "InitialRole");
1550:                String project = ps
1551:                        .instantiateProject("ExtraEntryPointsSimple1");
1552:                UserSessionHome usersh = UserSessionUtil.getHome();
1553:                UserSession usr = usersh.create();
1554:
1555:                usr.startActivity(project, "extraA");
1556:                usr.startActivity(project, "extraB");
1557:                usr.startActivity(project, "extraC");
1558:                usr.terminateActivity(project, "extraA");
1559:                usr.terminateActivity(project, "extraB");
1560:                usr.terminateActivity(project, "extraC");
1561:                assertTrue(
1562:                        "Error in ExtraEntryPointsSimple1, extraA failed",
1563:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1564:                assertTrue(
1565:                        "Error in ExtraEntryPointsSimple1, extraB failed",
1566:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1567:                assertTrue(
1568:                        "Error in ExtraEntryPointsSimple1, extraC failed",
1569:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1570:                assertTrue(
1571:                        "Error in ExtraEntryPointsSimple1, node2 failed",
1572:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
1573:
1574:                int index = 0;
1575:                while (index < 2) {
1576:                    usr.startActivity(project, "node1");
1577:                    usr.terminateActivity(project, "node1");
1578:                    assertTrue(
1579:                            "Error in ExtraEntryPointsSimple1, terminateActivity node1: node1 failed",
1580:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
1581:                    assertTrue(
1582:                            "Error in ExtraEntryPointsSimple1, terminateActivity node1: node2 failed",
1583:                            ps.getNodeValue("node2").getState() == Constants.Nd.READY);
1584:
1585:                    usr.startActivity(project, "node2");
1586:                    usr.terminateActivity(project, "node2");
1587:                    assertTrue(
1588:                            "Error in ExtraEntryPointsSimple1, terminateActivity node2: node2 failed",
1589:                            ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1590:                    assertTrue(
1591:                            "Error in ExtraEntryPointsSimple1, terminateActivity node2: node3 failed",
1592:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
1593:
1594:                    usr.startActivity(project, "node3");
1595:                    usr.terminateActivity(project, "node3");
1596:                    assertTrue(
1597:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: node1 failed",
1598:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
1599:                    assertTrue(
1600:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: node2 failed",
1601:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
1602:                    assertTrue(
1603:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: node3 failed",
1604:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
1605:                    assertTrue(
1606:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: node4 failed",
1607:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
1608:                    assertTrue(
1609:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraA failed",
1610:                            ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1611:                    assertTrue(
1612:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraB failed",
1613:                            ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1614:                    assertTrue(
1615:                            "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraC failed",
1616:                            ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1617:                    index++;
1618:                }
1619:                usr.startActivity(project, "node1");
1620:                usr.terminateActivity(project, "node1");
1621:                assertTrue(
1622:                        "Error in ExtraEntryPointsSimple1, terminateActivity node1: node1 failed",
1623:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
1624:                assertTrue(
1625:                        "Error in ExtraEntryPointsSimple1, terminateActivity node1: node2 failed",
1626:                        ps.getNodeValue("node2").getState() == Constants.Nd.READY);
1627:
1628:                usr.startActivity(project, "node2");
1629:                usr.terminateActivity(project, "node2");
1630:                assertTrue(
1631:                        "Error in ExtraEntryPointsSimple1, terminateActivity node2: node2 failed",
1632:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1633:                assertTrue(
1634:                        "Error in ExtraEntryPointsSimple1, terminateActivity node2: node3 failed",
1635:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
1636:
1637:                usr.startActivity(project, "node3");
1638:                ps.setProperty("iterate", "false");
1639:                usr.terminateActivity(project, "node3");
1640:                assertTrue(
1641:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: node1 failed",
1642:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
1643:                assertTrue(
1644:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: node2 failed",
1645:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1646:                assertTrue(
1647:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: node3 failed",
1648:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
1649:                assertTrue(
1650:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: node4 failed",
1651:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
1652:                assertTrue(
1653:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraA failed",
1654:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1655:                assertTrue(
1656:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraB failed",
1657:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1658:                assertTrue(
1659:                        "Error in ExtraEntryPointsSimple1, terminateActivity node3: extraC failed",
1660:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1661:
1662:                usr.startActivity(project, "node4");
1663:                usr.terminateActivity(project, "node4");
1664:            }
1665:
1666:            /**
1667:             * It tests extra entry points incoming to an iteration<br>
1668:             * Uses: node2 = AND_JOIN and a false condition<br>
1669:             * 
1670:             * @throws Exception
1671:             */
1672:            public void testExtraEntryPointsSimple2() throws Exception {
1673:                ProjectSessionHome projectSessionh = ProjectSessionUtil
1674:                        .getHome();
1675:                ProjectSession ps = projectSessionh.create();
1676:                ps.initModel("ExtraEntryPointsSimple2");
1677:
1678:                // Properties
1679:                ps.setProperty("condA", "true");
1680:                ps.setProperty("condB", "true");
1681:                ps.setProperty("condC", "false");
1682:                ps.setProperty("iterate", "true");
1683:
1684:                // add Nodes
1685:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
1686:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
1687:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
1688:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
1689:                // extra entry points
1690:                ps.addNode("extraA", Constants.Nd.AND_JOIN_NODE);
1691:                ps.addNode("extraB", Constants.Nd.AND_JOIN_NODE);
1692:                ps.addNode("extraC", Constants.Nd.AND_JOIN_NODE);
1693:
1694:                ps.setNodeTraditional("node1");
1695:                ps.setNodeTraditional("node2");
1696:                ps.setNodeTraditional("node3");
1697:                ps.setNodeTraditional("node4");
1698:                ps.setNodeTraditional("extraA");
1699:                ps.setNodeTraditional("extraB");
1700:                ps.setNodeTraditional("extraC");
1701:
1702:                // add Edges
1703:                ps.addEdge("node1", "node2");
1704:                ps.addEdge("node2", "node3");
1705:                String from3to4 = ps.addEdge("node3", "node4");
1706:
1707:                String fromAto2 = ps.addEdge("extraA", "node2");
1708:                String fromBto2 = ps.addEdge("extraB", "node2");
1709:                String fromCto2 = ps.addEdge("extraC", "node2");
1710:
1711:                ps.setEdgeCondition(from3to4, "iterate.equals(\"false\")");
1712:                ps.setEdgeCondition(fromAto2, "condA.equals(\"true\")");
1713:                ps.setEdgeCondition(fromBto2, "condB.equals(\"true\")");
1714:                ps.setEdgeCondition(fromCto2, "condC.equals(\"true\")");
1715:
1716:                // set Iteration
1717:                ps.addIteration("node3", "node1", "iterate.equals(\"true\")");
1718:
1719:                // checks if model is defined correctly
1720:                ps.checkModelDefinition();
1721:
1722:                // ******************************   MAIN   ******************************
1723:                ps.setUserRole("admin", "InitialRole");
1724:                String project = ps
1725:                        .instantiateProject("ExtraEntryPointsSimple2");
1726:                UserSessionHome usersh = UserSessionUtil.getHome();
1727:                UserSession usr = usersh.create();
1728:
1729:                usr.startActivity(project, "extraA");
1730:                usr.startActivity(project, "extraB");
1731:                usr.startActivity(project, "extraC");
1732:                usr.terminateActivity(project, "extraA");
1733:                usr.terminateActivity(project, "extraB");
1734:                usr.terminateActivity(project, "extraC");
1735:                assertTrue(
1736:                        "Error in ExtraEntryPointsSimple2, extraA failed",
1737:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1738:                assertTrue(
1739:                        "Error in ExtraEntryPointsSimple2, extraB failed",
1740:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1741:                assertTrue(
1742:                        "Error in ExtraEntryPointsSimple2, extraC failed",
1743:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1744:                assertTrue("Error in ExtraEntryPointsSimple2, node2 failed", ps
1745:                        .getNodeValue("node2").getState() == Constants.Nd.DEAD);
1746:                assertTrue("Error in ExtraEntryPointsSimple2, node3 failed", ps
1747:                        .getNodeValue("node3").getState() == Constants.Nd.DEAD);
1748:                assertTrue("Error in ExtraEntryPointsSimple2, node4 failed", ps
1749:                        .getNodeValue("node4").getState() == Constants.Nd.DEAD);
1750:
1751:                usr.startActivity(project, "node1");
1752:                assertTrue(
1753:                        "Error in ExtraEntryPointsSimple2, startActivity node1: node1 failed",
1754:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
1755:                usr.terminateActivity(project, "node1");
1756:            }
1757:
1758:            private void incrementAndTestNodeProperty(ProjectSession ps,
1759:                    String node, String prop, int expectedNewValue)
1760:                    throws Exception {
1761:                BnNodePropertyValue propValue = ps.getNodeProperty(node, prop);
1762:                int counter = Integer.parseInt(propValue.getTheValue());
1763:                counter++;
1764:                if (counter != expectedNewValue) {
1765:                    throw new Exception(
1766:                            "Error in testExtraEntryPointsSimple3, counter in "
1767:                                    + node + " should be " + expectedNewValue);
1768:                }
1769:                ps.setNodeProperty(node, prop, Integer.toString(counter));
1770:            }
1771:
1772:            /**
1773:             * It tests extra entry points incoming to an iteration<br>
1774:             * Also tests node properties propagation : when it iterates takes the previous value.<br>
1775:             *    nodeProperties are not propagated through the iteration<br>
1776:             * 
1777:             * Uses: node2 = OR_JOIN and has a true in edge from an extra entry<br>
1778:             * 
1779:             * @throws Exception
1780:             */
1781:            public void testExtraEntryPointsSimple3() throws Exception {
1782:                ProjectSessionHome projectSessionh = ProjectSessionUtil
1783:                        .getHome();
1784:                ProjectSession ps = projectSessionh.create();
1785:                ps.initModel("ExtraEntryPointsSimple3");
1786:
1787:                // Properties
1788:                ps.setProperty("cond0", "true");
1789:                ps.setProperty("condA", "true");
1790:                ps.setProperty("condB", "false");
1791:                ps.setProperty("condC", "false");
1792:                ps.setProperty("iterate", "true");
1793:
1794:                // add Nodes
1795:                ps.addNode("initial", Constants.Nd.AND_JOIN_NODE);
1796:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
1797:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
1798:                ps.addNode("node2", Constants.Nd.OR_JOIN_NODE);
1799:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
1800:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
1801:                // extra entry points
1802:                ps.addNode("extraA", Constants.Nd.OR_JOIN_NODE);
1803:                ps.addNode("extraB", Constants.Nd.OR_JOIN_NODE);
1804:                ps.addNode("extraC", Constants.Nd.OR_JOIN_NODE);
1805:
1806:                ps.setNodeTraditional("initial");
1807:                ps.setNodeTraditional("node0");
1808:                ps.setNodeTraditional("node1");
1809:                ps.setNodeTraditional("node2");
1810:                ps.setNodeTraditional("node3");
1811:                ps.setNodeTraditional("node4");
1812:                ps.setNodeTraditional("extraA");
1813:                ps.setNodeTraditional("extraB");
1814:                ps.setNodeTraditional("extraC");
1815:
1816:                // Node properties
1817:                ps.setNodeProperty("extraA", "counter", "0", true);
1818:
1819:                // add Edges
1820:                String from0to1 = ps.addEdge("node0", "node1");
1821:                ps.addEdge("node1", "node2");
1822:                ps.addEdge("node2", "node3");
1823:                String from3to4 = ps.addEdge("node3", "node4");
1824:
1825:                String fromAto2 = ps.addEdge("extraA", "node2");
1826:                String fromBto2 = ps.addEdge("extraB", "node2");
1827:                String fromCto2 = ps.addEdge("extraC", "node2");
1828:
1829:                ps.setEdgeCondition(from3to4, "iterate.equals(\"false\")");
1830:                ps.setEdgeCondition(from0to1, "cond0.equals(\"true\")");
1831:                ps.setEdgeCondition(fromAto2, "condA.equals(\"true\")");
1832:                ps.setEdgeCondition(fromBto2, "condB.equals(\"true\")");
1833:                ps.setEdgeCondition(fromCto2, "condC.equals(\"true\")");
1834:
1835:                // set Iteration
1836:                ps.addIteration("node3", "node0", "iterate.equals(\"true\")");
1837:
1838:                // checks if model is defined correctly
1839:                ps.checkModelDefinition();
1840:
1841:                // ******************************   MAIN   ******************************
1842:                ps.setUserRole("admin", "InitialRole");
1843:                String project = ps
1844:                        .instantiateProject("ExtraEntryPointsSimple3");
1845:                UserSessionHome usersh = UserSessionUtil.getHome();
1846:                UserSession usr = usersh.create();
1847:
1848:                usr.startActivity(project, "extraB");
1849:                usr.terminateActivity(project, "extraB");
1850:                assertTrue(
1851:                        "Error in ExtraEntryPointsSimple3, extraB failed",
1852:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1853:                assertTrue(
1854:                        "Error in ExtraEntryPointsSimple3, node2 failed",
1855:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
1856:
1857:                usr.startActivity(project, "extraC");
1858:                usr.terminateActivity(project, "extraC");
1859:                assertTrue(
1860:                        "Error in ExtraEntryPointsSimple3, extraC failed",
1861:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1862:                assertTrue(
1863:                        "Error in ExtraEntryPointsSimple3, node2 failed",
1864:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
1865:
1866:                this .incrementAndTestNodeProperty(ps, "extraA", "counter", 1);
1867:                usr.startActivity(project, "extraA");
1868:                usr.terminateActivity(project, "extraA");
1869:                assertTrue(
1870:                        "Error in ExtraEntryPointsSimple3, extraA failed",
1871:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1872:                assertTrue("Error in ExtraEntryPointsSimple3, node2 failed", ps
1873:                        .getNodeValue("node2").getState() == Constants.Nd.READY);
1874:
1875:                int index = 0;
1876:                while (index < 2) {
1877:                    this .incrementAndTestNodeProperty(ps, "node2", "counter",
1878:                            2 + index);
1879:                    usr.startActivity(project, "node2");
1880:                    usr.terminateActivity(project, "node2");
1881:                    assertTrue(
1882:                            "Error in ExtraEntryPointsSimple3, terminateActivity node2: node2 failed",
1883:                            ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1884:                    assertTrue(
1885:                            "Error in ExtraEntryPointsSimple3, terminateActivity node2: node3 failed",
1886:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
1887:
1888:                    this .incrementAndTestNodeProperty(ps, "node3", "counter",
1889:                            3 + index);
1890:                    usr.startActivity(project, "node3");
1891:                    usr.terminateActivity(project, "node3");
1892:                    assertTrue(
1893:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: node0 failed",
1894:                            ps.getNodeValue("node0").getState() == Constants.Nd.READY);
1895:                    try {
1896:                        assertTrue(
1897:                                "Error in ExtraEntryPointsSimple3, terminateActivity node3: node1 failed",
1898:                                ps.getNodeValue("node1").getState() == Constants.Nd.INITIAL);
1899:                        assertTrue(
1900:                                "Error in ExtraEntryPointsSimple3, node1 should not be instantiated yet",
1901:                                false);
1902:                    } catch (Exception e) {
1903:                    } // Expected execution
1904:                    assertTrue(
1905:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: initial failed",
1906:                            ps.getNodeValue("initial").getState() == Constants.Nd.READY);
1907:                    assertTrue(
1908:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: node2 failed",
1909:                            ps.getNodeValue("node2").getState() == Constants.Nd.READY);
1910:                    assertTrue(
1911:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: node3 failed",
1912:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
1913:                    assertTrue(
1914:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: node4 failed",
1915:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
1916:                    assertTrue(
1917:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: extraA failed",
1918:                            ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
1919:                    assertTrue(
1920:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: extraB failed",
1921:                            ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
1922:                    assertTrue(
1923:                            "Error in ExtraEntryPointsSimple3, terminateActivity node3: extraC failed",
1924:                            ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
1925:                    index++;
1926:                }
1927:                this .incrementAndTestNodeProperty(ps, "node2", "counter", 4);
1928:                usr.startActivity(project, "node2");
1929:                usr.terminateActivity(project, "node2");
1930:                assertTrue(
1931:                        "Error in ExtraEntryPointsSimple3, terminateActivity node2: node2 failed",
1932:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1933:                assertTrue(
1934:                        "Error in ExtraEntryPointsSimple3, terminateActivity node2: node3 failed",
1935:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
1936:
1937:                this .incrementAndTestNodeProperty(ps, "node3", "counter", 5);
1938:                usr.startActivity(project, "node3");
1939:                ps.setProperty("iterate", "false");
1940:                usr.terminateActivity(project, "node3");
1941:                assertTrue(
1942:                        "Error in ExtraEntryPointsSimple3, terminateActivity node3: initial failed",
1943:                        ps.getNodeValue("initial").getState() == Constants.Nd.READY);
1944:                assertTrue(
1945:                        "Error in ExtraEntryPointsSimple3, terminateActivity node3: node0 failed",
1946:                        ps.getNodeValue("node0").getState() == Constants.Nd.READY);
1947:                assertTrue(
1948:                        "Error in ExtraEntryPointsSimple3, terminateActivity node3: node2 failed",
1949:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
1950:                assertTrue(
1951:                        "Error in ExtraEntryPointsSimple3, terminateActivity node3: node3 failed",
1952:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
1953:                assertTrue(
1954:                        "Error in ExtraEntryPointsSimple3, terminateActivity node3: node4 failed",
1955:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
1956:
1957:                this .incrementAndTestNodeProperty(ps, "node4", "counter", 6);
1958:                usr.startActivity(project, "node4");
1959:                usr.terminateActivity(project, "node4");
1960:
1961:                try {
1962:                    this 
1963:                            .incrementAndTestNodeProperty(ps, "node0",
1964:                                    "counter", 6);
1965:                    assertTrue(
1966:                            "Error in ExtraEntryPointsSimple3, node node0 : 'counter' nodeProperty it would not have to be defined here",
1967:                            false);
1968:                } catch (Exception e) {
1969:                } // expected behaviour
1970:                // Execute other activities to finish the process
1971:                usr.startActivity(project, "node0");
1972:                usr.terminateActivity(project, "node0");
1973:                assertTrue(
1974:                        "Error in ExtraEntryPointsSimple3, terminateActivity node0: node0 failed",
1975:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
1976:                assertTrue(
1977:                        "Error in ExtraEntryPointsSimple3, terminateActivity node0: node1 failed",
1978:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
1979:
1980:                try {
1981:                    this 
1982:                            .incrementAndTestNodeProperty(ps, "node1",
1983:                                    "counter", 7);
1984:                    assertTrue(
1985:                            "Error in ExtraEntryPointsSimple3, node node1 : 'counter' nodeProperty it would not have to be defined here",
1986:                            false);
1987:                } catch (Exception e) {
1988:                } // expected behaviour
1989:                usr.startActivity(project, "node1");
1990:                usr.terminateActivity(project, "node1");
1991:                assertTrue(
1992:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: initial failed",
1993:                        ps.getNodeValue("initial").getState() == Constants.Nd.READY);
1994:                assertTrue(
1995:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: node0 failed",
1996:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
1997:                assertTrue(
1998:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: node1 failed",
1999:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2000:                assertTrue(
2001:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: node2 failed",
2002:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
2003:                assertTrue(
2004:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: node3 failed",
2005:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
2006:                assertTrue(
2007:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: node4 failed",
2008:                        ps.getNodeValue("node4").getState() == Constants.Nd.TERMINATED);
2009:                assertTrue(
2010:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: extraA failed",
2011:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2012:                assertTrue(
2013:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: extraB failed",
2014:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2015:                assertTrue(
2016:                        "Error in ExtraEntryPointsSimple3, terminateActivity node1: extraC failed",
2017:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2018:
2019:                try {
2020:                    this .incrementAndTestNodeProperty(ps, "initial", "counter",
2021:                            0);
2022:                    assertTrue(
2023:                            "Error in ExtraEntryPointsSimple3, node initial : 'counter' nodeProperty it would not have to be defined here",
2024:                            false);
2025:                } catch (Exception e) {
2026:                } // expected behaviour
2027:                usr.startActivity(project, "initial");
2028:                usr.terminateActivity(project, "initial");
2029:            }
2030:
2031:            /**
2032:             * It tests extra entry points incoming to an iteration<br>
2033:             * Uses: node2 = OR_JOIN_AUTOMATIC and has a true condition from an extra entry<br>
2034:             * 		 in this case it will start node2 automaticly before node1 due to setIterationPathInitial()
2035:             * 
2036:             * @throws Exception
2037:             */
2038:            public void testExtraEntryPointsSimple4() throws Exception {
2039:                ProjectSessionHome projectSessionh = ProjectSessionUtil
2040:                        .getHome();
2041:                ProjectSession ps = projectSessionh.create();
2042:                ps.initModel("ExtraEntryPointsSimple4");
2043:
2044:                // Properties
2045:                ps.setProperty("condA", "false");
2046:                ps.setProperty("condB", "true");
2047:                ps.setProperty("condC", "false");
2048:                ps.setProperty("cond1", "false");
2049:                ps.setProperty("iterate", "true");
2050:
2051:                // add Nodes
2052:                ps.addNode("node1", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
2053:                ps.addNode("node2", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
2054:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
2055:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
2056:                // extra entry points
2057:                ps.addNode("extraA", Constants.Nd.OR_JOIN_NODE);
2058:                ps.addNode("extraB", Constants.Nd.OR_JOIN_NODE);
2059:                ps.addNode("extraC", Constants.Nd.OR_JOIN_NODE);
2060:
2061:                ps.setNodeTraditional("node1");
2062:                ps.setNodeTraditional("node2");
2063:                ps.setNodeTraditional("node3");
2064:                ps.setNodeTraditional("node4");
2065:                ps.setNodeTraditional("extraA");
2066:                ps.setNodeTraditional("extraB");
2067:                ps.setNodeTraditional("extraC");
2068:
2069:                // add Edges
2070:                String from1to2 = ps.addEdge("node1", "node2");
2071:                ps.addEdge("node2", "node3");
2072:                String from3to4 = ps.addEdge("node3", "node4");
2073:                String fromAto2 = ps.addEdge("extraA", "node2");
2074:                String fromBto2 = ps.addEdge("extraB", "node2");
2075:                String fromCto2 = ps.addEdge("extraC", "node2");
2076:
2077:                ps.setEdgeCondition(from1to2, "cond1.equals(\"true\")");
2078:                ps.setEdgeCondition(from3to4, "iterate.equals(\"false\")");
2079:                ps.setEdgeCondition(fromAto2, "condA.equals(\"true\")");
2080:                ps.setEdgeCondition(fromBto2, "condB.equals(\"true\")");
2081:                ps.setEdgeCondition(fromCto2, "condC.equals(\"true\")");
2082:
2083:                // set Iteration
2084:                ps.addIteration("node3", "node1", "iterate.equals(\"true\")");
2085:
2086:                // checks if model is defined correctly
2087:                ps.checkModelDefinition();
2088:
2089:                // ******************************   MAIN   ******************************
2090:                ps.setUserRole("admin", "InitialRole");
2091:                String project = ps
2092:                        .instantiateProject("ExtraEntryPointsSimple4");
2093:                UserSessionHome usersh = UserSessionUtil.getHome();
2094:                UserSession usr = usersh.create();
2095:
2096:                assertTrue(
2097:                        "Error in ExtraEntryPointsSimple4 node1 failed",
2098:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2099:
2100:                usr.startActivity(project, "extraC");
2101:                usr.terminateActivity(project, "extraC");
2102:                assertTrue(
2103:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraC: extraC failed",
2104:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2105:                assertTrue(
2106:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraC: node2 failed",
2107:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
2108:
2109:                usr.startActivity(project, "extraA");
2110:                usr.terminateActivity(project, "extraA");
2111:                assertTrue(
2112:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraA: extraA failed",
2113:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2114:                assertTrue(
2115:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraA: node2 failed",
2116:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
2117:
2118:                usr.startActivity(project, "extraB");
2119:                usr.terminateActivity(project, "extraB");
2120:                assertTrue(
2121:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraB: extraB failed",
2122:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2123:                assertTrue(
2124:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraB: node2 failed",
2125:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
2126:                assertTrue(
2127:                        "Error in ExtraEntryPointsSimple4, terminateActivity extraB: node3 failed",
2128:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
2129:
2130:                int index = 0;
2131:                while (index < 2) {
2132:                    usr.startActivity(project, "node3");
2133:                    usr.terminateActivity(project, "node3");
2134:                    assertTrue(
2135:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: node1 failed",
2136:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2137:                    assertTrue(
2138:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: node2 failed",
2139:                            ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
2140:                    assertTrue(
2141:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: node3 failed",
2142:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
2143:                    assertTrue(
2144:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: node4 failed",
2145:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2146:                    assertTrue(
2147:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraA failed",
2148:                            ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2149:                    assertTrue(
2150:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraB failed",
2151:                            ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2152:                    assertTrue(
2153:                            "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraC failed",
2154:                            ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2155:                    index++;
2156:                }
2157:
2158:                usr.startActivity(project, "node3");
2159:                ps.setProperty("iterate", "false");
2160:                usr.terminateActivity(project, "node3");
2161:                assertTrue(
2162:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: node1 failed",
2163:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2164:                assertTrue(
2165:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: node2 failed",
2166:                        ps.getNodeValue("node2").getState() == Constants.Nd.TERMINATED);
2167:                assertTrue(
2168:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: node3 failed",
2169:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
2170:                assertTrue(
2171:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: node4 failed",
2172:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
2173:                assertTrue(
2174:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraA failed",
2175:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2176:                assertTrue(
2177:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraB failed",
2178:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2179:                assertTrue(
2180:                        "Error in ExtraEntryPointsSimple4, terminateActivity node3: extraC failed",
2181:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2182:
2183:                usr.startActivity(project, "node4");
2184:                usr.terminateActivity(project, "node4");
2185:            }
2186:
2187:            /**
2188:             * It tests extra entry points incoming to an iteration<br>
2189:             * Uses: node2 = OR_JOIN and all the conditions are false<br>
2190:             * 		 it propagates a CANCEL
2191:             * 
2192:             * @throws Exception
2193:             */
2194:            public void testExtraEntryPointsSimple5() throws Exception {
2195:                ProjectSessionHome projectSessionh = ProjectSessionUtil
2196:                        .getHome();
2197:                ProjectSession ps = projectSessionh.create();
2198:                ps.initModel("ExtraEntryPointsSimple5");
2199:
2200:                // Properties
2201:                ps.setProperty("condA", "false");
2202:                ps.setProperty("condB", "false");
2203:                ps.setProperty("condC", "false");
2204:                ps.setProperty("cond1", "false");
2205:                ps.setProperty("iterate", "true");
2206:
2207:                // add Nodes
2208:                ps.addNode("node1", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
2209:                ps.addNode("node2", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
2210:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
2211:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
2212:                // extra entry points
2213:                ps.addNode("extraA", Constants.Nd.OR_JOIN_NODE);
2214:                ps.addNode("extraB", Constants.Nd.OR_JOIN_NODE);
2215:                ps.addNode("extraC", Constants.Nd.OR_JOIN_NODE);
2216:
2217:                ps.setNodeTraditional("node1");
2218:                ps.setNodeTraditional("node2");
2219:                ps.setNodeTraditional("node3");
2220:                ps.setNodeTraditional("node4");
2221:                ps.setNodeTraditional("extraA");
2222:                ps.setNodeTraditional("extraB");
2223:                ps.setNodeTraditional("extraC");
2224:
2225:                // add Edges
2226:                String from1to2 = ps.addEdge("node1", "node2");
2227:                ps.addEdge("node2", "node3");
2228:                String from3to4 = ps.addEdge("node3", "node4");
2229:                String fromAto2 = ps.addEdge("extraA", "node2");
2230:                String fromBto2 = ps.addEdge("extraB", "node2");
2231:                String fromCto2 = ps.addEdge("extraC", "node2");
2232:
2233:                ps.setEdgeCondition(from1to2, "cond1.equals(\"true\")");
2234:                ps.setEdgeCondition(from3to4, "iterate.equals(\"false\")");
2235:                ps.setEdgeCondition(fromAto2, "condA.equals(\"true\")");
2236:                ps.setEdgeCondition(fromBto2, "condB.equals(\"true\")");
2237:                ps.setEdgeCondition(fromCto2, "condC.equals(\"true\")");
2238:
2239:                // set Iteration
2240:                ps.addIteration("node3", "node1", "iterate.equals(\"true\")");
2241:
2242:                // checks if model is defined correctly
2243:                ps.checkModelDefinition();
2244:
2245:                // ******************************   MAIN   ******************************
2246:                ps.setUserRole("admin", "InitialRole");
2247:                String project = ps
2248:                        .instantiateProject("ExtraEntryPointsSimple5");
2249:                UserSessionHome usersh = UserSessionUtil.getHome();
2250:                UserSession usr = usersh.create();
2251:
2252:                assertTrue(
2253:                        "Error in ExtraEntryPointsSimple5 node1 failed",
2254:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2255:
2256:                usr.startActivity(project, "extraC");
2257:                usr.terminateActivity(project, "extraC");
2258:                assertTrue(
2259:                        "Error in ExtraEntryPointsSimple5, terminateActivity extraC: extraC failed",
2260:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2261:                assertTrue(
2262:                        "Error in ExtraEntryPointsSimple5, terminateActivity extraC: node2 failed",
2263:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
2264:
2265:                usr.startActivity(project, "extraA");
2266:                usr.terminateActivity(project, "extraA");
2267:                assertTrue(
2268:                        "Error in ExtraEntryPointsSimple5, terminateActivity extraA: extraA failed",
2269:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2270:                assertTrue(
2271:                        "Error in ExtraEntryPointsSimple5, terminateActivity extraA: node2 failed",
2272:                        ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
2273:
2274:                usr.startActivity(project, "extraB");
2275:                usr.terminateActivity(project, "extraB");
2276:            }
2277:
2278:            /**
2279:             * Based on testFinalizeIteration() (iterates 3 times and then finalizes the iteration)<br>
2280:             * Now with more entry points. Normal behaviour.<br>
2281:             * Uses: Automatic and non automatic traditional activities<br>
2282:             *       Extra entry points = AND_JOIN (node3 & node5B)<br>
2283:             * 
2284:             * @throws Exception
2285:             */
2286:            public void testExtraEntryPointsBig1() throws Exception {
2287:                ProjectSessionHome projectSessionh = ProjectSessionUtil
2288:                        .getHome();
2289:                ProjectSession ps = projectSessionh.create();
2290:                ps.initModel("ExtraEntryPointsBig1");
2291:
2292:                // Properties
2293:                ps.setProperty("condA", "true");
2294:                ps.setProperty("iterate", "true");
2295:
2296:                // add Nodes
2297:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
2298:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
2299:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
2300:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
2301:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
2302:                ps.addNode("node5", Constants.Nd.AND_JOIN_NODE);
2303:                ps.addNode("node5A", Constants.Nd.AND_JOIN_NODE);
2304:                ps.addNode("node5B", Constants.Nd.AND_JOIN_NODE);
2305:                ps.addNode("node6", Constants.Nd.AND_JOIN_NODE);
2306:                ps.addNode("node7", Constants.Nd.AND_JOIN_NODE);
2307:                ps.addNode("node8", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2308:                ps.addNode("node9", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2309:                // extra entry points
2310:                ps.addNode("extraA", Constants.Nd.AND_JOIN_NODE);
2311:                ps.addNode("extraB", Constants.Nd.AND_JOIN_NODE);
2312:                ps.addNode("extraC", Constants.Nd.AND_JOIN_NODE);
2313:                ps.addNode("extraA0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2314:                ps.addNode("extraB0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2315:                ps.addNode("extraB1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2316:                ps.addNode("extraC0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2317:                ps.addNode("extraC1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2318:                ps.addNode("extraC2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2319:                ps.addNode("extraZ0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2320:                ps.addNode("extraZ1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2321:                ps.addNode("extraZ2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2322:
2323:                ps.setNodeTraditional("node0");
2324:                ps.setNodeTraditional("node1");
2325:                ps.setNodeTraditional("node2");
2326:                ps.setNodeTraditional("node3");
2327:                ps.setNodeTraditional("node4");
2328:                ps.setNodeTraditional("node5");
2329:                ps.setNodeTraditional("node5A");
2330:                ps.setNodeTraditional("node5B");
2331:                ps.setNodeTraditional("node6");
2332:                ps.setNodeTraditional("node7");
2333:                ps.setNodeTraditional("node8");
2334:                ps.setNodeTraditional("node9");
2335:                ps.setNodeTraditional("extraA");
2336:                ps.setNodeTraditional("extraB");
2337:                ps.setNodeTraditional("extraC");
2338:                ps.setNodeTraditional("extraA0");
2339:                ps.setNodeTraditional("extraB0");
2340:                ps.setNodeTraditional("extraB1");
2341:                ps.setNodeTraditional("extraC0");
2342:                ps.setNodeTraditional("extraC1");
2343:                ps.setNodeTraditional("extraC2");
2344:                ps.setNodeTraditional("extraZ0");
2345:                ps.setNodeTraditional("extraZ1");
2346:                ps.setNodeTraditional("extraZ2");
2347:
2348:                // add Edges
2349:                ps.addEdge("node0", "node1");
2350:                ps.addEdge("node1", "node3");
2351:                ps.addEdge("node1", "node4");
2352:                ps.addEdge("node1", "node5");
2353:                String from3to6 = ps.addEdge("node3", "node6");
2354:                String from3to8 = ps.addEdge("node3", "node8");
2355:                String from4to2 = ps.addEdge("node4", "node2");
2356:                String from4to6 = ps.addEdge("node4", "node6");
2357:                ps.addEdge("node5", "node4");
2358:                ps.addEdge("node5", "node6");
2359:                ps.addEdge("node5", "node5A");
2360:                ps.addEdge("node5A", "node5B");
2361:                ps.addEdge("node5B", "node6");
2362:                String from6to7 = ps.addEdge("node6", "node7");
2363:                ps.addEdge("node8", "node9");
2364:
2365:                String fromAto3 = ps.addEdge("extraA", "node3");
2366:                ps.addEdge("extraB", "node3");
2367:                ps.addEdge("extraC", "node3");
2368:                ps.addEdge("extraA0", "extraA");
2369:                ps.addEdge("extraB0", "extraB");
2370:                ps.addEdge("extraB1", "extraB");
2371:                ps.addEdge("extraC0", "extraC");
2372:                ps.addEdge("extraC1", "extraC");
2373:                ps.addEdge("extraC2", "extraC");
2374:                ps.addEdge("extraZ0", "node5B");
2375:                ps.addEdge("extraZ1", "node5B");
2376:                ps.addEdge("extraZ2", "node5B");
2377:
2378:                // set conditions to exit from the iteration (they are mandatory)
2379:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
2380:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
2381:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
2382:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
2383:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
2384:                ps.setEdgeCondition(fromAto3, "condA.equals(\"true\")");
2385:
2386:                // set Iteration
2387:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
2388:
2389:                // checks if model is defined correctly
2390:                ps.checkModelDefinition();
2391:
2392:                // ******************************   MAIN   ******************************
2393:                ps.setUserRole("admin", "InitialRole");
2394:                String project = ps.instantiateProject("ExtraEntryPointsBig1");
2395:                UserSessionHome usersh = UserSessionUtil.getHome();
2396:                UserSession usr = usersh.create();
2397:
2398:                assertTrue(
2399:                        "Error in ExtraEntryPointsBig1, extraA0 failed",
2400:                        ps.getNodeValue("extraA0").getState() == Constants.Nd.TERMINATED);
2401:                assertTrue(
2402:                        "Error in ExtraEntryPointsBig1, extraB0 failed",
2403:                        ps.getNodeValue("extraB0").getState() == Constants.Nd.TERMINATED);
2404:                assertTrue(
2405:                        "Error in ExtraEntryPointsBig1, extraB1 failed",
2406:                        ps.getNodeValue("extraB1").getState() == Constants.Nd.TERMINATED);
2407:                assertTrue(
2408:                        "Error in ExtraEntryPointsBig1, extraC0 failed",
2409:                        ps.getNodeValue("extraC0").getState() == Constants.Nd.TERMINATED);
2410:                assertTrue(
2411:                        "Error in ExtraEntryPointsBig1, extraC1 failed",
2412:                        ps.getNodeValue("extraC1").getState() == Constants.Nd.TERMINATED);
2413:                assertTrue(
2414:                        "Error in ExtraEntryPointsBig1, extraC2 failed",
2415:                        ps.getNodeValue("extraC2").getState() == Constants.Nd.TERMINATED);
2416:                assertTrue(
2417:                        "Error in ExtraEntryPointsBig1, extraZ0 failed",
2418:                        ps.getNodeValue("extraZ0").getState() == Constants.Nd.TERMINATED);
2419:                assertTrue(
2420:                        "Error in ExtraEntryPointsBig1, extraZ1 failed",
2421:                        ps.getNodeValue("extraZ1").getState() == Constants.Nd.TERMINATED);
2422:                assertTrue(
2423:                        "Error in ExtraEntryPointsBig1, extraZ2 failed",
2424:                        ps.getNodeValue("extraZ2").getState() == Constants.Nd.TERMINATED);
2425:
2426:                usr.startActivity(project, "extraA");
2427:                usr.startActivity(project, "extraB");
2428:                usr.startActivity(project, "extraC");
2429:                usr.terminateActivity(project, "extraC");
2430:                usr.terminateActivity(project, "extraB");
2431:                usr.terminateActivity(project, "extraA");
2432:                assertTrue(
2433:                        "Error in ExtraEntryPointsBig1, extraA failed",
2434:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2435:                assertTrue(
2436:                        "Error in ExtraEntryPointsBig1, extraB failed",
2437:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2438:                assertTrue(
2439:                        "Error in ExtraEntryPointsBig1, extraC failed",
2440:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2441:
2442:                usr.startActivity(project, "node0");
2443:                assertTrue(
2444:                        "Error in ExtraEntryPointsBig1, startActivity node0: node0 failed",
2445:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
2446:                assertTrue(
2447:                        "Error in ExtraEntryPointsBig1, startActivity node0: node1 failed",
2448:                        ps.getNodeValue("node1").getState() == Constants.Nd.INITIAL);
2449:
2450:                usr.terminateActivity(project, "node0");
2451:                assertTrue(
2452:                        "Error in ExtraEntryPointsBig1, terminateActivity node0: node0 failed",
2453:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
2454:                assertTrue(
2455:                        "Error in ExtraEntryPointsBig1, terminateActivity node0: node1 failed",
2456:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
2457:
2458:                int index = 0;
2459:                while (index < 2) {
2460:                    usr.startActivity(project, "node1");
2461:                    assertTrue(
2462:                            "Error in ExtraEntryPointsBig1, startActivity node1: node1 failed",
2463:                            ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
2464:                    assertTrue(
2465:                            "Error in ExtraEntryPointsBig1, startActivity node1: node3 failed",
2466:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
2467:                    assertTrue(
2468:                            "Error in ExtraEntryPointsBig1, startActivity node1: node4 failed",
2469:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2470:                    assertTrue(
2471:                            "Error in ExtraEntryPointsBig1, startActivity node1: node5 failed",
2472:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
2473:
2474:                    usr.terminateActivity(project, "node1");
2475:                    assertTrue(
2476:                            "Error in ExtraEntryPointsBig1, terminateActivity node1: node1 failed",
2477:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2478:                    assertTrue(
2479:                            "Error in ExtraEntryPointsBig1, terminateActivity node1: node3 failed",
2480:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
2481:                    assertTrue(
2482:                            "Error in ExtraEntryPointsBig1, terminateActivity node1: node4 failed",
2483:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2484:                    assertTrue(
2485:                            "Error in ExtraEntryPointsBig1, terminateActivity node1: node5 failed",
2486:                            ps.getNodeValue("node5").getState() == Constants.Nd.READY);
2487:
2488:                    usr.startActivity(project, "node3");
2489:                    usr.terminateActivity(project, "node3");
2490:                    assertTrue(
2491:                            "Error in ExtraEntryPointsBig1, terminateActivity node3: node8 failed",
2492:                            ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
2493:                    assertTrue(
2494:                            "Error in ExtraEntryPointsBig1, terminateActivity node3: node9 failed",
2495:                            ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
2496:
2497:                    usr.startActivity(project, "node5");
2498:                    usr.terminateActivity(project, "node5");
2499:                    assertTrue(
2500:                            "Error in ExtraEntryPointsBig1, terminateActivity node1: node4 failed",
2501:                            ps.getNodeValue("node4").getState() == Constants.Nd.READY);
2502:
2503:                    usr.startActivity(project, "node4");
2504:                    usr.terminateActivity(project, "node4");
2505:                    assertTrue(
2506:                            "Error in ExtraEntryPointsBig1, terminateActivity node4: node2 failed",
2507:                            ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
2508:
2509:                    try {
2510:                        usr.startActivity(project, "node2");
2511:                        assertTrue(
2512:                                "Error in ExtraEntryPointsBig1, startActivity node2: node2 should be failed",
2513:                                false);
2514:                    } catch (Exception e) {
2515:                    }
2516:                    try {
2517:                        usr.terminateActivity(project, "node2");
2518:                        assertTrue(
2519:                                "Error in ExtraEntryPointsBig1, terminateActivity node2: node2 should be failed",
2520:                                false);
2521:                    } catch (Exception e) {
2522:                    }
2523:
2524:                    usr.startActivity(project, "node5A");
2525:                    usr.terminateActivity(project, "node5A");
2526:
2527:                    usr.startActivity(project, "node5B");
2528:                    usr.terminateActivity(project, "node5B");
2529:
2530:                    usr.startActivity(project, "node6");
2531:                    usr.terminateActivity(project, "node6");
2532:                    assertTrue(
2533:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node0 failed",
2534:                            ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
2535:                    assertTrue(
2536:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node1 failed",
2537:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
2538:                    assertTrue(
2539:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node2 failed",
2540:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
2541:                    assertTrue(
2542:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node3 failed",
2543:                            ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
2544:                    assertTrue(
2545:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node4 failed",
2546:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2547:                    assertTrue(
2548:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node5 failed",
2549:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
2550:                    assertTrue(
2551:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node5A failed",
2552:                            ps.getNodeValue("node5A").getState() == Constants.Nd.INITIAL);
2553:                    assertTrue(
2554:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node5B failed",
2555:                            ps.getNodeValue("node5B").getState() == Constants.Nd.INITIAL);
2556:                    assertTrue(
2557:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node6 failed",
2558:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
2559:                    assertTrue(
2560:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node7 failed",
2561:                            ps.getNodeValue("node7").getState() == Constants.Nd.INITIAL);
2562:                    assertTrue(
2563:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node8 failed",
2564:                            ps.getNodeValue("node8").getState() == Constants.Nd.INITIAL);
2565:                    assertTrue(
2566:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: node9 failed",
2567:                            ps.getNodeValue("node9").getState() == Constants.Nd.INITIAL);
2568:                    assertTrue(
2569:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraA failed",
2570:                            ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2571:                    assertTrue(
2572:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraB failed",
2573:                            ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2574:                    assertTrue(
2575:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraC failed",
2576:                            ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2577:                    assertTrue(
2578:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraA0 failed",
2579:                            ps.getNodeValue("extraA0").getState() == Constants.Nd.TERMINATED);
2580:                    assertTrue(
2581:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraB0 failed",
2582:                            ps.getNodeValue("extraB0").getState() == Constants.Nd.TERMINATED);
2583:                    assertTrue(
2584:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraB1 failed",
2585:                            ps.getNodeValue("extraB1").getState() == Constants.Nd.TERMINATED);
2586:                    assertTrue(
2587:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraC0 failed",
2588:                            ps.getNodeValue("extraC0").getState() == Constants.Nd.TERMINATED);
2589:                    assertTrue(
2590:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraC1 failed",
2591:                            ps.getNodeValue("extraC1").getState() == Constants.Nd.TERMINATED);
2592:                    assertTrue(
2593:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraC2 failed",
2594:                            ps.getNodeValue("extraC2").getState() == Constants.Nd.TERMINATED);
2595:                    assertTrue(
2596:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraZ0 failed",
2597:                            ps.getNodeValue("extraZ0").getState() == Constants.Nd.TERMINATED);
2598:                    assertTrue(
2599:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraZ1 failed",
2600:                            ps.getNodeValue("extraZ1").getState() == Constants.Nd.TERMINATED);
2601:                    assertTrue(
2602:                            "Error in ExtraEntryPointsBig1, terminateActivity node6: extraZ2 failed",
2603:                            ps.getNodeValue("extraZ2").getState() == Constants.Nd.TERMINATED);
2604:
2605:                    index++;
2606:                }
2607:                usr.startActivity(project, "node1");
2608:                assertTrue(
2609:                        "Error in ExtraEntryPointsBig1, startActivity node1: node1 failed",
2610:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
2611:                assertTrue(
2612:                        "Error in ExtraEntryPointsBig1, startActivity node1: node3 failed",
2613:                        ps.getNodeValue("node3").getState() == Constants.Nd.INITIAL);
2614:                assertTrue(
2615:                        "Error in ExtraEntryPointsBig1, startActivity node1: node4 failed",
2616:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2617:                assertTrue(
2618:                        "Error in ExtraEntryPointsBig1, startActivity node1: node5 failed",
2619:                        ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
2620:
2621:                usr.terminateActivity(project, "node1");
2622:                assertTrue(
2623:                        "Error in ExtraEntryPointsBig1, terminateActivity node1: node1 failed",
2624:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2625:                assertTrue(
2626:                        "Error in ExtraEntryPointsBig1, terminateActivity node1: node3 failed",
2627:                        ps.getNodeValue("node3").getState() == Constants.Nd.READY);
2628:                assertTrue(
2629:                        "Error in ExtraEntryPointsBig1, terminateActivity node1: node4 failed",
2630:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2631:                assertTrue(
2632:                        "Error in ExtraEntryPointsBig1, terminateActivity node1: node5 failed",
2633:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
2634:
2635:                usr.startActivity(project, "node3");
2636:                usr.terminateActivity(project, "node3");
2637:                assertTrue(
2638:                        "Error in ExtraEntryPointsBig1, terminateActivity node3: node8 failed",
2639:                        ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
2640:                assertTrue(
2641:                        "Error in ExtraEntryPointsBig1, terminateActivity node3: node9 failed",
2642:                        ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
2643:
2644:                usr.startActivity(project, "node5");
2645:                usr.terminateActivity(project, "node5");
2646:                assertTrue(
2647:                        "Error in ExtraEntryPointsBig1, terminateActivity node1: node4 failed",
2648:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
2649:
2650:                usr.startActivity(project, "node4");
2651:                usr.terminateActivity(project, "node4");
2652:                assertTrue(
2653:                        "Error in ExtraEntryPointsBig1, terminateActivity node4: node2 failed",
2654:                        ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
2655:
2656:                usr.startActivity(project, "node5A");
2657:                usr.terminateActivity(project, "node5A");
2658:
2659:                usr.startActivity(project, "node5B");
2660:                usr.terminateActivity(project, "node5B");
2661:
2662:                // Finally, it will finalize throw node7.  Node2, node8 and node9 will become DEAD
2663:                ps.setProperty("iterate", "false");
2664:
2665:                usr.startActivity(project, "node6");
2666:                usr.terminateActivity(project, "node6");
2667:                assertTrue(
2668:                        "Error in ExtraEntryPointsBig1, terminateActivity node6, after iterate: node6 failed",
2669:                        ps.getNodeValue("node6").getState() == Constants.Nd.TERMINATED);
2670:                assertTrue(
2671:                        "Error in ExtraEntryPointsBig1, terminateActivity node6, after iterate: node7 failed",
2672:                        ps.getNodeValue("node7").getState() == Constants.Nd.READY);
2673:
2674:                usr.startActivity(project, "node7");
2675:                usr.terminateActivity(project, "node7");
2676:            }
2677:
2678:            /**
2679:             * Based on testExtraEntryPointsBig1()<br>
2680:             * Now extraA node has a false condition that CANCELS some nodes inside the iteration<br>
2681:             * Uses: Automatic and non automatic traditional activities<br>
2682:             *       Extra entry points : node3 = AND_JOIN_AUTOMATIC -- node5B = AND_JOIN<br>
2683:             * 
2684:             * @throws Exception
2685:             */
2686:            public void testExtraEntryPointsBig2() throws Exception {
2687:                ProjectSessionHome projectSessionh = ProjectSessionUtil
2688:                        .getHome();
2689:                ProjectSession ps = projectSessionh.create();
2690:                ps.initModel("ExtraEntryPointsBig2");
2691:
2692:                // Properties
2693:                ps.setProperty("condA", "false");
2694:                ps.setProperty("iterate", "true");
2695:
2696:                // add Nodes
2697:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
2698:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
2699:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
2700:                ps.addNode("node3", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2701:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
2702:                ps.addNode("node5", Constants.Nd.AND_JOIN_NODE);
2703:                ps.addNode("node5A", Constants.Nd.AND_JOIN_NODE);
2704:                ps.addNode("node5B", Constants.Nd.AND_JOIN_NODE);
2705:                ps.addNode("node6", Constants.Nd.AND_JOIN_NODE);
2706:                ps.addNode("node7", Constants.Nd.AND_JOIN_NODE);
2707:                ps.addNode("node8", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2708:                ps.addNode("node9", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2709:                // extra entry points
2710:                ps.addNode("extraA", Constants.Nd.AND_JOIN_NODE);
2711:                ps.addNode("extraB", Constants.Nd.AND_JOIN_NODE);
2712:                ps.addNode("extraC", Constants.Nd.AND_JOIN_NODE);
2713:                ps.addNode("extraA0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2714:                ps.addNode("extraB0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2715:                ps.addNode("extraB1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2716:                ps.addNode("extraC0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2717:                ps.addNode("extraC1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2718:                ps.addNode("extraC2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2719:                ps.addNode("extraZ0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2720:                ps.addNode("extraZ1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2721:                ps.addNode("extraZ2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
2722:
2723:                ps.setNodeTraditional("node0");
2724:                ps.setNodeTraditional("node1");
2725:                ps.setNodeTraditional("node2");
2726:                ps.setNodeTraditional("node3");
2727:                ps.setNodeTraditional("node4");
2728:                ps.setNodeTraditional("node5");
2729:                ps.setNodeTraditional("node5A");
2730:                ps.setNodeTraditional("node5B");
2731:                ps.setNodeTraditional("node6");
2732:                ps.setNodeTraditional("node7");
2733:                ps.setNodeTraditional("node8");
2734:                ps.setNodeTraditional("node9");
2735:                ps.setNodeTraditional("extraA");
2736:                ps.setNodeTraditional("extraB");
2737:                ps.setNodeTraditional("extraC");
2738:                ps.setNodeTraditional("extraA0");
2739:                ps.setNodeTraditional("extraB0");
2740:                ps.setNodeTraditional("extraB1");
2741:                ps.setNodeTraditional("extraC0");
2742:                ps.setNodeTraditional("extraC1");
2743:                ps.setNodeTraditional("extraC2");
2744:                ps.setNodeTraditional("extraZ0");
2745:                ps.setNodeTraditional("extraZ1");
2746:                ps.setNodeTraditional("extraZ2");
2747:
2748:                // add Edges
2749:                ps.addEdge("node0", "node1");
2750:                ps.addEdge("node1", "node3");
2751:                ps.addEdge("node1", "node4");
2752:                ps.addEdge("node1", "node5");
2753:                String from3to6 = ps.addEdge("node3", "node6");
2754:                String from3to8 = ps.addEdge("node3", "node8");
2755:                String from4to2 = ps.addEdge("node4", "node2");
2756:                String from4to6 = ps.addEdge("node4", "node6");
2757:                ps.addEdge("node5", "node4");
2758:                ps.addEdge("node5", "node6");
2759:                ps.addEdge("node5", "node5A");
2760:                ps.addEdge("node5A", "node5B");
2761:                ps.addEdge("node5B", "node6");
2762:                String from6to7 = ps.addEdge("node6", "node7");
2763:                ps.addEdge("node8", "node9");
2764:
2765:                String fromAto3 = ps.addEdge("extraA", "node3");
2766:                ps.addEdge("extraB", "node3");
2767:                ps.addEdge("extraC", "node3");
2768:                ps.addEdge("extraA0", "extraA");
2769:                ps.addEdge("extraB0", "extraB");
2770:                ps.addEdge("extraB1", "extraB");
2771:                ps.addEdge("extraC0", "extraC");
2772:                ps.addEdge("extraC1", "extraC");
2773:                ps.addEdge("extraC2", "extraC");
2774:                ps.addEdge("extraZ0", "node5B");
2775:                ps.addEdge("extraZ1", "node5B");
2776:                ps.addEdge("extraZ2", "node5B");
2777:
2778:                // set conditions to exit from the iteration (they are mandatory)
2779:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
2780:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
2781:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
2782:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
2783:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
2784:                ps.setEdgeCondition(fromAto3, "condA.equals(\"true\")");
2785:
2786:                // set Iteration
2787:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
2788:
2789:                // checks if model is defined correctly
2790:                ps.checkModelDefinition();
2791:
2792:                // ******************************   MAIN   ******************************
2793:                ps.setUserRole("admin", "InitialRole");
2794:                String project = ps.instantiateProject("ExtraEntryPointsBig2");
2795:                UserSessionHome usersh = UserSessionUtil.getHome();
2796:                UserSession usr = usersh.create();
2797:
2798:                assertTrue(
2799:                        "Error in ExtraEntryPointsBig2, extraA0 failed",
2800:                        ps.getNodeValue("extraA0").getState() == Constants.Nd.TERMINATED);
2801:                assertTrue(
2802:                        "Error in ExtraEntryPointsBig2, extraB0 failed",
2803:                        ps.getNodeValue("extraB0").getState() == Constants.Nd.TERMINATED);
2804:                assertTrue(
2805:                        "Error in ExtraEntryPointsBig2, extraB1 failed",
2806:                        ps.getNodeValue("extraB1").getState() == Constants.Nd.TERMINATED);
2807:                assertTrue(
2808:                        "Error in ExtraEntryPointsBig2, extraC0 failed",
2809:                        ps.getNodeValue("extraC0").getState() == Constants.Nd.TERMINATED);
2810:                assertTrue(
2811:                        "Error in ExtraEntryPointsBig2, extraC1 failed",
2812:                        ps.getNodeValue("extraC1").getState() == Constants.Nd.TERMINATED);
2813:                assertTrue(
2814:                        "Error in ExtraEntryPointsBig2, extraC2 failed",
2815:                        ps.getNodeValue("extraC2").getState() == Constants.Nd.TERMINATED);
2816:                assertTrue(
2817:                        "Error in ExtraEntryPointsBig2, extraZ0 failed",
2818:                        ps.getNodeValue("extraZ0").getState() == Constants.Nd.TERMINATED);
2819:                assertTrue(
2820:                        "Error in ExtraEntryPointsBig2, extraZ1 failed",
2821:                        ps.getNodeValue("extraZ1").getState() == Constants.Nd.TERMINATED);
2822:                assertTrue(
2823:                        "Error in ExtraEntryPointsBig2, extraZ2 failed",
2824:                        ps.getNodeValue("extraZ2").getState() == Constants.Nd.TERMINATED);
2825:
2826:                usr.startActivity(project, "extraA");
2827:                usr.terminateActivity(project, "extraA");
2828:                assertTrue(
2829:                        "Error in ExtraEntryPointsBig2, extraA failed",
2830:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
2831:                assertTrue("Error in ExtraEntryPointsBig2, node3 failed", ps
2832:                        .getNodeValue("node3").getState() == Constants.Nd.DEAD);
2833:                assertTrue("Error in ExtraEntryPointsBig2, node8 failed", ps
2834:                        .getNodeValue("node8").getState() == Constants.Nd.DEAD);
2835:                assertTrue("Error in ExtraEntryPointsBig2, node9 failed", ps
2836:                        .getNodeValue("node9").getState() == Constants.Nd.DEAD);
2837:                assertTrue("Error in ExtraEntryPointsBig2, node6 failed", ps
2838:                        .getNodeValue("node6").getState() == Constants.Nd.DEAD);
2839:                assertTrue("Error in ExtraEntryPointsBig2, node7 failed", ps
2840:                        .getNodeValue("node7").getState() == Constants.Nd.DEAD);
2841:
2842:                usr.startActivity(project, "extraB");
2843:                usr.terminateActivity(project, "extraB");
2844:                assertTrue(
2845:                        "Error in ExtraEntryPointsBig2, extraB failed",
2846:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
2847:                usr.startActivity(project, "extraC");
2848:                usr.terminateActivity(project, "extraC");
2849:                assertTrue(
2850:                        "Error in ExtraEntryPointsBig2, extraC failed",
2851:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
2852:
2853:                usr.startActivity(project, "node0");
2854:                assertTrue(
2855:                        "Error in ExtraEntryPointsBig2, startActivity node0: node0 failed",
2856:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
2857:                assertTrue(
2858:                        "Error in ExtraEntryPointsBig2, startActivity node0: node1 failed",
2859:                        ps.getNodeValue("node1").getState() == Constants.Nd.INITIAL);
2860:
2861:                usr.terminateActivity(project, "node0");
2862:                assertTrue(
2863:                        "Error in ExtraEntryPointsBig2, terminateActivity node0: node0 failed",
2864:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
2865:                assertTrue(
2866:                        "Error in ExtraEntryPointsBig2, terminateActivity node0: node1 failed",
2867:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
2868:
2869:                usr.startActivity(project, "node1");
2870:                assertTrue(
2871:                        "Error in ExtraEntryPointsBig2, startActivity node1: node1 failed",
2872:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
2873:                assertTrue(
2874:                        "Error in ExtraEntryPointsBig2, startActivity node1: node3 failed",
2875:                        ps.getNodeValue("node3").getState() == Constants.Nd.DEAD);
2876:                assertTrue(
2877:                        "Error in ExtraEntryPointsBig2, startActivity node1: node4 failed",
2878:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2879:                assertTrue(
2880:                        "Error in ExtraEntryPointsBig2, startActivity node1: node5 failed",
2881:                        ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
2882:
2883:                usr.terminateActivity(project, "node1");
2884:                assertTrue(
2885:                        "Error in ExtraEntryPointsBig2, terminateActivity node1: node1 failed",
2886:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
2887:                assertTrue(
2888:                        "Error in ExtraEntryPointsBig2, terminateActivity node1: node3 failed",
2889:                        ps.getNodeValue("node3").getState() == Constants.Nd.DEAD);
2890:                assertTrue(
2891:                        "Error in ExtraEntryPointsBig2, terminateActivity node1: node4 failed",
2892:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
2893:                assertTrue(
2894:                        "Error in ExtraEntryPointsBig2, terminateActivity node1: node5 failed",
2895:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
2896:
2897:                try {
2898:                    usr.startActivity(project, "node3");
2899:                    assertTrue(
2900:                            "Error in ExtraEntryPointsBig2, startActivity node3 is not possible",
2901:                            false);
2902:                } catch (Exception e) {
2903:                }
2904:                ;
2905:                try {
2906:                    usr.terminateActivity(project, "node3");
2907:                    assertTrue(
2908:                            "Error in ExtraEntryPointsBig2, terminateActivity node3 is not possible",
2909:                            false);
2910:                } catch (Exception e) {
2911:                }
2912:                ;
2913:
2914:                assertTrue("Error in ExtraEntryPointsBig2, node8 failed", ps
2915:                        .getNodeValue("node8").getState() == Constants.Nd.DEAD);
2916:                assertTrue("Error in ExtraEntryPointsBig2, node9 failed", ps
2917:                        .getNodeValue("node9").getState() == Constants.Nd.DEAD);
2918:
2919:                usr.startActivity(project, "node5");
2920:                usr.terminateActivity(project, "node5");
2921:                assertTrue(
2922:                        "Error in ExtraEntryPointsBig2, terminateActivity node1: node4 failed",
2923:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
2924:
2925:                usr.startActivity(project, "node4");
2926:                usr.terminateActivity(project, "node4");
2927:                assertTrue(
2928:                        "Error in ExtraEntryPointsBig2, terminateActivity node4: node2 failed",
2929:                        ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
2930:                assertTrue(
2931:                        "Error in ExtraEntryPointsBig2, terminateActivity node6, after iterate: node6 failed",
2932:                        ps.getNodeValue("node6").getState() == Constants.Nd.DEAD);
2933:                assertTrue(
2934:                        "Error in ExtraEntryPointsBig2, terminateActivity node6, after iterate: node7 failed",
2935:                        ps.getNodeValue("node7").getState() == Constants.Nd.DEAD);
2936:
2937:                usr.startActivity(project, "node5A");
2938:                usr.terminateActivity(project, "node5A");
2939:                assertTrue(
2940:                        "Error in ExtraEntryPointsBig2, terminateActivity node5A: node5A failed",
2941:                        ps.getNodeValue("node5A").getState() == Constants.Nd.TERMINATED);
2942:                assertTrue(
2943:                        "Error in ExtraEntryPointsBig2, terminateActivity node5A: node5B failed",
2944:                        ps.getNodeValue("node5B").getState() == Constants.Nd.READY);
2945:
2946:                usr.startActivity(project, "node5B");
2947:                usr.terminateActivity(project, "node5B");
2948:
2949:                try {
2950:                    usr.startActivity(project, "node6");
2951:                    assertTrue(
2952:                            "Error in ExtraEntryPointsBig2, startActivity node6 is not possible",
2953:                            false);
2954:                } catch (Exception e) {
2955:                }
2956:                ;
2957:                try {
2958:                    usr.terminateActivity(project, "node6");
2959:                    assertTrue(
2960:                            "Error in ExtraEntryPointsBig2, terminateActivity node6 is not possible",
2961:                            false);
2962:                } catch (Exception e) {
2963:                }
2964:                ;
2965:                try {
2966:                    usr.startActivity(project, "node7");
2967:                    assertTrue(
2968:                            "Error in ExtraEntryPointsBig2, startActivity node7 is not possible",
2969:                            false);
2970:                } catch (Exception e) {
2971:                }
2972:                ;
2973:                try {
2974:                    usr.terminateActivity(project, "node7");
2975:                    assertTrue(
2976:                            "Error in ExtraEntryPointsBig2, terminateActivity node7 is not possible",
2977:                            false);
2978:                } catch (Exception e) {
2979:                }
2980:                ;
2981:            }
2982:
2983:            /**
2984:             * Based on testExtraEntryPointsBig1() (iterates 3 times and then finalizes the iteration)<br>
2985:             * Uses: Automatic and non automatic traditional activities<br>
2986:             *       Extra entry points : node3 = OR_JOIN -- node5B = OR_JOIN_AUTOMATIC<br>
2987:             * Now: it will iterate extraB will be true. Edges comming from extraA, extraC, node1 will be false<br>
2988:             * 		extra5B will start before extra5A because extraZ2 will be executed before extra5A<br>
2989:             * 
2990:             * @throws Exception
2991:             */
2992:            public void testExtraEntryPointsBig3() throws Exception {
2993:                ProjectSessionHome projectSessionh = ProjectSessionUtil
2994:                        .getHome();
2995:                ProjectSession ps = projectSessionh.create();
2996:                ps.initModel("ExtraEntryPointsBig3");
2997:
2998:                // Properties
2999:                ps.setProperty("iterate", "true");
3000:                ps.setProperty("condA", "false");
3001:                ps.setProperty("condB", "true");
3002:                ps.setProperty("condC", "false");
3003:                ps.setProperty("condZ0", "false");
3004:                ps.setProperty("condZ1", "false");
3005:                ps.setProperty("condZ2", "true");
3006:                ps.setProperty("cond1", "false");
3007:
3008:                // add Nodes
3009:                ps.addNode("node0", Constants.Nd.AND_JOIN_NODE);
3010:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
3011:                ps.addNode("node2", Constants.Nd.AND_JOIN_NODE);
3012:                ps.addNode("node3", Constants.Nd.OR_JOIN_NODE);
3013:                ps.addNode("node4", Constants.Nd.AND_JOIN_NODE);
3014:                ps.addNode("node5", Constants.Nd.AND_JOIN_NODE);
3015:                ps.addNode("node5A", Constants.Nd.AND_JOIN_NODE);
3016:                ps.addNode("node5B", Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
3017:                ps.addNode("node6", Constants.Nd.AND_JOIN_NODE);
3018:                ps.addNode("node7", Constants.Nd.AND_JOIN_NODE);
3019:                ps.addNode("node8", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3020:                ps.addNode("node9", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3021:                // extra entry points
3022:                ps.addNode("extraA", Constants.Nd.AND_JOIN_NODE);
3023:                ps.addNode("extraB", Constants.Nd.AND_JOIN_NODE);
3024:                ps.addNode("extraC", Constants.Nd.AND_JOIN_NODE);
3025:                ps.addNode("extraA0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3026:                ps.addNode("extraB0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3027:                ps.addNode("extraB1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3028:                ps.addNode("extraC0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3029:                ps.addNode("extraC1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3030:                ps.addNode("extraC2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3031:                ps.addNode("extraZ0", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3032:                ps.addNode("extraZ1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3033:                ps.addNode("extraZ2", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
3034:
3035:                ps.setNodeTraditional("node0");
3036:                ps.setNodeTraditional("node1");
3037:                ps.setNodeTraditional("node2");
3038:                ps.setNodeTraditional("node3");
3039:                ps.setNodeTraditional("node4");
3040:                ps.setNodeTraditional("node5");
3041:                ps.setNodeTraditional("node5A");
3042:                ps.setNodeTraditional("node5B");
3043:                ps.setNodeTraditional("node6");
3044:                ps.setNodeTraditional("node7");
3045:                ps.setNodeTraditional("node8");
3046:                ps.setNodeTraditional("node9");
3047:                ps.setNodeTraditional("extraA");
3048:                ps.setNodeTraditional("extraB");
3049:                ps.setNodeTraditional("extraC");
3050:                ps.setNodeTraditional("extraA0");
3051:                ps.setNodeTraditional("extraB0");
3052:                ps.setNodeTraditional("extraB1");
3053:                ps.setNodeTraditional("extraC0");
3054:                ps.setNodeTraditional("extraC1");
3055:                ps.setNodeTraditional("extraC2");
3056:                ps.setNodeTraditional("extraZ0");
3057:                ps.setNodeTraditional("extraZ1");
3058:                ps.setNodeTraditional("extraZ2");
3059:
3060:                // add Edges
3061:                ps.addEdge("node0", "node1");
3062:                String from1to3 = ps.addEdge("node1", "node3");
3063:                ps.addEdge("node1", "node4");
3064:                ps.addEdge("node1", "node5");
3065:                String from3to6 = ps.addEdge("node3", "node6");
3066:                String from3to8 = ps.addEdge("node3", "node8");
3067:                String from4to2 = ps.addEdge("node4", "node2");
3068:                String from4to6 = ps.addEdge("node4", "node6");
3069:                ps.addEdge("node5", "node4");
3070:                ps.addEdge("node5", "node6");
3071:                ps.addEdge("node5", "node5A");
3072:                ps.addEdge("node5A", "node5B");
3073:                ps.addEdge("node5B", "node6");
3074:                String from6to7 = ps.addEdge("node6", "node7");
3075:                ps.addEdge("node8", "node9");
3076:
3077:                String fromAto3 = ps.addEdge("extraA", "node3");
3078:                String fromBto3 = ps.addEdge("extraB", "node3");
3079:                String fromCto3 = ps.addEdge("extraC", "node3");
3080:                ps.addEdge("extraA0", "extraA");
3081:                ps.addEdge("extraB0", "extraB");
3082:                ps.addEdge("extraB1", "extraB");
3083:                ps.addEdge("extraC0", "extraC");
3084:                ps.addEdge("extraC1", "extraC");
3085:                ps.addEdge("extraC2", "extraC");
3086:                String fromZ0to5B = ps.addEdge("extraZ0", "node5B");
3087:                String fromZ1to5B = ps.addEdge("extraZ1", "node5B");
3088:                String fromZ2to5B = ps.addEdge("extraZ2", "node5B");
3089:
3090:                // set conditions to exit from the iteration (they are mandatory)
3091:                ps.setEdgeCondition(from3to6, "iterate.equals(\"true\")");
3092:                ps.setEdgeCondition(from4to6, "iterate.equals(\"true\")");
3093:                ps.setEdgeCondition(from3to8, "iterate.equals(\"false\")");
3094:                ps.setEdgeCondition(from4to2, "iterate.equals(\"false\")");
3095:                ps.setEdgeCondition(from6to7, "iterate.equals(\"false\")");
3096:                ps.setEdgeCondition(fromAto3, "condA.equals(\"true\")");
3097:                ps.setEdgeCondition(fromBto3, "condB.equals(\"true\")");
3098:                ps.setEdgeCondition(fromCto3, "condC.equals(\"true\")");
3099:                ps.setEdgeCondition(fromZ0to5B, "condZ0.equals(\"true\")");
3100:                ps.setEdgeCondition(fromZ1to5B, "condZ1.equals(\"true\")");
3101:                ps.setEdgeCondition(fromZ2to5B, "condZ2.equals(\"true\")");
3102:                ps.setEdgeCondition(from1to3, "cond1.equals(\"true\")");
3103:
3104:                // set Iteration
3105:                ps.addIteration("node6", "node1", "iterate.equals(\"true\")");
3106:
3107:                // checks if model is defined correctly
3108:                ps.checkModelDefinition();
3109:
3110:                // ******************************   MAIN   ******************************
3111:                ps.setUserRole("admin", "InitialRole");
3112:                String project = ps.instantiateProject("ExtraEntryPointsBig3");
3113:                UserSessionHome usersh = UserSessionUtil.getHome();
3114:                UserSession usr = usersh.create();
3115:
3116:                assertTrue(
3117:                        "Error in ExtraEntryPointsBig3, extraA0 failed",
3118:                        ps.getNodeValue("extraA0").getState() == Constants.Nd.TERMINATED);
3119:                assertTrue(
3120:                        "Error in ExtraEntryPointsBig3, extraB0 failed",
3121:                        ps.getNodeValue("extraB0").getState() == Constants.Nd.TERMINATED);
3122:                assertTrue(
3123:                        "Error in ExtraEntryPointsBig3, extraB1 failed",
3124:                        ps.getNodeValue("extraB1").getState() == Constants.Nd.TERMINATED);
3125:                assertTrue(
3126:                        "Error in ExtraEntryPointsBig3, extraC0 failed",
3127:                        ps.getNodeValue("extraC0").getState() == Constants.Nd.TERMINATED);
3128:                assertTrue(
3129:                        "Error in ExtraEntryPointsBig3, extraC1 failed",
3130:                        ps.getNodeValue("extraC1").getState() == Constants.Nd.TERMINATED);
3131:                assertTrue(
3132:                        "Error in ExtraEntryPointsBig3, extraC2 failed",
3133:                        ps.getNodeValue("extraC2").getState() == Constants.Nd.TERMINATED);
3134:                assertTrue(
3135:                        "Error in ExtraEntryPointsBig3, extraZ0 failed",
3136:                        ps.getNodeValue("extraZ0").getState() == Constants.Nd.TERMINATED);
3137:                assertTrue(
3138:                        "Error in ExtraEntryPointsBig3, extraZ1 failed",
3139:                        ps.getNodeValue("extraZ1").getState() == Constants.Nd.TERMINATED);
3140:                assertTrue(
3141:                        "Error in ExtraEntryPointsBig3, extraZ2 failed",
3142:                        ps.getNodeValue("extraZ2").getState() == Constants.Nd.TERMINATED);
3143:                // Executed before node5A because it is an OR_JOIN_AUTOMATIC and condZ2 is true
3144:                assertTrue(
3145:                        "Error in ExtraEntryPointsBig3, terminateActivity node5B failed",
3146:                        ps.getNodeValue("node5B").getState() == Constants.Nd.TERMINATED);
3147:
3148:                usr.startActivity(project, "extraA");
3149:                usr.startActivity(project, "extraB");
3150:                usr.startActivity(project, "extraC");
3151:                usr.terminateActivity(project, "extraA");
3152:                usr.terminateActivity(project, "extraB");
3153:                usr.terminateActivity(project, "extraC");
3154:                assertTrue(
3155:                        "Error in ExtraEntryPointsBig3, extraA failed",
3156:                        ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
3157:                assertTrue(
3158:                        "Error in ExtraEntryPointsBig3, extraB failed",
3159:                        ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
3160:                assertTrue(
3161:                        "Error in ExtraEntryPointsBig3, extraC failed",
3162:                        ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
3163:                assertTrue("Error in ExtraEntryPointsBig3, node3 failed", ps
3164:                        .getNodeValue("node3").getState() == Constants.Nd.READY);
3165:
3166:                usr.startActivity(project, "node0");
3167:                assertTrue(
3168:                        "Error in ExtraEntryPointsBig3, startActivity node0: node0 failed",
3169:                        ps.getNodeValue("node0").getState() == Constants.Nd.EXECUTING);
3170:                assertTrue(
3171:                        "Error in ExtraEntryPointsBig3, startActivity node0: node1 failed",
3172:                        ps.getNodeValue("node1").getState() == Constants.Nd.INITIAL);
3173:
3174:                usr.terminateActivity(project, "node0");
3175:                assertTrue(
3176:                        "Error in ExtraEntryPointsBig3, terminateActivity node0: node0 failed",
3177:                        ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
3178:                assertTrue(
3179:                        "Error in ExtraEntryPointsBig3, terminateActivity node0: node1 failed",
3180:                        ps.getNodeValue("node1").getState() == Constants.Nd.READY);
3181:
3182:                int index = 0;
3183:                while (index < 2) {
3184:                    assertTrue(
3185:                            "Error in ExtraEntryPointsBig3, node6 failed",
3186:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
3187:
3188:                    // Executed before node1 because it is an OR_JOIN and condB is true
3189:                    usr.startActivity(project, "node3");
3190:                    usr.terminateActivity(project, "node3");
3191:                    assertTrue(
3192:                            "Error in ExtraEntryPointsBig3, terminateActivity node3 failed",
3193:                            ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
3194:                    assertTrue(
3195:                            "Error in ExtraEntryPointsBig3, node6 failed",
3196:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
3197:                    assertTrue(
3198:                            "Error in ExtraEntryPointsBig3, terminateActivity node3: node8 failed",
3199:                            ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
3200:                    assertTrue(
3201:                            "Error in ExtraEntryPointsBig3, terminateActivity node3: node9 failed",
3202:                            ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
3203:
3204:                    usr.startActivity(project, "node1");
3205:                    assertTrue(
3206:                            "Error in ExtraEntryPointsBig3, startActivity node1: node1 failed",
3207:                            ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
3208:                    assertTrue(
3209:                            "Error in ExtraEntryPointsBig3, startActivity node1: node3 failed",
3210:                            ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
3211:                    assertTrue(
3212:                            "Error in ExtraEntryPointsBig3, startActivity node1: node4 failed",
3213:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
3214:                    assertTrue(
3215:                            "Error in ExtraEntryPointsBig3, startActivity node1: node5 failed",
3216:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
3217:
3218:                    usr.terminateActivity(project, "node1");
3219:                    assertTrue(
3220:                            "Error in ExtraEntryPointsBig3, terminateActivity node1: node1 failed",
3221:                            ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
3222:                    assertTrue(
3223:                            "Error in ExtraEntryPointsBig3, terminateActivity node1: node3 failed",
3224:                            ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
3225:                    assertTrue(
3226:                            "Error in ExtraEntryPointsBig3, terminateActivity node1: node4 failed",
3227:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
3228:                    assertTrue(
3229:                            "Error in ExtraEntryPointsBig3, terminateActivity node1: node5 failed",
3230:                            ps.getNodeValue("node5").getState() == Constants.Nd.READY);
3231:
3232:                    try {
3233:                        usr.startActivity(project, "node3");
3234:                        assertTrue(
3235:                                "Error in ExtraEntryPointsBig3, startActivity node3 is not possible",
3236:                                false);
3237:                    } catch (Exception e) {
3238:                    }
3239:                    ;
3240:                    try {
3241:                        usr.terminateActivity(project, "node3");
3242:                        ;
3243:                        assertTrue(
3244:                                "Error in ExtraEntryPointsBig3, terminateActivity node3 is not possible",
3245:                                false);
3246:                    } catch (Exception e) {
3247:                    }
3248:                    ;
3249:
3250:                    usr.startActivity(project, "node5");
3251:                    usr.terminateActivity(project, "node5");
3252:                    assertTrue(
3253:                            "Error in ExtraEntryPointsBig3, terminateActivity node5: node5 failed",
3254:                            ps.getNodeValue("node5").getState() == Constants.Nd.TERMINATED);
3255:                    assertTrue(
3256:                            "Error in ExtraEntryPointsBig3, terminateActivity node5: node4 failed",
3257:                            ps.getNodeValue("node4").getState() == Constants.Nd.READY);
3258:
3259:                    usr.startActivity(project, "node4");
3260:                    usr.terminateActivity(project, "node4");
3261:                    assertTrue(
3262:                            "Error in ExtraEntryPointsBig3, terminateActivity node4: node4 failed",
3263:                            ps.getNodeValue("node4").getState() == Constants.Nd.TERMINATED);
3264:                    assertTrue(
3265:                            "Error in ExtraEntryPointsBig3, terminateActivity node4: node2 failed",
3266:                            ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
3267:                    assertTrue(
3268:                            "Error in ExtraEntryPointsBig3, terminateActivity node4: node6 failed",
3269:                            ps.getNodeValue("node6").getState() == Constants.Nd.READY);
3270:
3271:                    try {
3272:                        usr.startActivity(project, "node2");
3273:                        assertTrue(
3274:                                "Error in ExtraEntryPointsBig3, startActivity node2: node2 should be failed",
3275:                                false);
3276:                    } catch (Exception e) {
3277:                    }
3278:                    try {
3279:                        usr.terminateActivity(project, "node2");
3280:                        assertTrue(
3281:                                "Error in ExtraEntryPointsBig3, terminateActivity node2: node2 should be failed",
3282:                                false);
3283:                    } catch (Exception e) {
3284:                    }
3285:
3286:                    assertTrue(
3287:                            "Error in ExtraEntryPointsBig3, before startActivity node5A: node5B failed",
3288:                            ps.getNodeValue("node5B").getState() == Constants.Nd.TERMINATED);
3289:                    usr.startActivity(project, "node5A");
3290:                    usr.terminateActivity(project, "node5A");
3291:                    assertTrue(
3292:                            "Error in ExtraEntryPointsBig3, after terminateActivity node5A: node5A failed",
3293:                            ps.getNodeValue("node5A").getState() == Constants.Nd.TERMINATED);
3294:                    assertTrue(
3295:                            "Error in ExtraEntryPointsBig3, after terminateActivity node5A: node5B failed",
3296:                            ps.getNodeValue("node5B").getState() == Constants.Nd.TERMINATED);
3297:
3298:                    usr.startActivity(project, "node6");
3299:                    usr.terminateActivity(project, "node6");
3300:                    assertTrue(
3301:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node0 failed",
3302:                            ps.getNodeValue("node0").getState() == Constants.Nd.TERMINATED);
3303:                    assertTrue(
3304:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node1 failed",
3305:                            ps.getNodeValue("node1").getState() == Constants.Nd.READY);
3306:                    assertTrue(
3307:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node2 failed",
3308:                            ps.getNodeValue("node2").getState() == Constants.Nd.INITIAL);
3309:                    assertTrue(
3310:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node3 failed",
3311:                            ps.getNodeValue("node3").getState() == Constants.Nd.READY);
3312:                    assertTrue(
3313:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node4 failed",
3314:                            ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
3315:                    assertTrue(
3316:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node5 failed",
3317:                            ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
3318:                    assertTrue(
3319:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node5A failed",
3320:                            ps.getNodeValue("node5A").getState() == Constants.Nd.INITIAL);
3321:                    assertTrue(
3322:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node5B failed",
3323:                            ps.getNodeValue("node5B").getState() == Constants.Nd.TERMINATED); // It is an OR_JOIN_AUTOMATIC and has a true edge incoming
3324:                    assertTrue(
3325:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node6 failed",
3326:                            ps.getNodeValue("node6").getState() == Constants.Nd.INITIAL);
3327:                    assertTrue(
3328:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node7 failed",
3329:                            ps.getNodeValue("node7").getState() == Constants.Nd.INITIAL);
3330:                    assertTrue(
3331:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node8 failed",
3332:                            ps.getNodeValue("node8").getState() == Constants.Nd.INITIAL);
3333:                    assertTrue(
3334:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: node9 failed",
3335:                            ps.getNodeValue("node9").getState() == Constants.Nd.INITIAL);
3336:                    assertTrue(
3337:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraA failed",
3338:                            ps.getNodeValue("extraA").getState() == Constants.Nd.TERMINATED);
3339:                    assertTrue(
3340:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraB failed",
3341:                            ps.getNodeValue("extraB").getState() == Constants.Nd.TERMINATED);
3342:                    assertTrue(
3343:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraC failed",
3344:                            ps.getNodeValue("extraC").getState() == Constants.Nd.TERMINATED);
3345:                    assertTrue(
3346:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraA0 failed",
3347:                            ps.getNodeValue("extraA0").getState() == Constants.Nd.TERMINATED);
3348:                    assertTrue(
3349:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraB0 failed",
3350:                            ps.getNodeValue("extraB0").getState() == Constants.Nd.TERMINATED);
3351:                    assertTrue(
3352:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraB1 failed",
3353:                            ps.getNodeValue("extraB1").getState() == Constants.Nd.TERMINATED);
3354:                    assertTrue(
3355:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraC0 failed",
3356:                            ps.getNodeValue("extraC0").getState() == Constants.Nd.TERMINATED);
3357:                    assertTrue(
3358:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraC1 failed",
3359:                            ps.getNodeValue("extraC1").getState() == Constants.Nd.TERMINATED);
3360:                    assertTrue(
3361:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraC2 failed",
3362:                            ps.getNodeValue("extraC2").getState() == Constants.Nd.TERMINATED);
3363:                    assertTrue(
3364:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraZ0 failed",
3365:                            ps.getNodeValue("extraZ0").getState() == Constants.Nd.TERMINATED);
3366:                    assertTrue(
3367:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraZ1 failed",
3368:                            ps.getNodeValue("extraZ1").getState() == Constants.Nd.TERMINATED);
3369:                    assertTrue(
3370:                            "Error in ExtraEntryPointsBig3, terminateActivity node6: extraZ2 failed",
3371:                            ps.getNodeValue("extraZ2").getState() == Constants.Nd.TERMINATED);
3372:
3373:                    index++;
3374:                }
3375:
3376:                usr.startActivity(project, "node3");
3377:                usr.terminateActivity(project, "node3");
3378:                assertTrue(
3379:                        "Error in ExtraEntryPointsBig3, terminateActivity node3: node8 failed",
3380:                        ps.getNodeValue("node8").getState() == Constants.Nd.DEAD);
3381:                assertTrue(
3382:                        "Error in ExtraEntryPointsBig3, terminateActivity node3: node9 failed",
3383:                        ps.getNodeValue("node9").getState() == Constants.Nd.DEAD);
3384:
3385:                usr.startActivity(project, "node1");
3386:                assertTrue(
3387:                        "Error in ExtraEntryPointsBig3, startActivity node1: node1 failed",
3388:                        ps.getNodeValue("node1").getState() == Constants.Nd.EXECUTING);
3389:                assertTrue(
3390:                        "Error in ExtraEntryPointsBig3, startActivity node1: node3 failed",
3391:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
3392:                assertTrue(
3393:                        "Error in ExtraEntryPointsBig3, startActivity node1: node4 failed",
3394:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
3395:                assertTrue(
3396:                        "Error in ExtraEntryPointsBig3, startActivity node1: node5 failed",
3397:                        ps.getNodeValue("node5").getState() == Constants.Nd.INITIAL);
3398:
3399:                usr.terminateActivity(project, "node1");
3400:                assertTrue(
3401:                        "Error in ExtraEntryPointsBig3, terminateActivity node1: node1 failed",
3402:                        ps.getNodeValue("node1").getState() == Constants.Nd.TERMINATED);
3403:                assertTrue(
3404:                        "Error in ExtraEntryPointsBig3, terminateActivity node1: node3 failed",
3405:                        ps.getNodeValue("node3").getState() == Constants.Nd.TERMINATED);
3406:                assertTrue(
3407:                        "Error in ExtraEntryPointsBig3, terminateActivity node1: node4 failed",
3408:                        ps.getNodeValue("node4").getState() == Constants.Nd.INITIAL);
3409:                assertTrue(
3410:                        "Error in ExtraEntryPointsBig3, terminateActivity node1: node5 failed",
3411:                        ps.getNodeValue("node5").getState() == Constants.Nd.READY);
3412:
3413:                usr.startActivity(project, "node5");
3414:                usr.terminateActivity(project, "node5");
3415:                assertTrue(
3416:                        "Error in ExtraEntryPointsBig3, terminateActivity node1: node4 failed",
3417:                        ps.getNodeValue("node4").getState() == Constants.Nd.READY);
3418:
3419:                usr.startActivity(project, "node4");
3420:                usr.terminateActivity(project, "node4");
3421:                assertTrue(
3422:                        "Error in ExtraEntryPointsBig3, terminateActivity node4: node4 failed",
3423:                        ps.getNodeValue("node4").getState() == Constants.Nd.TERMINATED);
3424:                assertTrue(
3425:                        "Error in ExtraEntryPointsBig3, terminateActivity node4: node2 failed",
3426:                        ps.getNodeValue("node2").getState() == Constants.Nd.DEAD);
3427:                assertTrue(
3428:                        "Error in ExtraEntryPointsBig3, terminateActivity node4: node6 failed",
3429:                        ps.getNodeValue("node6").getState() == Constants.Nd.READY);
3430:
3431:                // Finally, it will finalize throw node7.  Node2, node8 and node9 will become DEAD
3432:                ps.setProperty("iterate", "false");
3433:
3434:                usr.startActivity(project, "node6");
3435:                usr.terminateActivity(project, "node6");
3436:                assertTrue(
3437:                        "Error in ExtraEntryPointsBig3, terminateActivity node6: node6 failed",
3438:                        ps.getNodeValue("node6").getState() == Constants.Nd.TERMINATED);
3439:                assertTrue(
3440:                        "Error in ExtraEntryPointsBig3, terminateActivity node6: node7 failed",
3441:                        ps.getNodeValue("node7").getState() == Constants.Nd.READY);
3442:
3443:                usr.startActivity(project, "node7");
3444:                usr.terminateActivity(project, "node7");
3445:
3446:                assertTrue(
3447:                        "Error in ExtraEntryPointsBig3, before startActivity node5A: node5B failed",
3448:                        ps.getNodeValue("node5B").getState() == Constants.Nd.TERMINATED);
3449:                usr.startActivity(project, "node5A");
3450:                usr.terminateActivity(project, "node5A");
3451:            }
3452:
3453:            // ---------------------------------------------------------------------- //
3454:            // -------------------------   SUBPROCESSES   --------------------------- //
3455:            // ---------------------------------------------------------------------- //
3456:
3457:            /**
3458:             * Tests that an iteration with a subprocess inside: node->subProc->node
3459:             * Uses: Non automatic anticipable activities
3460:             * 
3461:             * @throws Exception
3462:             */
3463:            public void testSubProcessesIteration() throws Exception {
3464:                ProjectSessionHome projectSessionh = ProjectSessionUtil
3465:                        .getHome();
3466:
3467:                ProjectSession ps1 = projectSessionh.create();
3468:                ps1.initModel("oneSubProject");
3469:                ps1.addNode("test1", Constants.Nd.AND_JOIN_NODE);
3470:                ps1.addNode("test2", Constants.Nd.AND_JOIN_NODE);
3471:                ps1.addEdge("test1", "test2");
3472:
3473:                ProjectSession ps = projectSessionh.create();
3474:                ps.initModel("oneTestProject");
3475:                ps.addNode("node1", Constants.Nd.AND_JOIN_NODE);
3476:                ps.addNode("node3", Constants.Nd.AND_JOIN_NODE);
3477:                ps.addNodeSubProcess("node2", "oneSubProject");
3478:
3479:                ps.addEdge("node1", "node2");
3480:                ps.addEdge("node2", "node3");
3481:
3482:                ps.setNodeProperty("node1", "prop", "ok", true);
3483:                ps.addRoleMapper("InitialRole", "roleMapperTest",
3484:                        Constants.Mapper.PROPERTIES);
3485:
3486:                ps.addIteration("node3", "node1", "prop.equals(\"ok\")");
3487:
3488:                ps.checkModelDefinition();
3489:
3490:                // ******************************   MAIN   ******************************
3491:                String instName = ps.instantiateProject("oneTestProject");
3492:                UserSessionHome userSessionh = UserSessionUtil.getHome();
3493:                UserSession us = userSessionh.create();
3494:                assertTrue("Error in roleMapper", us.getToDoList(instName)
3495:                        .contains("node1"));
3496:                int index = 0;
3497:                String actName = null;
3498:                while (index < 3) {
3499:                    us.startActivity(instName, "node1");
3500:                    us.terminateActivity(instName, "node1");
3501:                    Collection inst = us
3502:                            .getProjectInstancesNames("oneSubProject");
3503:                    Iterator instances = inst.iterator();
3504:                    actName = (String) instances.next();
3505:                    assertTrue(
3506:                            "Error in Iteration, subProcess is not reinitialized",
3507:                            us.getNode(actName, "test1").getState() == Constants.Nd.READY);
3508:
3509:                    us.startActivity(actName, "test1");
3510:                    us.terminateActivity(actName, "test1");
3511:                    us.startActivity(actName, "test2");
3512:                    us.terminateActivity(actName, "test2");
3513:
3514:                    us.startActivity(instName, "node3");
3515:                    us.terminateActivity(instName, "node3");
3516:                    assertTrue("Error in Iteration", us.getToDoList(instName)
3517:                            .contains("node1"));
3518:                    assertTrue(
3519:                            "Error in Iteration, subProcess is not reinitialized",
3520:                            us.getToDoList(actName).isEmpty());
3521:                    assertTrue(
3522:                            "Error in Iteration, subProcess is not reinitialized",
3523:                            us.getNode(actName, "test1").getState() == Constants.Nd.INITIAL);
3524:                    index++;
3525:                }
3526:
3527:                us.startActivity(instName, "node1");
3528:                us.terminateActivity(instName, "node1");
3529:                Collection inst = us.getProjectInstancesNames("oneSubProject");
3530:                Iterator instances = inst.iterator();
3531:                actName = (String) instances.next();
3532:
3533:                us.startActivity(actName, "test1");
3534:                us.terminateActivity(actName, "test1");
3535:                us.startActivity(actName, "test2");
3536:                us.terminateActivity(actName, "test2");
3537:
3538:                us.startActivity(instName, "node3");
3539:
3540:                ps.setNodeProperty("node3", "prop", "nok", true);
3541:
3542:                us.terminateActivity(instName, "node3");
3543:                try {
3544:                    us.getToDoList(instName);
3545:                    assertTrue("Should have throw FinderException", false);
3546:                } catch (Exception e) {
3547:                    //expected behavior
3548:                }
3549:                try {
3550:                    us.getToDoList(actName);
3551:                    assertTrue("Should have throw FinderException", false);
3552:                } catch (Exception e) {
3553:                    //expected behavior
3554:                }
3555:            }
3556:
3557:            /**
3558:             * Tests iterations between 2 subprocesses
3559:             * Uses: Non automatic anticipable activities
3560:             * 
3561:             * @throws Exception
3562:             */
3563:            public void testSubProcessesIterationOnlySubProcesses()
3564:                    throws Exception {
3565:                ProjectSessionHome projectSessionh = ProjectSessionUtil
3566:                        .getHome();
3567:
3568:                ProjectSession ps1 = projectSessionh.create();
3569:                ps1.initModel("SubProject1");
3570:                ps1.addNode("test1", Constants.Nd.AND_JOIN_NODE);
3571:                ps1.addNode("test2", Constants.Nd.AND_JOIN_NODE);
3572:                ps1.addEdge("test1", "test2");
3573:
3574:                ProjectSession ps2 = projectSessionh.create();
3575:                ps2.initModel("SubProject2");
3576:                ps2.addNode("test1", Constants.Nd.AND_JOIN_NODE);
3577:                ps2.addNode("test2", Constants.Nd.AND_JOIN_NODE);
3578:                ps2.addEdge("test1", "test2");
3579:
3580:                ProjectSession ps = projectSessionh.create();
3581:                ps.initModel("MyProjectIte");
3582:                ps.addNodeSubProcess("node1", "SubProject1");
3583:                ps.addNodeSubProcess("node2bis", "SubProject2");
3584:
3585:                ps.addEdge("node1", "node2bis");
3586:
3587:                ps.setNodeProperty("node1", "prop", "ok", true);
3588:                ps.addRoleMapper("InitialRole", "roleMapperTest",
3589:                        Constants.Mapper.PROPERTIES);
3590:
3591:                ps.addIteration("node2bis", "node1", "prop.equals(\"ok\")");
3592:
3593:                ps.checkModelDefinition();
3594:
3595:                // ******************************   MAIN   ******************************
3596:                String instName = ps.instantiateProject("MyProjectIte");
3597:                UserSessionHome userSessionh = UserSessionUtil.getHome();
3598:                UserSession us = userSessionh.create();
3599:
3600:                Collection inst = us.getProjectInstancesNames("SubProject1");
3601:                Iterator instances = inst.iterator();
3602:                String actName = (String) instances.next();
3603:
3604:                int index = 0;
3605:                while (index < 3) {
3606:                    us.startActivity(actName, "test1");
3607:                    us.terminateActivity(actName, "test1");
3608:                    us.startActivity(actName, "test2");
3609:                    us.terminateActivity(actName, "test2");
3610:
3611:                    inst = us.getProjectInstancesNames("SubProject2");
3612:                    instances = inst.iterator();
3613:                    actName = (String) instances.next();
3614:
3615:                    us.startActivity(actName, "test1");
3616:                    us.terminateActivity(actName, "test1");
3617:                    us.startActivity(actName, "test2");
3618:                    us.terminateActivity(actName, "test2");
3619:
3620:                    inst = us.getProjectInstancesNames("SubProject1");
3621:                    instances = inst.iterator();
3622:                    actName = (String) instances.next();
3623:
3624:                    index++;
3625:                }
3626:
3627:                us.startActivity(actName, "test1");
3628:                us.terminateActivity(actName, "test1");
3629:                us.startActivity(actName, "test2");
3630:                us.terminateActivity(actName, "test2");
3631:
3632:                inst = us.getProjectInstancesNames("SubProject2");
3633:                instances = inst.iterator();
3634:                String actName2 = (String) instances.next();
3635:
3636:                us.startActivity(actName2, "test1");
3637:                us.terminateActivity(actName2, "test1");
3638:                us.startActivity(actName2, "test2");
3639:
3640:                ps.initProject(actName2); // Special case for subprocess iteration
3641:                ps.setProperty("prop", "nok");
3642:                us.terminateActivity(actName2, "test2");
3643:
3644:                assertTrue("Error in SubProcess 1", us
3645:                        .getProjectInstancesNames("SubProject1").size() == 0);
3646:                assertTrue("Error in SubProcess 2", us
3647:                        .getProjectInstancesNames("SubProject2").size() == 0);
3648:                assertTrue("Error in SubProcess 3", us
3649:                        .getProjectInstancesNames("MyProjectIte").size() == 0);
3650:
3651:            }
3652:
3653:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.