KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > main > TestCmsShell


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/main/TestCmsShell.java,v $
3  * Date : $Date: 2006/03/27 14:52:59 $
4  * Version: $Revision: 1.10 $
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.main;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.test.OpenCmsTestCase;
36 import org.opencms.util.CmsFileUtil;
37
38 import java.io.File JavaDoc;
39 import java.io.FileInputStream JavaDoc;
40
41 /**
42  * Test cases for the OpenCms shell.<p>
43  *
44  * @author Alexander Kandzior
45  *
46  * @version $Revision: 1.10 $
47  *
48  * @since 6.0.0
49  */

50 public class TestCmsShell extends OpenCmsTestCase {
51
52     /**
53      * Default JUnit constructor.<p>
54      *
55      * @param arg0 JUnit parameters
56      */

57     public TestCmsShell(String JavaDoc arg0) {
58
59         super(arg0);
60     }
61
62     /**
63      * Tests the Junit OpenCms VFS test setup using the "base" test class.<p>
64      *
65      * @throws Throwable if something goes wrong
66      */

67     public void testCmsSetup() throws Throwable JavaDoc {
68
69         CmsObject cms;
70
71         // setup OpenCms using the base test class
72
cms = setupOpenCms("simpletest", "/sites/default/");
73         // check the returned CmsObject
74
assertEquals(cms.getRequestContext().currentUser(), cms.readUser("Admin"));
75         assertEquals(cms.getRequestContext().currentProject(), cms.readProject("Offline"));
76         assertEquals(cms.getRequestContext().getSiteRoot(), "/sites/default");
77
78         // check the CmsObject initialization
79
cms = getCmsObject();
80         // check the returned CmsObject
81
assertEquals(cms.getRequestContext().currentUser(), cms.readUser("Admin"));
82         assertEquals(cms.getRequestContext().currentProject(), cms.readProject("Offline"));
83         assertEquals(cms.getRequestContext().getSiteRoot(), "/sites/default");
84
85         // remove OpenCms
86
removeOpenCms();
87     }
88
89     /**
90      * Tests the CmsShell and setup procedure.<p>
91      *
92      * @throws Throwable if something goes wrong
93      */

94     public void testCmsShell() throws Throwable JavaDoc {
95
96         // create a new database first
97
setupDatabase();
98
99         // create a shell instance
100
CmsShell shell = new CmsShell(
101             getTestDataPath("WEB-INF" + File.separator),
102             null,
103             null,
104             "${user}@${project}>",
105             null);
106
107         // open the test script
108
File JavaDoc script;
109         FileInputStream JavaDoc stream;
110
111         // start the shell with the base script
112
script = new File JavaDoc(getTestDataPath("scripts/script_base.txt"));
113         stream = new FileInputStream JavaDoc(script);
114         shell.start(stream);
115
116         // add the default folders by script
117
script = new File JavaDoc(getTestDataPath("scripts/script_default_folders.txt"));
118         stream = new FileInputStream JavaDoc(script);
119         shell.start(stream);
120
121         // log in the Admin user and switch to the setup project
122
CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
123         cms.loginUser("Admin", "admin");
124         cms.getRequestContext().setCurrentProject(cms.readProject("_setupProject"));
125
126         // import the "simpletest" files
127
importResources(cms, "simpletest", "/sites/default/");
128
129         // publish the current project by script
130
script = new File JavaDoc(getTestDataPath("scripts/script_publish.txt"));
131         stream = new FileInputStream JavaDoc(script);
132         shell.start(stream);
133
134         // get the name of the folder for the backup configuration files
135
File JavaDoc configBackupDir = new File JavaDoc(getTestDataPath("WEB-INF/" + CmsSystemInfo.FOLDER_CONFIG + "backup/"));
136
137         // exit the shell
138
shell.exit();
139
140         // remove the database
141
removeDatabase();
142
143         // remove the backup configuration files
144
CmsFileUtil.purgeDirectory(configBackupDir);
145     }
146 }
147
Popular Tags