KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > TestConfiguration


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/configuration/TestConfiguration.java,v $
3  * Date : $Date: 2006/03/27 14:52:36 $
4  * Version: $Revision: 1.15 $
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.configuration;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.test.OpenCmsTestCase;
36 import org.opencms.util.CmsFileUtil;
37 import org.opencms.xml.CmsXmlEntityResolver;
38 import org.opencms.xml.CmsXmlUtils;
39
40 import java.io.FileInputStream JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.dom4j.Document;
46 import org.xml.sax.InputSource JavaDoc;
47
48 /**
49  * Tests for the OpenCms configuration handling.<p>
50  *
51  * @author Alexander Kandzior
52  *
53  * @version $Revision: 1.15 $
54  *
55  * @since 6.0.0
56  */

57 public class TestConfiguration extends OpenCmsTestCase {
58
59     /**
60      * Default JUnit constructor.<p>
61      *
62      * @param arg0 JUnit parameters
63      */

64     public TestConfiguration(String JavaDoc arg0) {
65
66         super(arg0, false);
67     }
68
69     /**
70      * Loads the configuration using the configuration manager,
71      * if anyting goes wrong an exception is thrown and the test fails.<p>
72      *
73      *
74      * @throws Exception if something goes wrong
75      */

76     public void testLoadXmlConfiguration() throws Exception JavaDoc {
77
78         // get the file name of the input resource
79
String JavaDoc inputFile = CmsFileUtil.getResourcePathFromClassloader("org/opencms/configuration/");
80
81         // generate the configuration manager
82
CmsConfigurationManager manager = new CmsConfigurationManager(inputFile);
83         // now digest the XML
84
manager.loadXmlConfiguration();
85         // generate an output XML format
86
List JavaDoc allConfigurations = new ArrayList JavaDoc();
87         allConfigurations.add(manager);
88         allConfigurations.addAll(manager.getConfigurations());
89
90         Iterator JavaDoc i = allConfigurations.iterator();
91         while (i.hasNext()) {
92             I_CmsXmlConfiguration config = (I_CmsXmlConfiguration)i.next();
93             String JavaDoc xmlOrigFile = inputFile + config.getXmlFileName();
94             System.out.println("\n\nConfiguration instance: " + config + ":\n");
95
96             // generate XML document for the configuration
97
Document outputDoc = manager.generateXml(config);
98             outputDoc.setName(config.getXmlFileName());
99
100             // load XML from original file and compare to generated document
101
InputSource JavaDoc source = new InputSource JavaDoc(new FileInputStream JavaDoc(xmlOrigFile));
102             Document inputDoc = CmsXmlUtils.unmarshalHelper(source, new CmsXmlEntityResolver(null));
103
104             // output the document
105
System.out.println("---");
106             System.out.println(CmsXmlUtils.marshal(outputDoc, CmsEncoder.ENCODING_UTF_8));
107             System.out.println("---");
108
109             assertEquals(outputDoc, inputDoc);
110         }
111     }
112 }
113
Popular Tags