1 13 14 package se.anatom.ejbca.ra.raadmin; 15 16 import javax.naming.Context ; 17 import javax.naming.NamingException ; 18 19 import junit.framework.TestCase; 20 21 import org.apache.log4j.Logger; 22 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionHome; 23 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionRemote; 24 import org.ejbca.core.model.log.Admin; 25 import org.ejbca.core.model.ra.raadmin.EndEntityProfile; 26 import org.ejbca.core.model.ra.raadmin.EndEntityProfileExistsException; 27 import org.ejbca.util.dn.DnComponents; 28 29 34 public class TestEndEntityProfile extends TestCase { 35 private static Logger log = Logger.getLogger(TestEndEntityProfile.class); 36 private IRaAdminSessionRemote cacheAdmin; 37 38 39 private static IRaAdminSessionHome cacheHome; 40 41 private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER); 42 43 48 public TestEndEntityProfile(String name) { 49 super(name); 50 } 51 52 protected void setUp() throws Exception { 53 54 log.debug(">setUp()"); 55 56 if (cacheAdmin == null) { 57 if (cacheHome == null) { 58 Context jndiContext = getInitialContext(); 59 Object obj1 = jndiContext.lookup("RaAdminSession"); 60 cacheHome = (IRaAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, IRaAdminSessionHome.class); 61 62 } 63 64 cacheAdmin = cacheHome.create(); 65 } 66 67 68 log.debug("<setUp()"); 69 } 70 71 protected void tearDown() throws Exception { 72 } 73 74 private Context getInitialContext() throws NamingException { 75 log.debug(">getInitialContext"); 76 77 Context ctx = new javax.naming.InitialContext (); 78 log.debug("<getInitialContext"); 79 80 return ctx; 81 } 82 83 84 89 public void test01AddEndEntityProfile() throws Exception { 90 log.debug(">test01AddEndEntityProfile()"); 91 boolean ret = false; 92 try { 93 EndEntityProfile profile = new EndEntityProfile(); 94 profile.addField(DnComponents.ORGANIZATIONUNIT); 95 96 cacheAdmin.addEndEntityProfile(admin, "TEST", profile); 97 98 ret = true; 99 } catch (EndEntityProfileExistsException pee) { 100 } 101 102 assertTrue("Creating End Entity Profile failed", ret); 103 log.debug("<test01AddEndEntityProfile()"); 104 } 105 106 111 public void test02RenameEndEntityProfile() throws Exception { 112 log.debug(">test02RenameEndEntityProfile()"); 113 114 boolean ret = false; 115 try { 116 cacheAdmin.renameEndEntityProfile(admin, "TEST", "TEST2"); 117 ret = true; 118 } catch (EndEntityProfileExistsException pee) { 119 } 120 assertTrue("Renaming End Entity Profile failed", ret); 121 122 log.debug("<test02RenameEndEntityProfile()"); 123 } 124 125 130 public void test03CloneEndEntityProfile() throws Exception { 131 log.debug(">test03CloneEndEntityProfile()"); 132 133 boolean ret = false; 134 try { 135 cacheAdmin.cloneEndEntityProfile(admin, "TEST2", "TEST"); 136 ret = true; 137 } catch (EndEntityProfileExistsException pee) { 138 } 139 assertTrue("Cloning End Entity Profile failed", ret); 140 141 log.debug("<test03CloneEndEntityProfile()"); 142 } 143 144 145 150 public void test04EditEndEntityProfile() throws Exception { 151 log.debug(">test04EditEndEntityProfile()"); 152 153 boolean ret = false; 154 155 EndEntityProfile profile = cacheAdmin.getEndEntityProfile(admin, "TEST"); 156 assertTrue("Retrieving EndEntityProfile failed", profile.getNumberOfField(DnComponents.ORGANIZATIONUNIT) == 1); 157 158 profile.addField(DnComponents.ORGANIZATIONUNIT); 159 160 cacheAdmin.changeEndEntityProfile(admin, "TEST", profile); 161 ret = true; 162 163 assertTrue("Editing EndEntityProfile failed", ret); 164 165 166 log.debug("<test04EditEndEntityProfile()"); 167 } 168 169 170 175 public void test05removeEndEntityProfiles() throws Exception { 176 log.debug(">test05removeEndEntityProfiles()"); 177 boolean ret = false; 178 try { 179 cacheAdmin.removeEndEntityProfile(admin, "TEST"); 180 cacheAdmin.removeEndEntityProfile(admin, "TEST2"); 181 ret = true; 182 } catch (Exception pee) { 183 } 184 assertTrue("Removing End Entity Profile failed", ret); 185 186 log.debug("<test05removeEndEntityProfiles()"); 187 } 188 189 190 } 191 | Popular Tags |