1 7 package org.jboss.remoting.detection.jndi; 8 9 import junit.framework.Test; 10 import junit.framework.TestSuite; 11 import junit.textui.TestRunner; 12 import org.apache.log4j.Level; 13 import org.jboss.dtf.DistributedTestCase; 14 import org.jgroups.Address; 15 import org.jnp.server.Main; 16 17 import java.net.InetAddress ; 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 31 public class JNDIDetectorTestCase extends DistributedTestCase 32 { 33 private List results = new ArrayList (); 34 35 public JNDIDetectorTestCase(String name) 36 { 37 super(name); 38 } 39 40 protected void setUp() throws Exception 41 { 42 int instances = 3; 43 int port = 1099; 44 String host = InetAddress.getLocalHost().getHostName(); 45 46 startJNP(port, host); 47 48 String clientcmd = "java -cp " + System.getProperty("java.class.path") + 49 " " + JNDIDetectorTest1.class.getName() + " " + instances + " " + 51 port + " " + host; 52 System.out.println("clientcmd: " + clientcmd); 53 String svrcmd = "java -cp " + System.getProperty("java.class.path") + 54 " " + JNDIDetectorTest2.class.getName() + " " + instances + " " + 56 port + " " + host; 57 System.out.println("svrcmd: " + svrcmd); 58 59 final Process local = Runtime.getRuntime().exec(clientcmd); 60 final Process remote = Runtime.getRuntime().exec(svrcmd); 61 62 } 63 64 72 private void startJNP(int port, String host) throws Exception 73 { 74 Main JNDIServer = new Main(); 76 JNDIServer.setPort(port); 77 JNDIServer.setBindAddress(host); 78 JNDIServer.start(); 79 System.out.println("Started JNDI server on " + host + ":" + port); 80 } 81 82 protected void tearDown() throws Exception 83 { 84 } 86 87 public void testInvokers() 88 { 89 try 90 { 91 startup(3); 92 System.out.println("startup() called"); 93 shutdown(); 94 System.out.println("shutdown() called"); 95 } 96 catch(Exception e) 97 { 98 e.printStackTrace(); 99 assertTrue("Problem starting or stopping client/server processes.", false); 100 } 101 finally 102 { 103 try 105 { 106 Thread.currentThread().sleep(120000); 107 } 108 catch(InterruptedException e) 109 { 110 e.printStackTrace(); 111 } 112 System.out.println("results.size() = " + results.size()); 113 if(results.size() > 0) 114 { 115 Iterator itr = results.iterator(); 116 while(itr.hasNext()) 117 { 118 String message = (String ) itr.next(); 119 assertTrue(message, false); 120 } 121 } 122 else 123 { 124 assertTrue("No test failures or errors.", true); 125 } 126 127 } 128 } 129 130 135 public void receiveAssert(Address source, String message) 136 { 137 super.receiveAssert(source, message); 138 results.add("Assert source: " + source + "\tmessage: " + message); 139 } 140 141 public static Test suite() 142 { 143 return new TestSuite(JNDIDetectorTestCase.class); 144 } 145 146 public static void main(String [] args) 147 { 148 149 org.apache.log4j.BasicConfigurator.configure(); 150 org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG); 151 152 TestRunner.run(suite()); 155 } 157 158 159 } | Popular Tags |