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