1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.derived;
18
19 import java.io.FileInputStream;
20 import java.io.InputStream;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 import org.apache.commons.betwixt.AbstractTestCase;
27 import org.apache.commons.betwixt.io.BeanReader;
28
29
30
31
32
33
34
35 public class TestDerived extends AbstractTestCase {
36
37 public static void main( String[] args ) {
38 TestRunner.run( suite() );
39 }
40
41 public static Test suite() {
42 return new TestSuite(TestDerived.class);
43 }
44
45 public TestDerived(String testName) {
46 super(testName);
47 }
48
49 public void testPersonList() throws Exception {
50
51 BeanReader reader = new BeanReader();
52 reader.registerBeanClass( PersonListBean.class );
53
54 InputStream in =
55 new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/derived/person-list.xml") );
56 try {
57
58 checkBean((PersonListBean) reader.parse( in ));
59
60 }
61 finally {
62 in.close();
63 }
64 }
65
66 protected void checkBean(PersonListBean bean) throws Exception {
67 PersonBean owner = bean.getOwner();
68 assertTrue("should have found an owner", owner != null );
69
70 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.EmployeeBean", owner.getClass().getName());
71
72
73 assertEquals("PersonList size", 4, bean.getPersonList().size());
74 assertEquals("PersonList value (1)", "Athos", ((PersonBean) bean.getPersonList().get(0)).getName());
75 assertEquals("PersonList value (2)", "Porthos", ((PersonBean) bean.getPersonList().get(1)).getName());
76 assertEquals("PersonList value (3)", "Aramis", ((PersonBean) bean.getPersonList().get(2)).getName());
77 assertEquals("PersonList value (4)", "D'Artagnan", ((PersonBean) bean.getPersonList().get(3)).getName());
78
79 PersonBean employee = (PersonBean) bean.getPersonList().get(1);
80 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.EmployeeBean", employee.getClass().getName());
81
82 PersonBean manager = (PersonBean) bean.getPersonList().get(2);
83 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.ManagerBean", manager.getClass().getName());
84
85
86
87 }
88
89 }
90