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:
18: package org.apache.commons.betwixt;
19:
20: import java.io.FileInputStream;
21: import java.io.InputStream;
22:
23: import junit.framework.Test;
24: import junit.framework.TestSuite;
25: import junit.textui.TestRunner;
26:
27: import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
28:
29: /** Test harness for the Digester of XMLBeanInfo
30: *
31: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
32: * @version $Revision: 438373 $
33: */
34: public class TestXMLBeanInfoDigester 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(TestXMLBeanInfoDigester.class);
42: }
43:
44: public TestXMLBeanInfoDigester(String testName) {
45: super (testName);
46: }
47:
48: public void testDigester() throws Exception {
49: XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
50: // TODO the digestion probably won't work without an XMLIntrospector
51: // so it might be better to enforce via a constructor
52: // or create a default one
53: digester.setXMLIntrospector(new XMLIntrospector());
54:
55: InputStream in = new FileInputStream(
56: getTestFile("src/test/org/apache/commons/digester/rss/Channel.betwixt"));
57:
58: assertTrue("Found betwixt config file", in != null);
59:
60: XMLBeanInfo info = (XMLBeanInfo) digester.parse(in);
61:
62: assertTrue("Found XMLBeanInfo", info != null);
63:
64: ElementDescriptor descriptor = info.getElementDescriptor();
65:
66: assertTrue("Found root element descriptor", descriptor != null);
67: assertEquals("Element name correct", "rss", descriptor
68: .getLocalName());
69:
70: ElementDescriptor[] elements = descriptor
71: .getElementDescriptors();
72:
73: assertTrue("Found elements", elements != null
74: && elements.length > 0);
75:
76: descriptor = elements[0];
77: assertEquals("Element name correct", "channel", descriptor
78: .getLocalName());
79:
80: }
81: }
|