1 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 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 53 56 reader.registerBeanClass( PersonListBean.class ); 58 59 InputStream in = 60 new FileInputStream ( getTestFile("src/test/org/apache/commons/betwixt/derived/person-list.xml") ); 61 try { 62 63 checkBean((PersonListBean) reader.parse( in )); 64 65 } 66 finally { 67 in.close(); 68 } 69 } 70 71 protected void checkBean(PersonListBean bean) throws Exception { 72 PersonBean owner = bean.getOwner(); 73 assertTrue("should have found an owner", owner != null ); 74 75 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.EmployeeBean", owner.getClass().getName()); 76 77 78 assertEquals("PersonList size", 4, bean.getPersonList().size()); 79 assertEquals("PersonList value (1)", "Athos", ((PersonBean) bean.getPersonList().get(0)).getName()); 80 assertEquals("PersonList value (2)", "Porthos", ((PersonBean) bean.getPersonList().get(1)).getName()); 81 assertEquals("PersonList value (3)", "Aramis", ((PersonBean) bean.getPersonList().get(2)).getName()); 82 assertEquals("PersonList value (4)", "D'Artagnan", ((PersonBean) bean.getPersonList().get(3)).getName()); 83 84 PersonBean employee = (PersonBean) bean.getPersonList().get(1); 85 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.EmployeeBean", employee.getClass().getName()); 86 87 PersonBean manager = (PersonBean) bean.getPersonList().get(2); 88 assertEquals("should be derived class", "org.apache.commons.betwixt.derived.ManagerBean", manager.getClass().getName()); 89 90 95 } 96 97 } 98 99 | Popular Tags |