KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/module/TestModuleLegacy.java,v $
3  * Date : $Date: 2006/03/27 14:53:04 $
4  * Version: $Revision: 1.14 $
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.main.OpenCms;
36 import org.opencms.report.CmsShellReport;
37 import org.opencms.test.OpenCmsTestCase;
38 import org.opencms.test.OpenCmsTestProperties;
39
40 import com.opencms.defaults.master.*;
41 import com.opencms.defaults.master.genericsql.*;
42
43 import junit.extensions.TestSetup;
44 import junit.framework.Test;
45 import junit.framework.TestSuite;
46
47 /**
48  * Unit tests for OpenCms legacy module.<p>
49  *
50  * @author Carsten Weinholz
51  *
52  * @version $Revision: 1.14 $
53  */

54 public class TestModuleLegacy extends OpenCmsTestCase {
55     
56     /** The DB pool url. */
57     public static final String JavaDoc POOL = "opencms:default";
58     
59     /**
60      * Default JUnit constructor.<p>
61      *
62      * @param arg0 JUnit parameters
63      */

64     public TestModuleLegacy(String JavaDoc arg0) {
65         super(arg0);
66     }
67     
68     /**
69      * Test suite for this test class.<p>
70      *
71      * @return the test suite
72      */

73     public static Test suite() {
74         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
75         
76         TestSuite suite = new TestSuite();
77         suite.setName(TestModuleLegacy.class.getName());
78                 
79         suite.addTest(new TestModuleLegacy("testLegacyImport"));
80         suite.addTest(new TestModuleLegacy("testLegacyInitialization"));
81         suite.addTest(new TestModuleLegacy("testLegacyMasterIO"));
82         
83         TestSetup wrapper = new TestSetup(suite) {
84             
85             protected void setUp() {
86                 setupOpenCms("simpletest", "/sites/default/");
87             }
88             
89             protected void tearDown() {
90                 removeOpenCms();
91             }
92         };
93         
94         return wrapper;
95     }
96     
97     /**
98      * Tests the legacy module import.<p>
99      *
100      * @throws Throwable if something goes wrong
101      *
102      * @deprecated because the master module is deprecated
103      */

104     public void testLegacyImport() throws Throwable JavaDoc {
105         CmsObject cms = getCmsObject();
106         echo("Testing legacy module import");
107         
108         // check that master tables are not already available
109
CmsDbAccess masterDbAccess = new CmsDbAccess(POOL);
110         if (masterDbAccess.checkTables()) {
111             fail("Master tables already created ?!");
112         } else {
113             echo ("Master tables not detected - ok");
114         }
115         
116         String JavaDoc moduleName = "org.opencms.legacy.compatibility";
117         String JavaDoc moduleFile = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("packages/" + moduleName + ".zip");
118         OpenCms.getImportExportManager().importData(cms, moduleFile, null, new CmsShellReport(cms.getRequestContext().getLocale()));
119         
120         // basic check if the module was imported correctly
121
if (! OpenCms.getModuleManager().hasModule(moduleName)) {
122             fail("Module '" + moduleName + "' was not imported!");
123         }
124     }
125
126     /**
127      * Tests the legacy module initialization during startup.<p>
128      * If not already available, master module tables will be created
129      * in the database.
130      *
131      * @throws Throwable if something goes wrong
132      *
133      * @deprecated because the master module is deprecated
134      */

135     public void testLegacyInitialization() throws Throwable JavaDoc {
136
137         echo("Testing legacy module initialization");
138         
139         restart();
140         
141         // start cms
142
getCmsObject();
143         
144         CmsDbAccess masterDbAccess = new CmsDbAccess(POOL);
145         if (!masterDbAccess.checkTables()) {
146             fail ("Master tables not created!");
147         }
148     }
149     
150     /**
151      * Tests wrinting and reading the master table.<p>
152      *
153      * @throws Throwable if something goes wrong
154      *
155      * @deprecated because the master module is deprecated
156      */

157     public void testLegacyMasterIO() throws Throwable JavaDoc {
158
159         echo("Testing legacy module i/o");
160
161         CmsObject cms = getCmsObject();
162         
163         CmsDbAccess masterDbAccess = new CmsDbAccess(POOL);
164         CmsMasterDataSet dataset1 = new CmsMasterDataSet(), dataset2 = new CmsMasterDataSet();
165         CmsMasterContent content = new CmsMasterContent(cms) {
166             public int getSubId() {
167                 return 4711;
168             }
169         };
170
171         dataset1.m_title = "Master Test Content";
172         masterDbAccess.insert(cms, content, dataset1);
173         masterDbAccess.read(cms, content, dataset2, dataset1.m_masterId);
174         
175         assertEquals(dataset1.m_title, dataset2.m_title);
176     }
177 }
Popular Tags