001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: XMLTest.java 7360 2005-09-09 09:25:52Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.jonasserver;
025:
026: import java.io.BufferedReader;
027: import java.io.File;
028: import java.io.FileReader;
029:
030: import org.custommonkey.xmlunit.Diff;
031: import org.custommonkey.xmlunit.DifferenceListener;
032: import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener;
033: import org.custommonkey.xmlunit.XMLTestCase;
034: import org.custommonkey.xmlunit.XMLUnit;
035: import org.w3c.dom.Document;
036: import org.xml.sax.InputSource;
037:
038: /**
039: * Class for testing XML format
040: * @author Paul Kemler
041: *
042: */
043: public class XMLTest extends XMLTestCase {
044:
045: /**
046: * Constructor
047: * @param name name of the test
048: */
049: public XMLTest(String name) {
050: super (name);
051: }
052:
053: /**
054: * Test server.xml
055: * @param file $JONAS_BASE/conf/server.xml
056: * @param port port of the added connector
057: * @throws Exception if an error occurs
058: */
059: public void testServerXml(File file, String port) throws Exception {
060: String controlConnector = "<Connector " + "port=\"value\" "
061: + "redirectPort=\"value\" "
062: + "minSpareThreads=\"value\" "
063: + "connectionTimeout=\"value\" "
064: + "maxSpareThreads=\"value\" "
065: + "maxThreads=\"value\" "
066: + "maxHttpHeaderSize=\"value\">" + "</Connector>";
067: String controlAddedConnector = "<Connector "
068: + "enableLookups=\"value\" " + "port=\"value\" "
069: + "redirectPort=\"value\" " + "acceptCount=\"value\">"
070: + "</Connector>";
071: String controlEngine = "<Engine " + "defaultHost=\"value\" "
072: + "name=\"value\">" + "<Realm className=\"value\" "
073: + "resourceName=\"value\"/>"
074: + "<Valve className=\"value\" "
075: + "fileDateFormat=\"value\" " + "suffix=\"value\"/>"
076: + "<Host " + "appBase=\"value\" "
077: + "autoDeploy=\"value\" "
078: + "deployOnStartup=\"value\" " + "deployXML=\"false\" "
079: + "liveDeploy=\"value\" " + "name=\"value\" "
080: + "unpackWARs=\"value\">" + "</Host>" + "</Engine>";
081: String controlXml = "<Server>"
082: + "<Listener className=\"value\"/>"
083: + "<Listener className=\"value\"/>"
084: + "<Listener className=\"value\"/>"
085: + "<GlobalNamingResources>"
086: + "</GlobalNamingResources>" + "<Service "
087: + "name=\"value\">" + controlConnector
088: + controlAddedConnector + controlEngine + "</Service>"
089: + "</Server>";
090: Document testDocument = XMLUnit
091: .buildTestDocument(new InputSource(new FileReader(file)));
092: String testText = "";
093:
094: // Transform file into string
095: BufferedReader read = new BufferedReader(new FileReader(file));
096: String temp = read.readLine();
097: while (temp != null) {
098: testText += temp + "\n";
099: temp = read.readLine();
100: }
101: read.close();
102:
103: // Verify if the new Connector exists
104: assertXpathEvaluatesTo("1", "count(//Connector[@port='" + port
105: + "'])", testDocument);
106:
107: // Verify the server.xml 'structure'
108: XMLUnit.setIgnoreWhitespace(true);
109: DifferenceListener diffListener = new IgnoreTextAndAttributeValuesDifferenceListener();
110: Diff diff = new Diff(controlXml, testText);
111: diff.overrideDifferenceListener(diffListener);
112:
113: assertTrue("The control structure:\n" + controlXml
114: + "\nand the server.xml struture:\n" + testText
115: + "\nare not similar: " + diff.toString(), diff
116: .similar());
117:
118: }
119: }
|