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.runtimeCA; 37 import org.objectweb.jonas.jtests.beans.j2eeca.runtimeCAHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 43 44 public class F_runtimeTest extends JTestCase { 45 46 private static UserTransaction utx = null; 47 48 static Context ctx = null; 49 50 52 protected static String BEAN_HOME = "runtimeCAHome"; 53 protected static runtimeCAHome home = null; 54 private static final String RAR_JNDI_NAME = "FictionalNolog"; 55 static runtimeCA bean = null; 56 final private int CLOSE_HANDLE = 0; 57 final private int CLOSE_PHYSICAL = 1; 58 int CloseType = 0; 59 60 public F_runtimeTest(String name) { 61 super(name); 62 } 63 64 protected void setUp() { 65 super.setUp(); 66 67 69 try { 70 71 73 if (ctx == null) { 74 ctx = new InitialContext (); 75 } 76 77 79 if (utx == null) { 80 utx = (UserTransaction ) ctx.lookup("javax.transaction.UserTransaction"); 81 } 82 83 if (home == null) { 84 useBeans("j2eeca", false); 85 } 86 87 89 if (home == null) { 90 home = (runtimeCAHome)PortableRemoteObject.narrow( 91 ctx.lookup(BEAN_HOME), 92 runtimeCAHome.class); 93 bean = home.create(); 94 } 95 96 assertTrue (5 == 5); 97 98 } catch (Exception e) { 99 fail("Cannot lookup UserTransaction in setUp: " +e); 100 } 101 } 102 103 protected void tearDown() throws Exception { 104 bean.closeUp(CloseType); 105 } 106 protected void startUp(String testName) { 107 try { 108 bean.method1(RAR_JNDI_NAME, testName); 109 } catch (Exception ee) { 110 ee.printStackTrace(); 111 System.exit(2); 112 } 113 } 114 136 public void testPrintWriterNull() throws Exception { 137 CloseType=CLOSE_PHYSICAL; 138 int isNull = 0; 139 int isNotNull = 1; 140 int isError = 2; 141 startUp("testPrintWriterNull"); 142 int x = bean.getMCF_Pwriter(); 143 assertEquals(isNull, x); 144 x = bean.getMC_Pwriter(); 145 assertEquals(isNull, x); 146 } 147 148 157 public void testSecurityContextApplication() throws Exception { 158 CloseType=CLOSE_PHYSICAL; 159 bean.setResAuth("Application"); 160 startUp("testSecurityContextApplication"); 161 String pw = bean.getSecurityPassword(); 163 String u = bean.getSecurityUserName(); 164 String realResAuth = bean.getResAuth(); 165 if (realResAuth.equals("Application")) { 166 assertEquals("__Jtest_Pass_word__", pw); 167 assertEquals("Fictional_User_Name", u); 168 } else { 169 assertFalse(pw.equals("__Jtest_Pass_word__")); 170 } 171 172 } 173 public static Test suite() { 174 return new TestSuite(F_runtimeTest.class); 175 } 176 177 public static void main (String args[]) { 178 179 String testtorun = null; 180 181 183 for (int argn = 0; argn < args.length; argn++) { 184 185 String s_arg = args[argn]; 186 Integer i_arg; 187 188 if (s_arg.equals("-n")) { 189 testtorun = args[++argn]; 190 } 191 } 192 193 if (testtorun == null) { 194 junit.textui.TestRunner.run(suite()); 195 } else { 196 junit.textui.TestRunner.run(new F_runtimeTest(testtorun)); 197 } 198 } 199 } 200 | Popular Tags |