1 22 package org.jboss.test.recover.test; 23 24 import java.net.URL ; 25 import java.util.Properties ; 26 27 import javax.management.MBeanServerConnection ; 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 34 import org.jboss.test.JBossTestCase; 35 import org.jboss.test.recover.bean.DummyRecoverableProxyService.RecoverableWrapper; 36 import org.jboss.test.recover.interfaces.DummyXAResource; 37 38 44 public abstract class JBossCrashRecoveryTestCase 45 extends JBossTestCase 46 { 47 protected int N = 10; 48 protected Properties resource1ServerJndiProps; 49 protected Properties resource2ServerJndiProps; 50 protected MBeanServerConnection resource1Server; 51 protected MBeanServerConnection resource2Server; 52 53 protected JBossCrashRecoveryTestCase(String name) 54 { 55 super(name); 56 } 57 58 protected String getUnqualifiedClassName() 59 { 60 String s = getClass().getName(); 61 int i = s.lastIndexOf('.') + 1; 62 return s.substring(i); 63 } 64 65 protected DummyXAResource getXAResource(String recoverableName) 66 throws Exception 67 { 68 RecoverableWrapper recoverable = 69 (RecoverableWrapper) getInitialContext().lookup(recoverableName); 70 DummyXAResource xaRes = 71 (DummyXAResource) recoverable.getUnwrappedResource(); 72 return xaRes; 73 } 74 75 protected Context getResource1ServerInitialContext() throws Exception 76 { 77 if( resource1ServerJndiProps == null ) 78 { 79 URL url = ClassLoader.getSystemResource("jndi.properties"); 80 resource1ServerJndiProps = new java.util.Properties (); 81 resource1ServerJndiProps.load(url.openStream()); 82 String jndiHost = System.getProperty("jbosstest.resource1.server.host", 83 "localhost"); 84 String jndiUrl = "jnp://"+jndiHost+":1099"; 85 resource1ServerJndiProps.setProperty("java.naming.provider.url", 86 jndiUrl); 87 } 88 return new InitialContext (resource1ServerJndiProps); 89 } 90 91 protected MBeanServerConnection getResource1Server() throws Exception 92 { 93 if (resource1Server == null) 94 { 95 String adaptorName = System.getProperty("jbosstest.server.name", 96 "jmx/invoker/RMIAdaptor"); 97 Context resCtx = getResource1ServerInitialContext(); 98 resource1Server = (MBeanServerConnection )resCtx.lookup(adaptorName); 99 } 100 return resource1Server; 101 } 102 103 protected Context getResource2ServerInitialContext() throws Exception 104 { 105 if( resource2ServerJndiProps == null ) 106 { 107 URL url = ClassLoader.getSystemResource("jndi.properties"); 108 resource2ServerJndiProps = new java.util.Properties (); 109 resource2ServerJndiProps.load(url.openStream()); 110 String jndiHost = System.getProperty("jbosstest.resource2.server.host", 111 "localhost"); 112 String jndiUrl = "jnp://"+jndiHost+":1099"; 113 resource2ServerJndiProps.setProperty("java.naming.provider.url", 114 jndiUrl); 115 } 116 return new InitialContext (resource2ServerJndiProps); 117 } 118 119 protected MBeanServerConnection getResource2Server() throws Exception 120 { 121 if (resource2Server == null) 122 { 123 String adaptorName = System.getProperty("jbosstest.server.name", 124 "jmx/invoker/RMIAdaptor"); 125 Context resCtx = getResource2ServerInitialContext(); 126 resource2Server = (MBeanServerConnection )resCtx.lookup(adaptorName); 127 } 128 return resource2Server; 129 } 130 131 public static Test suite(Class testCaseClass) 132 { 133 TestSuite suite = new TestSuite(); 134 suite.addTest(new TestSuite(testCaseClass)); 135 return suite; 136 } 137 138 } 139 | Popular Tags |