KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > module > TestModuleIssues


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/module/TestModuleIssues.java,v $
3  * Date : $Date: 2005/07/28 15:53:10 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package org.opencms.module;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsVfsResourceNotFoundException;
36 import org.opencms.main.OpenCms;
37 import org.opencms.report.CmsShellReport;
38 import org.opencms.test.OpenCmsTestCase;
39 import org.opencms.test.OpenCmsTestProperties;
40
41 import junit.extensions.TestSetup;
42 import junit.framework.Test;
43 import junit.framework.TestSuite;
44
45 /**
46  * Unit tests for issues found in the new module mechanism.<p>
47  *
48  * @author Alexander Kandzior
49  *
50  * @version $Revision: 1.12 $
51  */

52 public class TestModuleIssues extends OpenCmsTestCase {
53   
54     /**
55      * Default JUnit constructor.<p>
56      *
57      * @param arg0 JUnit parameters
58      */

59     public TestModuleIssues(String JavaDoc arg0) {
60         super(arg0);
61     }
62     
63     /**
64      * Test suite for this test class.<p>
65      *
66      * @return the test suite
67      */

68     public static Test suite() {
69         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
70         
71         TestSuite suite = new TestSuite();
72         suite.setName(TestModuleIssues.class.getName());
73                 
74         suite.addTest(new TestModuleIssues("testAdditionalSystemFolder"));
75         
76         // important: this must be the last called method since the OpenCms installation is removed from there
77
suite.addTest(new TestModuleIssues("testShutdownMethod"));
78         
79         TestSetup wrapper = new TestSetup(suite) {
80             
81             protected void setUp() {
82                 setupOpenCms("simpletest", "/sites/default/");
83             }
84             
85             protected void tearDown() {
86                 // done in "testShutdownMethod"
87
// removeOpenCms();
88
}
89         };
90         
91         return wrapper;
92     }
93
94     /**
95      * Issue: Additional "system" folder created in current site after module import.<p>
96      *
97      * @throws Throwable if something goes wrong
98      */

99     public void testAdditionalSystemFolder() throws Throwable JavaDoc {
100         
101         CmsObject cms = getCmsObject();
102         echo("Testing for additional 'system' folder after module import");
103               
104         String JavaDoc moduleName = "org.opencms.test.modules.test3";
105         String JavaDoc moduleFile = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("packages/" + moduleName + ".zip");
106         OpenCms.getImportExportManager().importData(cms, moduleFile, null, new CmsShellReport(cms.getRequestContext().getLocale()));
107         
108         // basic check if the module was imported correctly
109
if (! OpenCms.getModuleManager().hasModule(moduleName)) {
110             fail("Module '" + moduleName + "' was not imported!");
111         }
112         
113         cms.getRequestContext().setSiteRoot("/");
114         boolean found = true;
115         try {
116             cms.readFolder("/sites/default/system/");
117         } catch (CmsVfsResourceNotFoundException e) {
118             // this is the expected result
119
found = false;
120         }
121         
122         if (found) {
123             fail("Additional 'system' folder was created!");
124         }
125     }
126     
127     /**
128      * Issue: Sthudown method never called on module.<p>
129      *
130      * @throws Exception if something goews wrong
131      */

132     public void testShutdownMethod() throws Exception JavaDoc {
133         
134         echo("Testing module shutdown method");
135               
136         String JavaDoc moduleName = "org.opencms.configuration.TestModule1";
137         
138         // basic check if the module was imported correctly (during configuration)
139
if (! OpenCms.getModuleManager().hasModule(moduleName)) {
140             fail("Module '" + moduleName + "' was not imported!");
141         }
142         
143         I_CmsModuleAction actionInstance = OpenCms.getModuleManager().getModule(moduleName).getActionInstance();
144         
145         if (actionInstance == null) {
146             fail("Module '" + moduleName + "' has no action instance!");
147         }
148
149         if (! (actionInstance instanceof TestModuleActionImpl)) {
150             fail("Module '" + moduleName + "' has action class of unexpected type!");
151         }
152         
153         // remove OpenCms installations, must call shutdown
154
removeOpenCms();
155         
156         // check if shutdown flag was set to "true"
157
assertTrue(TestModuleActionImpl.m_shutDown);
158         
159         // reset flag for next test
160
TestModuleActionImpl.m_shutDown = false;
161     }
162 }
163
Popular Tags