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.dotbetwixt;
18  
19  import junit.framework.Test;
20  import junit.framework.TestSuite;
21  
22  import org.apache.commons.betwixt.ElementDescriptor;
23  import org.apache.commons.betwixt.XMLBeanInfo;
24  import org.apache.commons.betwixt.XMLIntrospector;
25  import org.apache.commons.betwixt.xmlunit.XmlTestCase;
26  
27  /*** 
28    * Test customization of xml to bean mapping using .betwixt files.
29    *
30    * @author Robert Burrell Donkin
31    */
32  public class TestIntrospection extends XmlTestCase {
33  
34  //--------------------------------- Test Suite
35      
36      public static Test suite() {
37          return new TestSuite(TestIntrospection.class);
38      }
39      
40  //--------------------------------- Constructor
41          
42      public TestIntrospection(String testName) {
43          super(testName);
44      }
45  
46  //---------------------------------- Tests
47  
48      public void testClassAttribute() throws Exception {
49          //SimpleLog log = new SimpleLog("[testClassAttribute:ElementRule]");
50          //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
51          //ElementRule.setLog(log);
52          
53          XMLIntrospector introspector = new XMLIntrospector();
54          XMLBeanInfo beanInfo = introspector.introspect(ExampleBean.class);
55          ElementDescriptor[] elementDescriptors = beanInfo.getElementDescriptor().getElementDescriptors();
56          ElementDescriptor elementsElementDescriptor = null;
57          for ( int i=0, size = elementDescriptors.length; i<size ; i++ ) {
58              if ( "example".equals( elementDescriptors[i].getLocalName() ) ) {
59                  elementsElementDescriptor = elementDescriptors[i];
60              }
61          }
62          
63          assertNotNull("Element descriptor for elements not found", elementsElementDescriptor);
64          assertEquals(
65                      "Class property not set", 
66                      ExampleImpl.class, 
67                      elementsElementDescriptor.getImplementationClass());
68      }
69  }
70