001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * CodeGenElementsTestCase.java
044: *
045: * Created on February 20, 2007, 4:39 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.test.uml.codegen;
052:
053: import org.netbeans.test.umllib.project.JavaProject;
054: import org.netbeans.test.umllib.project.elem.IClassElem;
055: import org.netbeans.test.umllib.project.elem.IPackageElem;
056: import org.netbeans.test.umllib.project.elem.VisibilityType;
057: import org.netbeans.test.umllib.project.elem.impl.AttributeElem;
058: import org.netbeans.test.umllib.project.elem.impl.ClassElem;
059: import org.netbeans.test.umllib.project.elem.impl.PackageElem;
060: import org.netbeans.test.umllib.project.elem.impl.PrimitiveType;
061: import org.netbeans.test.umllib.project.verifier.TestVerifier;
062: import org.netbeans.test.umllib.project.verifier.elem.ReflectionElementVerifier;
063: import org.netbeans.test.umllib.project.verifier.elem.TextElementVerifier;
064:
065: /**
066: *
067: * @author Alexandr Scherbatiy
068: *
069: */
070:
071: public class CodeGenAttributesTestCase extends CodeGenerationTestCase {
072:
073: IPackageElem parentPackage = new PackageElem("attributes");
074:
075: /** Creates a new instance CodeGenElementsTestCase_1 */
076: public CodeGenAttributesTestCase(String name) {
077: super (name);
078: }
079:
080: // =================================================================== //
081: // ====================== Class Element ====================== //
082: // =================================================================== //
083:
084: public void testAttributesGeneration() {
085: generateProject(parentPackage.getName());
086: }
087:
088: public IClassElem getInitializedPrimitiveDataTypes() {
089:
090: IClassElem elem = new ClassElem(
091: "InitializedPrimitiveDataTypes", parentPackage);
092:
093: elem.getAttributeList().add(
094: new AttributeElem("b", PrimitiveType.BYTE,
095: VisibilityType.PRIVATE, "1"));
096: elem.getAttributeList().add(
097: new AttributeElem("s", PrimitiveType.SHORT,
098: VisibilityType.PRIVATE, "10"));
099: elem.getAttributeList().add(
100: new AttributeElem("n", PrimitiveType.INT,
101: VisibilityType.PRIVATE, "Math.max(3,4)"));
102: elem.getAttributeList().add(
103: new AttributeElem("l", PrimitiveType.LONG,
104: VisibilityType.PRIVATE, "100"));
105: elem.getAttributeList().add(
106: new AttributeElem("f", PrimitiveType.FLOAT,
107: VisibilityType.PRIVATE, "1e10f"));
108: elem.getAttributeList().add(
109: new AttributeElem("d", PrimitiveType.DOUBLE,
110: VisibilityType.PRIVATE, "1.0001"));
111: elem.getAttributeList().add(
112: new AttributeElem("flag", PrimitiveType.BOOLEAN,
113: VisibilityType.PRIVATE, "true"));
114: elem.getAttributeList().add(
115: new AttributeElem("c", PrimitiveType.CHAR,
116: VisibilityType.PRIVATE, "'c'"));
117:
118: return elem;
119: }
120:
121: public void testInitializedPrimitiveDataTypesText() {
122:
123: IClassElem elem = getInitializedPrimitiveDataTypes();
124:
125: TestVerifier elementVerifier = new TextElementVerifier(
126: getEditorOperator(elem), elem);
127: assertVerification(elementVerifier);
128:
129: }
130:
131: public void testInitializedPrimitiveDataTypesClass() {
132: JavaProject javaProject = new JavaProject(getJavaProjectName());
133:
134: IClassElem elem = getInitializedPrimitiveDataTypes();
135:
136: Class cls = javaProject.getJavaClass(elem.getFullName());
137:
138: ReflectionElementVerifier elementVerifier = new ReflectionElementVerifier(
139: cls, elem);
140: assertVerification(elementVerifier);
141:
142: }
143:
144: public IClassElem getInitializedObjectDataTypesElem() {
145:
146: IClassElem elem = new ClassElem("InitializedObjectDataTypes",
147: parentPackage);
148:
149: elem.getAttributeList().add(
150: new AttributeElem("str", STRING,
151: VisibilityType.PRIVATE, "\"Hello world!\""));
152: elem.getAttributeList().add(
153: new AttributeElem("obj", OBJECT,
154: VisibilityType.PRIVATE, "new Object()"));
155: elem.getAttributeList().add(
156: new AttributeElem("cls", CLASS, VisibilityType.PRIVATE,
157: "InitializedObjectDataTypes.class"));
158:
159: return elem;
160: }
161:
162: public void testInitializedObjectDataTypesText() {
163:
164: IClassElem elem = getInitializedObjectDataTypesElem();
165:
166: TestVerifier elementVerifier = new TextElementVerifier(
167: getEditorOperator(elem), elem);
168: assertVerification(elementVerifier);
169:
170: }
171:
172: public void testInitializedObjectDataTypesClass() {
173:
174: JavaProject javaProject = new JavaProject(getJavaProjectName());
175:
176: IClassElem elem = getInitializedObjectDataTypesElem();
177:
178: Class cls = javaProject.getJavaClass(elem.getFullName());
179:
180: ReflectionElementVerifier elementVerifier = new ReflectionElementVerifier(
181: cls, elem);
182: assertVerification(elementVerifier);
183:
184: }
185:
186: }
|