1   /*
2    * Copyright 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.introspection;
18  
19  import org.apache.commons.betwixt.ElementDescriptor;
20  import org.apache.commons.betwixt.XMLBeanInfo;
21  import org.apache.commons.betwixt.XMLIntrospector;
22  
23  import junit.framework.TestCase;
24  
25  /***
26   * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
27   */
28  public class TestInterfaceIntrospection extends TestCase {
29  
30      public void testSuperInterfaceIntrospection() throws Exception {
31          
32          XMLIntrospector introspector = new XMLIntrospector();
33          
34          XMLBeanInfo beanInfo = introspector.introspect(ICopyableDateRange.class);
35          ElementDescriptor[] childDescriptors = beanInfo.getElementDescriptor().getElementDescriptors();
36          
37          assertEquals("Date range child elements", 2, childDescriptors.length);
38          int code = 0;
39          for (int i=0; i<2; i++)
40          {
41              String name = childDescriptors[i].getPropertyName();
42              if ("startDate".equals(name))
43              {
44                  code += 1;
45              }
46              if ("endDate".equals(name))
47              {
48                  code += 2;
49              }      
50          }
51          assertEquals("Expected date range elements", 3, code);       
52      }
53      
54  
55      public void testSuperInterfaceIntrospectionWithDotBetwixt() throws Exception {
56          
57          XMLIntrospector introspector = new XMLIntrospector();
58          
59          XMLBeanInfo beanInfo = introspector.introspect(ILaughingCount.class);
60          ElementDescriptor[] childDescriptors = beanInfo.getElementDescriptor().getElementDescriptors();
61          
62          assertEquals("Laughing count child elements", 1, childDescriptors.length);
63          assertEquals("Laughing count super interface matched", "count", childDescriptors[0].getPropertyName());    
64          assertEquals("Laughing count super interface matched", Integer.TYPE, childDescriptors[0].getPropertyType());  
65          assertNotNull("Laughing count updater matched", childDescriptors[0].getUpdater());
66      }
67      
68  }