1
2 /*
3 * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestIDRead.java,v 1.4 2002/12/30 18:16:48 mvdb Exp $
4 * $Revision: 1.4 $
5 * $Date: 2002/12/30 18:16:48 $
6 *
7 * ====================================================================
8 *
9 * The Apache Software License, Version 1.1
10 *
11 * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
12 * reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in
23 * the documentation and/or other materials provided with the
24 * distribution.
25 *
26 * 3. The end-user documentation included with the redistribution, if
27 * any, must include the following acknowlegement:
28 * "This product includes software developed by the
29 * Apache Software Foundation (http://www.apache.org/)."
30 * Alternately, this acknowlegement may appear in the software itself,
31 * if and wherever such third-party acknowlegements normally appear.
32 *
33 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
34 * Foundation" must not be used to endorse or promote products derived
35 * from this software without prior written permission. For written
36 * permission, please contact apache@apache.org.
37 *
38 * 5. Products derived from this software may not be called "Apache"
39 * nor may "Apache" appear in their names without prior written
40 * permission of the Apache Group.
41 *
42 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
46 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
49 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
52 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 * ====================================================================
55 *
56 * This software consists of voluntary contributions made by many
57 * individuals on behalf of the Apache Software Foundation. For more
58 * information on the Apache Software Foundation, please see
59 * <http://www.apache.org/>.
60 *
61 * $Id: TestIDRead.java,v 1.4 2002/12/30 18:16:48 mvdb Exp $
62 */
63 package org.apache.commons.betwixt.digester;
64
65 import java.io.FileInputStream;
66 import java.io.InputStream;
67
68 import junit.framework.Test;
69 import junit.framework.TestSuite;
70 import junit.textui.TestRunner;
71
72 import org.apache.commons.betwixt.AbstractTestCase;
73 import org.apache.commons.betwixt.io.BeanReader;
74 import org.apache.commons.betwixt.io.BeanWriter;
75
76 /*** Test harness for ID-IDRef reading.
77 *
78 * @author Robert Burrell Donkin
79 * @version $Revision: 1.4 $
80 */
81 public class TestIDRead extends AbstractTestCase {
82
83 public static void main( String[] args ) {
84 TestRunner.run( suite() );
85 }
86
87 public static Test suite() {
88 return new TestSuite(TestIDRead.class);
89 }
90
91 public TestIDRead(String testName) {
92 super(testName);
93 }
94
95 public void testSimpleRead() throws Exception {
96 BeanWriter writer = new BeanWriter();
97 IDBean bean = new IDBean("alpha","one");
98 bean.addChild(new IDBean("beta","two"));
99 bean.addChild(new IDBean("gamma","three"));
100 writer.write(bean);
101
102 BeanReader reader = new BeanReader();
103
104 // logging just for this method
105 // SimpleLog log = new SimpleLog("[testSimpleRead:XMLIntrospectorHelper]");
106 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
107 // XMLIntrospectorHelper.setLog(log);
108 //
109 // log = new SimpleLog("[testSimpleRead:MethodUpdater]");
110 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
111 // MethodUpdater.setLog(log);
112
113 // log = new SimpleLog("[testSimpleRead:BeanCreateRule]");
114 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
115 // BeanCreateRule.setLog(log);
116
117 // log = new SimpleLog("[testSimpleRead:IDBean]");
118 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
119 // IDBean.log = log;
120
121 // log = new SimpleLog("[testSimpleRead:BeanReader]");
122 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
123 // reader.setLog(log);
124
125 // log = new SimpleLog("[testSimpleRead:XMLIntrospector]");
126 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
127 // reader.getXMLIntrospector().setLog(log);
128
129 reader.registerBeanClass( IDBean.class );
130
131 InputStream in = new FileInputStream(
132 getTestFile("src/test/org/apache/commons/betwixt/digester/SimpleReadTest.xml") );
133
134 try {
135 // log = new SimpleLog("[testSimpleRead]");
136 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
137 Object obj = reader.parse( in );
138 // log.debug(obj);
139
140 assertEquals("Read bean type is incorrect", true, (obj instanceof IDBean) );
141 IDBean alpha = (IDBean) obj;
142
143 assertEquals("Wrong list size", 2 , alpha.getChildren().size());
144
145 IDBean beta = (IDBean) alpha.getChildren().get(0);
146 assertEquals("Wrong name (A)", "beta" , beta.getName());
147
148 IDBean gamma = (IDBean) alpha.getChildren().get(1);
149 assertEquals("Wrong name (B)", "gamma" , gamma.getName());
150 }
151 finally {
152 in.close();
153 }
154 }
155
156 public void testIDRead() throws Exception {
157
158 BeanReader reader = new BeanReader();
159
160 // logging just for this method
161 // SimpleLog log = new SimpleLog("[testIDRead:XMLIntrospectorHelper]");
162 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
163 // XMLIntrospectorHelper.setLog(log);
164 //
165 // log = new SimpleLog("[testIDRead:BeanCreateRule]");
166 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
167 // BeanCreateRule.setLog(log);
168 //
169 // log = new SimpleLog("[testIDRead:BeanReader]");
170 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
171 // reader.setLog(log);
172 //
173 // log = new SimpleLog("[testIDRead:XMLIntrospector]");
174 // log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
175 // reader.getXMLIntrospector().setLog(log);
176
177 reader.registerBeanClass( IDBean.class );
178
179 InputStream in = new FileInputStream(
180 getTestFile("src/test/org/apache/commons/betwixt/digester/IDTest1.xml") );
181
182 try {
183 Object obj = reader.parse( in );
184
185 assertEquals("Read bean type is incorrect", true, (obj instanceof IDBean) );
186 IDBean alpha = (IDBean) obj;
187
188 assertEquals("Wrong list size (A)", 2 , alpha.getChildren().size());
189
190 IDBean beta = (IDBean) alpha.getChildren().get(0);
191 assertEquals("Wrong name (A)", "beta" , beta.getName());
192
193 IDBean gamma = (IDBean) alpha.getChildren().get(1);
194 assertEquals("Wrong name (B)", "gamma" , gamma.getName());
195 assertEquals("Wrong list size (B)", 2 , gamma.getChildren().size());
196
197 IDBean sonOfGamma = (IDBean) gamma.getChildren().get(1);
198
199 assertEquals("Wrong id (A)", "two" , sonOfGamma.getId());
200 assertEquals("Wrong name (C)", "beta" , sonOfGamma.getName());
201
202 assertEquals("IDREF bean not equal to ID bean", beta, sonOfGamma);
203 }
204 finally {
205 in.close();
206 }
207 }
208 }
This page was automatically generated by Maven