package testcase; import java.io.Serializable; import junit.framework.TestCase; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.Dom4JDriver; public class XStreamCyclicReferenceTest extends TestCase { public void testGoodSelfReference() { XStream xstream = new XStream(new Dom4JDriver()); System.out.println("testGoodSelfReference\n" + xstream.toXML(new GoodSelfReference())); xstream.fromXML(xstream.toXML(new GoodSelfReference())); } public void testBadSelfReference() { XStream xstream = new XStream(new Dom4JDriver()); System.out.println("testBadSelfReference\n" + xstream.toXML(new BadSelfReference())); xstream.fromXML(xstream.toXML(new BadSelfReference())); } public void testGoodSelfReference2() { XStream xstream = new XStream(); System.out.println("testGoodSelfReference\n" + xstream.toXML(new GoodSelfReference())); xstream.fromXML(xstream.toXML(new GoodSelfReference())); } public void testBadSelfReference2() { XStream xstream = new XStream(); System.out.println("testBadSelfReference\n" + xstream.toXML(new BadSelfReference())); xstream.fromXML(xstream.toXML(new BadSelfReference())); } } class BadSelfReference implements Serializable { private static final long serialVersionUID = 38772160335615698L; private BadSelfReference owner = this; private String aString = "1234"; private Long aLong = new Long(500); public String getAString() { return aString; } public void setAString(String string) { aString = string; } public BadSelfReference getOwner() { return owner; } public void setOwner(BadSelfReference owner) { this.owner = owner; } public Long getALong() { return aLong; } public void setALong(Long long1) { aLong = long1; } } class GoodSelfReference implements Serializable { private static final long serialVersionUID = 38772160335615698L; private String aString = "1234"; private Long aLong = new Long(500); private GoodSelfReference owner = this; public String getAString() { return aString; } public void setAString(String string) { aString = string; } public GoodSelfReference getOwner() { return owner; } public void setOwner(GoodSelfReference owner) { this.owner = owner; } public Long getALong() { return aLong; } public void setALong(Long long1) { aLong = long1; } }