/*
* Copyright (C) 2004 Joe Walnes.
* Copyright (C) 2006, 2007 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 07. May 2004 by Joe Walnes
*/
package com.thoughtworks.acceptance;
import com.thoughtworks.xstream.XStream;
public class IDCircularReferenceTest extends AbstractCircularReferenceTest {
// inherits test from superclass
protected void setUp() throws Exception {
super.setUp();
xstream.setMode(XStream.ID_REFERENCES);
}
public void testCircularReferenceXml() {
Person bob = new Person("bob");
Person jane = new Person("jane");
bob.likes = jane;
jane.likes = bob;
String expected = "" +
"<person id=\"1\">\n" +
" <firstname>bob</firstname>\n" +
" <likes id=\"2\">\n" +
" <firstname>jane</firstname>\n" +
" <likes reference=\"1\"/>\n" +
" </likes>\n" +
"</person>";
assertEquals(expected, xstream.toXML(bob));
}
public void testCircularReferenceToSelfXml() {
Person bob = new Person("bob");
bob.likes = bob;
String expected = "" +
"<person id=\"1\">\n" +
" <firstname>bob</firstname>\n" +
" <likes reference=\"1\"/>\n" +
"</person>";
assertEquals(expected, xstream.toXML(bob));
}
}