KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > test > stress > InstancesTests


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: InstancesTests.java,v 1.7 2005/01/14 17:14:39 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.test.stress;
31
32 import javax.security.auth.login.LoginContext JavaDoc;
33 import hero.client.test.SimpleCallbackHandler;
34
35 import hero.interfaces.ProjectSession;
36 import hero.interfaces.ProjectSessionHome;
37 import hero.interfaces.ProjectSessionUtil;
38 import hero.interfaces.UserSession;
39 import hero.interfaces.UserSessionHome;
40 import hero.interfaces.UserSessionUtil;
41 import hero.interfaces.UserRegistration;
42 import hero.interfaces.UserRegistrationHome;
43 import hero.interfaces.UserRegistrationUtil;
44 import junit.framework.TestCase;
45 import junit.framework.TestSuite;
46 import hero.interfaces.Constants;
47 import java.util.Collection JavaDoc;
48 import java.util.Iterator JavaDoc;
49
50 public class InstancesTests extends TestCase {
51  
52     public InstancesTests(String JavaDoc testname) {
53     super(testname);
54     }
55     
56     public static TestSuite suite() {
57     return new TestSuite(InstancesTests.class);
58     }
59
60     public void setUp() throws Exception JavaDoc {
61     }
62     
63     public void testInstances() throws Exception JavaDoc {
64     ProjectSessionHome pHome = ProjectSessionUtil.getHome();
65     ProjectSession psSub = pHome.create();
66     try{
67         
68     psSub.initModel("node5Sub");
69     psSub.addNode("subNode1", Constants.Nd.AND_JOIN_NODE);
70     psSub.addNode("subNode2", Constants.Nd.AND_JOIN_NODE);
71     psSub.setNodeRole("subNode1", "admin");
72     psSub.setNodeRole("subNode2", "admin");
73     psSub.addEdge("subNode1", "subNode2");
74     String JavaDoc script =
75         "import hero.interfaces.BnInstanceLocal;\n"
76                 + "import hero.interfaces.BnNodeLocal;\n"
77                 + "afterStart (Object b,Object n) {\n\n\n"
78                 + "System.out.println(\"SPInstantiation test, SubProcess: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
79                 + "}";
80     psSub.addNodeInterHook("subNode2","subNode2",hero.interfaces.Constants.Nd.AFTERSTART,Constants.Hook.BSINTERACTIVE,script);
81     psSub.addUser("admin2");
82     psSub.setNodeRole("subNode1", "admin");
83     psSub.setNodeRole("subNode2", "admin");
84     
85     ProjectSession pss = pHome.create();
86     pss.initModel("Stress");
87     pss.addNode("node1", Constants.Nd.AND_JOIN_NODE);
88     pss.addNode("node2", Constants.Nd.AND_JOIN_NODE);
89     pss.addNode("node3", Constants.Nd.AND_JOIN_NODE);
90     pss.addNode("node4", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
91     pss.addNodeSubProcess("node5Sub","Stress");
92     //pss.addNode("node5Sub",Constants.Nd.AND_JOIN_NODE);
93
pss.addEdge("node1", "node2");
94     pss.addEdge("node2", "node3");
95     pss.addEdge("node2", "node4");
96     pss.addEdge("node3", "node5Sub");
97     script =
98         "import hero.interfaces.BnInstanceLocal;\n"
99             + "import hero.interfaces.BnNodeLocal;\n"
100             + "afterStart (Object b,Object n) {\n\n\n"
101             + "System.out.println(\"Stress test, node: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
102             + "}";
103     pss.addNodeInterHook("node2","node2",hero.interfaces.Constants.Nd.AFTERSTART,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.getNodeRoleName("node1").equals("admin"));
114     Collection JavaDoc users = pss1.getUsers();
115     assertTrue("Instantiation Error, user admin2 does not exist",users.contains("admin2"));
116     assertTrue("Instantiation Error, type error in node1",pss1.getNodeType("node1") == Constants.Nd.AND_JOIN_NODE);
117     assertTrue("Instantiation Error, type error in node4",pss1.getNodeType("node4") == Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
118     }catch(Exception JavaDoc e){}
119     int global = 0;
120     for (global=0;global<100;global++)
121     {
122         UserRegistrationHome urHome = UserRegistrationUtil.getHome();
123         UserRegistration userReg=urHome.create();
124         userReg.userCreate("user"+global,"user"+global,"miguel.valdes-faura@ext.bull.net");
125         userReg.remove();
126         String JavaDoc uName= "user"+global;
127         char[] password=uName.toCharArray();
128         SimpleCallbackHandler handler = new SimpleCallbackHandler(uName,password);
129         LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
130         lc.login();
131
132         int i=0;
133         for (i=0;i<10;i++){
134             ProjectSession ps = pHome.create();
135             ps.instantiateProject("Stress");
136             //Thread.sleep(100);
137
ps.remove();
138         }
139         
140         UserSessionHome uHome = UserSessionUtil.getHome();
141         UserSession us = uHome.create();
142         Collection JavaDoc instances = us.getInstancesListNames();
143         assertTrue("getInstancesList error",instances.size()>=1);
144         Iterator JavaDoc index = instances.iterator();
145         UserSession usUser = uHome.create();
146         while (index.hasNext())
147         {
148             String JavaDoc name = (String JavaDoc)index.next();
149             Collection JavaDoc task = usUser.getToDoList(name);
150             Iterator JavaDoc it = task.iterator();
151             while (it.hasNext())
152             {
153               String JavaDoc activity = (String JavaDoc)it.next();
154               usUser.startActivity(name,activity);
155               if (activity.matches(".*_instance.*"))
156                  this.executeSubProcess(activity);
157
158               usUser.terminateActivity(name,activity);
159               task = usUser.getToDoList(name);
160               it = task.iterator();
161             }
162         }
163     }
164    }
165
166    public void executeSubProcess(String JavaDoc subProcess) throws Exception JavaDoc{
167      UserSessionHome uHome = UserSessionUtil.getHome();
168      UserSession us = uHome.create();
169      us.startActivity(subProcess,"subNode1");
170      us.terminateActivity(subProcess,"subNode1");
171      us.startActivity(subProcess,"subNode2");
172      us.terminateActivity(subProcess,"subNode2");
173    }
174    
175     /*public void testInstancesInst() throws Exception {
176     UserSessionHome uHome = UserSessionUtil.getHome();
177     UserSession us = uHome.create();
178     Collection instances = us.getInstancesListNames();
179     assertTrue("getInstancesList error",instances.size()>=1);
180     Iterator index = instances.iterator();
181     UserSession usUser = uHome.create();
182     while (index.hasNext())
183     {
184         String name = (String)index.next();
185         Collection task = usUser.getToDoList(name);
186         Iterator it = task.iterator();
187         while (it.hasNext())
188         {
189           String activity = (String)it.next();
190           usUser.startActivity(name,activity);
191           if (activity.matches(".*_instance.*"))
192              this.executeSubProcess(activity);
193
194           usUser.terminateActivity(name,activity);
195           task = usUser.getToDoList(name);
196           it = task.iterator();
197         }
198     }
199   }*/

200    /*public void testUser() throws Exception {
201    int global =0;
202    for (global=0;global<50000;global++)
203     {
204         UserRegistrationHome urHome = UserRegistrationUtil.getHome();
205         UserRegistration userReg=urHome.create();
206         userReg.userCreate("user"+global,"user"+global,"miguel.valdes-faura@ext.bull.net");
207         userReg.remove();
208     }
209    }*/

210 }
211
Popular Tags