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.securedCA; 37 import org.objectweb.jonas.jtests.beans.j2eeca.securedCAHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 43 44 public class F_securityTest extends JTestCase { 45 46 private static UserTransaction utx = null; 47 48 static Context ctx = null; 49 50 52 protected static String BEAN_HOME = "securedCAHome"; 53 protected static securedCAHome home = null; 54 private static final String RAR_JNDI_NAME = "FictionalSecurity"; 55 static securedCA bean = null; 56 final public int CLOSE_HANDLE = 0; 57 final public int CLOSE_PHYSICAL = 1; 58 public int CloseType = 0; 59 public String UseBeans="j2eeca"; 60 61 public F_securityTest(String name) { 62 super(name); 63 } 64 65 protected void setUp() { 66 super.setUp(); 67 try { 68 70 if (ctx == null) { 71 ctx = new InitialContext (); 72 } 73 74 76 if (utx == null) { 77 utx = (UserTransaction ) ctx.lookup("javax.transaction.UserTransaction"); 78 } 79 80 if (home == null) { 81 useBeans(UseBeans, false); 82 } 83 getBean(); 84 assertTrue (5 == 5); 85 86 } catch (Exception e) { 87 fail("Cannot lookup UserTransaction in setUp: " +e); 88 } 89 } 90 private void getBean() throws Exception { 91 93 if (home == null) { 94 home = (securedCAHome)PortableRemoteObject.narrow( 95 ctx.lookup(BEAN_HOME), 96 securedCAHome.class); 97 bean = home.create(); 98 } 99 } 100 protected void tearDown() throws Exception { 101 bean.closeUp(CloseType); 102 } 103 protected void startUp(String testName) { 104 try { 105 bean.method1(RAR_JNDI_NAME, testName); 106 } catch (Exception ee) { 107 ee.printStackTrace(); 108 System.exit(2); 109 } 110 } 111 112 124 public void testSecurityContextContainer() throws Exception { 125 CloseType=CLOSE_PHYSICAL; 126 bean.setResAuth("Container"); 127 startUp("testSecurityContextContainer"); 128 String pw = bean.getSecurityPassword(); 130 String u = bean.getSecurityUserName(); 131 String realResAuth = bean.getResAuth(); 132 if (realResAuth.equals("Container")) { 133 assertEquals("defaultPassword", pw); 134 assertEquals("defaultUserName", u); 135 } else { 136 assertFalse(pw.equals("defaultPassword")); 137 } 138 } 139 141 public static Test suite() { 142 return new TestSuite(F_securityTest.class); 143 } 144 145 public static void main (String args[]) { 146 147 String testtorun = null; 148 149 151 for (int argn = 0; argn < args.length; argn++) { 152 153 String s_arg = args[argn]; 154 Integer i_arg; 155 156 if (s_arg.equals("-n")) { 157 testtorun = args[++argn]; 158 } 159 } 160 161 if (testtorun == null) { 162 junit.textui.TestRunner.run(suite()); 163 } else { 164 junit.textui.TestRunner.run(new F_securityTest(testtorun)); 165 } 166 } 167 } 168 | Popular Tags |