From: Naresh B. <NB...@sa...> - 2008-07-26 17:29:20
|
I am a newbie to XMLUnit. I was trying to match the following pieces of XML where 1) forums is an unordered collection for forum objects 2) forum is an unordered collection of thread objects 3) thread is an ordered collection of message objects Control ======= <forums> <forum> <name>forum1</name> <thread> <title>thread11</title> <message>msg111</message> <message>msg112</message> </thread> <thread> <title>thread12</title> <message>msg121</message> <message>msg122</message> </thread> </forum> <forum> <name>forum2</name> <thread> <title>thread21</title> <message>msg211</message> <message>msg212</message> </thread> <thread> <title>thread22</title> <message>msg221</message> <message>msg222</message> </thread> </forum> </forums> Test ==== <forums> <forum> <name>forum2</name> <thread> <title>thread22</title> <message>msg221</message> <message>msg222</message> </thread> <thread> <title>thread21</title> <message>msg211</message> <message>msg212</message> </thread> </forum> <forum> <name>forum1</name> <thread> <title>thread12</title> <message>msg121</message> <message>msg122</message> </thread> <thread> <title>thread11</title> <message>msg111</message> <message>msg112</message> </thread> </forum> </forums> 1) What is the best way to specify this in XMLUnit? Here's my attempt: Diff diff = new Diff(control, test); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); System.out.println(diff.toString()); This prints the following difference (obviously not what I want): [different] Expected text value 'forum1' but was 'forum2' - comparing <name ...>forum1</name> at /forums[1]/forum[1]/name[1]/text()[1] to <name ...>forum2</name> at /forums[1]/forum[1]/name[1]/text()[1] 2) What's interesting is that if I take out threads and messages from the data above, then diff.similar() returns true. So why does the addition of threads and messages choke at the forum level? 3) Is there a general way to specify ordered/unordered collections at different levels of nesting? I am trying to write a testing framework for my application and it would be nice to specify the matching criteria flexibly. Thanks. Naresh Bhatia |