From: "Wannheden, Knut" <[EMAIL PROTECTED]>
> > From: James Strachan [mailto:[EMAIL PROTECTED]]
> > From: "Michael Rettig" <[EMAIL PROTECTED]>
> > > In jellyUnit is there support for using assertEquals with
> > XPath? I have an
> > xml value that I want to compare like so:
> > >
> > > <test:assertEquals xpath="$doc/order/item/@quantity" value="4"/>
> > >
> > > I am presently using the assert with xpath...
> > >
> > > <test:assert xpath="$doc/order/item/@quantity = '4'"/>
> >
> > The above is the best way to perform XPath assertions right now.
> >
>
> Would it be possible to write a different <test:assertEquals/> tag that
has
> two nested elements as its body, whose output is then compared? Something
> like:
>
> <test:assertEquals>
> <foo:bar/>
> <foo:baz/>
> </test:assertEquals>
I'm sure it would be possible. Fancy submitting a patch :-)?
> Would a custom XMLOuput class have to be implemented for this?
Not necessarily. You could just use a SAX ContentHandler & LexicalHandler
that could convert the SAX events into, say, a DOM tree of some kind and
perform the comparison that way.
e.g. here's how you could implement it - the following code is based on the
<x:parse> tag source code
import org.dom4j.Document;
import org.dom4j.io.SAXContentHandler;
...
SAXContentHandler handler = new SAXContentHandler();
XMLOutput newOutput = new XMLOutput(handler);
handler.startDocument();
handler.startElement("", "dummy", "dummy", new AttributesImpl());
// pipe this tags body into the SAX handler
invokeBody(newOutput);
handler.endElement("", "dummy", "dummy");
handler.endDocument();
// now extract the Document created
Document document = handler.getDocument();
Note that there's an added complication in the example you gave, that an XML
document must have 1 root element. Hence the use of the <dummy> startElement
and endElement calls above.
I guess another approach to this could be to parse XML using <x:parse> and
then have a Document assertion. e.g.
<x:parse var="doc1">
<foo:bar/>
</x:parse>
<x:parse var="doc2">
<foo:baz/>
</x:parse>
<test:assertDocumentsEqual expected="${doc1}" actual="${doc2}"/>
> BTW, I noticed the following lines in
> junit.AssertEqualsTag#doTag(XMLOutput):
>
> if (expectedValue == null && expectedValue == null) {
> return;
> }
>
> Looks like this could be written differently ;-)
Looks like a bug to me :-)
Many thanks for spotting this, its fixed now in CVS.
James
-------
http://radio.weblogs.com/0112098/
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>