KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > hardtoken > TestHardTokenIssuer


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package se.anatom.ejbca.hardtoken;
15
16 import javax.naming.Context JavaDoc;
17 import javax.naming.NamingException JavaDoc;
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 /**
30  * Tests the Hard Token Issuer entity bean.
31  *
32  * @version $Id: TestHardTokenIssuer.java,v 1.2 2006/01/17 20:33:58 anatom Exp $
33  */

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     /**
44      * Creates a new TestHardTokenIssuer object.
45      *
46      * @param name name
47      */

48     public TestHardTokenIssuer(String JavaDoc name) {
49         super(name);
50     }
51
52     protected void setUp() throws Exception JavaDoc {
53
54         log.debug(">setUp()");
55
56         if (cacheAdmin == null) {
57             if (cacheHome == null) {
58                 Context JavaDoc jndiContext = getInitialContext();
59                 Object JavaDoc 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 JavaDoc {
71     }
72
73     private Context JavaDoc getInitialContext() throws NamingException JavaDoc {
74         log.debug(">getInitialContext");
75
76         Context JavaDoc ctx = new javax.naming.InitialContext JavaDoc();
77         log.debug("<getInitialContext");
78
79         return ctx;
80     }
81
82
83     /**
84      * adds a issuer to the database
85      *
86      * @throws Exception error
87      */

88     public void test01AddHardTokenIssuer() throws Exception JavaDoc {
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     /**
102      * renames issuer
103      *
104      * @throws Exception error
105      */

106     public void test02RenameHardTokenIssuer() throws Exception JavaDoc {
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     /**
117      * clones issuer
118      *
119      * @throws Exception error
120      */

121     public void test03CloneHardTokenIssuer() throws Exception JavaDoc {
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     /**
134      * edits issuer
135      *
136      * @throws Exception error
137      */

138     public void test04EditHardTokenIssuer() throws Exception JavaDoc {
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     /**
158      * removes all profiles
159      *
160      * @throws Exception error
161      */

162     public void test05removeHardTokenIssuers() throws Exception JavaDoc {
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 JavaDoc pee) {
170         }
171         assertTrue("Removing Certificate Profile failed", ret);
172
173         log.debug("<test05removeHardTokenIssuers()");
174     }
175
176
177 }
178
Popular Tags