KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > TestCmsSetupBean


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/setup/TestCmsSetupBean.java,v $
3  * Date : $Date: 2006/03/27 14:52:58 $
4  * Version: $Revision: 1.9 $
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.setup;
33
34 import org.opencms.main.CmsSystemInfo;
35 import org.opencms.test.OpenCmsTestCase;
36
37 import java.io.File JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.Vector JavaDoc;
41
42 import org.apache.commons.collections.ExtendedProperties;
43
44 /**
45  * @author Alexander Kandzior
46  *
47  * @version $Revision: 1.9 $
48  *
49  * @since 6.0.0
50  */

51 public class TestCmsSetupBean extends OpenCmsTestCase {
52
53     // DEBUG flag
54
// private static final boolean DEBUG = true;
55

56     // private static final String PROPERTIES = "/opencms/etc/config/opencms.properties";
57
// private static final String PROPERTIES = "/../OpenCms6-Setup/webapp/WEB-INF/config/opencms.properties";
58

59     /**
60      * Default JUnit constructor.<p>
61      *
62      * @param arg0 JUnit parameters
63      */

64     public TestCmsSetupBean(String JavaDoc arg0) {
65
66         super(arg0);
67     }
68
69     /**
70      * Tests the method saveProperties.<p>
71      *
72      * @throws IOException if something goes wrong
73      */

74     public void testSaveProperties() throws IOException JavaDoc {
75
76         CmsSetupBean bean = new CmsSetupBean();
77         bean.init("", null, null);
78
79         String JavaDoc base = getTestDataPath(File.separator + "WEB-INF" + File.separator + CmsSystemInfo.FOLDER_CONFIG);
80         String JavaDoc inputFile = base + CmsSystemInfo.FILE_PROPERTIES;
81         String JavaDoc outputFile = base + "output.properties";
82
83         System.out.println("Reading properties from " + inputFile);
84         ExtendedProperties oldProperties = bean.loadProperties(inputFile);
85
86         System.out.println("Writing properties to " + outputFile);
87         bean.copyFile(inputFile, outputFile);
88         bean.saveProperties(oldProperties, outputFile, false);
89
90         System.out.println("Checking properties from " + outputFile);
91         ExtendedProperties newProperties = bean.loadProperties(outputFile);
92
93         for (Iterator JavaDoc i = oldProperties.keySet().iterator(); i.hasNext();) {
94             String JavaDoc key = (String JavaDoc)i.next();
95             String JavaDoc oldValue = "", newValue = "";
96             Object JavaDoc obj = oldProperties.get(key);
97
98             if (obj instanceof Vector JavaDoc) {
99                 StringBuffer JavaDoc buf;
100
101                 buf = new StringBuffer JavaDoc();
102                 for (Iterator JavaDoc j = ((Vector JavaDoc)obj).iterator(); j.hasNext();) {
103                     buf.append("[" + (String JavaDoc)j.next() + "]");
104                 }
105                 oldValue = buf.toString();
106
107                 buf = new StringBuffer JavaDoc();
108                 for (Iterator JavaDoc j = ((Vector JavaDoc)newProperties.get(key)).iterator(); j.hasNext();) {
109                     buf.append("[" + (String JavaDoc)j.next() + "]");
110                 }
111                 newValue = buf.toString();
112
113             } else {
114                 oldValue = (String JavaDoc)obj;
115                 newValue = (String JavaDoc)newProperties.get(key);
116             }
117             System.out.println(key);
118             System.out.println(oldValue);
119             System.out.println(newValue);
120             System.out.println("---");
121             assertEquals(oldValue, newValue);
122         }
123
124         // clean up - remvove generated file
125
File JavaDoc output = new File JavaDoc(outputFile);
126         output.delete();
127     }
128 }
129
Popular Tags