KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > FieldTest3


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.codegen;
20
21 import java.util.List JavaDoc;
22 import junit.textui.TestRunner;
23 import org.netbeans.jmi.javamodel.*;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26 import org.openide.filesystems.FileStateInvalidException;
27
28 /**
29  * Tests more transaction on file with fields. Tests fields generating and
30  * also update.
31  *
32  * @author Pavel Flaska
33  */

34 public class FieldTest3 extends NbTestCase {
35
36     /** Creates a new instance of FieldTest3 */
37     public FieldTest3() {
38         super("FieldTest3");
39     }
40     
41     public static NbTestSuite suite() {
42         NbTestSuite suite = new NbTestSuite(FieldTest3.class);
43         return suite;
44     }
45     
46     JavaClass clazz;
47     JavaModelPackage pkg;
48     
49     protected void setUp() {
50         clazz = Utility.findClass("org.netbeans.test.codegen.FieldTest3");
51         pkg = (JavaModelPackage) clazz.refImmediatePackage();
52     }
53
54     /**
55      * Tests inital value for fields in field group.
56      */

57     public void testGroupInitValues() throws java.io.IOException JavaDoc, FileStateInvalidException {
58         boolean fail = true;
59         Utility.beginTrans(true);
60         try {
61             FieldGroup group = (FieldGroup) clazz.getContents().get(2);
62             List JavaDoc fields = group.getFields();
63             ((Field) fields.get(0)).setInitialValueText("\"prvni\"");
64             ((Field) fields.get(2)).setInitialValueText("\"treti\"");
65             fail = false;
66         } finally {
67             Utility.endTrans(fail);
68         }
69         assertFile("File is not correctly generated.",
70             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/FieldTest3.java"),
71             getGoldenFile("testGroupInitValues_FieldTest3.pass"),
72             getWorkDir()
73         );
74     }
75     
76     /**
77      * Tests group separation
78      */

79     public void testGroupSeparation() throws java.io.IOException JavaDoc, FileStateInvalidException {
80         boolean fail = true;
81         Utility.beginTrans(true);
82         try {
83             Field second = (Field) clazz.getFeatures().remove(3);
84             Field third = (Field) clazz.getFeatures().remove(3);
85             clazz.getFeatures().add(second);
86             clazz.getFeatures().add(third);
87             fail = false;
88         } finally {
89             Utility.endTrans(fail);
90         }
91         assertFile("File is not correctly generated.",
92             Utility.getFile(getDataDir(), "org/netbeans/test/codegen/FieldTest3.java"),
93             getGoldenFile("testGroupSeparation_FieldTest3.pass"),
94             getWorkDir()
95         );
96     }
97     
98     /**
99      * @param args the command line arguments
100      */

101     public static void main(String JavaDoc[] args) {
102         TestRunner.run(suite());
103     }
104     
105 }
106
Popular Tags