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  package org.apache.commons.betwixt.introspection;
17  
18  import junit.framework.TestCase;
19  
20  import org.apache.commons.beanutils.*;
21  import org.apache.commons.betwixt.*;
22  
23  /***
24   * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
25   */
26  public class TestDynaBeanIntrospection extends TestCase {
27  
28      public void testSimpleIntrospectionTest() throws Exception {
29          DynaProperty[] dynaProperties = {
30                  new DynaProperty("one", Integer.class),
31                  new DynaProperty("two", String.class)};
32          BasicDynaClass dynaClass = new BasicDynaClass("WibbleDynaBean", BasicDynaBean.class, 
33                  dynaProperties);
34          DynaBean dynaBean = dynaClass.newInstance();
35          XMLIntrospector xmlIntrospector = new XMLIntrospector();
36          XMLBeanInfo xmlBeanInfo = xmlIntrospector.introspect(dynaBean);
37          
38          ElementDescriptor dynaBeanDescriptor = xmlBeanInfo.getElementDescriptor();
39          ElementDescriptor[] dynaPropertyDescriptors = dynaBeanDescriptor.getElementDescriptors();
40          assertEquals("Two dyna properties expected", 2, dynaPropertyDescriptors.length);
41          
42          for (int i=0; i<2; i++) {
43              if ("one".equals(dynaPropertyDescriptors[i].getPropertyName()) 
44                      || "two".equals(dynaPropertyDescriptors[i].getPropertyName())) {
45                  assertNotNull("Property updater", dynaPropertyDescriptors[1].getUpdater());
46              } else {
47                  fail("Properties should be named one and two");
48              }
49          }
50      }
51      
52  }