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: package org.netbeans.modules.uml.core.reverseengineering.reframework;
043:
044: import org.dom4j.Element;
045: import org.dom4j.Node;
046:
047: import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.BaseElement;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.IMultiplicity;
050: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
051: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IParameter;
052: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IStructuralFeature;
053: import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
054: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
055: import org.netbeans.modules.uml.core.support.umlutils.ETList;
056:
057: /**
058: * Test cases for REOperation.
059: */
060: public class REOperationTestCase extends AbstractRETestCase {
061: public static void main(String[] args) {
062: junit.textui.TestRunner.run(REOperationTestCase.class);
063: }
064:
065: private REOperation reo;
066: private IOperation op;
067:
068: /* (non-Javadoc)
069: * @see junit.framework.TestCase#setUp()
070: */
071: protected void setUp() throws Exception {
072: super .setUp();
073: reo = new REOperation();
074:
075: IClass c = createClass("Clazz");
076: op = c.createOperation("int", "walter");
077: c.addOperation(op);
078: op.addParameter(op.createParameter("int", "dyke"));
079: op.addParameter(op.createParameter("char", "seebeck"));
080: op.setReturnType2("int");
081:
082: op.getParameters().get(0).getElementNode().addAttribute("type",
083: "int");
084: op.getParameters().get(1).getElementNode().addAttribute("type",
085: "char");
086: op.getParameters().get(2).getElementNode().addAttribute("type",
087: "int");
088:
089: element = op.getReturnType().getElementNode();
090: addToken("IsPrimitive", "true");
091:
092: op.setConcurrency(BaseElement.CCK_GUARDED);
093:
094: reo.setEventData(op.getElementNode());
095:
096: element = op.getElementNode();
097: Element o = (Element) element
098: .selectSingleNode("UML:Element.ownedElement");
099: Element exc = XMLManip.createElement(o, "UML:Exception");
100: exc.addAttribute("name", "IOException");
101:
102: IStructuralFeature feat = createType("NavigableEnd");
103: IMultiplicity mul = createType("Multiplicity");
104: mul.setRangeThroughString("[0..2]");
105: feat.setMultiplicity(mul);
106:
107: Node n = feat.getElementNode().selectSingleNode(
108: "UML:TypedElement.multiplicity");
109: n.detach();
110: element.add(n);
111: }
112:
113: public void testClone() {
114: IClass x = createClass("X");
115: IOperation o = reo.clone(x);
116: assertEquals("walter", o.getName());
117: assertEquals("int", o.getReturnType2());
118:
119: ETList<IParameter> pars = o.getParameters();
120: assertEquals(3, pars.size());
121: assertEquals("dyke", pars.get(1).getName());
122: assertEquals("seebeck", pars.get(2).getName());
123: }
124:
125: public void testGetConcurrency() {
126: assertEquals(BaseElement.CCK_GUARDED, reo.getConcurrency());
127: }
128:
129: public void testGetIsAbstract() {
130: op.setIsAbstract(true);
131: assertTrue(reo.getIsAbstract());
132: }
133:
134: public void testGetIsConstructor() {
135: op.setIsConstructor(true);
136: assertTrue(reo.getIsConstructor());
137: }
138:
139: public void testGetIsNative() {
140: op.setIsNative(true);
141: assertTrue(reo.getIsNative());
142: }
143:
144: public void testGetIsPrimitive() {
145: assertTrue(reo.getIsPrimitive());
146: }
147:
148: public void testGetIsStrictFP() {
149: op.setIsStrictFP(true);
150: assertTrue(reo.getIsStrictFP());
151: }
152:
153: public void testGetMultiplicity() {
154: ETList<IREMultiplicityRange> ranges = reo.getMultiplicity();
155: assertEquals(1, ranges.size());
156: IREMultiplicityRange r = ranges.get(0);
157: assertEquals("0", r.getLower());
158: assertEquals("2", r.getUpper());
159: }
160:
161: public void testGetParameters() {
162: ETList<IREParameter> pars = reo.getParameters();
163: assertEquals(3, pars.size());
164: assertEquals("dyke", pars.get(1).getName());
165: assertEquals("seebeck", pars.get(2).getName());
166: }
167:
168: public void testGetRaisedExceptions() {
169: IStrings s = reo.getRaisedExceptions();
170: assertEquals(1, s.getCount());
171: assertEquals("IOException", s.get(0));
172: }
173: }
|