1 22 package org.jboss.test.perf.test; 23 24 import javax.rmi.PortableRemoteObject ; 25 import javax.security.auth.login.LoginContext ; 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 42 public class Setup extends JBossTestSetup 43 { 44 LoginContext lc = null; 45 String filename; 46 boolean isSecure; 47 48 Setup(TestSuite suite, String filename, boolean isSecure) throws Exception 49 { 50 super(suite); 51 this.filename = filename; 52 this.isSecure = isSecure; 53 } 54 55 protected void setUp() throws Exception 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 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 e) 86 { 87 } try 90 { 91 removeEntity2Beans(getBeanCount()); 92 } 93 catch (Exception e) 94 { 95 } } 98 99 private void createEntityBeans(int max) throws Exception 100 { 101 String jndiName = isSecure ? "secure/perf/Entity" : "perfEntity"; 102 Object 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 110 { 111 String jndiName = isSecure ? "secure/perf/Entity" : "perfEntity"; 112 Object 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 120 { 121 String jndiName = isSecure ? "secure/perf/Entity2" : "perfEntity2"; 122 Object 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 (n), n); 128 } 129 private void removeEntity2Beans(int max) throws Exception 130 { 131 String jndiName = isSecure ? "secure/perf/Entity2" : "perfEntity2"; 132 Object 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 (n))); 138 } 139 140 private void login() throws Exception 141 { 142 flushAuthCache(); 143 String username = "jduke"; 144 char[] password = "theduke".toCharArray(); 145 AppCallbackHandler handler = new AppCallbackHandler(username, password); 146 getLog().debug("Creating LoginContext(other)"); 147 lc = new LoginContext ("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 e) 159 { 160 getLog().error("logout error: ", e); 161 } 162 } 163 } 164 | Popular Tags |