001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: InstancesTests.java,v 1.7 2005/01/14 17:14:39 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.test.stress;
029:
030: import javax.security.auth.login.LoginContext;
031: import hero.client.test.SimpleCallbackHandler;
032:
033: import hero.interfaces.ProjectSession;
034: import hero.interfaces.ProjectSessionHome;
035: import hero.interfaces.ProjectSessionUtil;
036: import hero.interfaces.UserSession;
037: import hero.interfaces.UserSessionHome;
038: import hero.interfaces.UserSessionUtil;
039: import hero.interfaces.UserRegistration;
040: import hero.interfaces.UserRegistrationHome;
041: import hero.interfaces.UserRegistrationUtil;
042: import junit.framework.TestCase;
043: import junit.framework.TestSuite;
044: import hero.interfaces.Constants;
045: import java.util.Collection;
046: import java.util.Iterator;
047:
048: public class InstancesTests extends TestCase {
049:
050: public InstancesTests(String testname) {
051: super (testname);
052: }
053:
054: public static TestSuite suite() {
055: return new TestSuite(InstancesTests.class);
056: }
057:
058: public void setUp() throws Exception {
059: }
060:
061: public void testInstances() throws Exception {
062: ProjectSessionHome pHome = ProjectSessionUtil.getHome();
063: ProjectSession psSub = pHome.create();
064: try {
065:
066: psSub.initModel("node5Sub");
067: psSub.addNode("subNode1", Constants.Nd.AND_JOIN_NODE);
068: psSub.addNode("subNode2", Constants.Nd.AND_JOIN_NODE);
069: psSub.setNodeRole("subNode1", "admin");
070: psSub.setNodeRole("subNode2", "admin");
071: psSub.addEdge("subNode1", "subNode2");
072: String script = "import hero.interfaces.BnInstanceLocal;\n"
073: + "import hero.interfaces.BnNodeLocal;\n"
074: + "afterStart (Object b,Object n) {\n\n\n"
075: + "System.out.println(\"SPInstantiation test, SubProcess: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
076: + "}";
077: psSub.addNodeInterHook("subNode2", "subNode2",
078: hero.interfaces.Constants.Nd.AFTERSTART,
079: Constants.Hook.BSINTERACTIVE, script);
080: psSub.addUser("admin2");
081: psSub.setNodeRole("subNode1", "admin");
082: psSub.setNodeRole("subNode2", "admin");
083:
084: ProjectSession pss = pHome.create();
085: pss.initModel("Stress");
086: pss.addNode("node1", Constants.Nd.AND_JOIN_NODE);
087: pss.addNode("node2", Constants.Nd.AND_JOIN_NODE);
088: pss.addNode("node3", Constants.Nd.AND_JOIN_NODE);
089: pss.addNode("node4", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
090: pss.addNodeSubProcess("node5Sub", "Stress");
091: //pss.addNode("node5Sub",Constants.Nd.AND_JOIN_NODE);
092: pss.addEdge("node1", "node2");
093: pss.addEdge("node2", "node3");
094: pss.addEdge("node2", "node4");
095: pss.addEdge("node3", "node5Sub");
096: script = "import hero.interfaces.BnInstanceLocal;\n"
097: + "import hero.interfaces.BnNodeLocal;\n"
098: + "afterStart (Object b,Object n) {\n\n\n"
099: + "System.out.println(\"Stress test, node: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
100: + "}";
101: pss.addNodeInterHook("node2", "node2",
102: hero.interfaces.Constants.Nd.AFTERSTART,
103: Constants.Hook.BSINTERACTIVE, script);
104: pss.addUser("admin2");
105: pss.setUserRole("admin2", "InitialRole");
106: pss.setNodeRole("node1", "admin");
107: pss.setNodeRole("node2", "admin");
108: pss.setNodeRole("node3", "admin");
109: pss.setNodeRole("node4", "admin");
110: pss.setNodeRole("node5Sub", "admin");
111: ProjectSession pss1 = pHome.create();
112: pss1.instantiateProject("Stress");
113: assertTrue("Instantiation Error, role error in node1", pss1
114: .getNodeRoleName("node1").equals("admin"));
115: Collection users = pss1.getUsers();
116: assertTrue(
117: "Instantiation Error, user admin2 does not exist",
118: users.contains("admin2"));
119: assertTrue("Instantiation Error, type error in node1", pss1
120: .getNodeType("node1") == Constants.Nd.AND_JOIN_NODE);
121: assertTrue(
122: "Instantiation Error, type error in node4",
123: pss1.getNodeType("node4") == Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
124: } catch (Exception e) {
125: }
126: int global = 0;
127: for (global = 0; global < 100; global++) {
128: UserRegistrationHome urHome = UserRegistrationUtil
129: .getHome();
130: UserRegistration userReg = urHome.create();
131: userReg.userCreate("user" + global, "user" + global,
132: "miguel.valdes-faura@ext.bull.net");
133: userReg.remove();
134: String uName = "user" + global;
135: char[] password = uName.toCharArray();
136: SimpleCallbackHandler handler = new SimpleCallbackHandler(
137: uName, password);
138: LoginContext lc = new LoginContext("TestClient", handler);
139: lc.login();
140:
141: int i = 0;
142: for (i = 0; i < 10; i++) {
143: ProjectSession ps = pHome.create();
144: ps.instantiateProject("Stress");
145: //Thread.sleep(100);
146: ps.remove();
147: }
148:
149: UserSessionHome uHome = UserSessionUtil.getHome();
150: UserSession us = uHome.create();
151: Collection instances = us.getInstancesListNames();
152: assertTrue("getInstancesList error", instances.size() >= 1);
153: Iterator index = instances.iterator();
154: UserSession usUser = uHome.create();
155: while (index.hasNext()) {
156: String name = (String) index.next();
157: Collection task = usUser.getToDoList(name);
158: Iterator it = task.iterator();
159: while (it.hasNext()) {
160: String activity = (String) it.next();
161: usUser.startActivity(name, activity);
162: if (activity.matches(".*_instance.*"))
163: this .executeSubProcess(activity);
164:
165: usUser.terminateActivity(name, activity);
166: task = usUser.getToDoList(name);
167: it = task.iterator();
168: }
169: }
170: }
171: }
172:
173: public void executeSubProcess(String subProcess) throws Exception {
174: UserSessionHome uHome = UserSessionUtil.getHome();
175: UserSession us = uHome.create();
176: us.startActivity(subProcess, "subNode1");
177: us.terminateActivity(subProcess, "subNode1");
178: us.startActivity(subProcess, "subNode2");
179: us.terminateActivity(subProcess, "subNode2");
180: }
181:
182: /*public void testInstancesInst() throws Exception {
183: UserSessionHome uHome = UserSessionUtil.getHome();
184: UserSession us = uHome.create();
185: Collection instances = us.getInstancesListNames();
186: assertTrue("getInstancesList error",instances.size()>=1);
187: Iterator index = instances.iterator();
188: UserSession usUser = uHome.create();
189: while (index.hasNext())
190: {
191: String name = (String)index.next();
192: Collection task = usUser.getToDoList(name);
193: Iterator it = task.iterator();
194: while (it.hasNext())
195: {
196: String activity = (String)it.next();
197: usUser.startActivity(name,activity);
198: if (activity.matches(".*_instance.*"))
199: this.executeSubProcess(activity);
200:
201: usUser.terminateActivity(name,activity);
202: task = usUser.getToDoList(name);
203: it = task.iterator();
204: }
205: }
206: }*/
207: /*public void testUser() throws Exception {
208: int global =0;
209: for (global=0;global<50000;global++)
210: {
211: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
212: UserRegistration userReg=urHome.create();
213: userReg.userCreate("user"+global,"user"+global,"miguel.valdes-faura@ext.bull.net");
214: userReg.remove();
215: }
216: }*/
217: }
|