1 8 package org.apache.avalon.excalibur.naming.rmi.test; 9 10 import java.util.Hashtable ; 11 import javax.naming.Context ; 12 import java.lang.reflect.Method ; 13 import org.apache.avalon.excalibur.naming.test.AbstractContextTestCase; 14 import org.apache.avalon.excalibur.naming.rmi.server.Main; 15 import org.apache.avalon.excalibur.naming.rmi.RMIInitialContextFactory; 16 17 23 public class RMIContextTestCase 24 extends AbstractContextTestCase 25 { 26 private static int m_numTests = 0; 27 private static int m_id = 0; 28 private static Main m_server = new Main(); 29 private static Thread m_serverThread; 30 private Context m_rootContext; 31 private static boolean m_setUp = false; 32 33 static 34 { 35 Class testCase = AbstractContextTestCase.class; 36 37 Method [] methods = testCase.getMethods(); 38 39 for (int i = 0; i < methods.length; i++) 40 { 41 if (methods[i].getName().startsWith("test")) 42 { 43 RMIContextTestCase.m_numTests++; 44 } 45 } 46 } 47 48 public RMIContextTestCase( String name ) 49 { 50 super( name ); 51 } 52 53 public void setUp() 54 { 55 try 56 { 57 if ( ! RMIContextTestCase.m_setUp ) 58 { 59 RMIContextTestCase.m_server.start(); 60 61 RMIContextTestCase.m_serverThread = new Thread ( m_server ); 62 RMIContextTestCase.m_serverThread.start(); 63 RMIContextTestCase.m_setUp = true; 64 } 65 66 final RMIInitialContextFactory factory = new RMIInitialContextFactory(); 67 m_rootContext = factory.getInitialContext( new Hashtable () ); 68 69 m_context = m_rootContext.createSubcontext( "test" + RMIContextTestCase.m_id++ ); 70 } 71 catch( final Exception e ) 72 { 73 System.out.println( "Failed test initialisation " + e ); 74 e.printStackTrace(); 75 } 76 } 77 78 public void tearDown() 79 { 80 try 81 { 82 m_context.close(); 83 m_context = null; 84 m_rootContext.close(); 85 86 if ( RMIContextTestCase.m_id >= RMIContextTestCase.m_numTests ) 87 { 88 RMIContextTestCase.m_server.stop(); 89 RMIContextTestCase.m_serverThread.interrupt(); 90 } 91 } 92 catch( final Exception e ) 93 { 94 System.out.println( "Failed test destruction" + e ); 95 e.printStackTrace(); 96 } 97 } 98 } 99 | Popular Tags |