...
| Code Block |
|---|
// require(groupId:'xmlunit', artifactId:'xmlunit', version:'1.0')
// require(groupId:'jdom', artifactId:'jdom', version:'1.0')
import javax.xml.parsers.DocumentBuilderFactory
import org.jdom.input.SAXBuilder
import org.custommonkey.xmlunit.*
import org.jdom.output.XMLOutputter
import org.jdom.*
def addCar(root, name, make, year, country, type, text) {
def car = new Element('car')
car.setAttribute('name', name)
car.setAttribute('make', make)
car.setAttribute('year', year)
root.addContent(car)
def countryNode = new Element('country').setText(country)
car.addContent(countryNode)
def record = new Element('record').setText(text)
record.setAttribute('type', type)
car.addContent(record)
}
def root = new Element('records')
def document = new Document(root)
document.setRootElement(root)
addCar(root, 'HSV Maloo', 'Holden', '2006', 'Australia',
'speed', 'Production Pickup Truck with speed of 271kph')
addCar(root, 'P50', 'Peel', '1962', 'Isle of Man',
'size', 'Smallest Street-Legal Car at 99cm wide and 59 kg in weight')
addCar(root, 'Royale', 'Bugatti', '1931', 'France',
'price', 'Most Valuable Car at $15 million')
// convert resulting document to a string so that we can compare
XMLUnit.setIgnoreWhitespace(true)
def writer = new StringWriter()
new XMLOutputter().output(document, writer)
def xmlDiff = new Diff(writer.toString(), XmlExamples.CAR_RECORDS)
assert xmlDiff.similar()
|
...