KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > test > JBossCrashRecoveryTestCase


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.recover.test;
23
24 import java.net.URL JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import javax.management.MBeanServerConnection JavaDoc;
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
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 /**
39  * A JBossCrashRecoveryTestCase.
40  *
41  * @author <a HREF="reverbel@ime.usp.br">Francisco Reverbel</a>
42  * @version $Revision: 58484 $
43  */

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