KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > ca > caadmin > TestRemoveCA


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.ca.caadmin;
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.ca.caadmin.ICAAdminSessionHome;
23 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionRemote;
24 import org.ejbca.core.model.log.Admin;
25
26 /**
27  * Tests and removes the ca data entity bean.
28  *
29  * @version $Id: TestRemoveCA.java,v 1.4.2.2 2007/06/05 13:37:23 anatom Exp $
30  */

31 public class TestRemoveCA extends TestCase {
32     private static Logger log = Logger.getLogger(TestCAs.class);
33
34     private ICAAdminSessionRemote cacheAdmin;
35     private static ICAAdminSessionHome cacheHome;
36
37     private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER);
38
39     /**
40      * Creates a new TestCAs object.
41      *
42      * @param name name
43      */

44     public TestRemoveCA(String JavaDoc name) {
45         super(name);
46     }
47
48     protected void setUp() throws Exception JavaDoc {
49
50         log.debug(">setUp()");
51
52         if (cacheAdmin == null) {
53             if (cacheHome == null) {
54                 Context JavaDoc jndiContext = getInitialContext();
55                 Object JavaDoc obj1 = jndiContext.lookup("CAAdminSession");
56                 cacheHome = (ICAAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, ICAAdminSessionHome.class);
57             }
58
59             cacheAdmin = cacheHome.create();
60         }
61
62         log.debug("<setUp()");
63     }
64
65     protected void tearDown() throws Exception JavaDoc {
66     }
67
68     private Context JavaDoc getInitialContext() throws NamingException JavaDoc {
69         log.debug(">getInitialContext");
70
71         Context JavaDoc ctx = new javax.naming.InitialContext JavaDoc();
72         log.debug("<getInitialContext");
73
74         return ctx;
75     }
76
77     /**
78      * removes RSA CA
79      *
80      * @throws Exception error
81      */

82     public void test02removeRSACA() throws Exception JavaDoc {
83         log.debug(">test02removeRSACA()");
84         boolean ret = false;
85         try {
86             cacheAdmin.removeCA(admin, "CN=TEST".hashCode());
87             ret = true;
88         } catch (Exception JavaDoc pee) {
89         }
90         assertTrue("Removing RSA CA failed", ret);
91
92         log.debug("<test02removeRSACA()");
93     }
94
95     /**
96      * removes ECDSA CA
97      *
98      * @throws Exception error
99      */

100     public void test03removeECDSACA() throws Exception JavaDoc {
101         log.debug(">test03removeECDSACA()");
102         boolean ret = false;
103         try {
104             cacheAdmin.removeCA(admin, "CN=TESTECDSA".hashCode());
105             ret = true;
106         } catch (Exception JavaDoc pee) {
107         }
108         assertTrue("Removing ECDSA CA failed", ret);
109
110         try {
111             cacheAdmin.removeCA(admin, "CN=TESTECDSAImplicitlyCA".hashCode());
112             ret = true;
113         } catch (Exception JavaDoc pee) {
114         }
115         assertTrue("Removing ECDSA ImplicitlyCA CA failed", ret);
116
117         log.debug("<test03removeECDSACA()");
118     }
119
120     /**
121      * removes RSA CA
122      *
123      * @throws Exception error
124      */

125     public void test04removeRSASha256WithMGF1CA() throws Exception JavaDoc {
126         log.debug(">test04removeRSASha256WithMGF1CA()");
127         boolean ret = false;
128         try {
129             cacheAdmin.removeCA(admin, "CN=TESTSha256WithMGF1".hashCode());
130             ret = true;
131         } catch (Exception JavaDoc pee) {
132         }
133         assertTrue("Removing RSA SHA256WithMGF1 CA failed", ret);
134
135         log.debug("<test04removeRSASha256WithMGF1CA()");
136     }
137
138 }
139
Popular Tags