1 26 27 package org.objectweb.jonas.jtests.util; 28 29 import java.io.File ; 30 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import javax.rmi.PortableRemoteObject ; 35 36 import junit.framework.TestCase; 37 38 import org.objectweb.jonas.adm.AdmInterface; 39 40 import com.meterware.httpunit.WebConversation; 41 42 48 public class JWebServicesTestCase extends TestCase { 49 50 53 private static String jonasName = "jonas"; 54 55 58 protected static Context ictx = null; 59 60 63 private static AdmInterface admI = null; 64 65 68 protected WebConversation wc = null; 69 70 73 protected String url = null; 74 75 78 private String prefixUrl = null; 79 80 85 protected String getAbsoluteUrl (String url) { 86 return (this.prefixUrl + url); 87 } 88 89 92 private void init() { 93 String port = System.getProperty("http.port"); 94 if (port == null) { 95 port = "9000"; 96 } 97 98 prefixUrl = "http://localhost:" + port; 99 } 100 101 105 public JWebServicesTestCase(String s) { 106 super(s); 107 init(); 108 } 109 114 public JWebServicesTestCase(String s, String url) { 115 super(s); 116 wc = new WebConversation(); 117 init(); 118 this.url = getAbsoluteUrl(url); 119 } 120 121 126 private Context getInitialContext() throws NamingException { 127 return new InitialContext (); 128 } 129 130 134 protected void setUp() throws Exception { 135 try { 136 if (ictx == null) { 138 ictx = getInitialContext(); 139 } 140 if (admI == null) { 141 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 142 } 143 144 145 } catch (NamingException e) { 146 System.err.println("Cannot setup test: " + e); 147 e.printStackTrace(); 148 } 149 } 150 151 152 157 public void useEar(String filename) throws Exception { 158 159 try { 160 if (ictx == null) { 162 ictx = getInitialContext(); 163 } 164 165 if (admI == null) { 166 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 167 } 168 169 String appsFileName = filename + ".ear"; 171 String autoloadAppsFileName = "autoload" + File.separator + filename + ".ear"; 172 if (!admI.isEarLoaded(appsFileName) && !admI.isEarLoaded(autoloadAppsFileName)) { 173 admI.addEar(appsFileName); 175 } 176 177 } catch (Exception e) { 178 throw new Exception ("Cannot load Ear : " + e.getMessage()); 179 } 180 } 181 182 187 public void useWar(String filename) throws Exception { 188 189 try { 190 if (ictx == null) { 192 ictx = getInitialContext(); 193 } 194 195 if (admI == null) { 196 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 197 } 198 199 String webappsFileName = filename + ".war"; 201 String autoloadWebappsFileName = "autoload" + File.separator + filename + ".war"; 202 if (!admI.isWarLoaded(webappsFileName) && !admI.isWarLoaded(autoloadWebappsFileName)) { 203 admI.addWar(webappsFileName); 205 } 206 207 } catch (Exception e) { 208 throw new Exception ("Cannot load War : " + e.getMessage()); 209 } 210 } 211 212 217 public void useBeans(String filename) throws Exception { 218 try { 219 if (ictx == null) { 221 ictx = getInitialContext(); 222 } 223 if (admI == null) { 224 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 225 } 226 if (!admI.isLoaded(filename + ".jar")) { 227 admI.addBeans(filename + ".jar"); 228 } 229 } catch (Exception e) { 230 throw new Exception ("Cannot load Bean : " + e.getMessage()); 231 } 232 } 233 234 235 240 public void unUseBeans(String filename) throws Exception { 241 try { 242 if (ictx == null) { 244 ictx = getInitialContext(); 245 } 246 if (admI == null) { 247 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 248 } 249 if (admI.isLoaded(filename + ".jar")) { 250 admI.removeBeans(filename + ".jar"); 251 } 252 } catch (Exception e) { 253 throw new Exception ("Cannot unload Bean : " + e.getMessage()); 254 } 255 } 256 257 258 259 260 } 261 | Popular Tags |