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.netbeans.modules.uml.core.support.umlsupport.XMLManip;
046: import org.netbeans.modules.uml.core.support.umlutils.ETList;
047: import org.netbeans.modules.uml.core.metamodel.core.constructs.IClass;
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
049:
050: /**
051: * Test cases for REClass.
052: */
053: public class REClassTestCase extends AbstractRETestCase {
054: public static void main(String[] args) {
055: junit.textui.TestRunner.run(REClassTestCase.class);
056: }
057:
058: private REClass rec;
059: private IClass c;
060:
061: /* (non-Javadoc)
062: * @see junit.framework.TestCase#setUp()
063: */
064: protected void setUp() throws Exception {
065: super .setUp();
066: rec = new REClass();
067: c = createClass("P");
068:
069: IClass a = createClass("A");
070: IClass b = createClass("B");
071:
072: c.addOwnedElement(a);
073: c.addOwnedElement(b);
074: c.addAttribute(c.createAttribute("int", "a"));
075: c.addAttribute(c.createAttribute("char", "b"));
076: c.setIsAbstract(true);
077:
078: rec.setEventData(c.getNode());
079:
080: Element e = c.getElementNode();
081: element = e;
082:
083: addToken("Package", "cucumber::anemone");
084: Element tds = XMLManip.createElement(e, "TokenDescriptors");
085: Element r = XMLManip.createElement(tds, "TRealization");
086: Element i = XMLManip.createElement(r, "Interface");
087: i.addAttribute("value", "Real");
088: r = XMLManip.createElement(tds, "TGeneralization");
089: i = XMLManip.createElement(r, "SuperClass");
090: i.addAttribute("value", "Unreal");
091: }
092:
093: public void testGetGeneralizations() {
094: IREGeneralization regs = rec.getGeneralizations();
095: assertEquals(1, regs.getCount());
096: assertEquals("Unreal", regs.item(0).getName());
097: }
098:
099: public void testGetRealizations() {
100: assertEquals("Real", rec.getRealizations().item(0).getName());
101: }
102:
103: public void testGetPackage() {
104: IPackage p = createType("Package");
105: p.addOwnedElement(c);
106: assertEquals("cucumber::anemone", rec.getPackage());
107: }
108:
109: public void testGetAllInnerClasses() {
110: ETList<IREClass> cs = rec.getAllInnerClasses();
111: assertEquals(2, cs.size());
112: assertEquals("A", cs.get(0).getName());
113: assertEquals("B", cs.get(1).getName());
114: }
115:
116: public void testGetAttributes() {
117: ETList<IREAttribute> cs = rec.getAttributes();
118: assertEquals(2, cs.size());
119: assertEquals("a", cs.get(0).getName());
120: assertEquals("b", cs.get(1).getName());
121: }
122:
123: public void testGetIsAbstract() {
124: assertTrue(rec.getIsAbstract());
125: }
126:
127: public void testGetIsInterface() {
128: assertFalse(rec.getIsInterface());
129: }
130:
131: public void testGetIsLeaf() {
132: c.setIsAbstract(false);
133: c.setIsLeaf(true);
134: assertTrue(rec.getIsLeaf());
135: }
136:
137: public void testGetOperations() {
138: c.addOperation(c.createOperation("float", "a"));
139: c.addOperation(c.createOperation("double", "b"));
140: ETList<IREOperation> ops = rec.getOperations();
141:
142: // 7 = 4 accessors for the two existing attributes, plus constructor
143: // and the two operations we created above.
144: // assertEquals(7, ops.size());
145: // assertEquals("a", ops.get(5).getName());
146: // assertEquals("b", ops.get(6).getName());
147: // IZ=119824 - conover
148: // something must have changed because there is never any operations
149: // until the above two are added.
150: assertEquals(2, ops.size());
151: assertEquals("a", ops.get(0).getName());
152: assertEquals("b", ops.get(1).getName());
153: }
154: }
|