KickJava   Java API By Example, From Geeks To Geeks.

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


1 package hero.client.test;
2
3 /*
4 *
5 * UserRegistrationTests.java -
6 * Copyright (C) 2002 Ecoo Team
7 * valdes@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 hero.interfaces.UserRegistration;
26 import hero.interfaces.UserRegistrationHome;
27 import hero.interfaces.UserRegistrationUtil;
28 import hero.interfaces.BnUser;
29 import hero.interfaces.BnUserHome;
30 import hero.interfaces.BnUserUtil;
31 import hero.interfaces.BnAuthRole;
32 import hero.interfaces.BnAuthRoleHome;
33 import hero.interfaces.BnAuthRoleUtil;
34 import hero.interfaces.ProjectSession;
35 import hero.interfaces.ProjectSessionHome;
36 import hero.interfaces.ProjectSessionUtil;
37 import hero.interfaces.UserSession;
38 import hero.interfaces.UserSessionHome;
39 import hero.interfaces.UserSessionUtil;
40 import junit.framework.TestCase;
41 import junit.framework.TestSuite;
42
43 public class UserRegistrationTests extends TestCase {
44  
45     public UserRegistrationTests(String JavaDoc testname) {
46     super(testname);
47     }
48     
49     public static TestSuite suite() {
50     return new TestSuite(UserRegistrationTests.class);
51     }
52
53     public void setUp() throws Exception JavaDoc {
54     }
55
56     public void testCreateUser() throws Exception JavaDoc {
57      UserRegistrationHome urHome = UserRegistrationUtil.getHome();
58      UserRegistration userReg=urHome.create();
59      userReg.userCreate("pouet","toto","admin@pouet.com");
60      BnUserHome uHome = BnUserUtil.getHome();
61      try{
62        BnUser user = uHome.findByName("pouet");
63      }catch(Exception JavaDoc cu){
64         assertTrue("Should have throw Exception in createUser",false);
65      }
66     
67     }
68     
69     public void testCreateAuthRole() throws Exception JavaDoc {
70     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
71     UserRegistration userReg=urHome.create();
72     userReg.roleCreate("pouet","ADMIN");
73     BnAuthRoleHome aHome = BnAuthRoleUtil.getHome();
74     try{
75        BnAuthRole role = aHome.findByName("pouet");
76      }catch(Exception JavaDoc cu){
77         assertTrue("Should have throw Exception in createAuthRole",false);
78      }
79
80     
81     }
82
83     public void testSetUserRole() throws Exception JavaDoc {
84      UserRegistrationHome urHome = UserRegistrationUtil.getHome();
85      UserRegistration userReg=urHome.create();
86      userReg.userCreate("testrole","toto","admin@pouet.com");
87      userReg.roleCreate("roletest","ADMIN");
88      userReg.setUserRole("testrole","roletest");
89      BnUserHome uHome = BnUserUtil.getHome();
90      
91      BnUser user = uHome.findByName("testrole");
92      hero.interfaces.BnAuthRoleValue[] roles = user.getBnUserValue().getBnAuthRoles();
93      assertTrue("Should have throw Exception in createUser",roles.length==2);
94     
95     }
96     
97     public void testDeleteUser() throws Exception JavaDoc {
98       UserRegistrationHome urHome = UserRegistrationUtil.getHome();
99       UserRegistration userReg=urHome.create();
100       userReg.userCreate("deleteUser","toto","admin@pouet.com");
101       
102       ProjectSessionHome projectSessionh=ProjectSessionUtil.getHome();
103       ProjectSession pss = projectSessionh.create();
104       pss.initProject("oneProject");
105       pss.addNode("node1",1);
106       pss.addUser("deleteUser");
107       pss.setNodeRole("node1","deleteUser");
108       pss.setUserRole("deleteUser",hero.interfaces.Constants.ADMIN);
109       
110       ProjectSession pss2 = projectSessionh.create();
111       pss2.initProject("oneProject2");
112       pss2.addUser("deleteUser");
113       
114       ProjectSession pss3 = projectSessionh.create();
115       pss3.initProject("oneProject3");
116       pss3.addUser("deleteUser");
117       pss3.addNode("node1",1);
118       pss3.setNodeRole("node1","deleteUser");
119       
120       try {
121          userReg.deleteUser("deleteUser");
122          assertTrue("Should have throw EJBException in deleteUser when initial state",false);
123       } catch (Exception JavaDoc e) {
124          //expected behavior
125
}
126       UserSessionHome usersh=UserSessionUtil.getHome();
127       UserSession usr=usersh.create();
128       usr.startActivity("oneProject","node1");
129       try {
130          userReg.deleteUser("deleteUser");
131          assertTrue("Should have throw EJBException in deleteUser when started activity",false);
132       } catch (Exception JavaDoc e) {
133                //expected behavior
134
}
135       usr.terminateActivity("oneProject","node1");
136       usr.terminate("oneProject");
137       usr.removeProject("oneProject3");
138       usr.removeProject("oneProject2");
139       
140       try {
141          userReg.deleteUser("deleteUser");
142       } catch (Exception JavaDoc e) {
143         assertTrue("Error in deleteUser: "+e.getMessage(),false);
144       }
145     }
146 }
147
Popular Tags