Reputation: 1623
I've an XML Beans Interface called SynonymsRequest with:
public interface SynonymsRequest extends org.apache.xmlbeans.XmlObject {...}
I want to test two instances of SynonymsRequest for equality:
SynonymsRequest s1 = SynonymsRequest.Factory.newInstance();
s1.setQueryText("blub");
s1.setRequesterId(BigInteger.valueOf(1));
SynonymsRequest s2 = SynonymsRequest.Factory.newInstance();
s2.setQueryText("guck");
s2.setRequesterId(BigInteger.valueOf(1));
I've tried the following:
assertTrue(s1.equals(s2));
=> assertion does not passassertEquals(0, s1.compareTo(s2));
=> throws ClassCastExceptionassertEquals(0, s1.compareValue(s2));
=> assertion does not pass (returns 2, not compareable)assertTrue(s1.valueEquals(s2));
=> always returns true, no matter if the two instances are equalSo what is the proper way of doing this?
Upvotes: 1
Views: 1372
Reputation: 399
Noticed this a while back - if the two objects have toString() methods generated when they were made, then you can to an .equals on the toString() methods of the objects. These can be compared with relativ ease, since they will check if the output xml is equivalent.
Upvotes: 0
Reputation: 610
XmlBeans doesn't support a deep comparison so you'll have to write your own. There was a thread on the dev mailing list a while ago about a schema-aware comparison, but I'm not sure anything became of it:
http://www.mail-archive.com/[email protected]/msg01960.html
Upvotes: 0
Reputation: 6322
If it doesn't impact the performance of your program, you could compare them like this:
assertTrue(s1.xmlText().equals(s2.xmlText()));
Otherwise, I guess you will have to write your own custom comparator.
Upvotes: 3
Reputation: 28961
As I understand, the comparison compares two simple values only. It cannot deduct your desired comparison algorithm.
Or I don't understand what exactly do you mean?
Upvotes: 1