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