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