KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > getters > JavaClassCreationTest


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 package org.netbeans.jmi.javamodel.getters;
20
21 import junit.textui.TestRunner;
22 import org.netbeans.jmi.javamodel.*;
23 import org.netbeans.jmi.javamodel.codegen.Utility;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.modules.javacore.ClassIndex;
27
28 /**
29  * Test for javaClass creation with creaJavaClass() method without parameters.
30  * It is connected also with classIndex, where the class should be added.
31  *
32  * todo (#pf): We still need to solve situation, when class is not added to
33  * resource. Such a class is never removed from the index. There is no guarantee
34  * that jmi user adds it.
35  *
36  * @author Pavel Flaska
37  */

38 public class JavaClassCreationTest extends NbTestCase {
39     
40     JavaClass clazz;
41     JavaModelPackage pkg;
42     
43     /** Creates a new instance of JavaClassCreationTest */
44     public JavaClassCreationTest() {
45         super("JavaClassCreationTest");
46     }
47     
48     public static NbTestSuite suite() {
49         NbTestSuite suite = new NbTestSuite(JavaClassCreationTest.class);
50         return suite;
51     }
52     
53     protected void setUp() {
54         clazz = (JavaClass) Utility.findClass("examples.colorpicker.ColorPicker");
55         pkg = (JavaModelPackage) clazz.refImmediatePackage();
56     }
57     
58     /**
59      * Create javaClass model element. Use proxy method createJavaClass()
60      * without parameters.
61      */

62     public void testJavaClassCreation() {
63         boolean fail = true;
64         Utility.beginTrans(true);
65         try {
66             clazz = pkg.getJavaClass().createJavaClass();
67             clazz.setName("SetTheNameOnClassWhichHadNotNameYet");
68             fail = false;
69         }
70         finally {
71             Utility.endTrans(fail);
72         }
73     }
74     
75     /**
76      * Look for class created in previous test. If such a class is not in index,
77      * something is wrong.
78      */

79     public void testLookForCreatedClassInIndex() {
80         ClassIndex index = ClassIndex.getIndex(pkg);
81         clazz = index.getClassByFqn("SetTheNameOnClassWhichHadNotNameYet");
82         assertNotNull(clazz);
83     }
84     
85     /**
86      * @param args the command line arguments
87      */

88     public static void main(String JavaDoc[] args) {
89         TestRunner.run(suite());
90     }
91     
92 }
93
Popular Tags