KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thoughtworks.xstream.core;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
7
8 public class TreeUnmarshallerTest extends AbstractAcceptanceTest {
9
10     protected void setUp() throws Exception JavaDoc {
11         super.setUp();
12     }
13     
14     public void testUnmarshallingOfAliasedInterfaces() {
15         xstream.alias("addressBookInfo", AddressBookInfo.class, AddressBook.class);
16         xstream.alias("addressInfo", AddressInfo.class, Address.class);
17         AddressBookInfo initialObject = new AddressBook();
18         String JavaDoc marshalledXML = xstream.toXML(initialObject);
19         AddressBookInfo unmarshalledObject = (AddressBookInfo) xstream.fromXML(marshalledXML);
20         assertEquals(marshalledXML, xstream.toXML(unmarshalledObject));
21     }
22     
23     public interface AddressBookInfo {
24         public List JavaDoc getAddresses();
25
26         public void setAddresses(List JavaDoc address);
27     }
28
29     public class AddressBook implements AddressBookInfo {
30         private List JavaDoc addresses;
31
32         public AddressBook() {
33             addresses = new ArrayList JavaDoc();
34             AddressInfo addr = new Address("Home", "Home");
35             AddressInfo addr1 = new Address("Office", "Office");
36             addresses.add(addr);
37             addresses.add(addr1);
38         }
39
40         public List JavaDoc getAddresses() {
41             return addresses;
42         }
43
44         public void setAddresses(List JavaDoc addresses) {
45             this.addresses = addresses;
46         }
47     }
48
49     public interface AddressInfo {
50         public String JavaDoc getAddr1();
51
52         public String JavaDoc getAddr2();
53
54         public void setAddr1(String JavaDoc addr1);
55
56         public void setAddr2(String JavaDoc addr2);
57     }
58
59     public class Address implements AddressInfo {
60         private String JavaDoc addr1 = "addr1";
61
62         private String JavaDoc addr2 = "addr2";
63
64         public Address(String JavaDoc addr1, String JavaDoc addr2) {
65             this.addr1 = addr1;
66             this.addr2 = addr2;
67         }
68
69         public String JavaDoc getAddr1() {
70             return addr1;
71         }
72
73         public String JavaDoc getAddr2() {
74             return addr2;
75         }
76
77         public void setAddr1(String JavaDoc addr1) {
78             this.addr1 = addr1;
79         }
80
81         public void setAddr2(String JavaDoc addr2) {
82             this.addr2 = addr2;
83         }
84     }
85 }
86
Popular Tags