KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > ReferenceByXPathMarshallingStrategyTest


1 package com.thoughtworks.xstream.core;
2
3 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
4 import com.thoughtworks.acceptance.StandardObject;
5 import com.thoughtworks.xstream.XStream;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10 public class ReferenceByXPathMarshallingStrategyTest extends AbstractAcceptanceTest {
11
12     protected void setUp() throws Exception JavaDoc {
13         super.setUp();
14         xstream.setMode(XStream.XPATH_REFERENCES);
15         xstream.alias("thing", Thing.class);
16     }
17
18     public static class Thing extends StandardObject {
19         private String JavaDoc name;
20
21         public Thing() {
22         }
23
24         public Thing(String JavaDoc name) {
25             this.name = name;
26         }
27     }
28
29     public void testStoresReferencesUsingXPath() {
30         Thing a = new Thing("a");
31         Thing b = new Thing("b");
32         Thing c = b;
33
34         List JavaDoc list = new ArrayList JavaDoc();
35         list.add(a);
36         list.add(b);
37         list.add(c);
38
39         String JavaDoc expected = "" +
40                 "<list>\n" +
41                 " <thing>\n" +
42                 " <name>a</name>\n" +
43                 " </thing>\n" +
44                 " <thing>\n" +
45                 " <name>b</name>\n" +
46                 " </thing>\n" +
47                 " <thing reference=\"../thing[2]\"/>\n" + // xpath
48
"</list>";
49
50         assertBothWays(list, expected);
51     }
52
53 }
54
Popular Tags