KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > perf > test > Setup


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.perf.test;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
25 import javax.security.auth.login.LoginContext JavaDoc;
26
27 import junit.framework.TestSuite;
28
29 import org.jboss.test.perf.interfaces.EntityPK;
30 import org.jboss.test.perf.interfaces.Entity2PK;
31 import org.jboss.test.perf.interfaces.EntityHome;
32 import org.jboss.test.perf.interfaces.Entity2Home;
33
34 import org.jboss.test.util.AppCallbackHandler;
35 import org.jboss.test.JBossTestSetup;
36
37 /** Setup utility class.
38  
39  @author Scott.Stark@jboss.org
40  @version $Revision: 37406 $
41  */

42 public class Setup extends JBossTestSetup
43 {
44    LoginContext JavaDoc lc = null;
45    String JavaDoc filename;
46    boolean isSecure;
47
48    Setup(TestSuite suite, String JavaDoc filename, boolean isSecure) throws Exception JavaDoc
49    {
50       super(suite);
51       this.filename = filename;
52       this.isSecure = isSecure;
53    }
54
55    protected void setUp() throws Exception JavaDoc
56    {
57       super.setUp();
58       getLog().debug("+++ Performing the TestSuite setup");
59       if( isSecure )
60       {
61          login();
62       }
63       deploy(filename);
64       removeAll();
65       createEntityBeans(getBeanCount());
66       createEntity2Beans(getBeanCount());
67    }
68    protected void tearDown() throws Exception JavaDoc
69    {
70       getLog().debug("+++ Performing the TestSuite tear down");
71       removeAll();
72       undeploy(filename);
73       if( isSecure )
74       {
75          logout();
76       }
77    }
78
79    private void removeAll()
80    {
81       try
82       {
83          removeEntityBeans(getBeanCount());
84       }
85       catch (Exception JavaDoc e)
86       {
87          //ignore
88
} // end of try-catch
89
try
90       {
91          removeEntity2Beans(getBeanCount());
92       }
93       catch (Exception JavaDoc e)
94       {
95          //ignore
96
} // end of try-catch
97
}
98
99    private void createEntityBeans(int max) throws Exception JavaDoc
100    {
101       String JavaDoc jndiName = isSecure ? "secure/perf/Entity" : "perfEntity";
102       Object JavaDoc obj = getInitialContext().lookup(jndiName);
103       obj = PortableRemoteObject.narrow(obj, EntityHome.class);
104       EntityHome home = (EntityHome) obj;
105       getLog().debug("Creating "+max+" Entity beans");
106       for(int n = 0; n < max; n ++)
107          home.create(n, n);
108    }
109    private void removeEntityBeans(int max) throws Exception JavaDoc
110    {
111       String JavaDoc jndiName = isSecure ? "secure/perf/Entity" : "perfEntity";
112       Object JavaDoc obj = getInitialContext().lookup(jndiName);
113       obj = PortableRemoteObject.narrow(obj, EntityHome.class);
114       EntityHome home = (EntityHome) obj;
115       getLog().debug("Removing "+max+" Entity beans");
116       for(int n = 0; n < max; n ++)
117          home.remove(new EntityPK(n));
118    }
119    private void createEntity2Beans(int max) throws Exception JavaDoc
120    {
121       String JavaDoc jndiName = isSecure ? "secure/perf/Entity2" : "perfEntity2";
122       Object JavaDoc obj = getInitialContext().lookup(jndiName);
123       obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
124       Entity2Home home = (Entity2Home) obj;
125       getLog().debug("Creating "+max+" Entity2 beans");
126       for(int n = 0; n < max; n ++)
127          home.create(n, "String"+n, new Double JavaDoc(n), n);
128    }
129    private void removeEntity2Beans(int max) throws Exception JavaDoc
130    {
131       String JavaDoc jndiName = isSecure ? "secure/perf/Entity2" : "perfEntity2";
132       Object JavaDoc obj = getInitialContext().lookup(jndiName);
133       obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
134       Entity2Home home = (Entity2Home) obj;
135       getLog().debug("Removing "+max+" Entity2 beans");
136       for(int n = 0; n < max; n ++)
137          home.remove(new Entity2PK(n, "String"+n, new Double JavaDoc(n)));
138    }
139
140    private void login() throws Exception JavaDoc
141    {
142       flushAuthCache();
143       String JavaDoc username = "jduke";
144       char[] password = "theduke".toCharArray();
145       AppCallbackHandler handler = new AppCallbackHandler(username, password);
146       getLog().debug("Creating LoginContext(other)");
147       lc = new LoginContext JavaDoc("spec-test", handler);
148       lc.login();
149       getLog().debug("Created LoginContext, subject="+lc.getSubject());
150    }
151
152    private void logout()
153    {
154       try
155       {
156          lc.logout();
157       }
158       catch(Exception JavaDoc e)
159       {
160          getLog().error("logout error: ", e);
161       }
162    }
163 }
164
Popular Tags