1 25 26 package org.objectweb.jonas.jtests.clients.j2eeca; 27 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.rmi.PortableRemoteObject ; 31 import javax.transaction.UserTransaction ; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.objectweb.jonas.jtests.beans.j2eeca.connectorCA; 37 import org.objectweb.jonas.jtests.beans.j2eeca.connectorCAHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 43 44 public class F_connectorTest extends JTestCase { 45 46 private static UserTransaction utx = null; 47 48 static Context ctx = null; 49 50 52 protected static String BEAN_HOME = "connectorCAHome"; 53 static connectorCAHome home = null; 54 static connectorCA bean = null; 55 static connectorCA bean2 = null; 56 private static final String RAR_JNDI_NAME = "FictionalEIS"; 57 final private int CLOSE_HANDLE = 0; 58 final private int CLOSE_PHYSICAL = 1; 59 int CloseType = 0; 60 61 public F_connectorTest(String name) { 62 super(name); 63 } 64 65 protected void setUp() { 66 super.setUp(); 67 68 70 try { 71 72 74 if (ctx == null) { 75 ctx = new InitialContext (); 76 } 77 78 80 if (utx == null) { 81 utx = (UserTransaction ) ctx.lookup("javax.transaction.UserTransaction"); 82 } 83 84 if (home == null) { 85 useBeans("j2eeca", false); } 87 88 90 if (home == null) { 91 home = (connectorCAHome)PortableRemoteObject.narrow( 92 ctx.lookup(BEAN_HOME), 93 connectorCAHome.class); 94 bean = home.create(); 95 } 96 97 assertTrue (5 == 5); 98 99 } catch (Exception e) { 100 fail("Cannot lookup UserTransaction in setUp: " +e); 101 } 102 } 103 115 protected void tearDown() throws Exception { 116 bean.closeUp(CloseType); 117 } 118 protected void startUp(String testName) { 119 try { 120 bean.method1(RAR_JNDI_NAME, testName); 121 } catch (Exception ee) { 122 ee.printStackTrace(); 123 System.exit(2); 124 } 125 } 126 133 public void testSetterMethods() throws Exception { 134 CloseType=CLOSE_PHYSICAL; 140 startUp("testSetterMethods"); 141 String cp = bean.getServerName(); 142 assertEquals("111.222.333.444", cp); 143 cp = bean.getProtocolProperty(); 144 assertEquals("LINE", cp); 145 } 146 151 public void testCreatedCMInstance() throws Exception { 152 CloseType=CLOSE_PHYSICAL; 153 startUp("testCreatedCMInstance"); 154 assertTrue(bean.getCMInstance()); 155 } 156 159 public void testConnectionProduct() throws Exception { 160 CloseType=CLOSE_PHYSICAL; 161 startUp("testConnectionProduct"); 162 String p = bean.getConnectionProduct(); 163 assertEquals("Fictional EIS", p); 164 } 165 173 public void testRegisteredListener() throws Exception { 174 CloseType=CLOSE_PHYSICAL; 175 startUp("testRegisteredListener"); 176 int b = bean.cntListeners(); 177 assertTrue(b>0); 178 } 179 182 public void testConnectionBasics() throws Exception { 183 CloseType=CLOSE_PHYSICAL; 184 startUp("testConnectionBasics"); 185 assertTrue(bean.isConnectionSpec()); 186 assertTrue(bean.isConnection()); 187 assertTrue(bean.isInteraction()); 188 } 189 212 public void testPrintWriter() throws Exception { 213 CloseType=CLOSE_PHYSICAL; 214 int isNull = 0; 215 int isNotNull = 1; 216 int isError = 2; 217 startUp("testPrintWriter"); 218 int x = bean.getMCF_Pwriter(); 219 assertEquals(isNotNull, x); 220 x = bean.getMC_Pwriter(); 221 assertEquals(isNotNull, x); 222 } 223 225 public static Test suite() { 226 return new TestSuite(F_connectorTest.class); 227 } 228 229 public static void main (String args[]) { 230 231 String testtorun = null; 232 233 235 for (int argn = 0; argn < args.length; argn++) { 236 237 String s_arg = args[argn]; 238 Integer i_arg; 239 240 if (s_arg.equals("-n")) { 241 testtorun = args[++argn]; 242 } 243 } 244 245 if (testtorun == null) { 246 junit.textui.TestRunner.run(suite()); 247 } else { 248 junit.textui.TestRunner.run(new F_connectorTest(testtorun)); 249 } 250 } 251 } 252 | Popular Tags |