KickJava   Java API By Example, From Geeks To Geeks.

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


1 package hero.client.test;
2
3 /**
4 *
5 * Bonita
6 * Copyright (C) 1999 Bull S.A.
7 * Bull 68 route de versailles 78434 Louveciennes Cedex France
8 * Further information: bonita@objectweb.org
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library 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 GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 *
26 --------------------------------------------------------------------------
27 * $Id: AdminSessionTests.java,v 1.1 2004/09/13 16:29:41 mvaldes Exp $
28 *
29 --------------------------------------------------------------------------
30 */

31 import javax.security.auth.login.LoginContext JavaDoc;
32 import hero.interfaces.ProjectSession;
33 import hero.interfaces.ProjectSessionHome;
34 import hero.interfaces.ProjectSessionUtil;
35 import hero.interfaces.BnNodeValue;
36 import hero.interfaces.UserRegistration;
37 import hero.interfaces.UserRegistrationHome;
38 import hero.interfaces.UserRegistrationUtil;
39
40 import hero.interfaces.AdminSessionHome;
41 import hero.interfaces.AdminSession;
42 import hero.interfaces.AdminSessionUtil;
43
44 import java.util.Collection JavaDoc;
45 import junit.framework.TestCase;
46 import junit.framework.TestSuite;
47
48
49 public class AdminSessionTests extends TestCase {
50
51     private ProjectSessionHome projectsesh;
52
53     public AdminSessionTests(String JavaDoc testname) {
54     super(testname);
55     }
56     
57     public static TestSuite suite() {
58     return new TestSuite(AdminSessionTests.class);
59     }
60
61     public void setUp() throws Exception JavaDoc {
62     }
63
64    public void testGetModels() throws Exception JavaDoc {
65     UserRegistrationHome urHome = UserRegistrationUtil.getHome();
66     UserRegistration userReg=urHome.create();
67     userReg.userCreate("userAdmin1","userAdmin1","miguel.valdes-faura@ext.bull.net");
68     userReg.userCreate("userAdmin2","userAdmin2","miguel.valdes-faura@ext.bull.net");
69     
70     SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray());
71     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
72     lc.login();
73     
74     projectsesh=ProjectSessionUtil.getHome();
75     ProjectSession p = projectsesh.create();
76     p.initProject("project1");
77     p.initModel("project2");
78         
79     handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray());
80     lc = new LoginContext JavaDoc("TestClient", handler);
81     lc.login();
82     
83     ProjectSession p2 = projectsesh.create();
84     p2.initModel("project3");
85     p2.initModel("project4");
86     
87     AdminSessionHome aHome = AdminSessionUtil.getHome();
88     AdminSession adminsession = aHome.create();
89     
90     Collection JavaDoc models = adminsession.getModels();
91     assertTrue("Error in getModels, "+models.size(), models.size() == 2);
92     
93     handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray());
94     lc = new LoginContext JavaDoc("TestClient", handler);
95     lc.login();
96     }
97    
98    public void testInstances() throws Exception JavaDoc {
99     projectsesh=ProjectSessionUtil.getHome();
100     ProjectSession p = projectsesh.create();
101     p.initProject("project5");
102     p.initModel("project6");
103     
104     p.instantiateProject("project6");
105     p.instantiateProject("project6");
106         
107     SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray());
108     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
109     lc.login();
110     
111     ProjectSession p2 = projectsesh.create();
112     p2.initModel("project7");
113     p2.initModel("project8");
114     
115     p2.instantiateProject("project7");
116     p2.instantiateProject("project7");
117     p2.instantiateProject("project7");
118     
119     handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray());
120     lc = new LoginContext JavaDoc("TestClient", handler);
121     lc.login();
122     
123     ProjectSession p3 = projectsesh.create();
124     p3.instantiateProject("project8");
125     p3.instantiateProject("project8");
126     
127     handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray());
128     lc = new LoginContext JavaDoc("TestClient", handler);
129     lc.login();
130     
131     ProjectSession p4 = projectsesh.create();
132     p4.instantiateProject("project8");
133     
134     AdminSessionHome aHome = AdminSessionUtil.getHome();
135     AdminSession adminsession = aHome.create();
136     
137     Collection JavaDoc instances = adminsession.getInstances();
138     assertTrue("Error in getInstances, "+instances.size(), instances.size() == 6);
139     
140     handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray());
141     lc = new LoginContext JavaDoc("TestClient", handler);
142     lc.login();
143     }
144     
145    public void testActivities() throws Exception JavaDoc {
146     projectsesh=ProjectSessionUtil.getHome();
147     ProjectSession p = projectsesh.create();
148     p.initProject("project9");
149     p.addNode("node1",1);
150     
151     p.initModel("project10");
152     p.addNode("node1",1);
153     
154     p.instantiateProject("project10");
155     p.instantiateProject("project10");
156         
157     SimpleCallbackHandler handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray());
158     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
159     lc.login();
160     
161     ProjectSession p2 = projectsesh.create();
162     p2.initModel("project11");
163     p2.addNode("node1",1);
164     p2.addNode("node2",1);
165     
166     p2.initModel("project12");
167     p2.addNode("node1",1);
168     
169     p2.instantiateProject("project11");
170     p2.instantiateProject("project11");
171     p2.instantiateProject("project11");
172     
173     handler = new SimpleCallbackHandler("userAdmin1", "userAdmin1".toCharArray());
174     lc = new LoginContext JavaDoc("TestClient", handler);
175     lc.login();
176     
177     ProjectSession p3 = projectsesh.create();
178     p3.instantiateProject("project12");
179     p3.instantiateProject("project12");
180     
181     handler = new SimpleCallbackHandler("userAdmin2", "userAdmin2".toCharArray());
182     lc = new LoginContext JavaDoc("TestClient", handler);
183     lc.login();
184     
185     ProjectSession p4 = projectsesh.create();
186     p4.instantiateProject("project12");
187     
188     AdminSessionHome aHome = AdminSessionUtil.getHome();
189     AdminSession adminsession = aHome.create();
190     
191     ProjectSession p5 = projectsesh.create();
192     p5.initProject("project13");
193     p5.addNode("node1",1);
194     
195     Collection JavaDoc activities = adminsession.getActivities();
196     assertTrue("Error in getInstances, "+activities.size(), activities.size() == 10);
197         
198     handler = new SimpleCallbackHandler("admin", "toto".toCharArray());
199     lc = new LoginContext JavaDoc("TestClient", handler);
200     lc.login();
201     }
202 }
203
Popular Tags