01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: /** Test harness for the BeanReader
30: *
31: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
32: * @version $Revision: 438373 $
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 = new FileInputStream(
54: getTestFile("src/test/org/apache/commons/betwixt/derived/person-list.xml"));
55: try {
56:
57: checkBean((PersonListBean) reader.parse(in));
58:
59: } finally {
60: in.close();
61: }
62: }
63:
64: protected void checkBean(PersonListBean bean) throws Exception {
65: PersonBean owner = bean.getOwner();
66: assertTrue("should have found an owner", owner != null);
67:
68: assertEquals("should be derived class",
69: "org.apache.commons.betwixt.derived.EmployeeBean",
70: owner.getClass().getName());
71:
72: assertEquals("PersonList size", 4, bean.getPersonList().size());
73: assertEquals("PersonList value (1)", "Athos",
74: ((PersonBean) bean.getPersonList().get(0)).getName());
75: assertEquals("PersonList value (2)", "Porthos",
76: ((PersonBean) bean.getPersonList().get(1)).getName());
77: assertEquals("PersonList value (3)", "Aramis",
78: ((PersonBean) bean.getPersonList().get(2)).getName());
79: assertEquals("PersonList value (4)", "D'Artagnan",
80: ((PersonBean) bean.getPersonList().get(3)).getName());
81:
82: PersonBean employee = (PersonBean) bean.getPersonList().get(1);
83: assertEquals("should be derived class",
84: "org.apache.commons.betwixt.derived.EmployeeBean",
85: employee.getClass().getName());
86:
87: PersonBean manager = (PersonBean) bean.getPersonList().get(2);
88: assertEquals("should be derived class",
89: "org.apache.commons.betwixt.derived.ManagerBean",
90: manager.getClass().getName());
91:
92: // test derived properties
93: //assertEquals("should have a derived property", 12, ((ManagerBean) manager).getCheeseSize());
94: }
95:
96: }
|