KickJava   Java API By Example, From Geeks To Geeks.

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


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.GlobalConfiguration;
26
27 /**
28  * Tests the global configuration entity bean.
29  *
30  * @version $Id: TestGlobalConfiguration.java,v 1.2 2006/01/17 20:34:15 anatom Exp $
31  */

32 public class TestGlobalConfiguration extends TestCase {
33     private static Logger log = Logger.getLogger(TestGlobalConfiguration.class);
34
35     private IRaAdminSessionRemote cacheAdmin;
36
37     private static IRaAdminSessionHome cacheHome;
38
39     private static GlobalConfiguration original = null;
40
41
42     /**
43      * Creates a new TestGlobalConfiguration object.
44      *
45      * @param name name
46      */

47     public TestGlobalConfiguration(String JavaDoc name) {
48         super(name);
49     }
50
51     protected void setUp() throws Exception JavaDoc {
52
53         log.debug(">setUp()");
54
55         if (cacheAdmin == null) {
56             if (cacheHome == null) {
57                 Context JavaDoc jndiContext = getInitialContext();
58                 Object JavaDoc obj1 = jndiContext.lookup("RaAdminSession");
59                 cacheHome = (IRaAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, IRaAdminSessionHome.class);
60
61             }
62
63             cacheAdmin = cacheHome.create();
64         }
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      * tests adding a global configuration
85      *
86      * @throws Exception error
87      */

88     public void test01AddGlobalConfiguration() throws Exception JavaDoc {
89         log.debug(">test01AddGlobalConfiguration()");
90
91         Admin administrator = new Admin(Admin.TYPE_INTERNALUSER);
92
93         // First save the original
94
original = this.cacheAdmin.loadGlobalConfiguration(administrator);
95
96         GlobalConfiguration conf = new GlobalConfiguration();
97         conf.setEjbcaTitle("TESTTITLE");
98         this.cacheAdmin.saveGlobalConfiguration(administrator, conf);
99
100         log.debug("<test01AddGlobalConfiguration()");
101     }
102
103     /**
104      * tests modifying an global configuration
105      *
106      * @throws Exception error
107      */

108     public void test02ModifyGlobalConfiguration() throws Exception JavaDoc {
109         log.debug(">test01ModifyGlobalConfiguration()");
110
111         Admin administrator = new Admin(Admin.TYPE_INTERNALUSER);
112
113         GlobalConfiguration conf = this.cacheAdmin.loadGlobalConfiguration(administrator);
114         assertTrue("Error Retreiving Global Configuration.", conf.getEjbcaTitle().equals("TESTTITLE"));
115
116         conf.setEjbcaTitle("TESTTITLE2");
117         this.cacheAdmin.saveGlobalConfiguration(administrator, conf);
118
119         // Replace with original
120
this.cacheAdmin.saveGlobalConfiguration(administrator, original);
121
122         log.debug("<test01ModifyGlobalConfiguration()");
123     }
124
125
126 }
127
Popular Tags