KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > jonasserver > XMLTest


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: XMLTest.java,v 1.1 2005/07/11 16:01:34 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.jonasserver;
27
28 import java.io.BufferedReader JavaDoc;
29 import java.io.File JavaDoc;
30 import java.io.FileReader JavaDoc;
31
32 import org.custommonkey.xmlunit.Diff;
33 import org.custommonkey.xmlunit.DifferenceListener;
34 import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
35 import org.custommonkey.xmlunit.XMLTestCase;
36 import org.custommonkey.xmlunit.XMLUnit;
37 import org.w3c.dom.Document JavaDoc;
38 import org.xml.sax.InputSource JavaDoc;
39
40
41 /**
42  * Class for testing XML format
43  * @author Paul Kemler
44  *
45  */

46 public class XMLTest extends XMLTestCase {
47
48     /**
49      * Constructor
50      * @param name name of the test
51      */

52     public XMLTest(String JavaDoc name) {
53         super(name);
54     }
55
56     /**
57      * Test server.xml
58      * @param file $JONAS_BASE/conf/server.xml
59      * @param port port of the added connector
60      * @throws Exception if an error occurs
61      */

62     public void testServerXml(File JavaDoc file, String JavaDoc port) throws Exception JavaDoc {
63         String JavaDoc controlConnector = "<Connector " +
64                 "port=\"value\" " +
65                 "redirectPort=\"value\" " +
66                 "minSpareThreads=\"value\" " +
67                 "connectionTimeout=\"value\" " +
68                 "maxSpareThreads=\"value\" " +
69                 "maxThreads=\"value\" " +
70                 "maxHttpHeaderSize=\"value\">" +
71                 "</Connector>";
72         String JavaDoc controlAddedConnector = "<Connector " +
73                 "enableLookups=\"value\" " +
74                 "port=\"value\" " +
75                 "redirectPort=\"value\" " +
76                 "maxProcessors=\"value\" " +
77                 "debug=\"0\" " +
78                 "acceptCount=\"value\" " +
79                 "minProcessors=\"value\">" +
80                 "</Connector>";
81         String JavaDoc controlEngine = "<Engine " +
82                 "defaultHost=\"value\" " +
83                 "name=\"value\">" +
84                 "<Realm className=\"value\" " +
85                 "resourceName=\"value\"/>" +
86                 "<Valve className=\"value\" " +
87                 "fileDateFormat=\"value\" " +
88                 "suffix=\"value\"/>" +
89                 "<Host " +
90                 "appBase=\"value\" " +
91                 "autoDeploy=\"value\" " +
92                 "deployOnStartup=\"value\" " +
93                 "liveDeploy=\"value\" " +
94                 "name=\"value\">" +
95                 "</Host>" +
96                 "</Engine>";
97         String JavaDoc controlXml = "<Server>" +
98                 "<Listener className=\"value\"/>" +
99                 "<Listener className=\"value\"/>" +
100                 "<Listener className=\"value\"/>" +
101                 "<GlobalNamingResources>" +
102                 "</GlobalNamingResources>" +
103                 "<Service " +
104                 "name=\"value\">" +
105                 controlConnector +
106                 controlAddedConnector +
107                 controlEngine +
108                 "</Service>" +
109                 "</Server>";
110         Document JavaDoc testDocument = XMLUnit.buildTestDocument(new InputSource JavaDoc(new FileReader JavaDoc(file)));
111         String JavaDoc testText = "";
112
113         // Transform file into string
114
BufferedReader JavaDoc read = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
115         String JavaDoc temp = read.readLine();
116         while (temp != null) {
117             testText += temp + "\n";
118             temp = read.readLine();
119         }
120         read.close();
121
122         // Verify if the new Connector exists
123
assertXpathEvaluatesTo("1", "count(//Connector[@port='" + port + "'])", testDocument);
124
125         // Verify the server.xml 'structure'
126
XMLUnit.setIgnoreWhitespace(true);
127         DifferenceListener diffListener = new IgnoreTextAndAttributeValuesDifferenceListener();
128         Diff diff = new Diff(controlXml, testText);
129         diff.overrideDifferenceListener(diffListener);
130
131         assertTrue("The control structure:\n" + controlXml + "\nand the server.xml struture:\n" + testText + "\nare not similar.", diff.similar());
132
133     }
134 }
135
Popular Tags