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.ProjectType;
055: import org.netbeans.test.umllib.project.UMLProject;
056: import org.netbeans.test.umllib.project.elem.IArgumentElem;
057: import org.netbeans.test.umllib.project.elem.IClassElem;
058: import org.netbeans.test.umllib.project.elem.IPackageElem;
059: import org.netbeans.test.umllib.project.elem.VisibilityType;
060: import org.netbeans.test.umllib.project.elem.impl.ArgumentElem;
061: import org.netbeans.test.umllib.project.elem.impl.AttributeElem;
062: import org.netbeans.test.umllib.project.elem.impl.ClassElem;
063: import org.netbeans.test.umllib.project.elem.impl.OperationElem;
064: import org.netbeans.test.umllib.project.elem.impl.PackageElem;
065: import org.netbeans.test.umllib.project.elem.impl.PrimitiveType;
066: import org.netbeans.jellytools.nodes.Node;
067: import org.netbeans.test.umllib.project.elem.IInterfaceElem;
068: import org.netbeans.test.umllib.project.elem.ModifierType;
069: import org.netbeans.test.umllib.project.elem.impl.InterfaceElem;
070: import org.netbeans.test.umllib.project.verifier.elem.ReflectionElementVerifier;
071: import org.netbeans.test.umllib.project.verifier.elem.TextElementVerifier;
072:
073: /**
074: *
075: * @author Alexandr Scherbatiy
076: */
077:
078: public class CodeGenElementsTestCase extends CodeGenerationTestCase {
079:
080: /** Creates a new instance of GenCodeLinksTestCase */
081: public CodeGenElementsTestCase(String name) {
082: super (name);
083: }
084:
085: //*
086:
087: // =================================================================== //
088: // ====================== Class Element ====================== //
089: // =================================================================== //
090:
091: public void testClassElementGeneration() {
092:
093: JavaProject javaProject = JavaProject.createProject(
094: getNextJavaProjectName(), ProjectType.JAVA_APPLICATION,
095: true, false);
096: UMLProject umlProject = new UMLProject(UML_PROJECT_NAME,
097: ProjectType.UML_JAVA_PLATFORM_MODEL);
098:
099: Node umlNode = new Node(umlProject.getProjectNode(),
100: "Model|elements|pclass");
101: umlProject.generateCode(umlNode, javaProject);
102:
103: compileJavaProject(getJavaProjectName());
104:
105: }
106:
107: public IClassElem getClassElem() {
108:
109: IPackageElem elementPackage = new PackageElem("elements");
110: IPackageElem pack = new PackageElem("pclass", elementPackage);
111:
112: IClassElem elem = new ClassElem("Class1", pack);
113:
114: elem.getAttributeList().add(
115: new AttributeElem("attribute1", OBJECT,
116: VisibilityType.PRIVATE));
117:
118: elem.getOperationList().add(
119: new OperationElem("getAttribute1", OBJECT,
120: VisibilityType.PUBLIC));
121: elem.getOperationList().add(
122: new OperationElem("setAttribute1", PrimitiveType.VOID,
123: VisibilityType.PUBLIC,
124: new IArgumentElem[] { new ArgumentElem("val",
125: OBJECT) }));
126: elem.getOperationList().add(
127: new OperationElem("operation1", STRING,
128: VisibilityType.PUBLIC));
129:
130: return elem;
131: }
132:
133: public void testClassElementText() {
134:
135: IClassElem elem = getClassElem();
136:
137: assertVerification(new TextElementVerifier(
138: getEditorOperator(elem), elem));
139:
140: }
141:
142: public void testClassElementClass() {
143: JavaProject javaProject = new JavaProject(getJavaProjectName());
144:
145: IClassElem elem = getClassElem();
146:
147: Class cls = javaProject.getJavaClass(elem.getFullName());
148:
149: assertVerification(new ReflectionElementVerifier(cls, elem));
150:
151: }
152:
153: //*/
154:
155: // =================================================================== //
156: // ====================== Interface Element ====================== //
157: // =================================================================== //
158:
159: public void testInterfaceElementGeneration() {
160:
161: JavaProject javaProject = JavaProject.createProject(
162: getNextJavaProjectName(), ProjectType.JAVA_APPLICATION,
163: true, false);
164: UMLProject umlProject = new UMLProject(UML_PROJECT_NAME,
165: ProjectType.UML_JAVA_PLATFORM_MODEL);
166:
167: Node umlNode = new Node(umlProject.getProjectNode(),
168: "Model|elements|pinterface");
169: umlProject.generateCode(umlNode, javaProject);
170:
171: compileJavaProject(getJavaProjectName(), 82262);
172:
173: }
174:
175: public IInterfaceElem getInterfaceElem() {
176:
177: IPackageElem elementPackage = new PackageElem("elements");
178: IPackageElem pack = new PackageElem("pinterface",
179: elementPackage);
180:
181: IInterfaceElem elem = new InterfaceElem("Interface1", pack);
182:
183: elem.getAttributeList().add(
184: new AttributeElem("CONST1", PrimitiveType.INT,
185: VisibilityType.PUBLIC,
186: new ModifierType[] { ModifierType.STATIC,
187: ModifierType.FINAL }, "1"));
188:
189: elem.getOperationList().add(
190: new OperationElem("op1", PrimitiveType.VOID,
191: VisibilityType.PUBLIC));
192:
193: return elem;
194: }
195:
196: public void testInterfaceElementText() {
197:
198: IInterfaceElem elem = getInterfaceElem();
199:
200: assertVerification(new TextElementVerifier(
201: getEditorOperator(elem), elem));
202:
203: }
204:
205: public void testInterfaceElementClass() {
206: JavaProject javaProject = new JavaProject(getJavaProjectName());
207:
208: IInterfaceElem elem = getInterfaceElem();
209:
210: Class cls = javaProject.getJavaClass(elem.getFullName());
211:
212: assertVerification(new ReflectionElementVerifier(cls, elem));
213:
214: }
215:
216: //*/
217:
218: }
|