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.IOperationElem;
056: import org.netbeans.test.umllib.project.elem.IPackageElem;
057: import org.netbeans.test.umllib.project.elem.VisibilityType;
058: import org.netbeans.test.umllib.project.elem.impl.ArgumentElem;
059: import org.netbeans.test.umllib.project.elem.impl.ClassElem;
060: import org.netbeans.test.umllib.project.elem.impl.DataTypeElem;
061: import org.netbeans.test.umllib.project.elem.impl.OperationElem;
062: import org.netbeans.test.umllib.project.elem.impl.PackageElem;
063: import org.netbeans.test.umllib.project.elem.impl.PrimitiveType;
064: import org.netbeans.test.umllib.project.verifier.TestVerifier;
065: import org.netbeans.test.umllib.project.verifier.elem.ReflectionElementVerifier;
066: import org.netbeans.test.umllib.project.verifier.elem.TextElementVerifier;
067:
068: /**
069: *
070: * @author Alexandr Scherbatiy
071: * @email sunflower@netbeans.org
072: *
073: */
074:
075: public class CodeGenOperationTestCase extends CodeGenerationTestCase {
076:
077: IPackageElem parentPackage = new PackageElem("operations");
078:
079: /** Creates a new instance CodeGenElementsTestCase_1 */
080: public CodeGenOperationTestCase(String name) {
081: super (name);
082: }
083:
084: // =================================================================== //
085: // ====================== Class Element ====================== //
086: // =================================================================== //
087:
088: public void testOperationGeneration() {
089: generateProject(parentPackage.getName());
090: }
091:
092: public IClassElem getExceptionListClass() {
093:
094: IClassElem elem = new ClassElem("Exceptions", parentPackage);
095:
096: // public void exceptionOp () throws Exception
097: IOperationElem op = new OperationElem("exceptionOp",
098: PrimitiveType.VOID, VisibilityType.PUBLIC);
099: op.getExceptionList().add(new DataTypeElem("Exception"));
100: elem.getOperationList().add(op);
101:
102: // public double throwableOp () throws Throwable
103: op = new OperationElem("throwableOp", PrimitiveType.DOUBLE,
104: VisibilityType.PUBLIC);
105: op.getExceptionList().add(new DataTypeElem("Throwable"));
106: elem.getOperationList().add(op);
107:
108: // public String mixedExceptionsOp () throws java.io.IOException, Exception, ClassCastException, java.util.IllegalFormatException
109: op = new OperationElem("mixedExceptionsOp", STRING,
110: VisibilityType.PUBLIC);
111: op.getExceptionList().add(
112: new DataTypeElem("java.io.IOException"));
113: op.getExceptionList().add(new DataTypeElem("Exception"));
114: op.getExceptionList().add(
115: new DataTypeElem("ClassCastException"));
116: op.getExceptionList().add(
117: new DataTypeElem("java.util.IllegalFormatException"));
118: elem.getOperationList().add(op);
119:
120: // public java.io.File ioExceptionsOp (java.io.Reader reader) throws java.io.IOException
121: //op = new OperationElem("ioExceptionsOp", new ClassElem("File", javaIO), VisibilityType.PUBLIC);
122: op = new OperationElem("ioExceptionsOp", new DataTypeElem(
123: "java.io.File"), VisibilityType.PUBLIC);
124: op.getArgumentList().add(
125: new ArgumentElem("reader", new DataTypeElem(
126: "java.io.Reader")));
127: op.getExceptionList().add(
128: new DataTypeElem("java.io.IOException"));
129: elem.getOperationList().add(op);
130:
131: return elem;
132: }
133:
134: public void testOperationExceptionListText() {
135:
136: IClassElem elem = getExceptionListClass();
137:
138: TestVerifier elementVerifier = new TextElementVerifier(
139: getEditorOperator(elem), elem);
140: assertVerification(elementVerifier);
141:
142: }
143:
144: public void testOperationExceptionListClass() {
145: JavaProject javaProject = new JavaProject(getJavaProjectName());
146:
147: IClassElem elem = getExceptionListClass();
148:
149: Class cls = javaProject.getJavaClass(elem.getFullName());
150:
151: ReflectionElementVerifier elementVerifier = new ReflectionElementVerifier(
152: cls, elem);
153: assertVerification(elementVerifier);
154:
155: }
156:
157: }
|