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 ; 8 import java.util.List ; 9 10 public class ReferenceByXPathMarshallingStrategyTest extends AbstractAcceptanceTest { 11 12 protected void setUp() throws Exception { 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 name; 20 21 public Thing() { 22 } 23 24 public Thing(String 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 list = new ArrayList (); 35 list.add(a); 36 list.add(b); 37 list.add(c); 38 39 String 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" + "</list>"; 49 50 assertBothWays(list, expected); 51 } 52 53 } 54 | Popular Tags |