KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > test > UserSessionTests


1 package hero.client.test;
2
3 /*
4 *
5 * NodeTests.java -
6 * Copyright (C) 2002 Ecoo Team
7 * charoy@loria.fr
8 *
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */

24
25 import javax.security.auth.login.LoginContext JavaDoc;
26
27 import hero.interfaces.BnNodeValue;
28 import hero.interfaces.BnProjectHome;
29 import hero.interfaces.BnUserHome;
30 import hero.interfaces.BnUserPropertyValue;
31 import hero.interfaces.Constants;
32 import hero.interfaces.ProjectSession;
33 import hero.interfaces.ProjectSessionHome;
34 import hero.interfaces.ProjectSessionUtil;
35 import hero.interfaces.UserSession;
36 import hero.interfaces.UserSessionHome;
37 import hero.interfaces.UserSessionUtil;
38 import hero.util.HeroException;
39
40 import java.util.Collection JavaDoc;
41 import java.util.Hashtable JavaDoc;
42 import java.util.Iterator JavaDoc;
43
44 import org.apache.axis.client.Call;
45 import org.apache.axis.client.Service;
46
47 import junit.framework.TestCase;
48 import junit.framework.TestSuite;
49
50 import hero.interfaces.UserRegistration;
51 import hero.interfaces.UserRegistrationHome;
52 import hero.interfaces.UserRegistrationUtil;
53
54 public class UserSessionTests extends TestCase {
55
56     private BnProjectHome projecth;
57     private ProjectSessionHome projectsesh;
58     private BnUserHome userh;
59     private UserSessionHome usersessionh;
60
61     public UserSessionTests(String JavaDoc testname) {
62     super(testname);
63     }
64     
65     public static TestSuite suite() {
66     return new TestSuite(UserSessionTests.class);
67     }
68
69     public void setUp() throws Exception JavaDoc {
70     }
71
72    public void testGetProjectListSession() throws Exception JavaDoc {
73     projectsesh=ProjectSessionUtil.getHome();
74     ProjectSession p = projectsesh.create();
75     p.initProject("Failure");
76     p.addNode("t1",1);
77     p.addNode("t2",1);
78     p.addEdge("t1","t2");
79     usersessionh=UserSessionUtil.getHome();
80     UserSession usersession = usersessionh.create();
81     ProjectSession lproj1 = projectsesh.create();
82     lproj1.initProject("p1SS");
83     ProjectSession lproj2 = projectsesh.create();
84     lproj2.initProject("p2SS");
85     System.out.println("usersession home ?"+usersessionh);
86
87     System.out.println("usersession ?"+usersession);
88     Collection JavaDoc c = usersession.getProjectList();
89     assertTrue("getProjectList Error",c.size() != 0);
90     Collection JavaDoc c2 = usersession.getToDoList("p1SS");
91     Collection JavaDoc c3 = usersession.getToDoList("p2SS");
92     usersession.startActivity("Failure","t1");
93     usersession.startActivity("Failure","t2");
94     usersession.terminateActivity("Failure","t1");
95     }
96
97     public void testGetProjectList() throws Exception JavaDoc {
98     projectsesh=ProjectSessionUtil.getHome();
99     usersessionh=UserSessionUtil.getHome();
100     UserSession usersession = usersessionh.create();
101     ProjectSession lproj1 = projectsesh.create();
102     lproj1.initProject("p1");
103     ProjectSession lproj2 = projectsesh.create();
104     lproj2.initProject("p2");
105     System.out.println("usersession home ?"+usersessionh);
106
107     System.out.println("usersession ?"+usersession);
108     Collection JavaDoc c = usersession.getProjectList();
109     assertTrue("getProjectList Error",c.size() != 0);
110     }
111
112     
113     // getToDoList test method in order to verify user ready activities
114

115
116     public void testGetToDoList1() throws Exception JavaDoc {
117     projectsesh=ProjectSessionUtil.getHome();
118     usersessionh=UserSessionUtil.getHome();
119     ProjectSession proj = projectsesh.create();
120     proj.initProject("p3");
121     
122     proj.addNode("name1",Constants.Nd.AND_JOIN_NODE);
123     proj.setUserRole("admin","InitialRole");
124
125     UserSession usersession = usersessionh.create();
126     Collection JavaDoc c = usersession.getToDoList("p3");
127     Iterator JavaDoc i = c.iterator();
128     assertTrue("getToDoList Error",((String JavaDoc)i.next()).equals("name1"));
129     }
130
131     public void testGetToDoList2() throws Exception JavaDoc {
132     projectsesh=ProjectSessionUtil.getHome();
133     usersessionh=UserSessionUtil.getHome();
134     ProjectSession proj = projectsesh.create();
135     proj.initProject("p4");
136     
137     proj.addNode("name1",Constants.Nd.AND_JOIN_NODE);
138     proj.addNode("name2",Constants.Nd.AND_JOIN_NODE);
139     
140     proj.setUserRole("admin","InitialRole");
141
142     UserSession usersession = usersessionh.create();
143     Collection JavaDoc c = usersession.getToDoList("p4");
144     Iterator JavaDoc i = c.iterator();
145     String JavaDoc node1 = (String JavaDoc)i.next();
146     String JavaDoc node2 = (String JavaDoc)i.next();
147
148     assertTrue("getToDoList Error",node1.equals("name1") || node1.equals("name2"));
149     assertTrue("getToDoList Error",node2.equals("name1") || node2.equals("name2"));
150     }
151
152     // getActivityList test method in order to verify startActivity method
153
// and obtain new executing users activities
154

155     public void testGetActivityList() throws Exception JavaDoc {
156     projectsesh=ProjectSessionUtil.getHome();
157     usersessionh=UserSessionUtil.getHome();
158     ProjectSession proj = projectsesh.create();
159     proj.initProject("p5");
160     
161     proj.addNode("NodeExecuting",Constants.Nd.AND_JOIN_NODE);
162     
163     proj.setUserRole("admin","InitialRole");
164      
165     UserSession usersession = usersessionh.create();
166     Collection JavaDoc c=usersession.getActivityList("p5");
167     assertTrue("getActivityList Error",c.size()==0);
168     usersession.startActivity("p5","NodeExecuting");
169     c = usersession.getActivityList("p5");
170     Iterator JavaDoc i = c.iterator();
171     assertTrue("getActivityList Error",((String JavaDoc)i.next()).equals("NodeExecuting"));
172     }
173     
174     public void testGetNode() throws Exception JavaDoc {
175     projectsesh=ProjectSessionUtil.getHome();
176     usersessionh=UserSessionUtil.getHome();
177     ProjectSession proj = projectsesh.create();
178     proj.initProject("testgetnode");
179     proj.addNode("pouet",Constants.Nd.AND_JOIN_NODE);
180     UserSession usr=usersessionh.create();
181     try {
182         BnNodeValue nv=usr.getNode("testgetnode","pouet");
183     } catch (HeroException h) {
184         assertTrue("Should be a success",false);
185     }
186     }
187     
188     public void testProperty() throws Exception JavaDoc {
189     usersessionh=UserSessionUtil.getHome();
190     UserSession usr=usersessionh.create();
191
192     usr.setUserProperty("prop1","val1");
193     usr.setUserProperty("prop2","val2");
194     usr.setUserProperty("prop3","val3");
195     
196     }
197     public void testDeleteProperty() throws Exception JavaDoc {
198     usersessionh=UserSessionUtil.getHome();
199     UserSession usr=usersessionh.create();
200     usr.deleteUserProperty("prop2");
201     usr.deleteUserProperty("prop3");
202     }
203
204     public void testGetProperties() throws Exception JavaDoc {
205     usersessionh=UserSessionUtil.getHome();
206     UserSession usr=usersessionh.create();
207     
208     Collection JavaDoc c=usr.getUserProperties();
209         
210     for(Iterator JavaDoc i=c.iterator();i.hasNext();){
211         BnUserPropertyValue p=(BnUserPropertyValue)i.next();
212         String JavaDoc key=p.getTheKey();
213         String JavaDoc value=p.getTheValue();
214         assertTrue("Get Properties",key.equalsIgnoreCase("prop1"));
215         
216     }
217     }
218
219
220   public void testSpeedCheckOneCallRMI() throws Exception JavaDoc {
221     usersessionh=UserSessionUtil.getHome();
222     UserSession usr=usersessionh.create();
223     usr.getUser();
224     usr.getUserPassword();
225     
226   }
227   public void testSpeedCheckTenCallRMI() throws Exception JavaDoc {
228     usersessionh=UserSessionUtil.getHome();
229     UserSession usr=usersessionh.create();
230     for(int i=0;i<10;i++){
231         usr.getUser();
232         usr.getUserPassword();
233     }
234   }
235
236
237   public void testSpeedCheckOneCallSOAP() throws Exception JavaDoc {
238          //String endpoint = "http://localhost:8080/jboss-net/services/UserSession";
239
String JavaDoc endpoint = System.getProperty("bonita.host")+"/bonita_ws/services/UserSession";
240      
241      Service service = new Service();
242      Call call = (Call) service.createCall();
243      
244      call.setTargetEndpointAddress( new java.net.URL JavaDoc(endpoint) );
245
246      call.setMaintainSession(true);
247      call.setUsername("admin");
248      call.setPassword("toto");
249
250      call.setOperationName("getUser");
251      String JavaDoc resp = (String JavaDoc) call.invoke( new Object JavaDoc[] {} );
252      call.setOperationName("getUserPassword");
253      String JavaDoc ret2 = (String JavaDoc) call.invoke( new Object JavaDoc[] {} );
254      
255   }
256
257  public void testSpeedCheckTenCallSOAP() throws Exception JavaDoc {
258     // String endpoint = "http://localhost:8080/jboss-net/services/UserSession";
259
String JavaDoc endpoint = System.getProperty("bonita.host")+"/bonita_ws/services/UserSession";
260      
261      Service service = new Service();
262      Call call = (Call) service.createCall();
263      
264      call.setTargetEndpointAddress( new java.net.URL JavaDoc(endpoint) );
265
266      call.setMaintainSession(true);
267      call.setUsername("admin");
268      call.setPassword("toto");
269
270      for(int i=0;i<10;i++){
271          call.setOperationName("getUser");
272          String JavaDoc resp = (String JavaDoc) call.invoke( new Object JavaDoc[] {} );
273          call.setOperationName("getUserPassword");
274          String JavaDoc ret2 = (String JavaDoc) call.invoke( new Object JavaDoc[] {} );
275      }
276   }
277 public void testGetProjectInstances() throws Exception JavaDoc {
278     projectsesh = ProjectSessionUtil.getHome();
279     ProjectSession p = projectsesh.create();
280     p.initModel("GPI");
281     p.initModel("GPIGPI");
282
283     String JavaDoc name1 = p.instantiateProject("GPI");
284     String JavaDoc name2 = p.instantiateProject("GPI");
285
286     usersessionh = UserSessionUtil.getHome();
287     UserSession usr = usersessionh.create();
288
289     Collection JavaDoc instances = usr.getProjectInstancesNames("GPI");
290     assertTrue("getProjectInstances Error",instances.size()==2);
291 }
292
293 public void testInstancesByProperty() throws Exception JavaDoc {
294     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
295     ProjectSession ps = projectSessionh.create();
296     ps.initModel("instProp");
297     
298     ProjectSession ps2 = projectSessionh.create();
299     ps2.initModel("instProp2");
300
301     ProjectSession ps3 = projectSessionh.create();
302     ps3.initModel("instProp3");
303
304     ps.setProperty("id", "1234");
305     ps2.setProperty("id", "1234");
306     ps3.setProperty("id2", "1234");
307         
308     UserSessionHome uHome = UserSessionUtil.getHome();
309     UserSession usersession = uHome.create();
310     Collection JavaDoc names = usersession.getInstancesByPropertyNames("id", "1234");
311
312     assertTrue("Error in Instances by Property. Project error",names.size() == 0);
313     String JavaDoc prop1 = ps.instantiateProject("instProp");
314     String JavaDoc prop2 = ps2.instantiateProject("instProp2");
315     String JavaDoc prop3 = ps3.instantiateProject("instProp3");
316     ps.setProperty("id", "1234");
317     ps2.setProperty("id", "1234");
318     ps3.setProperty("id2", "1234");
319     names = usersession.getInstancesByPropertyNames("id", "1234");
320     assertTrue(
321         "Error in Instances by Property. Instance error",
322         names.size() == 2);
323 }
324
325 public void testProjectsByProperty() throws Exception JavaDoc {
326     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
327     ProjectSession ps = projectSessionh.create();
328     ps.initModel("projProp");
329     
330     ProjectSession ps2 = projectSessionh.create();
331     ps2.initModel("projProp2");
332     
333     ps.setProperty("id", "123");
334     ps2.setProperty("id", "123");
335     
336     UserSessionHome uHome = UserSessionUtil.getHome();
337     UserSession usersession = uHome.create();
338     Collection JavaDoc names = usersession.getProjectsByPropertyNames("id", "123");
339
340     assertTrue("Error in Projects by Property", names.size() == 2);
341     String JavaDoc prop1 = ps.instantiateProject("projProp");
342     String JavaDoc prop2 = ps2.instantiateProject("projProp2");
343     ps.setProperty("id", "123");
344     ps2.setProperty("id", "123");
345     names = usersession.getProjectsByPropertyNames("id", "123");
346     assertTrue("Error in Projects by Property", names.size() == 2);
347 }
348
349 public void testGetInstancesList() throws Exception JavaDoc {
350     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
351     UserRegistration userReg = urHome.create();
352     userReg.userCreate("GetInst","GetInst","miguel.valdes-faura@ext.bull.net");
353
354     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
355     ProjectSession ps = projectSessionh.create();
356     ps.initModel("GetInstancesList");
357     ps.addNode("node1", 1);
358     ps.addUser("GetInst");
359     ps.setNodeRole("node1", "GetInst");
360
361     ProjectSession ps2 = projectSessionh.create();
362     ps2.initModel("GetInstancesList2");
363
364     ProjectSession ps3 = projectSessionh.create();
365     ps3.initModel("GetInstancesList3");
366     ps3.addNode("node1", 1);
367     ps3.addUser("GetInst");
368     ps3.setNodeRole("node1", "GetInst");
369
370     SimpleCallbackHandler handler =
371         new SimpleCallbackHandler("GetInst", "GetInst".toCharArray());
372     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
373     lc.login();
374
375     UserSessionHome uHome = UserSessionUtil.getHome();
376     UserSession usersession = uHome.create();
377
378     Collection JavaDoc names = usersession.getInstancesListNames();
379     assertTrue(
380         "Error in getInstancesList. GetInstancesListNames",
381         names.size() == 0);
382
383     names = usersession.getProjectListNames();
384     assertTrue(
385         "Error in getInstancesList. GetProjectListNames",
386         names.size() == 2);
387
388     names = usersession.getInstancesList();
389     assertTrue(
390         "Error in getInstancesList. GetInstancesList",
391         names.size() == 0);
392
393     names = usersession.getProjectList();
394     assertTrue("Error in getInstancesList. GetProjectList", names.size() == 2);
395
396     ps.instantiateProject("GetInstancesList");
397     ps.instantiateProject("GetInstancesList3");
398
399     names = usersession.getInstancesListNames();
400     assertTrue(
401         "Error in getInstancesList. GetInstancesListNames",
402         names.size() == 2);
403
404     names = usersession.getProjectListNames();
405     assertTrue(
406         "Error in getInstancesList. GetProjectListNames",
407         names.size() == 4);
408
409     names = usersession.getInstancesList();
410     assertTrue(
411         "Error in getInstancesList. GetInstancesList",
412         names.size() == 2);
413
414     names = usersession.getProjectList();
415     assertTrue("Error in getInstancesList. GetProjectList", names.size() == 4);
416
417     char[] password2 = { 't', 'o', 't', 'o' };
418     handler = new SimpleCallbackHandler("admin", password2);
419     lc = new LoginContext JavaDoc("TestClient", handler);
420     lc.login();
421 }
422
423 public void testGetTodoListAllInstances() throws Exception JavaDoc {
424     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
425     UserRegistration userReg = urHome.create();
426     userReg.userCreate("tdai", "tdai", "miguel.valdes-faura@ext.bull.net");
427
428     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
429     ProjectSession ps = projectSessionh.create();
430     ps.initModel("TDAI");
431     ps.addNode("node1", 1);
432     ps.addNode("node2", 1);
433     ps.addUser("tdai");
434     ps.setNodeRole("node1", "tdai");
435
436     ProjectSession ps2 = projectSessionh.create();
437     ps2.initModel("TDAI2");
438     ps2.addNode("node2", 1);
439
440     ProjectSession ps3 = projectSessionh.create();
441     ps3.initModel("TDAI3");
442     ps3.addNode("node1", 1);
443     ps3.addNode("node2", 1);
444     ps3.addUser("tdai");
445     ps3.setNodeRole("node1", "tdai");
446     
447     ProjectSession ps4 = projectSessionh.create();
448     ps4.initProject("TDAI4");
449     ps4.addNode("node1",1);
450     ps4.addUser("tdai");
451     ps4.setNodeRole("node1","tdai");
452         
453     SimpleCallbackHandler handler = new SimpleCallbackHandler("tdai", "tdai".toCharArray());
454     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
455     lc.login();
456     
457     ps.instantiateProject("TDAI");
458     ps2.instantiateProject("TDAI2");
459     ps3.instantiateProject("TDAI3");
460
461     UserSessionHome uHome = UserSessionUtil.getHome();
462     UserSession usersession = uHome.create();
463     
464     Collection JavaDoc names = usersession.getToDoListAllInstances();
465     assertTrue("Error in getTodoListAllInstances",names.size() == 3);
466     
467     char[] password2 = { 't', 'o', 't', 'o' };
468     handler = new SimpleCallbackHandler("admin", password2);
469     lc = new LoginContext JavaDoc("TestClient", handler);
470     lc.login();
471 }
472
473 public void testGetActivityListAllInstances() throws Exception JavaDoc {
474     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
475     UserRegistration userReg = urHome.create();
476     userReg.userCreate("taai", "taai", "miguel.valdes-faura@ext.bull.net");
477
478     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
479     ProjectSession ps = projectSessionh.create();
480     ps.initModel("TAAI");
481     ps.addNode("node1", 1);
482     ps.addNode("node2", 1);
483     ps.addUser("taai");
484     ps.setNodeRole("node1", "taai");
485
486     ProjectSession ps2 = projectSessionh.create();
487     ps2.initModel("TAAI2");
488     ps2.addNode("node2", 1);
489
490     ProjectSession ps3 = projectSessionh.create();
491     ps3.initModel("TAAI3");
492     ps3.addNode("node1", 1);
493     ps3.addNode("node2", 1);
494     ps3.addUser("taai");
495     ps3.setNodeRole("node1", "taai");
496
497     SimpleCallbackHandler handler = new SimpleCallbackHandler("taai", "taai".toCharArray());
498     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
499     lc.login();
500     
501     String JavaDoc name1 = ps.instantiateProject("TAAI");
502     String JavaDoc name2 = ps2.instantiateProject("TAAI2");
503     String JavaDoc name3 = ps3.instantiateProject("TAAI3");
504
505     UserSessionHome uHome = UserSessionUtil.getHome();
506     UserSession usersession = uHome.create();
507
508     Collection JavaDoc names = usersession.getActivityListAllInstances();
509     assertTrue("Error in getActivityAllInstancesList.1 ",names.size() == 0);
510     
511     usersession.startActivity(name1,"node1");
512     
513     names = usersession.getActivityListAllInstances();
514     assertTrue("Error in getActivityAllInstancesList.2 ",names.size() == 1);
515     
516     usersession.startActivity(name3,"node1");
517     
518     names = usersession.getActivityListAllInstances();
519     assertTrue("Error in getActivityAllInstancesList.3 ",names.size() == 2);
520     
521     usersession.terminateActivity(name3,"node1");
522
523     names = usersession.getActivityListAllInstances();
524     assertTrue("Error in getActivityAllInstancesList.4 ",names.size() == 1);
525
526     char[] password2 = { 't', 'o', 't', 'o' };
527     handler = new SimpleCallbackHandler("admin", password2);
528     lc = new LoginContext JavaDoc("TestClient", handler);
529     lc.login();
530 }
531
532 public void testGetTodoListByProperty() throws Exception JavaDoc {
533     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
534     UserRegistration userReg = urHome.create();
535     userReg.userCreate("tdp", "tdp", "miguel.valdes-faura@ext.bull.net");
536
537     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
538     ProjectSession ps = projectSessionh.create();
539     ps.initModel("TDP");
540     ps.addNode("node1", 1);
541     ps.setProperty("test","111");
542     ps.setNodeProperty("node1","test","111");
543     ps.setNodeProperty("node1","test","1112");
544     ps.addNode("node2", 1);
545     ps.addUser("tdp");
546     ps.setNodeRole("node1", "tdp");
547     ps.setNodeRole("node2", "tdp");
548
549     ProjectSession ps2 = projectSessionh.create();
550     ps2.initModel("TDP2");
551     ps2.addNode("node2", 1);
552
553     ProjectSession ps3 = projectSessionh.create();
554     ps3.initModel("TDP3");
555     ps3.addNode("node1", 1);
556     ps3.setNodeProperty("node1","test","111");
557     ps3.addNode("node2", 1);
558     ps3.setNodeProperty("node2","test3","111");
559     ps3.addUser("tdp");
560     ps3.setNodeRole("node1", "tdp");
561
562     SimpleCallbackHandler handler = new SimpleCallbackHandler("tdp", "tdp".toCharArray());
563     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
564     lc.login();
565     
566     String JavaDoc name = ps.instantiateProject("TDP");
567     ps.setNodeProperty("node2","test","111");
568     ps.setProperty("test","111");
569     ps2.instantiateProject("TDP2");
570     ps3.instantiateProject("TDP3");
571
572     UserSessionHome uHome = UserSessionUtil.getHome();
573     UserSession usersession = uHome.create();
574
575     Collection JavaDoc names = usersession.getToDoListByProperty("test","111");
576     assertTrue("Error in getTodoListByProperty.1", names.size() == 2);
577
578     ps.setNodeProperty("node1","test","111");
579     ps.setNodeProperty("node2","test3","11122");
580     
581     ps.setProperty("test","111");
582     ps.setProperty("test3","11122");
583
584     names = usersession.getToDoListByProperty("test","111");
585     assertTrue("Error in getTodoListByProperty.2", names.size() == 2);
586
587     names = usersession.getToDoListByProperty("test","1111");
588     assertTrue("Error in getTodoListByProperty.3", names.size() == 0);
589     
590     usersession.startActivity(name,"node1");
591
592     names = usersession.getToDoListByProperty("test","111");
593     assertTrue("Error in getTodoListByProperty.4", names.size() == 1);
594
595     char[] password2 = { 't', 'o', 't', 'o' };
596     handler = new SimpleCallbackHandler("admin", password2);
597     lc = new LoginContext JavaDoc("TestClient", handler);
598     lc.login();
599 }
600
601 public void testGetTodoListByPropertiesAND() throws Exception JavaDoc {
602     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
603     UserRegistration userReg = urHome.create();
604     userReg.userCreate("tdtp", "tdtp", "miguel.valdes-faura@ext.bull.net");
605
606     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
607     ProjectSession ps = projectSessionh.create();
608     ps.initModel("TDTP");
609     ps.addNode("node1", 1);
610     ps.setProperty("test","111");
611     ps.setNodeProperty("node1","test","111");
612     ps.setProperty("testTwo","1112");
613     ps.addNode("node2", 1);
614     ps.addUser("tdtp");
615     ps.setNodeRole("node1", "tdtp");
616     ps.setNodeRole("node2", "tdtp");
617
618     ProjectSession ps2 = projectSessionh.create();
619     ps2.initModel("TDTP2");
620     ps2.addNode("node2", 1);
621
622     ProjectSession ps3 = projectSessionh.create();
623     ps3.initModel("TDTP3");
624     ps3.addNode("node1", 1);
625     ps3.setNodeProperty("node1","test","111");
626     ps3.addNode("node2", 1);
627     ps3.setNodeProperty("node2","test3","111");
628     ps3.addUser("tdtp");
629     ps3.setNodeRole("node1", "tdtp");
630
631     SimpleCallbackHandler handler = new SimpleCallbackHandler("tdtp", "tdtp".toCharArray());
632     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
633     lc.login();
634     
635     String JavaDoc name = ps.instantiateProject("TDTP");
636     ps.setNodeProperty("node2","test","111");
637     ps.setProperty("test","111");
638     ps2.instantiateProject("TDTP2");
639     ps3.instantiateProject("TDTP3");
640
641     UserSessionHome uHome = UserSessionUtil.getHome();
642     UserSession usersession = uHome.create();
643     
644     Hashtable JavaDoc prop = new Hashtable JavaDoc();
645     prop.put("test","111");
646     
647     Collection JavaDoc names = usersession.getToDoListByProperties(Constants.AND,prop);
648     assertTrue("Error in getTodoListByProperties.0", names.size() == 2 );
649     
650     prop.put("testTwo","1112");
651     
652     names = usersession.getToDoListByProperties(Constants.AND,prop);
653     assertTrue("Error in getTodoListByProperties.1", names.size() == 2 );
654     
655     ps.setNodeProperty("node1","test","111");
656     ps.setNodeProperty("node2","test3","11122");
657     
658     ps2.setProperty("test","111");
659     ps2.setProperty("testTwo","1112");
660     ps2.setProperty("testThree","1113");
661     ps3.setProperty("test","111");
662     ps3.setProperty("testTwo","1112");
663     ps3.setProperty("testThree","1113");
664
665     names = usersession.getToDoListByProperties(Constants.AND,prop);
666     assertTrue("Error in getTodoListByProperties.2", names.size() == 3);
667
668     prop.put("testTwo","1114");
669     
670     names = usersession.getToDoListByProperties(Constants.AND,prop);
671     assertTrue("Error in getTodoListByProperties.3", names.size() == 0);
672     
673     usersession.startActivity(name,"node1");
674
675     prop.put("testTwo","1112");
676     prop.put("testThree","1113");
677         
678     names = usersession.getToDoListByProperties(Constants.AND,prop);
679     assertTrue("Error in getTodoListByProperties.4", names.size() == 1);
680
681     char[] password2 = { 't', 'o', 't', 'o' };
682     handler = new SimpleCallbackHandler("admin", password2);
683     lc = new LoginContext JavaDoc("TestClient", handler);
684     lc.login();
685 }
686
687 public void testGetTodoListByPropertiesOR() throws Exception JavaDoc {
688     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
689     UserRegistration userReg = urHome.create();
690     userReg.userCreate("tdtpor", "tdtpor", "miguel.valdes-faura@ext.bull.net");
691
692     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
693     ProjectSession ps = projectSessionh.create();
694     ps.initModel("TDTPOR");
695     ps.addNode("node1", 1);
696     ps.setProperty("test","111");
697     ps.setNodeProperty("node1","test","111");
698     ps.setProperty("testTwo","1112");
699     ps.addNode("node2", 1);
700     ps.addUser("tdtpor");
701     ps.setNodeRole("node1", "tdtpor");
702     ps.setNodeRole("node2", "tdtpor");
703
704     ProjectSession ps2 = projectSessionh.create();
705     ps2.initModel("TDTP2OR");
706     ps2.addNode("node2", 1);
707
708     ProjectSession ps3 = projectSessionh.create();
709     ps3.initModel("TDTP3OR");
710     ps3.addNode("node1", 1);
711     ps3.setNodeProperty("node1","test","111");
712     ps3.addNode("node2", 1);
713     ps3.setNodeProperty("node2","test3","111");
714     ps3.addUser("tdtpor");
715     ps3.setNodeRole("node1", "tdtpor");
716
717     SimpleCallbackHandler handler = new SimpleCallbackHandler("tdtpor", "tdtpor".toCharArray());
718     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
719     lc.login();
720     
721     String JavaDoc name = ps.instantiateProject("TDTPOR");
722     ps.setNodeProperty("node2","test","111");
723     ps.setProperty("test","111");
724     ps2.instantiateProject("TDTP2OR");
725     ps3.instantiateProject("TDTP3OR");
726     ps3.setProperty("testTwo","1112");
727
728     UserSessionHome uHome = UserSessionUtil.getHome();
729     UserSession usersession = uHome.create();
730     
731     Hashtable JavaDoc prop = new Hashtable JavaDoc();
732     prop.put("test","111");
733         
734     Collection JavaDoc names = usersession.getToDoListByProperties(Constants.OR,prop);
735     assertTrue("Error in getTodoListByProperties.0", names.size() == 2 );
736     
737     prop.put("testTwo","1112");
738     
739     names = usersession.getToDoListByProperties(Constants.OR,prop);
740     assertTrue("Error in getTodoListByProperties.1", names.size() == 3 );
741     
742     ps.setNodeProperty("node1","test","111");
743     ps.setNodeProperty("node2","test3","11122");
744     
745     ps2.setProperty("test","111");
746     ps2.setProperty("testTwo","1112");
747     ps2.setProperty("testThree","1113");
748     ps3.setProperty("test","111");
749     ps3.setProperty("testTwo","1112");
750     ps3.setProperty("testThree","1113");
751
752     names = usersession.getToDoListByProperties(Constants.OR,prop);
753     assertTrue("Error in getTodoListByProperties.2", names.size() == 3);
754
755     prop.put("testThree","1113");
756     
757     names = usersession.getToDoListByProperties(Constants.OR,prop);
758     assertTrue("Error in getTodoListByProperties.3", names.size() == 3);
759     
760     prop.put("testFour","1114");
761     try{
762         names = usersession.getToDoListByProperties(Constants.OR,prop);
763         assertTrue("Error in getToDoListByProperties.4, operation should be failed",false);
764     }catch(Exception JavaDoc e){}
765     
766     char[] password2 = { 't', 'o', 't', 'o' };
767     handler = new SimpleCallbackHandler("admin", password2);
768     lc = new LoginContext JavaDoc("TestClient", handler);
769     lc.login();
770 }
771
772 public void testActivityListByProperty() throws Exception JavaDoc {
773     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
774     UserRegistration userReg = urHome.create();
775     userReg.userCreate("alp", "alp", "miguel.valdes-faura@ext.bull.net");
776
777     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
778     ProjectSession ps = projectSessionh.create();
779     ps.initModel("ALP");
780     ps.addNode("node1", 1);
781     ps.setProperty("test","111");
782     ps.setNodeProperty("node1","test","111");
783     ps.setNodeProperty("node1","test","1112");
784     ps.addNode("node2", 1);
785     ps.addUser("alp");
786     ps.setNodeRole("node1", "alp");
787     ps.setNodeRole("node2", "alp");
788
789     ProjectSession ps2 = projectSessionh.create();
790     ps2.initModel("ALP2");
791     ps2.addNode("node2", 1);
792
793     ProjectSession ps3 = projectSessionh.create();
794     ps3.initModel("ALP3");
795     ps3.addNode("node1", 1);
796     ps3.setNodeProperty("node1","test","111");
797     ps3.setProperty("test","111");
798     ps3.setProperty("test","111");
799     ps3.setNodeProperty("node1","test","111");
800     ps3.addNode("node2", 1);
801     ps3.setNodeProperty("node2","test3","111");
802     ps3.addUser("alp");
803     ps3.setNodeRole("node1", "alp");
804
805     SimpleCallbackHandler handler = new SimpleCallbackHandler("alp", "alp".toCharArray());
806     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
807     lc.login();
808     
809     String JavaDoc name = ps.instantiateProject("ALP");
810     ps.setProperty("test","111");
811     ps.setNodeProperty("node2","test","111");
812     ps2.instantiateProject("ALP2");
813     ps3.instantiateProject("ALP3");
814
815     UserSessionHome uHome = UserSessionUtil.getHome();
816     UserSession usersession = uHome.create();
817
818     Collection JavaDoc names = usersession.getActivityListByProperty("test","111");
819     assertTrue("Error in getActivityListByProperty.1", names.size() == 0);
820     
821     usersession.startActivity(name,"node2");
822
823     names = usersession.getActivityListByProperty("test","111");
824     assertTrue("Error in getActivityListByProperty.2", names.size() == 1);
825
826     ps.setNodeProperty("node1","test","111");
827     ps.setNodeProperty("node2","test3","11122");
828     ps.setProperty("test","111");
829     ps.setProperty("test3","11122");
830
831     names = usersession.getActivityListByProperty("test","111");
832     assertTrue("Error in getActivityListByProperty.2", names.size() == 1);
833
834     names = usersession.getToDoListByProperty("test","1111");
835     assertTrue("Error in getActivityListByProperty.3", names.size() == 0);
836     
837     usersession.terminateActivity(name,"node2");
838
839     names = usersession.getActivityListByProperty("test","111");
840     assertTrue("Error in getActivityListByProperty.4", names.size() == 0);
841
842     char[] password2 = { 't', 'o', 't', 'o' };
843     handler = new SimpleCallbackHandler("admin", password2);
844     lc = new LoginContext JavaDoc("TestClient", handler);
845     lc.login();
846 }
847
848 public void testGetTodoListByActivityProperty() throws Exception JavaDoc {
849     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
850     ProjectSession ps = projectSessionh.create();
851     ps.initModel("instActProp");
852     
853     ProjectSession ps2 = projectSessionh.create();
854     ps2.initModel("instActProp2");
855
856     ProjectSession ps3 = projectSessionh.create();
857     ps3.initModel("instActProp3");
858
859     ps.setProperty("id", "1234");
860     ps2.setProperty("id", "1234");
861     ps3.setProperty("id2", "1234");
862         
863     UserSessionHome uHome = UserSessionUtil.getHome();
864     UserSession usersession = uHome.create();
865     Collection JavaDoc names = usersession.getToDoListByActivityProperty("id", "1234");
866
867     assertTrue("Error in Instances by Property. Project error",names.size() == 0);
868     String JavaDoc prop1 = ps.instantiateProject("instProp");
869     String JavaDoc prop2 = ps2.instantiateProject("instProp2");
870     String JavaDoc prop3 = ps3.instantiateProject("instProp3");
871     ps.setProperty("id", "1234");
872     ps2.setProperty("id", "1234");
873     ps3.setProperty("id2", "1234");
874     names = usersession.getToDoListByActivityProperty("id", "1234");
875     assertTrue("Error in Instances by Property. Instance error",names.size() == 0);
876     
877     
878     ps.addNode("node1",1);
879     ps.setNodeRole("node1","admin");
880     ps.setNodeProperty("node1","test","ok",true);
881     ps2.addNode("node2",1);
882     ps2.setNodeRole("node2","admin");
883     ps2.setNodeProperty("node2","test","nok",true);
884     prop1 = ps.instantiateProject("instProp");
885     prop2 = ps2.instantiateProject("instProp2");
886     prop3 = ps3.instantiateProject("instProp3");
887     
888     names = usersession.getToDoListByActivityProperty("test", "ok");
889     assertTrue("Error in Instances by ActivityProperty. Instance error",names.size() == 1);
890 }
891
892 public void testGetTodoListByActivityPropertyTwoUsers() throws Exception JavaDoc {
893     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
894     UserRegistration userReg = urHome.create();
895     userReg.userCreate("tdptu", "tdptu", "miguel.valdes-faura@ext.bull.net");
896
897     ProjectSessionHome projectSessionh = ProjectSessionUtil.getHome();
898     ProjectSession ps = projectSessionh.create();
899     ps.initModel("TDPTU");
900     ps.addNode("node1", 1);
901     ps.setNodeProperty("node1","testtu","111");
902     ps.addNode("node2", 1);
903     ps.addUser("tdptu");
904     ps.setNodeRole("node1", "tdptu");
905     ps.setNodeRole("node2", "tdptu");
906
907     ProjectSession ps2 = projectSessionh.create();
908     ps2.initModel("TDPTU2");
909     ps2.addNode("node2", 1);
910     ps2.setNodeProperty("node2","testtu","111");
911
912     ProjectSession ps3 = projectSessionh.create();
913     ps3.initModel("TDPTU3");
914     ps3.addNode("node1", 1);
915     ps3.setNodeProperty("node1","testtu","111");
916     ps3.addNode("node2", 1);
917     ps3.setNodeProperty("node2","test3","111");
918     ps3.addUser("tdptu");
919     ps3.setNodeRole("node1", "tdptu");
920
921     SimpleCallbackHandler handler = new SimpleCallbackHandler("tdptu", "tdptu".toCharArray());
922     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
923     lc.login();
924     
925     String JavaDoc name = ps.instantiateProject("TDPTU");
926     ps2.instantiateProject("TDPTU2");
927     ps3.instantiateProject("TDPTU3");
928
929     UserSessionHome uHome = UserSessionUtil.getHome();
930     UserSession usersession = uHome.create();
931
932     Collection JavaDoc names = usersession.getToDoListByActivityProperty("testtu","111");
933     java.util.Iterator JavaDoc i = names.iterator();
934     BnNodeValue nd=null;
935     while (i.hasNext())
936     {
937         nd = (BnNodeValue)i.next();
938     }
939
940     assertTrue("Error in getTodoListByProperty.1: "+nd.getName()+"+"+nd.getBnProject().getName(), names.size() == 2);
941
942     ps3.setNodeProperty("node1","testtu","1112");
943     ps3.setNodeProperty("node2","test3","11122");
944     
945     names = usersession.getToDoListByActivityProperty("testtu","111");
946     assertTrue("Error in getTodoListByActivityProperty.2: "+names.size(), names.size() == 1);
947     
948     usersession.startActivity(name,"node1");
949
950     names = usersession.getToDoListByActivityProperty("testtu","111");
951     assertTrue("Error in getTodoListByActivityProperty.4: "+names.size(), names.size() == 0);
952
953     char[] password2 = { 't', 'o', 't', 'o' };
954     handler = new SimpleCallbackHandler("admin", password2);
955     lc = new LoginContext JavaDoc("TestClient", handler);
956     lc.login();
957 }
958
959 public void testFindModels() throws Exception JavaDoc {
960     UserSessionHome uHome = UserSessionUtil.getHome();
961     UserSession usersession = uHome.create();
962     Collection JavaDoc names = usersession.getModels();
963     assertTrue("Error in findModels", names.size() >0);
964 }
965
966 }
967
Popular Tags