0001: package hero.client.test;
0002:
0003: /*
0004: *
0005: * EngineTest.java -
0006: * Copyright (C) 2003 Ecoo Team
0007: * valdes@loria.fr
0008: *
0009: *
0010: * This program is free software; you can redistribute it and/or
0011: * modify it under the terms of the GNU Lesser General Public License
0012: * as published by the Free Software Foundation; either version 2
0013: * of the License, or (at your option) any later version.
0014: *
0015: * This program 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
0018: * GNU Lesser General Public License for more details.
0019: *
0020: * You should have received a copy of the GNU Lesser General Public License
0021: * along with this program; if not, write to the Free Software
0022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0023: */
0024:
0025: import hero.interfaces.BnEdgeValue;
0026: import hero.interfaces.BnNodeValue;
0027: import hero.interfaces.BnProjectValue;
0028: import hero.interfaces.Constants;
0029: import hero.interfaces.Engine;
0030: import hero.interfaces.EngineHome;
0031: import hero.interfaces.EngineUtil;
0032: import hero.interfaces.ProjectSession;
0033: import hero.interfaces.ProjectSessionHome;
0034: import hero.interfaces.ProjectSessionUtil;
0035: import hero.util.EngineException;
0036: import hero.util.HeroException;
0037: import junit.framework.TestCase;
0038: import junit.framework.TestSuite;
0039:
0040: public class EngineTests extends TestCase {
0041: private ProjectSessionHome psh;
0042: private ProjectSession ps;
0043: private EngineHome eh;
0044: private Engine eng;
0045:
0046: public EngineTests(String testname) {
0047: super (testname);
0048: }
0049:
0050: public static TestSuite suite() {
0051: return new TestSuite(EngineTests.class);
0052: }
0053:
0054: public void setUp() throws Exception {
0055: psh = ProjectSessionUtil.getHome();
0056: eh = EngineUtil.getHome();
0057: }
0058:
0059: public void testEngineAND() throws Exception {
0060: ProjectSession proj;
0061: BnProjectValue pm;
0062: BnNodeValue nd;
0063: BnEdgeValue ev;
0064:
0065: // creation du projet
0066: proj = psh.create();
0067: proj.initProject("work");
0068: proj.addNode("init", Constants.Nd.AND_JOIN_NODE);
0069: proj.addNode("sp1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0070: proj.addNode("ac1", Constants.Nd.AND_JOIN_NODE);
0071: proj.addNode("ac2", Constants.Nd.AND_JOIN_NODE);
0072: proj.addNode("jn1", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0073: proj.addNode("ac3", Constants.Nd.AND_JOIN_NODE);
0074: String e1 = proj.addEdge("init", "sp1");
0075: String e2 = proj.addEdge("sp1", "ac1");
0076: String e3 = proj.addEdge("sp1", "ac2");
0077: String e4 = proj.addEdge("ac1", "jn1");
0078: String e5 = proj.addEdge("ac2", "jn1");
0079: String e6 = proj.addEdge("jn1", "ac3");
0080: proj.addRole("test", "testeur");
0081: proj.setUserRole("admin", "test");
0082:
0083: proj.checkModelDefinition();
0084:
0085: eng = eh.create();
0086:
0087: try {
0088: eng.startActivity("work", "ac1");
0089: assertTrue("start ac1 should have failed", false);
0090: } catch (EngineException e) {
0091: // normal behavior
0092: }
0093:
0094: try {
0095: eng.terminateActivity("work", "init");
0096: assertTrue("terminate init should have failed", false);
0097: } catch (EngineException e) {
0098: // normal behavior
0099: }
0100:
0101: eng.startActivity("work", "init");
0102: proj = psh.create();
0103: proj.initProject("work");
0104:
0105: assertTrue("BnNode State Error init", proj.getNodeValue("init")
0106: .getState() == Constants.Nd.EXECUTING);
0107: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0108: .getState() == Constants.Ed.ANTICIPATING);
0109: assertTrue("BnNode State Error sp1", proj.getNodeValue("sp1")
0110: .getState() == Constants.Nd.ANTICIPATING);
0111: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0112: .getState() == Constants.Ed.ANTICIPATING);
0113: assertTrue("BnNode State Error ac1", proj.getNodeValue("ac1")
0114: .getState() == Constants.Nd.ANTICIPABLE);
0115: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0116: .getState() == Constants.Ed.ANTICIPATING);
0117: assertTrue("BnNode State Error ac2", proj.getNodeValue("ac2")
0118: .getState() == Constants.Nd.ANTICIPABLE);
0119: assertTrue("BnEdge State Error e4", proj.getEdgeValue(e4)
0120: .getState() == Constants.Ed.INITIAL);
0121: assertTrue("BnEdge State Error e5", proj.getEdgeValue(e5)
0122: .getState() == Constants.Ed.INITIAL);
0123: assertTrue("BnNode State Error jn1", proj.getNodeValue("jn1")
0124: .getState() == Constants.Nd.INITIAL);
0125: assertTrue("BnEdge State Error e6", proj.getEdgeValue(e6)
0126: .getState() == Constants.Ed.INITIAL);
0127: assertTrue("BnNode State Error ac3", proj.getNodeValue("ac3")
0128: .getState() == Constants.Nd.INITIAL);
0129:
0130: try {
0131: eng.terminateActivity("work", "sp1");
0132: assertTrue("terminate sp1 should have failed", false);
0133: } catch (EngineException e) {
0134: // normal behavior
0135: }
0136:
0137: eng.terminateActivity("work", "init");
0138:
0139: assertTrue("BnNode State Error Term init", proj.getNodeValue(
0140: "init").getState() == Constants.Nd.TERMINATED);
0141: assertTrue("BnEdge State Error Term e1", proj.getEdgeValue(e1)
0142: .getState() == Constants.Ed.ACTIVE);
0143: assertTrue("BnNode State Error Term sp1", proj.getNodeValue(
0144: "sp1").getState() == Constants.Nd.TERMINATED);
0145: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0146: .getState() == Constants.Ed.ACTIVE);
0147: assertTrue("BnNode State Error ac1", proj.getNodeValue("ac1")
0148: .getState() == Constants.Nd.READY);
0149: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0150: .getState() == Constants.Ed.ACTIVE);
0151: assertTrue("BnNode State Error ac2", proj.getNodeValue("ac2")
0152: .getState() == Constants.Nd.READY);
0153: assertTrue("BnEdge State Error e4", proj.getEdgeValue(e4)
0154: .getState() == Constants.Ed.INITIAL);
0155: assertTrue("BnEdge State Error e5", proj.getEdgeValue(e5)
0156: .getState() == Constants.Ed.INITIAL);
0157: assertTrue("BnNode State Error jn1", proj.getNodeValue("jn1")
0158: .getState() == Constants.Nd.INITIAL);
0159: assertTrue("BnEdge State Error e6", proj.getEdgeValue(e6)
0160: .getState() == Constants.Ed.INITIAL);
0161: assertTrue("BnNode State Error ac3", proj.getNodeValue("ac3")
0162: .getState() == Constants.Nd.INITIAL);
0163:
0164: eng.startActivity("work", "ac1");
0165:
0166: assertTrue(
0167: "BnNode State Error start ac1 : init",
0168: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0169: assertTrue("BnEdge State Error start ac1 : e1", proj
0170: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0171: assertTrue(
0172: "BnNode State Error start ac1 : sp1",
0173: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0174: assertTrue("BnEdge State Error start ac1 : e2", proj
0175: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0176: assertTrue(
0177: "BnNode State Error start ac1 : ac1",
0178: proj.getNodeValue("ac1").getState() == Constants.Nd.EXECUTING);
0179: assertTrue("BnEdge State Error start ac1 : e3", proj
0180: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0181: assertTrue("BnNode State Error start ac1 : ac2", proj
0182: .getNodeValue("ac2").getState() == Constants.Nd.READY);
0183: assertTrue(
0184: "BnEdge State Error start ac1 : e4",
0185: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0186: assertTrue("BnEdge State Error start ac1 : e5", proj
0187: .getEdgeValue(e5).getState() == Constants.Ed.INITIAL);
0188: assertTrue("BnNode State Error start ac1 : jn1", proj
0189: .getNodeValue("jn1").getState() == Constants.Nd.INITIAL);
0190: assertTrue("BnEdge State Error start ac1 : e6", proj
0191: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0192: assertTrue("BnNode State Error start ac1 : ac3", proj
0193: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0194:
0195: eng.startActivity("work", "ac2");
0196:
0197: assertTrue(
0198: "BnNode State Error start ac2 : init",
0199: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0200: assertTrue("BnEdge State Error start ac2 : e1", proj
0201: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0202: assertTrue(
0203: "BnNode State Error start ac2 : sp1",
0204: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0205: assertTrue("BnEdge State Error start ac2 : e2", proj
0206: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0207: assertTrue(
0208: "BnNode State Error start ac2 : ac1",
0209: proj.getNodeValue("ac1").getState() == Constants.Nd.EXECUTING);
0210: assertTrue("BnEdge State Error start ac2 : e3", proj
0211: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0212: assertTrue(
0213: "BnNode State Error start ac2 : ac2",
0214: proj.getNodeValue("ac2").getState() == Constants.Nd.EXECUTING);
0215: assertTrue(
0216: "BnEdge State Error start ac2 : e4",
0217: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0218: assertTrue(
0219: "BnEdge State Error start ac2 : e5",
0220: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0221: assertTrue(
0222: "BnNode State Error start ac2 : jn1",
0223: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPATING);
0224: assertTrue(
0225: "BnEdge State Error start ac2 : e6",
0226: proj.getEdgeValue(e6).getState() == Constants.Ed.ANTICIPATING);
0227: assertTrue(
0228: "BnNode State Error start ac2 : ac3",
0229: proj.getNodeValue("ac3").getState() == Constants.Nd.ANTICIPABLE);
0230:
0231: eng.startActivity("work", "ac3");
0232:
0233: try {
0234: eng.terminate("work");
0235: assertTrue("should have failed", false);
0236: } catch (HeroException h) {
0237: // normal behavior
0238: }
0239:
0240: assertTrue(
0241: "BnNode State Error start ac3 : init",
0242: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0243: assertTrue("BnEdge State Error start ac3 : e1", proj
0244: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0245: assertTrue(
0246: "BnNode State Error start ac3 : sp1",
0247: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0248: assertTrue("BnEdge State Error start ac3 : e2", proj
0249: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0250: assertTrue(
0251: "BnNode Value Error start ac3 : ac1",
0252: proj.getNodeValue("ac1").getState() == Constants.Nd.EXECUTING);
0253: assertTrue("BnEdge Value Error start ac3 : e3", proj
0254: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0255: assertTrue(
0256: "BnNode Value Error start ac3 : ac2",
0257: proj.getNodeValue("ac2").getState() == Constants.Nd.EXECUTING);
0258: assertTrue(
0259: "BnEdge Value Error start ac3 : e4",
0260: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0261: assertTrue(
0262: "BnEdge Value Error start ac3 : e5",
0263: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0264: assertTrue(
0265: "BnNode Value Error start ac3 : jn1",
0266: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPATING);
0267: assertTrue(
0268: "BnEdge Value Error start ac3 : e6",
0269: proj.getEdgeValue(e6).getState() == Constants.Ed.ANTICIPATING);
0270: assertTrue(
0271: "BnNode Value Error start ac3 : ac3",
0272: proj.getNodeValue("ac3").getState() == Constants.Nd.ANTICIPATING);
0273:
0274: try {
0275: eng.terminateActivity("work", "ac3");
0276: assertTrue("terminate ac3 should have failed", false);
0277: } catch (EngineException e) {
0278: // normal behavior
0279: }
0280:
0281: eng.terminateActivity("work", "ac1");
0282:
0283: assertTrue(
0284: "BnNode Value Error terminate ac1 : init",
0285: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0286: assertTrue("BnEdge Value Error terminate ac1 : e1", proj
0287: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0288: assertTrue(
0289: "BnNode Value Error terminate ac1 : sp1",
0290: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0291: assertTrue("BnEdge Value Error terminate ac1 : e2", proj
0292: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0293: assertTrue(
0294: "BnNode Value Error terminate ac1 : ac1",
0295: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0296: assertTrue("BnEdge Value Error terminate ac1 : e3", proj
0297: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0298: assertTrue(
0299: "BnNode Value Error terminate ac1 : ac2",
0300: proj.getNodeValue("ac2").getState() == Constants.Nd.EXECUTING);
0301: assertTrue("BnEdge Value Error terminate ac1 : e4", proj
0302: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0303: assertTrue(
0304: "BnEdge Value Error terminate ac1 : e5",
0305: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0306: assertTrue(
0307: "BnNode Value Error terminate ac1 : jn1",
0308: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPATING);
0309: assertTrue(
0310: "BnEdge Value Error terminate ac1 : e6",
0311: proj.getEdgeValue(e6).getState() == Constants.Ed.ANTICIPATING);
0312: assertTrue(
0313: "BnNode Value Error terminate ac1 : ac3",
0314: proj.getNodeValue("ac3").getState() == Constants.Nd.ANTICIPATING);
0315:
0316: eng.terminateActivity("work", "ac2");
0317:
0318: assertTrue(
0319: "BnNode Value Error terminate ac2 : init",
0320: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0321: assertTrue("BnEdge Value Error terminate ac2 : e1", proj
0322: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0323: assertTrue(
0324: "BnNode Value Error terminate ac2 : sp1",
0325: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0326: assertTrue("BnEdge Value Error terminate ac2 : e2", proj
0327: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0328: assertTrue(
0329: "BnNode Value Error terminate ac2 : ac1",
0330: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0331: assertTrue("BnEdge Value Error terminate ac2 : e3", proj
0332: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0333: assertTrue(
0334: "BnNode Value Error terminate ac2 : ac2",
0335: proj.getNodeValue("ac2").getState() == Constants.Nd.TERMINATED);
0336: assertTrue("BnEdge Value Error terminate ac2 : e4", proj
0337: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0338: assertTrue("BnEdge Value Error terminate ac2 : e5", proj
0339: .getEdgeValue(e5).getState() == Constants.Ed.ACTIVE);
0340: assertTrue(
0341: "BnNode Value Error terminate ac2 : jn1",
0342: proj.getNodeValue("jn1").getState() == Constants.Nd.TERMINATED);
0343: assertTrue("BnEdge Value Error terminate ac2 : e6", proj
0344: .getEdgeValue(e6).getState() == Constants.Ed.ACTIVE);
0345: assertTrue(
0346: "BnNode Value Error terminate ac2 : ac3",
0347: proj.getNodeValue("ac3").getState() == Constants.Nd.EXECUTING);
0348:
0349: eng.terminateActivity("work", "ac3");
0350:
0351: assertTrue(
0352: "BnNode Value Error terminate ac2 : init",
0353: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0354: assertTrue("BnEdge Value Error terminate ac2 : e1", proj
0355: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0356: assertTrue(
0357: "BnNode Value Error terminate ac2 : sp1",
0358: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0359: assertTrue("BnEdge Value Error terminate ac2 : e2", proj
0360: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0361: assertTrue(
0362: "BnNode Value Error terminate ac2 : ac1",
0363: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0364: assertTrue("BnEdge Value Error terminate ac2 : e3", proj
0365: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0366: assertTrue(
0367: "BnNode Value Error terminate ac2 : ac2",
0368: proj.getNodeValue("ac2").getState() == Constants.Nd.TERMINATED);
0369: assertTrue("BnEdge Value Error terminate ac2 : e4", proj
0370: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0371: assertTrue("BnEdge Value Error terminate ac2 : e5", proj
0372: .getEdgeValue(e5).getState() == Constants.Ed.ACTIVE);
0373: assertTrue(
0374: "BnNode Value Error terminate ac2 : jn1",
0375: proj.getNodeValue("jn1").getState() == Constants.Nd.TERMINATED);
0376: assertTrue("BnEdge Value Error terminate ac2 : e6", proj
0377: .getEdgeValue(e6).getState() == Constants.Ed.ACTIVE);
0378: assertTrue(
0379: "BnNode Value Error terminate ac2 : ac3",
0380: proj.getNodeValue("ac3").getState() == Constants.Nd.TERMINATED);
0381:
0382: try {
0383: eng.startActivity("work", "ac2");
0384: assertTrue("start ac2 should have failed", false);
0385: } catch (EngineException e) {
0386: // normal behavior
0387: }
0388:
0389: eng.terminate("work");
0390: assertTrue("Wrong project state",
0391: proj.getDetails().getState() == Constants.Pj.TERMINATED);
0392: }
0393:
0394: public void testEngineOR() throws Exception {
0395: ProjectSession proj;
0396: BnProjectValue pm;
0397: BnNodeValue nd;
0398: BnEdgeValue ev;
0399:
0400: // creation du projet
0401: proj = psh.create();
0402: proj.initProject("workOR");
0403: proj.addNode("init", Constants.Nd.AND_JOIN_NODE);
0404: proj.addNode("sp1", Constants.Nd.AND_JOIN_NODE);
0405: proj.addNode("ac1", Constants.Nd.AND_JOIN_NODE);
0406: proj.addNode("ac2", Constants.Nd.AND_JOIN_NODE);
0407: proj.addNode("jn1", Constants.Nd.OR_JOIN_NODE);
0408: proj.addNode("ac3", Constants.Nd.AND_JOIN_NODE);
0409: String e1 = proj.addEdge("init", "sp1");
0410: String e2 = proj.addEdge("sp1", "ac1");
0411: String e3 = proj.addEdge("sp1", "ac2");
0412: String e4 = proj.addEdge("ac1", "jn1");
0413: String e5 = proj.addEdge("ac2", "jn1");
0414: String e6 = proj.addEdge("jn1", "ac3");
0415: proj.addRole("test", "testeur");
0416: proj.setUserRole("admin", "test");
0417:
0418: proj.checkModelDefinition();
0419:
0420: eng = eh.create();
0421: eng.startActivity("workOR", "init");
0422: eng.startActivity("workOR", "sp1");
0423: proj = psh.create();
0424: proj.initProject("workOR");
0425: eng.terminateActivity("workOR", "init");
0426:
0427: assertTrue("BnNode State Error init", proj.getNodeValue("init")
0428: .getState() == Constants.Nd.TERMINATED);
0429: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0430: .getState() == Constants.Ed.ACTIVE);
0431: assertTrue("BnNode State Error sp1", proj.getNodeValue("sp1")
0432: .getState() == Constants.Nd.EXECUTING);
0433: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0434: .getState() == Constants.Ed.ANTICIPATING);
0435: assertTrue("BnNode State Error ac1", proj.getNodeValue("ac1")
0436: .getState() == Constants.Nd.ANTICIPABLE);
0437: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0438: .getState() == Constants.Ed.ANTICIPATING);
0439: assertTrue("BnNode State Error ac2", proj.getNodeValue("ac2")
0440: .getState() == Constants.Nd.ANTICIPABLE);
0441: assertTrue("BnEdge State Error e4", proj.getEdgeValue(e4)
0442: .getState() == Constants.Ed.INITIAL);
0443: assertTrue("BnEdge State Error e5", proj.getEdgeValue(e5)
0444: .getState() == Constants.Ed.INITIAL);
0445: assertTrue("BnNode State Error jn1", proj.getNodeValue("jn1")
0446: .getState() == Constants.Nd.INITIAL);
0447: assertTrue("BnEdge State Error e6", proj.getEdgeValue(e6)
0448: .getState() == Constants.Ed.INITIAL);
0449: assertTrue("BnNode State Error ac3", proj.getNodeValue("ac3")
0450: .getState() == Constants.Nd.INITIAL);
0451:
0452: eng.startActivity("workOR", "ac1");
0453:
0454: assertTrue(
0455: "BnNode State Error start ac1 : init",
0456: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0457: assertTrue("BnEdge State Error start ac1 : e1", proj
0458: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0459: assertTrue(
0460: "BnNode State Error start ac1 : sp1",
0461: proj.getNodeValue("sp1").getState() == Constants.Nd.EXECUTING);
0462: assertTrue(
0463: "BnEdge State Error start ac1 : e2",
0464: proj.getEdgeValue(e2).getState() == Constants.Ed.ANTICIPATING);
0465: assertTrue(
0466: "BnNode State Error start ac1 : ac1",
0467: proj.getNodeValue("ac1").getState() == Constants.Nd.ANTICIPATING);
0468: assertTrue(
0469: "BnEdge State Error start ac1 : e3",
0470: proj.getEdgeValue(e3).getState() == Constants.Ed.ANTICIPATING);
0471: assertTrue(
0472: "BnNode State Error start ac1 : ac2",
0473: proj.getNodeValue("ac2").getState() == Constants.Nd.ANTICIPABLE);
0474: assertTrue(
0475: "BnEdge State Error start ac1 : e4",
0476: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0477: assertTrue("BnEdge State Error start ac1 : e5", proj
0478: .getEdgeValue(e5).getState() == Constants.Ed.INITIAL);
0479: assertTrue(
0480: "BnNode State Error start ac1 : jn1",
0481: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPABLE);
0482: assertTrue("BnEdge State Error start ac1 : e6", proj
0483: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0484: assertTrue("BnNode State Error start ac1 : ac3", proj
0485: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0486:
0487: eng.startActivity("workOR", "ac2");
0488:
0489: assertTrue(
0490: "BnNode State Error start ac1 : init",
0491: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0492: assertTrue("BnEdge State Error start ac1 : e1", proj
0493: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0494: assertTrue(
0495: "BnNode State Error start ac1 : sp1",
0496: proj.getNodeValue("sp1").getState() == Constants.Nd.EXECUTING);
0497: assertTrue(
0498: "BnEdge State Error start ac1 : e2",
0499: proj.getEdgeValue(e2).getState() == Constants.Ed.ANTICIPATING);
0500: assertTrue(
0501: "BnNode State Error start ac1 : ac1",
0502: proj.getNodeValue("ac1").getState() == Constants.Nd.ANTICIPATING);
0503: assertTrue(
0504: "BnEdge State Error start ac1 : e3",
0505: proj.getEdgeValue(e3).getState() == Constants.Ed.ANTICIPATING);
0506: assertTrue(
0507: "BnNode State Error start ac1 : ac2",
0508: proj.getNodeValue("ac2").getState() == Constants.Nd.ANTICIPATING);
0509: assertTrue(
0510: "BnEdge State Error start ac1 : e4",
0511: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0512: assertTrue(
0513: "BnEdge State Error start ac1 : e5",
0514: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0515: assertTrue(
0516: "BnNode State Error start ac1 : jn1",
0517: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPABLE);
0518: assertTrue("BnEdge State Error start ac1 : e6", proj
0519: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0520: assertTrue("BnNode State Error start ac1 : ac3", proj
0521: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0522:
0523: eng.terminateActivity("workOR", "sp1");
0524:
0525: assertTrue(
0526: "BnNode State Error start ac1 : init",
0527: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0528: assertTrue("BnEdge State Error start ac1 : e1", proj
0529: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0530: assertTrue(
0531: "BnNode State Error start ac1 : sp1",
0532: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0533: assertTrue("BnEdge State Error start ac1 : e2", proj
0534: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0535: assertTrue(
0536: "BnNode State Error start ac1 : ac1",
0537: proj.getNodeValue("ac1").getState() == Constants.Nd.EXECUTING);
0538: assertTrue("BnEdge State Error start ac1 : e3", proj
0539: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0540: assertTrue(
0541: "BnNode State Error start ac1 : ac2",
0542: proj.getNodeValue("ac2").getState() == Constants.Nd.EXECUTING);
0543: assertTrue(
0544: "BnEdge State Error start ac1 : e4",
0545: proj.getEdgeValue(e4).getState() == Constants.Ed.ANTICIPATING);
0546: assertTrue(
0547: "BnEdge State Error start ac1 : e5",
0548: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0549: assertTrue(
0550: "BnNode State Error start ac1 : jn1",
0551: proj.getNodeValue("jn1").getState() == Constants.Nd.ANTICIPABLE);
0552: assertTrue("BnEdge State Error start ac1 : e6", proj
0553: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0554: assertTrue("BnNode State Error start ac1 : ac3", proj
0555: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0556:
0557: eng.terminateActivity("workOR", "ac1");
0558:
0559: assertTrue(
0560: "BnNode State Error start ac1 : init",
0561: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0562: assertTrue("BnEdge State Error start ac1 : e1", proj
0563: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0564: assertTrue(
0565: "BnNode State Error start ac1 : sp1",
0566: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0567: assertTrue("BnEdge State Error start ac1 : e2", proj
0568: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0569: assertTrue(
0570: "BnNode State Error start ac1 : ac1",
0571: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0572: assertTrue("BnEdge State Error start ac1 : e3", proj
0573: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0574: assertTrue(
0575: "BnNode State Error start ac1 : ac2",
0576: proj.getNodeValue("ac2").getState() == Constants.Nd.EXECUTING);
0577: assertTrue("BnEdge State Error start ac1 : e4", proj
0578: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0579: assertTrue(
0580: "BnEdge State Error start ac1 : e5",
0581: proj.getEdgeValue(e5).getState() == Constants.Ed.ANTICIPATING);
0582: assertTrue("BnNode State Error start ac1 : jn1", proj
0583: .getNodeValue("jn1").getState() == Constants.Nd.READY);
0584: assertTrue("BnEdge State Error start ac1 : e6", proj
0585: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0586: assertTrue("BnNode State Error start ac1 : ac3", proj
0587: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0588:
0589: eng.terminateActivity("workOR", "ac2");
0590:
0591: assertTrue(
0592: "BnNode State Error start ac1 : init",
0593: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0594: assertTrue("BnEdge State Error start ac1 : e1", proj
0595: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0596: assertTrue(
0597: "BnNode State Error start ac1 : sp1",
0598: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0599: assertTrue("BnEdge State Error start ac1 : e2", proj
0600: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0601: assertTrue(
0602: "BnNode State Error start ac1 : ac1",
0603: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0604: assertTrue("BnEdge State Error start ac1 : e3", proj
0605: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0606: assertTrue(
0607: "BnNode State Error start ac1 : ac2",
0608: proj.getNodeValue("ac2").getState() == Constants.Nd.TERMINATED);
0609: assertTrue("BnEdge State Error start ac1 : e4", proj
0610: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0611: assertTrue("BnEdge State Error start ac1 : e5", proj
0612: .getEdgeValue(e5).getState() == Constants.Ed.ACTIVE);
0613: assertTrue("BnNode State Error start ac1 : jn1", proj
0614: .getNodeValue("jn1").getState() == Constants.Nd.READY);
0615: assertTrue("BnEdge State Error start ac1 : e6", proj
0616: .getEdgeValue(e6).getState() == Constants.Ed.INITIAL);
0617: assertTrue("BnNode State Error start ac1 : ac3", proj
0618: .getNodeValue("ac3").getState() == Constants.Nd.INITIAL);
0619:
0620: eng.startActivity("workOR", "jn1");
0621: eng.startActivity("workOR", "ac3");
0622:
0623: assertTrue(
0624: "BnNode State Error start ac1 : init",
0625: proj.getNodeValue("init").getState() == Constants.Nd.TERMINATED);
0626: assertTrue("BnEdge State Error start ac1 : e1", proj
0627: .getEdgeValue(e1).getState() == Constants.Ed.ACTIVE);
0628: assertTrue(
0629: "BnNode State Error start ac1 : sp1",
0630: proj.getNodeValue("sp1").getState() == Constants.Nd.TERMINATED);
0631: assertTrue("BnEdge State Error start ac1 : e2", proj
0632: .getEdgeValue(e2).getState() == Constants.Ed.ACTIVE);
0633: assertTrue(
0634: "BnNode State Error start ac1 : ac1",
0635: proj.getNodeValue("ac1").getState() == Constants.Nd.TERMINATED);
0636: assertTrue("BnEdge State Error start ac1 : e3", proj
0637: .getEdgeValue(e3).getState() == Constants.Ed.ACTIVE);
0638: assertTrue(
0639: "BnNode State Error start ac1 : ac2",
0640: proj.getNodeValue("ac2").getState() == Constants.Nd.TERMINATED);
0641: assertTrue("BnEdge State Error start ac1 : e4", proj
0642: .getEdgeValue(e4).getState() == Constants.Ed.ACTIVE);
0643: assertTrue("BnEdge State Error start ac1 : e5", proj
0644: .getEdgeValue(e5).getState() == Constants.Ed.ACTIVE);
0645: assertTrue(
0646: "BnNode State Error start ac1 : jn1",
0647: proj.getNodeValue("jn1").getState() == Constants.Nd.EXECUTING);
0648: assertTrue(
0649: "BnEdge State Error start ac1 : e6",
0650: proj.getEdgeValue(e6).getState() == Constants.Ed.ANTICIPATING);
0651: assertTrue(
0652: "BnNode State Error start ac1 : ac3",
0653: proj.getNodeValue("ac3").getState() == Constants.Nd.ANTICIPATING);
0654:
0655: try {
0656: eng.terminateActivity("workOR", "ac3");
0657: assertTrue("should have failed", false);
0658: } catch (HeroException h) {
0659: // normal behavior
0660: }
0661:
0662: eng.terminateActivity("workOR", "jn1");
0663: eng.terminateActivity("workOR", "ac3");
0664:
0665: eng.terminate("workOR");
0666: assertTrue("Wrong project state",
0667: proj.getDetails().getState() == Constants.Pj.TERMINATED);
0668: }
0669:
0670: public void testCancelANDActivity() throws Exception {
0671: ProjectSession proj;
0672: BnProjectValue pm;
0673: BnNodeValue nd;
0674: BnEdgeValue ev;
0675:
0676: // creation du projet
0677: proj = psh.create();
0678: proj.initProject("workCancel");
0679: proj.addNode("init", Constants.Nd.AND_JOIN_NODE);
0680: proj.addNode("sp1", Constants.Nd.AND_JOIN_NODE);
0681: proj.addNode("ac1", Constants.Nd.AND_JOIN_NODE);
0682: proj.addNode("ac2", Constants.Nd.AND_JOIN_NODE);
0683:
0684: String e1 = proj.addEdge("init", "sp1");
0685: String e2 = proj.addEdge("sp1", "ac1");
0686: String e3 = proj.addEdge("sp1", "ac2");
0687:
0688: proj.addRole("test", "testeur");
0689: proj.setUserRole("admin", "test");
0690:
0691: proj.checkModelDefinition();
0692:
0693: eng = eh.create();
0694: eng.startActivity("workCancel", "init");
0695: eng.startActivity("workCancel", "sp1");
0696: proj = psh.create();
0697: proj.initProject("workCancel");
0698: eng.terminateActivity("workCancel", "init");
0699: eng.cancelActivity("workCancel", "sp1");
0700:
0701: assertTrue("BnNode State Error init", proj.getNodeValue("init")
0702: .getState() == Constants.Nd.TERMINATED);
0703: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0704: .getState() == Constants.Ed.ACTIVE);
0705: assertTrue("BnNode State Error sp1", proj.getNodeValue("sp1")
0706: .getState() == Constants.Nd.DEAD);
0707: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0708: .getState() == Constants.Ed.DEAD);
0709: assertTrue("BnNode State Error ac1", proj.getNodeValue("ac1")
0710: .getState() == Constants.Nd.DEAD);
0711: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0712: .getState() == Constants.Ed.DEAD);
0713: assertTrue("BnNode State Error ac2", proj.getNodeValue("ac2")
0714: .getState() == Constants.Nd.DEAD);
0715:
0716: eng.terminate("workCancel");
0717: assertTrue("Wrong project state",
0718: proj.getDetails().getState() == Constants.Pj.TERMINATED);
0719: }
0720:
0721: public void testCancelORActivity() throws Exception {
0722: ProjectSession proj;
0723: BnProjectValue pm;
0724: BnNodeValue nd;
0725: BnEdgeValue ev;
0726:
0727: // creation du projet
0728: proj = psh.create();
0729: proj.initProject("workCancelOR");
0730: proj.addNode("init", Constants.Nd.AND_JOIN_NODE);
0731: proj.addNode("sp1", Constants.Nd.AND_JOIN_NODE);
0732: proj.addNode("ac1", Constants.Nd.AND_JOIN_NODE);
0733: proj.addNode("ac2", Constants.Nd.AND_JOIN_NODE);
0734: proj.addNode("ac3", Constants.Nd.OR_JOIN_NODE);
0735:
0736: String e1 = proj.addEdge("init", "sp1");
0737: String e2 = proj.addEdge("sp1", "ac1");
0738: String e3 = proj.addEdge("sp1", "ac2");
0739: String e4 = proj.addEdge("ac1", "ac3");
0740: String e5 = proj.addEdge("ac2", "ac3");
0741:
0742: proj.addRole("test", "testeur");
0743: proj.setUserRole("admin", "test");
0744:
0745: proj.checkModelDefinition();
0746:
0747: eng = eh.create();
0748: eng.startActivity("workCancelOR", "init");
0749: eng.startActivity("workCancelOR", "sp1");
0750: eng.terminateActivity("workCancelOR", "init");
0751: eng.terminateActivity("workCancelOR", "sp1");
0752: eng.startActivity("workCancelOR", "ac2");
0753: eng.cancelActivity("workCancelOR", "ac1");
0754:
0755: assertTrue("BnNode State Error init", proj.getNodeValue("init")
0756: .getState() == Constants.Nd.TERMINATED);
0757: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0758: .getState() == Constants.Ed.ACTIVE);
0759: assertTrue("BnNode State Error sp1", proj.getNodeValue("sp1")
0760: .getState() == Constants.Nd.TERMINATED);
0761: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0762: .getState() == Constants.Ed.ACTIVE);
0763: assertTrue("BnNode State Error ac1", proj.getNodeValue("ac1")
0764: .getState() == Constants.Nd.DEAD);
0765: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0766: .getState() == Constants.Ed.ACTIVE);
0767: assertTrue("BnNode State Error ac2", proj.getNodeValue("ac2")
0768: .getState() == Constants.Nd.EXECUTING);
0769: assertTrue("BnEdge State Error e4", proj.getEdgeValue(e4)
0770: .getState() == Constants.Ed.DEAD);
0771: assertTrue("BnEdge State Error e5", proj.getEdgeValue(e5)
0772: .getState() == Constants.Ed.ANTICIPATING);
0773: assertTrue("BnNode State Error ac3", proj.getNodeValue("ac3")
0774: .getState() == Constants.Nd.ANTICIPABLE);
0775: }
0776:
0777: public void testAutomaticNode() throws Exception {
0778: ProjectSession proj = psh.create();
0779: proj.initProject("testoto");
0780: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0781: proj.addNode("supernonode",
0782: Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0783: proj.addEdge("nonode", "supernonode");
0784:
0785: proj.checkModelDefinition();
0786:
0787: Engine eng = eh.create();
0788: eng.startActivity("testoto", "nonode");
0789: assertTrue("Supernonode will be terminated", proj.getNodeValue(
0790: "supernonode").getState() == Constants.Nd.ANTICIPATING);
0791: eng.terminateActivity("testoto", "nonode");
0792: assertTrue("Supernonode will be terminated", proj.getNodeValue(
0793: "supernonode").getState() == Constants.Nd.TERMINATED);
0794: }
0795:
0796: public void testAutomaticNodeOR() throws Exception {
0797: ProjectSession proj = psh.create();
0798: proj.initProject("testoto2");
0799: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0800: proj.addNode("nonode2", Constants.Nd.AND_JOIN_NODE);
0801: proj
0802: .addNode("supernonode",
0803: Constants.Nd.OR_JOIN_AUTOMATIC_NODE);
0804: proj.addEdge("nonode", "supernonode");
0805: proj.addEdge("nonode2", "supernonode");
0806:
0807: proj.checkModelDefinition();
0808:
0809: Engine eng = eh.create();
0810: eng.startActivity("testoto2", "nonode");
0811: assertTrue(
0812: "Supernonode will be anticipating ",
0813: proj.getNodeValue("supernonode").getState() == Constants.Nd.ANTICIPATING);
0814: eng.startActivity("testoto2", "nonode2");
0815: eng.terminateActivity("testoto2", "nonode");
0816: assertTrue(
0817: "Supernonode will be anticipating",
0818: proj.getNodeValue("supernonode").getState() == Constants.Nd.TERMINATED);
0819: }
0820:
0821: public void testTraditionalActivityNode() throws Exception {
0822: ProjectSession proj = psh.create();
0823: proj.initProject("testtradacti");
0824: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0825: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
0826: proj.setNodeTraditional("supernonode");
0827: proj.addEdge("nonode", "supernonode");
0828:
0829: proj.checkModelDefinition();
0830:
0831: Engine eng = eh.create();
0832: eng.startActivity("testtradacti", "nonode");
0833: assertTrue("Supernonode will be initial", proj.getNodeValue(
0834: "supernonode").getState() == Constants.Nd.INITIAL);
0835: eng.terminateActivity("testtradacti", "nonode");
0836: assertTrue("Supernonode will be ready", proj.getNodeValue(
0837: "supernonode").getState() == Constants.Nd.READY);
0838: }
0839:
0840: public void testTraditionalAutomaticNode() throws Exception {
0841: ProjectSession proj = psh.create();
0842: proj.initProject("testtrad");
0843: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0844: proj.addNode("supernonode",
0845: Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
0846: proj.setNodeTraditional("supernonode");
0847: proj.addEdge("nonode", "supernonode");
0848:
0849: proj.checkModelDefinition();
0850:
0851: Engine eng = eh.create();
0852: eng.startActivity("testtrad", "nonode");
0853: assertTrue("Supernonode will be initial", proj.getNodeValue(
0854: "supernonode").getState() == Constants.Nd.INITIAL);
0855: eng.terminateActivity("testtrad", "nonode");
0856: assertTrue("Supernonode will be terminated", proj.getNodeValue(
0857: "supernonode").getState() == Constants.Nd.TERMINATED);
0858: }
0859:
0860: public void testEdgeConditionPropagation() throws Exception {
0861: ProjectSession proj = psh.create();
0862: proj.initProject("edgeCondP");
0863: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0864: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
0865: String e1 = proj.addEdge("nonode", "supernonode");
0866: proj
0867: .setEdgeCondition(e1,
0868: "(node.getName()).equals(\"nonode\")");
0869:
0870: proj.checkModelDefinition();
0871:
0872: Engine eng = eh.create();
0873: eng.startActivity("edgeCondP", "nonode");
0874: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0875: "nonode").getState() == Constants.Nd.EXECUTING);
0876: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0877: "supernonode").getState() == Constants.Nd.ANTICIPABLE);
0878: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0879: .getState() == Constants.Ed.ANTICIPATING);
0880: eng.terminateActivity("edgeCondP", "nonode");
0881: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0882: "nonode").getState() == Constants.Nd.TERMINATED);
0883: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0884: "supernonode").getState() == Constants.Nd.READY);
0885: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0886: .getState() == Constants.Ed.ACTIVE);
0887: }
0888:
0889: public void testEdgeConditionPropagationProperty() throws Exception {
0890: ProjectSession proj = psh.create();
0891: proj.initProject("edgeCondPP");
0892: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0893: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
0894: proj.setNodeProperty("nonode", "prop1", "value1", true);
0895: String e1 = proj.addEdge("nonode", "supernonode");
0896: proj.setEdgeCondition(e1, "prop1.equals(\"value1\")");
0897:
0898: proj.checkModelDefinition();
0899:
0900: Engine eng = eh.create();
0901: eng.startActivity("edgeCondPP", "nonode");
0902: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0903: "nonode").getState() == Constants.Nd.EXECUTING);
0904: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0905: "supernonode").getState() == Constants.Nd.ANTICIPABLE);
0906: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0907: .getState() == Constants.Ed.ANTICIPATING);
0908: eng.terminateActivity("edgeCondPP", "nonode");
0909: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0910: "nonode").getState() == Constants.Nd.TERMINATED);
0911: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0912: "supernonode").getState() == Constants.Nd.READY);
0913: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0914: .getState() == Constants.Ed.ACTIVE);
0915: }
0916:
0917: public void testEdgeConditionNotPropagation() throws Exception {
0918: ProjectSession proj = psh.create();
0919: proj.initProject("edgeCondNP");
0920: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0921: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
0922: String e1 = proj.addEdge("nonode", "supernonode");
0923: proj.setEdgeCondition(e1,
0924: "(node.getName()).equals(\"supernonode\")");
0925:
0926: proj.checkModelDefinition();
0927:
0928: Engine eng = eh.create();
0929: eng.startActivity("edgeCondNP", "nonode");
0930: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0931: "nonode").getState() == Constants.Nd.EXECUTING);
0932: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0933: "supernonode").getState() == Constants.Nd.ANTICIPABLE);
0934: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0935: .getState() == Constants.Ed.ANTICIPATING);
0936: eng.terminateActivity("edgeCondNP", "nonode");
0937: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0938: "nonode").getState() == Constants.Nd.TERMINATED);
0939: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0940: "supernonode").getState() == Constants.Nd.DEAD);
0941: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0942: .getState() == Constants.Ed.DEAD);
0943: }
0944:
0945: public void testEdgeConditionANDSplitPropagation() throws Exception {
0946: ProjectSession proj = psh.create();
0947: proj.initProject("edgeCondSP");
0948: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
0949: proj.addNode("nonode1", Constants.Nd.AND_JOIN_NODE);
0950: proj.addNode("nonode2", Constants.Nd.AND_JOIN_NODE);
0951: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
0952: String e1 = proj.addEdge("nonode", "nonode1");
0953: String e2 = proj.addEdge("nonode1", "nonode2");
0954: String e3 = proj.addEdge("nonode1", "supernonode");
0955: proj
0956: .setEdgeCondition(e1,
0957: "(node.getName()).equals(\"nonode\")");
0958: proj.setEdgeCondition(e2,
0959: "(node.getName()).equals(\"nonode1\")");
0960: proj.setEdgeCondition(e3,
0961: "(node.getName()).equals(\"nonode1\")");
0962:
0963: proj.checkModelDefinition();
0964:
0965: Engine eng = eh.create();
0966: eng.startActivity("edgeCondSP", "nonode");
0967: eng.startActivity("edgeCondSP", "nonode1");
0968:
0969: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0970: "nonode").getState() == Constants.Nd.EXECUTING);
0971: assertTrue("BnNode State Error nonode1", proj.getNodeValue(
0972: "nonode1").getState() == Constants.Nd.ANTICIPATING);
0973: assertTrue("BnNode State Error nonode2", proj.getNodeValue(
0974: "nonode2").getState() == Constants.Nd.ANTICIPABLE);
0975: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0976: "supernonode").getState() == Constants.Nd.ANTICIPABLE);
0977: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0978: .getState() == Constants.Ed.ANTICIPATING);
0979: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0980: .getState() == Constants.Ed.ANTICIPATING);
0981: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
0982: .getState() == Constants.Ed.ANTICIPATING);
0983:
0984: eng.terminateActivity("edgeCondSP", "nonode");
0985: eng.terminateActivity("edgeCondSP", "nonode1");
0986:
0987: assertTrue("BnNode State Error nonode", proj.getNodeValue(
0988: "nonode").getState() == Constants.Nd.TERMINATED);
0989: assertTrue("BnNode State Error nonode1", proj.getNodeValue(
0990: "nonode1").getState() == Constants.Nd.TERMINATED);
0991: assertTrue("BnNode State Error nonode2", proj.getNodeValue(
0992: "nonode2").getState() == Constants.Nd.READY);
0993: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
0994: "supernonode").getState() == Constants.Nd.READY);
0995: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
0996: .getState() == Constants.Ed.ACTIVE);
0997: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
0998: .getState() == Constants.Ed.ACTIVE);
0999: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
1000: .getState() == Constants.Ed.ACTIVE);
1001: }
1002:
1003: public void testEdgeConditionORSplitPropagation() throws Exception {
1004: ProjectSession proj = psh.create();
1005: proj.initProject("edgeCondOP");
1006: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
1007: proj.addNode("nonode1", Constants.Nd.AND_JOIN_NODE);
1008: proj.addNode("nonode2", Constants.Nd.AND_JOIN_NODE);
1009: proj.addNode("supernonode", Constants.Nd.AND_JOIN_NODE);
1010: String e1 = proj.addEdge("nonode", "nonode1");
1011: String e2 = proj.addEdge("nonode", "nonode2");
1012: String e3 = proj.addEdge("nonode", "supernonode");
1013: proj.setEdgeCondition(e1,
1014: "(node.getName()).equals(\"nonode1\")");
1015: proj
1016: .setEdgeCondition(e2,
1017: "(node.getName()).equals(\"nonode\")");
1018: proj.setEdgeCondition(e3,
1019: "(node.getName()).equals(\"nonode1\")");
1020:
1021: proj.checkModelDefinition();
1022:
1023: Engine eng = eh.create();
1024: eng.startActivity("edgeCondOP", "nonode");
1025: eng.terminateActivity("edgeCondOP", "nonode");
1026:
1027: assertTrue("BnNode State Error nonode", proj.getNodeValue(
1028: "nonode").getState() == Constants.Nd.TERMINATED);
1029: assertTrue("BnNode State Error nonode1", proj.getNodeValue(
1030: "nonode1").getState() == Constants.Nd.DEAD);
1031: assertTrue("BnNode State Error nonode2", proj.getNodeValue(
1032: "nonode2").getState() == Constants.Nd.READY);
1033: assertTrue("BnNode State Error supernonode", proj.getNodeValue(
1034: "supernonode").getState() == Constants.Nd.DEAD);
1035: assertTrue("BnEdge State Error e1", proj.getEdgeValue(e1)
1036: .getState() == Constants.Ed.DEAD);
1037: assertTrue("BnEdge State Error e2", proj.getEdgeValue(e2)
1038: .getState() == Constants.Ed.ACTIVE);
1039: assertTrue("BnEdge State Error e3", proj.getEdgeValue(e3)
1040: .getState() == Constants.Ed.DEAD);
1041: }
1042:
1043: /* public void testExternalAgentWithANDJoinNode() throws Exception {
1044: ProjectSession proj = psh.create();
1045: proj.initProject("externalAgent");
1046: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
1047: proj.addNode("nonode1", Constants.Nd.AND_JOIN_NODE);
1048: proj.addNode("nonode2", Constants.Nd.AND_JOIN_NODE);
1049: proj.addAgent("superagent");
1050: String e1 = proj.addEdge("nonode", "nonode1");
1051: String e2 = proj.addEdge("nonode1", "nonode2");
1052: String e3 = proj.addAgentEdge("superagent", "nonode1");
1053: Engine eng = eh.create();
1054: eng.startActivity("externalAgent","nonode");
1055: eng.activeAgent("externalAgent","superagent");
1056:
1057: assertTrue("BnNode State Error nonode",proj.getNodeValue("nonode").getState() == Constants.Nd.EXECUTING);
1058: assertTrue("BnNode State Error nonode1",proj.getNodeValue("nonode1").getState() == Constants.Nd.ANTICIPABLE);
1059: assertTrue("BnNode State Error nonode2",proj.getNodeValue("nonode2").getState() == Constants.Nd.INITIAL);
1060: assertTrue("BnNode State Error superagent",proj.getAgentValue("superagent").getState() == Constants.Ag.ACTIVE);
1061: assertTrue("BnEdge State Error e1",proj.getEdgeValue(e1).getState() == Constants.Ed.ANTICIPATING);
1062: assertTrue("BnEdge State Error e2",proj.getEdgeValue(e2).getState() == Constants.Ed.INITIAL);
1063: assertTrue("BnEdge State Error e3",proj.getAgentEdgeValue(e3).getState() == Constants.Ed.ANTICIPATING);
1064: }
1065:
1066: public void testExternalAgentWithORJoinNode() throws Exception {
1067: ProjectSession proj = psh.create();
1068: proj.initProject("externalAgentOr");
1069: proj.addNode("nonode", Constants.Nd.AND_JOIN_NODE);
1070: proj.addNode("nonode1", Constants.Nd.OR_JOIN_NODE);
1071: proj.addNode("nonode2", Constants.Nd.AND_JOIN_NODE);
1072: proj.addAgent("superagent");
1073: String e1 = proj.addEdge("nonode", "nonode1");
1074: String e2 = proj.addEdge("nonode1", "nonode2");
1075: String e3 = proj.addAgentEdge("superagent", "nonode1");
1076: Engine eng = eh.create();
1077: eng.activeAgent("externalAgentOr","superagent");
1078:
1079: assertTrue("BnNode State Error nonode",proj.getNodeValue("nonode").getState() == Constants.Nd.READY);
1080: assertTrue("BnNode State Error nonode1",proj.getNodeValue("nonode1").getState() == Constants.Nd.ANTICIPABLE);
1081: assertTrue("BnNode State Error nonode2",proj.getNodeValue("nonode2").getState() == Constants.Nd.INITIAL);
1082: assertTrue("BnNode State Error superagent",proj.getAgentValue("superagent").getState() == Constants.Ag.ACTIVE);
1083: assertTrue("BnEdge State Error e1",proj.getEdgeValue(e1).getState() == Constants.Ed.INITIAL);
1084: assertTrue("BnEdge State Error e2",proj.getEdgeValue(e2).getState() == Constants.Ed.INITIAL);
1085: assertTrue("BnEdge State Error e3",proj.getAgentEdgeValue(e3).getState() == Constants.Ed.ANTICIPATING);
1086: }*/
1087:
1088: }
|