KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > derived > TestDerived


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.betwixt.derived;
17
18 import java.io.FileInputStream JavaDoc;
19 import java.io.InputStream JavaDoc;
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: 1.6 $
33   */

34 public class TestDerived extends AbstractTestCase {
35     
36     public static void main( String JavaDoc[] args ) {
37         TestRunner.run( suite() );
38     }
39     
40     public static Test suite() {
41         return new TestSuite(TestDerived.class);
42     }
43     
44     public TestDerived(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void testPersonList() throws Exception JavaDoc {
49
50         BeanReader reader = new BeanReader();
51 // reader.getXMLIntrospector().setLog(log);
52

53 // SimpleLog log = new SimpleLog("[TestPersonList:BeanReader]");
54
// log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
55

56 // reader.setLog(log);
57
reader.registerBeanClass( PersonListBean.class );
58         
59         InputStream JavaDoc in =
60             new FileInputStream JavaDoc( 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 JavaDoc {
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         // derived properties are not implemented yet...
91
/*
92         ManagerBean manager2 = (ManagerBean) manager;
93         assertEquals("should have a derived property", 12, manager2.getCheeseSize());
94 */

95     }
96     
97 }
98
99
Popular Tags