1 22 package org.jboss.test.jbossmessaging; 23 24 import java.net.URL ; 25 import java.util.Properties ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingEnumeration ; 28 import javax.naming.NameClassPair ; 29 30 import org.objectweb.jtests.jms.admin.Admin; 31 import org.objectweb.jtests.jms.admin.AdminFactory; 32 33 import org.jboss.logging.Logger; 34 import org.jboss.util.NestedRuntimeException; 35 import org.jboss.test.JBossTestCase; 36 37 49 public class JMSTestCase extends JBossTestCase 50 { 51 private static String PROP_FILE_NAME = "provider.properties" ; 52 private static String PROP_NAME = "jms.provider.resources.dir" ; 53 54 protected Admin admin; 55 56 60 public JMSTestCase(String name) 61 { 62 super(name); 63 } 64 65 69 protected void setUp() throws Exception 70 { 71 super.setUp() ; 73 74 try { 75 log.info("setting up Admin") ; 76 admin = AdminFactory.getAdmin() ; 79 } catch (Exception e) { 80 throw new NestedRuntimeException("getAdmin() operation failed", e) ; 81 } 82 } 83 84 92 public void createQueue(String name) 93 { 94 try { 95 admin.createQueue(name) ; 96 } catch (Exception e) { 97 throw new NestedRuntimeException("createQueue() operation failed", e) ; 98 } 99 } 100 101 109 public void deleteQueue(String name) 110 { 111 try { 112 admin.deleteQueue(name) ; 113 } catch (Exception e) { 114 throw new NestedRuntimeException("deleteQueue() operation failed", e) ; 115 } 116 } 117 118 126 public void createTopic(String name) 127 { 128 try { 129 admin.createTopic(name) ; 130 } catch (Exception e) { 131 throw new NestedRuntimeException("createTopic() operation failed", e) ; 132 } 133 } 134 135 143 public void deleteTopic(String name) 144 { 145 try { 146 admin.deleteTopic(name) ; 147 } catch (Exception e) { 148 throw new NestedRuntimeException("deleteTopic() operation failed", e) ; 149 } 150 } 151 152 160 public void createConnectionFactory(String name) 161 { 162 try { 163 admin.createConnectionFactory(name) ; 164 } catch (Exception e) { 165 throw new NestedRuntimeException("createConnectionFactory() operation failed", e) ; 166 } 167 } 168 169 177 public void deleteConnectionFactory(String name) 178 { 179 try { 180 admin.deleteConnectionFactory(name) ; 181 } catch (Exception e) { 182 throw new NestedRuntimeException("deleteConnectionFactory() operation failed", e) ; 183 } 184 } 185 186 protected void dumpJNDIContext(String context) 187 { 188 try 189 { 190 log.info("Dumping JNDI context:" + context) ; 191 192 InitialContext ic = getInitialContext() ; 194 NamingEnumeration list = ic.list(context); 195 196 while (list.hasMore()) { 197 NameClassPair nc = (NameClassPair )list.next(); 198 log.info(nc.toString()); 199 } 200 log.info("Dumped JNDI context") ; 201 } catch (Exception e) { 202 throw new NestedRuntimeException("error dumping JNDI context", e) ; 203 } 204 } 205 206 215 public static String getJMSResourceRelativePathname(String name) 216 { 217 String directoryName ; 218 219 if (name == null) 221 return name ; 222 223 try { 224 Properties props = new Properties () ; 226 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 227 URL propsURL = loader.getResource(PROP_FILE_NAME); 228 System.err.println("using provider.properties: "+propsURL); 229 props.load(propsURL.openStream()) ; 230 directoryName = props.getProperty(PROP_NAME) ; 231 } catch (Exception e) { 232 throw new NestedRuntimeException("error getting JMS provider directory name", e) ; 233 } 234 235 if (directoryName == null) { 236 throw new NestedRuntimeException("Property " + PROP_NAME + " has not been found in the file " 237 + PROP_FILE_NAME + ".") ; 238 } 239 240 return (String ) (directoryName + "/" + name) ; 242 } 243 } 244 | Popular Tags |