1 13 14 package se.anatom.ejbca.hardtoken; 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.hardtoken.IHardTokenSessionHome; 23 import org.ejbca.core.ejb.hardtoken.IHardTokenSessionRemote; 24 import org.ejbca.core.model.hardtoken.HardTokenIssuer; 25 import org.ejbca.core.model.hardtoken.HardTokenIssuerData; 26 import org.ejbca.core.model.log.Admin; 27 28 29 34 public class TestHardTokenIssuer extends TestCase { 35 private static Logger log = Logger.getLogger(TestHardTokenIssuer.class); 36 private IHardTokenSessionRemote cacheAdmin; 37 38 39 private static IHardTokenSessionHome cacheHome; 40 41 private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER); 42 43 48 public TestHardTokenIssuer(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("HardTokenSession"); 60 cacheHome = (IHardTokenSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, IHardTokenSessionHome.class); 61 62 } 63 64 cacheAdmin = cacheHome.create(); 65 } 66 67 log.debug("<setUp()"); 68 } 69 70 protected void tearDown() throws Exception { 71 } 72 73 private Context getInitialContext() throws NamingException { 74 log.debug(">getInitialContext"); 75 76 Context ctx = new javax.naming.InitialContext (); 77 log.debug("<getInitialContext"); 78 79 return ctx; 80 } 81 82 83 88 public void test01AddHardTokenIssuer() throws Exception { 89 log.debug(">test01AddHardTokenIssuer()"); 90 boolean ret = false; 91 HardTokenIssuer issuer = new HardTokenIssuer(); 92 issuer.setDescription("TEST"); 93 94 ret = cacheAdmin.addHardTokenIssuer(admin, "TEST", 3, issuer); 95 96 97 assertTrue("Creating Hard Token Issuer failed", ret); 98 log.debug("<test01AddHardTokenIssuer()"); 99 } 100 101 106 public void test02RenameHardTokenIssuer() throws Exception { 107 log.debug(">test02RenameHardTokenIssuer()"); 108 109 boolean ret = false; 110 ret = cacheAdmin.renameHardTokenIssuer(admin, "TEST", "TEST2", 4); 111 assertTrue("Renaming Hard Token Issuer failed", ret); 112 113 log.debug("<test02RenameHardTokenIssuer()"); 114 } 115 116 121 public void test03CloneHardTokenIssuer() throws Exception { 122 log.debug(">test03CloneHardTokenIssuer()"); 123 124 boolean ret = false; 125 ret = cacheAdmin.cloneHardTokenIssuer(admin, "TEST2", "TEST", 4); 126 127 assertTrue("Cloning Certificate Profile failed", ret); 128 129 log.debug("<test03CloneHardTokenIssuer()"); 130 } 131 132 133 138 public void test04EditHardTokenIssuer() throws Exception { 139 log.debug(">test04EditHardTokenIssuer()"); 140 141 boolean ret = false; 142 143 HardTokenIssuerData issuerdata = cacheAdmin.getHardTokenIssuerData(admin, "TEST"); 144 assertTrue("Retrieving HardTokenIssuer failed", issuerdata.getHardTokenIssuer().getDescription().equals("TEST")); 145 146 issuerdata.getHardTokenIssuer().setDescription("TEST2"); 147 148 ret = cacheAdmin.changeHardTokenIssuer(admin, "TEST", issuerdata.getHardTokenIssuer()); 149 150 assertTrue("Editing HardTokenIssuer failed", ret); 151 152 153 log.debug("<test04EditHardTokenIssuer()"); 154 } 155 156 157 162 public void test05removeHardTokenIssuers() throws Exception { 163 log.debug(">test05removeHardTokenIssuers()"); 164 boolean ret = false; 165 try { 166 cacheAdmin.removeHardTokenIssuer(admin, "TEST"); 167 cacheAdmin.removeHardTokenIssuer(admin, "TEST2"); 168 ret = true; 169 } catch (Exception pee) { 170 } 171 assertTrue("Removing Certificate Profile failed", ret); 172 173 log.debug("<test05removeHardTokenIssuers()"); 174 } 175 176 177 } 178 | Popular Tags |