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;
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.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[] args ) {
36          TestRunner.run( suite() );
37      }
38      
39      public static Test suite() {
40          return new TestSuite(TestXMLBeanInfoDigester.class);
41      }
42          
43      public TestXMLBeanInfoDigester(String testName) {
44          super(testName);
45      }
46      
47      public void testDigester() throws Exception {
48          XMLBeanInfoDigester digester = new XMLBeanInfoDigester();
49  
50          InputStream in = new FileInputStream( getTestFile("src/test/org/apache/commons/digester/rss/Channel.betwixt") );
51          
52          assertTrue( "Found betwixt config file", in != null );
53          
54          XMLBeanInfo info = (XMLBeanInfo) digester.parse( in );
55          
56          assertTrue( "Found XMLBeanInfo", info != null );
57          
58          ElementDescriptor descriptor = info.getElementDescriptor();
59          
60          assertTrue( "Found root element descriptor", descriptor != null );
61          assertEquals( "Element name correct", "rss", descriptor.getLocalName() );
62          
63          ElementDescriptor[] elements = descriptor.getElementDescriptors();
64          
65          assertTrue( "Found elements", elements != null && elements.length > 0 );
66          
67          descriptor = elements[0];
68          assertEquals( "Element name correct", "channel", descriptor.getLocalName() );
69      }
70  }
71