KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > TestXMLBeanInfoDigester


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  
17 package org.apache.commons.betwixt;
18
19 import java.io.FileInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25
26 import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
27
28 /** Test harness for the Digester of XMLBeanInfo
29   *
30   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
31   * @version $Revision: 1.5 $
32   */

33 public class TestXMLBeanInfoDigester extends AbstractTestCase {
34     
35     public static void main( String JavaDoc[] args ) {
36         TestRunner.run( suite() );
37     }
38     
39     public static Test suite() {
40         return new TestSuite(TestXMLBeanInfoDigester.class);
41     }
42         
43     public TestXMLBeanInfoDigester(String JavaDoc testName) {
44         super(testName);
45     }
46     
47     public void testDigester() throws Exception JavaDoc {
48         XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
49         // TODO the digestion probably won't work without an XMLIntrospector
50
// so it might be better to enforce via a constructor
51
// or create a default one
52
digester.setXMLIntrospector(new XMLIntrospector());
53
54         InputStream JavaDoc in = new FileInputStream JavaDoc( getTestFile("src/test/org/apache/commons/digester/rss/Channel.betwixt") );
55         
56         assertTrue( "Found betwixt config file", in != null );
57         
58         XMLBeanInfo info = (XMLBeanInfo) digester.parse( in );
59         
60         assertTrue( "Found XMLBeanInfo", info != null );
61         
62         ElementDescriptor descriptor = info.getElementDescriptor();
63         
64         assertTrue( "Found root element descriptor", descriptor != null );
65         assertEquals( "Element name correct", "rss", descriptor.getLocalName() );
66         
67         ElementDescriptor[] elements = descriptor.getElementDescriptors();
68         
69         assertTrue( "Found elements", elements != null && elements.length > 0 );
70         
71         descriptor = elements[0];
72         assertEquals( "Element name correct", "channel", descriptor.getLocalName() );
73         
74     }
75 }
76
77
Popular Tags