1 25 26 package org.objectweb.jonas.jtests.clients.jca15; 27 28 import junit.framework.*; 29 import java.io.BufferedReader ; 30 import java.io.FileInputStream ; 31 import java.io.InputStreamReader ; 32 import java.io.IOException ; 33 import java.lang.String ; 34 import java.rmi.RemoteException ; 35 import javax.rmi.PortableRemoteObject ; 36 import java.util.Collection ; 37 import java.util.Enumeration ; 38 import java.util.Hashtable ; 39 import java.util.Properties ; 40 import javax.ejb.FinderException ; 41 import javax.ejb.RemoveException ; 42 import javax.naming.Context ; 43 import javax.naming.InitialContext ; 44 import javax.naming.NamingException ; 45 46 import org.objectweb.jonas.jtests.beans.jca15.ConnectorCAHome; 47 import org.objectweb.jonas.jtests.beans.jca15.ConnectorCA; 48 import org.objectweb.jonas.jtests.util.JTestCase; 49 50 53 54 public class F_connectorTest extends JTestCase { 55 56 static Context ctx = null; 57 58 60 protected static String BEAN_HOME = "ConnectorCAHome"; 61 static ConnectorCAHome home = null; 62 static ConnectorCA bean = null; 63 static ConnectorCA bean2 = null; 64 private static final String RAR_JNDI_NAME = "eis/ErsatzEIS"; 65 final private int CLOSE_HANDLE = 0; 66 final private int CLOSE_PHYSICAL = 1; 67 int CloseType = 0; 68 69 public F_connectorTest(String name) { 70 super(name); 71 } 72 73 protected void setUp() { 74 super.setUp(); 75 76 78 try { 79 80 82 if (ctx == null) { 83 ctx = new InitialContext (); 84 } 85 86 } catch (Exception e) { 87 fail("Cannot do InitialContext(): " +e); 88 } 89 90 try { 91 if (home == null) { 92 useBeans("jca15", false); } 94 } catch (Exception e) { 95 fail("Cannot do useBeans(jca15, false): " +e); 96 } 97 98 100 try { 101 if (home == null) { 102 home = (ConnectorCAHome)PortableRemoteObject.narrow( 103 ctx.lookup(BEAN_HOME), 104 ConnectorCAHome.class); 105 } 106 107 assertTrue (5 == 5); 108 109 } catch (Exception e) { 110 fail("Cannot do ctx.lookup(BEAN_HOME): " +e); 111 } 112 try { 113 bean = home.create(); 114 assertTrue (5 == 5); 115 116 } catch (Exception e) { 117 fail("Cannot do home.create(): " +e); 118 } 119 } 120 132 protected void tearDown() throws Exception { 133 bean.closeUp(CloseType); 134 } 135 protected void startUp(String testName) { 136 try { 137 bean.method1(RAR_JNDI_NAME, testName); 138 } catch (Exception ee) { 139 ee.printStackTrace(); 140 System.exit(2); 141 } 142 } 143 150 public void testSetterMethods() throws Exception { 151 CloseType=CLOSE_PHYSICAL; 157 startUp("testSetterMethods"); 158 String cp = bean.getServerName(); 159 assertEquals("111.111.111.111", cp); 160 cp = bean.getProtocolProperty(); 161 assertEquals("LINE", cp); 162 } 163 168 public void testCreatedCMInstance() throws Exception { 169 CloseType=CLOSE_PHYSICAL; 170 startUp("testCreatedCMInstance"); 171 assertTrue(bean.getCMInstance()); 172 } 173 176 public void testConnectionProduct() throws Exception { 177 CloseType=CLOSE_PHYSICAL; 178 startUp("testConnectionProduct"); 179 String p = bean.getConnectionProduct(); 180 assertEquals("Ersatz EIS", p); 181 } 182 190 public void testRegisteredListener() throws Exception { 191 CloseType=CLOSE_PHYSICAL; 192 startUp("testRegisteredListener"); 193 int b = bean.cntListeners(); 194 assertTrue(b>0); 195 } 196 199 public void testConnectionBasics() throws Exception { 200 CloseType=CLOSE_PHYSICAL; 201 startUp("testConnectionBasics"); 202 assertTrue(bean.isConnectionSpec()); 203 assertTrue(bean.isConnection()); 204 assertTrue(bean.isInteraction()); 205 } 206 229 public void testPrintWriter() throws Exception { 230 CloseType=CLOSE_PHYSICAL; 231 int isNull = 0; 232 int isNotNull = 1; 233 int isError = 2; 234 startUp("testPrintWriter"); 235 int x = bean.getMCF_Pwriter(); 236 assertEquals(isNotNull, x); 237 x = bean.getMC_Pwriter(); 238 assertEquals(isNotNull, x); 239 } 240 242 public static Test suite() { 243 return new TestSuite(F_connectorTest.class); 244 } 245 246 public static void main (String args[]) { 247 248 String testtorun = null; 249 250 252 for (int argn = 0; argn < args.length; argn++) { 253 254 String s_arg = args[argn]; 255 Integer i_arg; 256 257 if (s_arg.equals("-n")) { 258 testtorun = args[++argn]; 259 } 260 } 261 262 if (testtorun == null) { 263 junit.textui.TestRunner.run(suite()); 264 } else { 265 junit.textui.TestRunner.run(new F_connectorTest(testtorun)); 266 } 267 } 268 } 269 | Popular Tags |