01: /*
02: * Copyright (C) 2004 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 07. May 2004 by Joe Walnes
11: */
12: package com.thoughtworks.acceptance;
13:
14: import com.thoughtworks.xstream.XStream;
15:
16: public class IDCircularReferenceTest extends
17: AbstractCircularReferenceTest {
18:
19: // inherits test from superclass
20: protected void setUp() throws Exception {
21: super .setUp();
22: xstream.setMode(XStream.ID_REFERENCES);
23: }
24:
25: public void testCircularReferenceXml() {
26: Person bob = new Person("bob");
27: Person jane = new Person("jane");
28: bob.likes = jane;
29: jane.likes = bob;
30:
31: String expected = "" + "<person id=\"1\">\n"
32: + " <firstname>bob</firstname>\n"
33: + " <likes id=\"2\">\n"
34: + " <firstname>jane</firstname>\n"
35: + " <likes reference=\"1\"/>\n" + " </likes>\n"
36: + "</person>";
37:
38: assertEquals(expected, xstream.toXML(bob));
39: }
40:
41: public void testCircularReferenceToSelfXml() {
42: Person bob = new Person("bob");
43: bob.likes = bob;
44:
45: String expected = "" + "<person id=\"1\">\n"
46: + " <firstname>bob</firstname>\n"
47: + " <likes reference=\"1\"/>\n" + "</person>";
48:
49: assertEquals(expected, xstream.toXML(bob));
50: }
51:
52: }
|