KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.PrintStream JavaDoc;
22 import junit.textui.TestRunner;
23 import org.netbeans.jmi.javamodel.codegen.Utility;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.jmi.javamodel.*;
27
28 /**
29  * Test getters of Attribute model element.
30  *
31  * @author Pavel Flaska
32  */

33 public class AnnTypeAttrTest extends NbTestCase {
34
35     private static String JavaDoc[] correctIdentifiers = {
36         "id",
37         "synopsis",
38         "engineer",
39         "date"
40     };
41
42     private static String JavaDoc[] correctDefValuesText = {
43         null,
44         "\"MaM likes M&M's.\"",
45         null,
46         null
47     };
48     
49     private static String JavaDoc[] correctTypeNames = {
50         "int",
51         "String",
52         "String",
53         "String"
54     };
55     
56     private static String JavaDoc[] correctTypes = {
57         "int",
58         "java.lang.String",
59         "java.lang.String",
60         "java.lang.String"
61     };
62     
63     AnnotationType clazz;
64     JavaModelPackage pkg;
65     Attribute[] attribute;
66     
67     /** Creates a new instance of AnnTypeAttrTest */
68     public AnnTypeAttrTest() {
69         super("AnnTypeAttrTest");
70         attribute = new Attribute[4];
71     }
72     
73     public static NbTestSuite suite() {
74         NbTestSuite suite = new NbTestSuite(AnnTypeAttrTest.class);
75         return suite;
76     }
77     
78     protected void setUp() {
79         clazz = (AnnotationType) Utility.findClass("org.netbeans.test.getters.AnnotationType");
80         pkg = (JavaModelPackage) clazz.refImmediatePackage();
81         for (int i = 0; i < 4; i++) {
82             attribute[i] = (Attribute) clazz.getContents().get(i);
83         }
84     }
85     
86     public void testAttributeIdentifier() {
87         PrintStream JavaDoc log = getLog();
88         log.println("Found identifiers:");
89         for (int i = 0; i < 4; i++) {
90             String JavaDoc name = attribute[i].getName();
91             log.println("\t" + name);
92             assertEquals("Identifier differs!", name, correctIdentifiers[i]);
93         }
94     }
95     
96     public void testAttributeDefaultValue() {
97         /*
98         PrintStream log = getLog();
99         log.println("Found default value texts:");
100         for (int i = 0; i < 4; i++) {
101             String defaultValue = ((InitialValueImpl) attribute[i].getDefaultValue()).getSourceText();
102             log.print("\t" + defaultValue);
103             assertEquals("Default values differ!", defaultValue, correctDefValuesText[i]);
104         }
105          */

106     }
107     
108     public void testAttributeDefaultValueText() {
109         PrintStream JavaDoc log = getLog();
110         log.println("Found default value texts:");
111         for (int i = 0; i < 4; i++) {
112             String JavaDoc defaultValueText = attribute[i].getDefaultValueText();
113             log.println("\t" + defaultValueText);
114             assertEquals("Default Values differ!", defaultValueText, correctDefValuesText[i]);
115         }
116     }
117     
118     public void testAttributeType() {
119         PrintStream JavaDoc log = getLog();
120         log.println("Found types:");
121         for (int i = 0; i < 4; i++) {
122             String JavaDoc type = attribute[i].getType().getName();
123             log.println("\t" + type + "; " + correctTypes[i]);
124             assertEquals("Attribute types differ!", type, correctTypes[i]);
125         }
126     }
127     
128     public void testAttributeTypeName() {
129         PrintStream JavaDoc log = getLog();
130         log.println("Found type names:");
131         for (int i = 0; i < 4; i++) {
132             String JavaDoc typeName = attribute[i].getTypeName().getName();
133             log.println("\t" + typeName + "; " + correctTypeNames[i]);
134             assertEquals("Attribute type names differ!", typeName, correctTypeNames[i]);
135         }
136     }
137     
138     public void testAttributeGetType() {
139         boolean fail = true;
140         Utility.beginTrans(true);
141         try {
142             Attribute attr = pkg.getAttribute().createAttribute("newA", null, 0, null, null, null, null, null);
143             Type type = attr.getType();
144             getLog().println("Type is '" + type + "'.");
145             fail = false;
146         }
147         finally {
148             Utility.endTrans(fail);
149         }
150     }
151
152     /**
153      * @param args the command line arguments
154      */

155     public static void main(String JavaDoc[] args) {
156         TestRunner.run(suite());
157     }
158     
159 }
160
Popular Tags