KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > ra > raadmin > TestEndEntityProfile


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.ra.raadmin;
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.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 /**
30  * Tests the end entity profile entity bean.
31  *
32  * @version $Id: TestEndEntityProfile.java,v 1.3 2006/12/02 11:18:30 anatom Exp $
33  */

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

48     public TestEndEntityProfile(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("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 JavaDoc {
72     }
73
74     private Context JavaDoc getInitialContext() throws NamingException JavaDoc {
75         log.debug(">getInitialContext");
76
77         Context JavaDoc ctx = new javax.naming.InitialContext JavaDoc();
78         log.debug("<getInitialContext");
79
80         return ctx;
81     }
82
83
84     /**
85      * adds a publishers to the database
86      *
87      * @throws Exception error
88      */

89     public void test01AddEndEntityProfile() throws Exception JavaDoc {
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     /**
107      * renames profile
108      *
109      * @throws Exception error
110      */

111     public void test02RenameEndEntityProfile() throws Exception JavaDoc {
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     /**
126      * clones profile
127      *
128      * @throws Exception error
129      */

130     public void test03CloneEndEntityProfile() throws Exception JavaDoc {
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     /**
146      * edits profile
147      *
148      * @throws Exception error
149      */

150     public void test04EditEndEntityProfile() throws Exception JavaDoc {
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     /**
171      * removes all profiles
172      *
173      * @throws Exception error
174      */

175     public void test05removeEndEntityProfiles() throws Exception JavaDoc {
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 JavaDoc pee) {
183         }
184         assertTrue("Removing End Entity Profile failed", ret);
185
186         log.debug("<test05removeEndEntityProfiles()");
187     }
188
189
190 }
191
Popular Tags