001: package hero.client.test;
002:
003: /**
004: *
005: * Bonita
006: * Copyright (C) 1999 Bull S.A.
007: * Bull 68 route de versailles 78434 Louveciennes Cedex France
008: * Further information: bonita@objectweb.org
009: *
010: * This library is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU Lesser General Public
012: * License as published by the Free Software Foundation; either
013: * version 2.1 of the License, or any later version.
014: *
015: * This library 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 GNU
018: * Lesser General Public License for more details.
019: *
020: * You should have received a copy of the GNU Lesser General Public
021: * License along with this library; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
023: * USA
024: *
025: *
026: --------------------------------------------------------------------------
027: * $Id: AdminSessionTests.java,v 1.3 2006/03/31 14:27:31 mvaldes Exp $
028: *
029: --------------------------------------------------------------------------
030: */
031: import javax.security.auth.login.LoginContext;
032: import hero.interfaces.ProjectSession;
033: import hero.interfaces.ProjectSessionHome;
034: import hero.interfaces.ProjectSessionUtil;
035: import hero.interfaces.BnNodeValue;
036: import hero.interfaces.UserRegistration;
037: import hero.interfaces.UserRegistrationHome;
038: import hero.interfaces.UserRegistrationUtil;
039:
040: import hero.interfaces.AdminSessionHome;
041: import hero.interfaces.AdminSession;
042: import hero.interfaces.AdminSessionUtil;
043:
044: import java.util.Collection;
045: import junit.framework.TestCase;
046: import junit.framework.TestSuite;
047:
048: public class AdminSessionTests extends TestCase {
049:
050: private ProjectSessionHome projectsesh;
051:
052: public AdminSessionTests(String testname) {
053: super (testname);
054: }
055:
056: public static TestSuite suite() {
057: return new TestSuite(AdminSessionTests.class);
058: }
059:
060: public void setUp() throws Exception {
061: }
062:
063: public void testGetModels() throws Exception {
064: UserRegistrationHome urHome = UserRegistrationUtil.getHome();
065: UserRegistration userReg = urHome.create();
066: userReg.userCreate("userAdmin1", "userAdmin1",
067: "miguel.valdes-faura@ext.bull.net");
068: userReg.userCreate("userAdmin2", "userAdmin2",
069: "miguel.valdes-faura@ext.bull.net");
070:
071: SimpleCallbackHandler handler = new SimpleCallbackHandler(
072: "userAdmin1", "userAdmin1".toCharArray());
073: LoginContext lc = new LoginContext("TestClient", handler);
074: lc.login();
075:
076: projectsesh = ProjectSessionUtil.getHome();
077: ProjectSession p = projectsesh.create();
078: p.initProject("project1");
079: p.initModel("project2");
080:
081: handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2"
082: .toCharArray());
083: lc = new LoginContext("TestClient", handler);
084: lc.login();
085:
086: ProjectSession p2 = projectsesh.create();
087: p2.initModel("project3");
088: p2.initModel("project4");
089:
090: AdminSessionHome aHome = AdminSessionUtil.getHome();
091: AdminSession adminsession = aHome.create();
092:
093: Collection models = adminsession.getModels();
094: assertTrue("Error in getModels, " + models.size(), models
095: .size() == 2);
096:
097: handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1"
098: .toCharArray());
099: lc = new LoginContext("TestClient", handler);
100: lc.login();
101: }
102:
103: public void testInstances() throws Exception {
104: projectsesh = ProjectSessionUtil.getHome();
105: ProjectSession p = projectsesh.create();
106: p.initProject("project5");
107: p.initModel("project6");
108:
109: p.instantiateProject("project6");
110: p.instantiateProject("project6");
111:
112: SimpleCallbackHandler handler = new SimpleCallbackHandler(
113: "userAdmin2", "userAdmin2".toCharArray());
114: LoginContext lc = new LoginContext("TestClient", handler);
115: lc.login();
116:
117: ProjectSession p2 = projectsesh.create();
118: p2.initModel("project7");
119: p2.initModel("project8");
120:
121: p2.instantiateProject("project7");
122: p2.instantiateProject("project7");
123: p2.instantiateProject("project7");
124:
125: handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1"
126: .toCharArray());
127: lc = new LoginContext("TestClient", handler);
128: lc.login();
129:
130: ProjectSession p3 = projectsesh.create();
131: p3.instantiateProject("project8");
132: p3.instantiateProject("project8");
133:
134: handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2"
135: .toCharArray());
136: lc = new LoginContext("TestClient", handler);
137: lc.login();
138:
139: ProjectSession p4 = projectsesh.create();
140: p4.instantiateProject("project8");
141:
142: AdminSessionHome aHome = AdminSessionUtil.getHome();
143: AdminSession adminsession = aHome.create();
144:
145: Collection instances = adminsession.getInstances();
146: assertTrue("Error in getInstances, " + instances.size(),
147: instances.size() == 6);
148:
149: handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1"
150: .toCharArray());
151: lc = new LoginContext("TestClient", handler);
152: lc.login();
153: }
154:
155: public void testActivities() throws Exception {
156: projectsesh = ProjectSessionUtil.getHome();
157: ProjectSession p = projectsesh.create();
158: p.initProject("project9");
159: p.addNode("node1", 1);
160:
161: p.initModel("project10");
162: p.addNode("node1", 1);
163:
164: p.instantiateProject("project10");
165: p.addUser("userAdmin2");
166: p.instantiateProject("project10");
167:
168: SimpleCallbackHandler handler = new SimpleCallbackHandler(
169: "userAdmin2", "userAdmin2".toCharArray());
170: LoginContext lc = new LoginContext("TestClient", handler);
171: lc.login();
172:
173: ProjectSession p2 = projectsesh.create();
174: p2.initModel("project11");
175: p2.addNode("node1", 1);
176: p2.addNode("node2", 1);
177:
178: p2.initModel("project12");
179: p2.addNode("node1", 1);
180:
181: p2.instantiateProject("project11");
182: p2.instantiateProject("project11");
183: p2.instantiateProject("project11");
184:
185: handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1"
186: .toCharArray());
187: lc = new LoginContext("TestClient", handler);
188: lc.login();
189:
190: ProjectSession p3 = projectsesh.create();
191: p3.instantiateProject("project12");
192: p3.instantiateProject("project12");
193:
194: handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2"
195: .toCharArray());
196: lc = new LoginContext("TestClient", handler);
197: lc.login();
198:
199: ProjectSession p4 = projectsesh.create();
200: p4.instantiateProject("project12");
201:
202: AdminSessionHome aHome = AdminSessionUtil.getHome();
203: AdminSession adminsession = aHome.create();
204:
205: ProjectSession p5 = projectsesh.create();
206: p5.initProject("project13");
207: p5.addNode("node1", 1);
208:
209: Collection activities = adminsession.getActivities();
210: assertTrue("Error in getInstances, " + activities.size(),
211: activities.size() == 10);
212:
213: handler = new SimpleCallbackHandler("admin", "toto"
214: .toCharArray());
215: lc = new LoginContext("TestClient", handler);
216: lc.login();
217: }
218: }
|