1 25 26 package org.objectweb.jonas.jonasadmin.test.jonasserver; 27 28 import java.io.BufferedReader ; 29 import java.io.File ; 30 import java.io.FileReader ; 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 ; 38 import org.xml.sax.InputSource ; 39 40 41 46 public class XMLTest extends XMLTestCase { 47 48 52 public XMLTest(String name) { 53 super(name); 54 } 55 56 62 public void testServerXml(File file, String port) throws Exception { 63 String 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 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 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 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 testDocument = XMLUnit.buildTestDocument(new InputSource (new FileReader (file))); 111 String testText = ""; 112 113 BufferedReader read = new BufferedReader (new FileReader (file)); 115 String temp = read.readLine(); 116 while (temp != null) { 117 testText += temp + "\n"; 118 temp = read.readLine(); 119 } 120 read.close(); 121 122 assertXpathEvaluatesTo("1", "count(//Connector[@port='" + port + "'])", testDocument); 124 125 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 |