1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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( getTestFile("src/test/org/apache/commons/digester/rss/Channel.betwixt") );
56          
57          assertTrue( "Found betwixt config file", in != null );
58          
59          XMLBeanInfo info = (XMLBeanInfo) digester.parse( in );
60          
61          assertTrue( "Found XMLBeanInfo", info != null );
62          
63          ElementDescriptor descriptor = info.getElementDescriptor();
64          
65          assertTrue( "Found root element descriptor", descriptor != null );
66          assertEquals( "Element name correct", "rss", descriptor.getLocalName() );
67          
68          ElementDescriptor[] elements = descriptor.getElementDescriptors();
69          
70          assertTrue( "Found elements", elements != null && elements.length > 0 );
71          
72          descriptor = elements[0];
73          assertEquals( "Element name correct", "channel", descriptor.getLocalName() );
74          
75      }
76  }
77