KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > DConfigBeanBeanInfoTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.share.configbean;
21
22 import java.beans.BeanDescriptor JavaDoc;
23 import java.beans.BeanInfo JavaDoc;
24 import java.beans.EventSetDescriptor JavaDoc;
25 import java.beans.FeatureDescriptor JavaDoc;
26 import java.beans.MethodDescriptor JavaDoc;
27 import java.beans.PropertyDescriptor JavaDoc;
28 import junit.framework.TestCase;
29
30 /**
31  *
32  * @author Peter Williams
33  */

34 public class DConfigBeanBeanInfoTest extends TestCase {
35     
36     /** -----------------------------------------------------------------------
37      * Test harness code
38      */

39     /** Constructor
40      */

41     public DConfigBeanBeanInfoTest(String JavaDoc testName) {
42         super(testName);
43     }
44     
45     /** -----------------------------------------------------------------------
46      * All tests to follow
47      */

48     /** WebAppRoot
49      */

50     public void testWebAppRootBeanInfo() {
51         testBeanInfo(new WebAppRootBeanInfo());
52     }
53     
54     /** SessionConfiguration
55      */

56     /*public void testSessionConfigurationBeanInfo() {
57         testBeanInfo(new SessionConfigurationBeanInfo());
58     }*/

59     
60     /** ServletRef
61      */

62     public void testServletRefBeanInfo() {
63         testBeanInfo(new ServletRefBeanInfo());
64     }
65
66     /** SecurityRoleMapping
67      */

68     public void testSecurityRoleMappingBeanInfo() {
69         testBeanInfo(new SecurityRoleMappingBeanInfo());
70     }
71
72     /** EjbRef
73      */

74     public void testEjbRefBeanInfo() {
75         testBeanInfo(new EjbRefBeanInfo());
76     }
77     
78     /** ResourceRef
79      */

80     public void testResourceRefBeanInfo() {
81         testBeanInfo(new ResourceRefBeanInfo());
82     }
83     
84     /** ResourceEnvRef
85      */

86     public void testResourceEnvRefBeanInfo() {
87         testBeanInfo(new ResourceEnvRefBeanInfo());
88     }
89     
90     /** ServiceRef
91      */

92     public void testServiceRefBeanInfo() {
93         testBeanInfo(new ServiceRefBeanInfo());
94     }
95     
96     /** Test specified BeanInfo for integrity
97      */

98     private void testBeanInfo(BeanInfo JavaDoc beanInfo) {
99         String JavaDoc beanInfoName = beanInfo.getClass().getName();
100 // String beanName = beanInfoName.substring(0, beanInfoName.length()-8);
101
System.out.println("Testing integrity of " + beanInfoName);
102         
103         BeanDescriptor JavaDoc bd = beanInfo.getBeanDescriptor();
104         assertNotNull(beanInfoName + " does not specify a customizer", bd.getCustomizerClass());
105
106         PropertyDescriptor JavaDoc pd[] = beanInfo.getPropertyDescriptors();
107         verifyDescriptorArray("PropertDescriptor", pd);
108         
109         MethodDescriptor JavaDoc md[] = beanInfo.getMethodDescriptors();
110         verifyDescriptorArray("MethodDescriptor", md);
111         
112         EventSetDescriptor JavaDoc esd[] = beanInfo.getEventSetDescriptors();
113         verifyDescriptorArray("EventSetDescriptor", esd);
114     }
115     
116     private void verifyDescriptorArray(String JavaDoc descriptorName, FeatureDescriptor JavaDoc[] fd) {
117         if(fd == null) {
118             return; // null is ok
119
}
120         
121         for(int i = 0; i < fd.length; i++) {
122             if(fd[i] == null) {
123                 fail(descriptorName + " array null at index " + i);
124             }
125         }
126     }
127 }
128
Popular Tags