01: package hero.client.test;
02:
03: import hero.interfaces.*;
04: import hero.util.BonitaProjectLocator;
05: import hero.util.BonitaServiceException;
06: import hero.util.HeroException;
07: import junit.framework.*;
08: import java.util.*;
09:
10: public class DbReset extends TestCase {
11:
12: private BnUserHome uhome;
13: private BnAuthRoleHome arhome;
14: private BnProjectHome pHome;
15: private BnUserHome uHome;
16: private BnAuthRoleHome aHome;
17:
18: public DbReset(String testname) {
19: super (testname);
20: }
21:
22: public static TestSuite suite() {
23:
24: return new TestSuite(DbReset.class);
25: }
26:
27: public void setUp() throws Exception {
28: }
29:
30: public void testDbReset() throws Exception {
31:
32: // Get all projects and remove them.
33: pHome = hero.interfaces.BnProjectUtil.getHome();
34: Collection projects = pHome.findAll();
35: Iterator pr = projects.iterator();
36: while (pr.hasNext()) {
37: BnProject project = (BnProject) pr.next();
38: try {
39: if (project.getType().equals(Constants.Pj.MODEL))
40: BonitaProjectLocator.getInstance().cleanModelValue(
41: project.getName(), project.getVersion());
42: } catch (BonitaServiceException se) {
43: throw new HeroException(se.getMessage());
44: }
45: project.remove();
46: }
47:
48: // Get all users and remove them.
49: uHome = hero.interfaces.BnUserUtil.getHome();
50: Collection users = uHome.findAll();
51: Iterator ur = users.iterator();
52: while (ur.hasNext()) {
53: BnUser user = (BnUser) ur.next();
54: user.remove();
55: }
56:
57: // Get all AuthRole and remove them.
58: aHome = hero.interfaces.BnAuthRoleUtil.getHome();
59: Collection auths = aHome.findAll();
60: Iterator au = auths.iterator();
61: while (au.hasNext()) {
62: BnAuthRole auth = (BnAuthRole) au.next();
63: auth.remove();
64: }
65:
66: // Init default users and authRoles
67: InsertAuthRoleUserHome lHome = InsertAuthRoleUserUtil.getHome();
68: InsertAuthRoleUser lBean = (InsertAuthRoleUser) lHome.create();
69: lBean.initializeUser("admin", "toto", "toxic@loria.fr");
70: lBean.initializeUser("admin2", "toto2", "toxic@loria.fr");
71: lBean.initializeUser("nobody", "nobody", "toxic@loria.fr");
72: lBean.initializeAuthRole("BONITAUSER", "BONITAUSER");
73: lBean.initializeAuthRole("nobody", "nobody");
74: lBean.initialize("admin", "BONITAUSER");
75: lBean.initialize("admin", "nobody");
76: lBean.initialize("admin2", "BONITAUSER");
77: lBean.initialize("admin2", "nobody");
78: lBean.initialize("nobody", "nobody");
79:
80: }
81: }
|