001: package hero.client.test;
002:
003: /*
004: *
005: * UserRegistrationTests.java -
006: * Copyright (C) 2002 Ecoo Team
007: * valdes@loria.fr
008: *
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
023: */
024:
025: import hero.interfaces.UserRegistration;
026: import hero.interfaces.UserRegistrationHome;
027: import hero.interfaces.UserRegistrationUtil;
028: import hero.interfaces.BnUser;
029: import hero.interfaces.BnUserHome;
030: import hero.interfaces.BnUserUtil;
031: import hero.interfaces.BnAuthRole;
032: import hero.interfaces.BnAuthRoleHome;
033: import hero.interfaces.BnAuthRoleUtil;
034: import hero.interfaces.ProjectSession;
035: import hero.interfaces.ProjectSessionHome;
036: import hero.interfaces.ProjectSessionUtil;
037: import hero.interfaces.UserSession;
038: import hero.interfaces.UserSessionHome;
039: import hero.interfaces.UserSessionUtil;
040: import junit.framework.TestCase;
041: import junit.framework.TestSuite;
042:
043: public class UserRegistrationTests extends TestCase {
044:
045: public UserRegistrationTests(String testname) {
046: super (testname);
047: }
048:
049: public static TestSuite suite() {
050: return new TestSuite(UserRegistrationTests.class);
051: }
052:
053: public void setUp() throws Exception {
054: }
055:
056: public void testCreateUser() throws Exception {
057: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
058: UserRegistration userReg = urHome.create();
059: userReg.userCreate("pouet", "toto", "admin@pouet.com");
060: BnUserHome uHome = BnUserUtil.getHome();
061: try {
062: BnUser user = uHome.findByName("pouet");
063: } catch (Exception cu) {
064: assertTrue("Should have throw Exception in createUser",
065: false);
066: }
067:
068: }
069:
070: public void testCreateAuthRole() throws Exception {
071: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
072: UserRegistration userReg = urHome.create();
073: userReg.roleCreate("pouet", "ADMIN");
074: BnAuthRoleHome aHome = BnAuthRoleUtil.getHome();
075: try {
076: BnAuthRole role = aHome.findByName("pouet");
077: } catch (Exception cu) {
078: assertTrue("Should have throw Exception in createAuthRole",
079: false);
080: }
081:
082: }
083:
084: public void testSetUserRole() throws Exception {
085: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
086: UserRegistration userReg = urHome.create();
087: userReg.userCreate("testrole", "toto", "admin@pouet.com");
088: userReg.roleCreate("roletest", "ADMIN");
089: userReg.setUserRole("testrole", "roletest");
090: BnUserHome uHome = BnUserUtil.getHome();
091:
092: BnUser user = uHome.findByName("testrole");
093: hero.interfaces.BnAuthRoleValue[] roles = user.getBnUserValue()
094: .getBnAuthRoles();
095: assertTrue("Should have throw Exception in createUser",
096: roles.length == 2);
097:
098: }
099:
100: public void testDeleteUser() throws Exception {
101: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
102: UserRegistration userReg = urHome.create();
103: userReg.userCreate("deleteUser", "toto", "admin@pouet.com");
104:
105: ProjectSessionHome projectSessionh = ProjectSessionUtil
106: .getHome();
107: ProjectSession pss = projectSessionh.create();
108: pss.initProject("oneProject");
109: pss.addNode("node1", 1);
110: pss.addUser("deleteUser");
111: pss.setNodeRole("node1", "deleteUser");
112: pss.setUserRole("deleteUser", hero.interfaces.Constants.ADMIN);
113:
114: ProjectSession pss2 = projectSessionh.create();
115: pss2.initProject("oneProject2");
116: pss2.addUser("deleteUser");
117:
118: ProjectSession pss3 = projectSessionh.create();
119: pss3.initProject("oneProject3");
120: pss3.addUser("deleteUser");
121: pss3.addNode("node1", 1);
122: pss3.setNodeRole("node1", "deleteUser");
123:
124: try {
125: userReg.deleteUser("deleteUser");
126: assertTrue(
127: "Should have throw EJBException in deleteUser when initial state",
128: false);
129: } catch (Exception e) {
130: //expected behavior
131: }
132: UserSessionHome usersh = UserSessionUtil.getHome();
133: UserSession usr = usersh.create();
134: usr.startActivity("oneProject", "node1");
135: try {
136: userReg.deleteUser("deleteUser");
137: assertTrue(
138: "Should have throw EJBException in deleteUser when started activity",
139: false);
140: } catch (Exception e) {
141: //expected behavior
142: }
143: usr.terminateActivity("oneProject", "node1");
144: usr.terminate("oneProject");
145: usr.removeProject("oneProject3");
146: usr.removeProject("oneProject2");
147:
148: try {
149: userReg.deleteUser("deleteUser");
150: } catch (Exception e) {
151: assertTrue("Error in deleteUser: " + e.getMessage(), false);
152: }
153: }
154: }
|