KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > execute > ResultSetTableModelSupportTest


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.db.sql.execute;
21
22 import java.lang.reflect.Field JavaDoc;
23 import java.lang.reflect.Modifier JavaDoc;
24 import java.sql.Types JavaDoc;
25 import org.netbeans.junit.NbTestCase;
26
27 /**
28  *
29  * @author Andrei Badea
30  */

31 public class ResultSetTableModelSupportTest extends NbTestCase {
32
33     public ResultSetTableModelSupportTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     /**
38      * Tests that a ColumnTypeDef is defined for each type from java.sql.Types
39      * in the TYPE_TO_DEF map.
40      */

41     public void testAllTypes() throws IllegalAccessException JavaDoc {
42         Class JavaDoc clazz = Types JavaDoc.class;
43         Field JavaDoc[] fields = clazz.getFields();
44         for (int i = 0; i < fields.length; i++) {
45             Field JavaDoc field = fields[i];
46             if (field.getType() == int.class && Modifier.isStatic(field.getModifiers())) {
47                 int type = field.getInt(clazz);
48                 if (ResultSetTableModelSupport.TYPE_TO_DEF.get(new Integer JavaDoc(type)) == null) {
49                     fail("No ColumnTypeDef for java.Types." + field.getName());
50                 }
51             }
52         }
53     }
54     
55     /**
56      * Tests that a ColumnTypeDef is defined even for types not in
57      * java.sql.Types.
58      */

59     public void testUnknownTypesIssue71040() throws IllegalAccessException JavaDoc {
60         // for the test to be meaningful we have to ensure
61
// our type is not in java.sql.Types
62
int type = Integer.MAX_VALUE;
63         Class JavaDoc clazz = Types JavaDoc.class;
64         Field JavaDoc[] fields = clazz.getFields();
65         for (int i = 0; i < fields.length; i++) {
66             Field JavaDoc field = fields[i];
67             if (field.getType() == int.class && Modifier.isStatic(field.getModifiers())) {
68                 if (type == field.getInt(clazz)) {
69                     fail("Type " + type + " already defined in java.sql.Types as " + field.getName());
70                 }
71             }
72         }
73         assertNotNull(ResultSetTableModelSupport.getColumnTypeDef(type));
74     }
75 }
76
Popular Tags