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.test.uml.cdfs;
043:
044: import org.netbeans.jemmy.TimeoutExpiredException;
045: import org.netbeans.test.uml.cdfs.utils.CDFSUtil;
046: import org.netbeans.jellytools.nodes.Node;
047: import org.netbeans.jellytools.actions.ActionNoBlock;
048: import org.netbeans.jemmy.EventTool;
049: import org.netbeans.jemmy.operators.JPopupMenuOperator;
050: import org.netbeans.junit.NbTestSuite;
051: import org.netbeans.test.umllib.DiagramElementOperator;
052: import org.netbeans.test.umllib.DiagramOperator;
053: import org.netbeans.test.umllib.LinkOperator;
054: import org.netbeans.test.umllib.LinkTypes;
055: import org.netbeans.test.umllib.NewDiagramWizardOperator;
056: import org.netbeans.test.umllib.customelements.LifelineOperator;
057: import org.netbeans.test.umllib.project.JavaProject;
058: import org.netbeans.test.umllib.project.Project;
059: import org.netbeans.test.umllib.project.ProjectType;
060: import org.netbeans.test.umllib.project.UMLProject;
061: import org.netbeans.test.umllib.testcases.UMLTestCase;
062:
063: public class CreateSequenceDiagramTests extends UMLTestCase {
064:
065: private EventTool eventTool = new EventTool();
066:
067: public CreateSequenceDiagramTests(String name) {
068: super (name);
069: }
070:
071: public static NbTestSuite suite() {
072: NbTestSuite suite = new NbTestSuite();
073: suite.addTest(new CreateSequenceDiagramTests(
074: "testCreateSequenceDiagramFromClass"));
075: suite.addTest(new CreateSequenceDiagramTests(
076: "testCreateSQDDiagramFromManyClasses"));
077: suite.addTest(new CreateSequenceDiagramTests(
078: "testCreateSQDDiagramFromOperation"));
079: suite.addTest(new CreateSequenceDiagramTests(
080: "testCreateSQDDiagramFromTwoOperations"));
081: return suite;
082: }
083:
084: /******************const section*************************/
085: private String PROJECT_NAME = "CDFS_uml_Seq";
086: private String EXCEPTION_DLG = "Exception";
087: private String JAVA_PROJECT_NAME = "CDFS_java";
088: private final String PROJECT_PATH = System
089: .getProperty("xtest.workdir");
090: /********************************************************/
091:
092: private static boolean isNotInitialized = true;
093: CDFSUtil util = new CDFSUtil(PROJECT_NAME);
094:
095: public void testCreateSequenceDiagramFromClass() {
096: final String PATH_TO_CLASS = "Model|cdfs|Customer";
097: final String CLASS_NAME = "Customer";
098: final String DIA_NAME = "DGCSQD";
099: util = new CDFSUtil(PROJECT_NAME, this );
100:
101: Node node = util.getNode(PATH_TO_CLASS);
102:
103: util.createDiagram(new Node[] { node },
104: NewDiagramWizardOperator.SEQUENCE_DIAGRAM, DIA_NAME);
105:
106: //checking diagram was opened
107: DiagramOperator dia = new DiagramOperator(DIA_NAME);
108:
109: LifelineOperator line = new LifelineOperator(dia, "",
110: CLASS_NAME);
111:
112: //checking only required elements are present on diagram
113: if (!util.diagramHasExactElements(
114: new DiagramElementOperator[] { line }, dia)) {
115: fail("testCreateSequenceDiagramFromClass verification failed");
116: }
117:
118: //checking a node was created
119: //TODO: add later
120:
121: }
122:
123: public void testCreateSQDDiagramFromManyClasses() {
124: final String PATH_TO_CLASSES = "Model|cdfs|";
125: final String[] classNames = new String[] { "Address",
126: "Customer", "CustomerAccount", "GovermentCustomer" };
127: final String DIA_NAME = "DGAllSQD";
128: util = new CDFSUtil(PROJECT_NAME, this );
129:
130: Node[] nodes = new Node[classNames.length];
131: for (int i = 0; i < classNames.length; i++) {
132: nodes[i] = util.getNode(PATH_TO_CLASSES + classNames[i]);
133: }
134:
135: util.createDiagram(nodes,
136: NewDiagramWizardOperator.SEQUENCE_DIAGRAM, DIA_NAME);
137:
138: //checking diagram was opened
139: DiagramOperator dia = new DiagramOperator(DIA_NAME);
140:
141: DiagramElementOperator[] lines = new DiagramElementOperator[classNames.length];
142: for (int i = 0; i < classNames.length; i++) {
143: lines[i] = new LifelineOperator(dia, "", classNames[i]);
144: }
145:
146: //checking only required elements are present on diagram
147: if (!util.diagramHasExactElements(lines, dia)) {
148: fail("testCreateSQDDiagramFromManyClasses verification failed");
149: }
150:
151: //checking a node was created
152: //TODO: add later
153:
154: }
155:
156: public void testCreateSQDDiagramFromOperation() {
157: final String PATH_TO_OPERATION = "Model|cdfs|Customer|Operations|process";
158: final String DIA_NAME = "DGOPSQD";
159: util = new CDFSUtil(PROJECT_NAME, this );
160:
161: Node node = util.getNode(PATH_TO_OPERATION);
162:
163: util.createDiagram(new Node[] { node },
164: NewDiagramWizardOperator.SEQUENCE_DIAGRAM, DIA_NAME);
165:
166: //checking diagram was opened
167: DiagramOperator dia = new DiagramOperator(DIA_NAME);
168:
169: LifelineOperator lineCust = new LifelineOperator(dia, "self",
170: "Customer");
171: LifelineOperator lineOrder = new LifelineOperator(dia, "ord",
172: "Order");
173: LifelineOperator lineGen = new LifelineOperator(dia, "gen",
174: "IDGenerator");
175:
176: //checking only required elements are present on diagram
177: if (!util.diagramHasExactElements(new DiagramElementOperator[] {
178: lineCust, lineOrder, lineGen }, dia)) {
179: fail("testCreateSQDDiagramFromOperation verification failed");
180: }
181:
182: new LinkOperator(lineCust, lineGen, LinkTypes.MESSAGE, 0);
183: new LinkOperator(lineCust, lineGen, LinkTypes.MESSAGE, 1);
184: new LinkOperator(lineCust, lineOrder, LinkTypes.MESSAGE, 0);
185: new LinkOperator(lineCust, lineOrder, LinkTypes.MESSAGE, 1);
186: new LinkOperator(lineCust, lineOrder, LinkTypes.MESSAGE, 2);
187:
188: //checking a node was created
189: //TODO: add later
190:
191: }
192:
193: public void testCreateSQDDiagramFromTwoOperations() {
194: final String PATH_TO_OPERATION_1 = "Model|cdfs|Customer|Operations|process";
195: final String PATH_TO_OPERATION_2 = "Model|cdfs|Order|setGenerator";
196: final String DIA_NAME = "DG2OPSQD";
197: util = new CDFSUtil(PROJECT_NAME, this );
198:
199: Node node1 = util.getNode(PATH_TO_OPERATION_1);
200: Node node2 = util.getNode(PATH_TO_OPERATION_2);
201:
202: // select the 2 operations
203: util.selectNode(PATH_TO_OPERATION_1);
204: util.selectNode(PATH_TO_OPERATION_2);
205:
206: // popup the menu
207: new ActionNoBlock(null, util.CDFS_MENU)
208: .performPopup(new Node[] { node1, node2 });
209:
210: // verify that the CDFS menu item does not exist for 2 selected operations
211: if (util.isPopupMenuItemExist(new JPopupMenuOperator(),
212: util.CDFS_MENU)) {
213: fail("testCreateSQDDiagramFromTwoOperations: CDFS menu item exists for 2 selected operations");
214: }
215: }
216:
217: protected void setUp() {
218: if (isNotInitialized) {
219: Project.openProject(CDFSUtil.CDFS_XTEST_PROJECT_DIR + "/"
220: + JAVA_PROJECT_NAME);
221: UMLProject.createProject(PROJECT_NAME,
222: ProjectType.UML_JAVA_REVERSE_ENGINEERING,
223: new JavaProject(JAVA_PROJECT_NAME));
224: isNotInitialized = false;
225: }
226: }
227:
228: public void tearDown() {
229: closeAllModal();
230: org.netbeans.test.umllib.util.Utils.tearDown();
231: new EventTool().waitNoEvent(1000);
232:
233: try {
234: DiagramOperator d = new DiagramOperator("DG");
235: d.closeAllDocuments();
236: } catch (TimeoutExpiredException tee) {
237: }
238:
239: new EventTool().waitNoEvent(1000);
240: }
241:
242: }
|