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.test.uml.cdfs.utils.CDFSUtil;
045: import org.netbeans.jellytools.nodes.Node;
046: import org.netbeans.jemmy.EventTool;
047: import org.netbeans.jemmy.TimeoutExpiredException;
048: import org.netbeans.junit.NbTestSuite;
049: import org.netbeans.test.umllib.DiagramElementOperator;
050: import org.netbeans.test.umllib.DiagramOperator;
051: import org.netbeans.test.umllib.NewDiagramWizardOperator;
052: import org.netbeans.test.umllib.customelements.LifelineOperator;
053: import org.netbeans.test.umllib.project.JavaProject;
054: import org.netbeans.test.umllib.project.Project;
055: import org.netbeans.test.umllib.project.ProjectType;
056: import org.netbeans.test.umllib.project.UMLProject;
057: import org.netbeans.test.umllib.testcases.UMLTestCase;
058:
059: public class CreateCollaborationDiagramTests extends UMLTestCase {
060:
061: private EventTool eventTool = new EventTool();
062:
063: public CreateCollaborationDiagramTests(String name) {
064: super (name);
065: }
066:
067: public static NbTestSuite suite() {
068: NbTestSuite suite = new NbTestSuite(
069: CreateCollaborationDiagramTests.class);
070: return suite;
071: }
072:
073: /******************const section*************************/
074: private String PROJECT_NAME = "CDFS_uml_Collab";
075: private String EXCEPTION_DLG = "Exception";
076: private String JAVA_PROJECT_NAME = "CDFS_java";
077: private final String PROJECT_PATH = System
078: .getProperty("xtest.workdir");
079: /********************************************************/
080:
081: private static boolean isNotInitialized = true;
082: CDFSUtil util = new CDFSUtil(PROJECT_NAME);
083:
084: public void testCreateCollaborationDiagramFromClass() {
085: final String PATH_TO_CLASS = "Model|cdfs|Customer";
086: final String CLASS_NAME = "Customer";
087: final String DIA_NAME = "DGCCLD";
088: util = new CDFSUtil(PROJECT_NAME, this );
089:
090: Node node = util.getNode(PATH_TO_CLASS);
091:
092: util.createDiagram(new Node[] { node },
093: NewDiagramWizardOperator.COLLABORATION_DIAGRAM,
094: DIA_NAME);
095:
096: //checking diagram was opened
097: DiagramOperator dia = new DiagramOperator(DIA_NAME);
098:
099: LifelineOperator line = new LifelineOperator(dia, "",
100: CLASS_NAME);
101:
102: //checking only required elements are present on diagram
103: if (!util.diagramHasExactElements(
104: new DiagramElementOperator[] { line }, dia)) {
105: fail("testCreateCollaborationDiagramFromClass verification failed");
106: }
107:
108: //checking a node was created
109: //TODO: add later
110:
111: }
112:
113: public void testCreateCollaborationDiagramFromManyClasses() {
114: final String PATH_TO_CLASSES = "Model|cdfs|";
115: final String[] classNames = new String[] { "Address",
116: "Customer", "CustomerAccount", "GovermentCustomer" };
117: final String DIA_NAME = "DGAllSQD";
118: util = new CDFSUtil(PROJECT_NAME, this );
119:
120: Node[] nodes = new Node[classNames.length];
121: for (int i = 0; i < classNames.length; i++) {
122: nodes[i] = util.getNode(PATH_TO_CLASSES + classNames[i]);
123: }
124:
125: util.createDiagram(nodes,
126: NewDiagramWizardOperator.COLLABORATION_DIAGRAM,
127: DIA_NAME);
128:
129: //checking diagram was opened
130: DiagramOperator dia = new DiagramOperator(DIA_NAME);
131:
132: DiagramElementOperator[] lines = new DiagramElementOperator[classNames.length];
133: for (int i = 0; i < classNames.length; i++) {
134: lines[i] = new LifelineOperator(dia, "", classNames[i]);
135: }
136:
137: //checking only required elements are present on diagram
138: if (!util.diagramHasExactElements(lines, dia)) {
139: fail("testCreateCollaborationDiagramFromManyClasses verification failed");
140: }
141:
142: //checking a node was created
143: //TODO: add later
144:
145: }
146:
147: public void testCreateCollaborationDiagramFromOperation() {
148: final String PATH_TO_OPER = "Model|cdfs|Customer|Operations|getAddresses";
149: final String DIA_NAME = "DGOper";
150: util = new CDFSUtil(PROJECT_NAME, this );
151:
152: Node node = util.getNode(PATH_TO_OPER);
153:
154: util.createDiagram(new Node[] { node },
155: NewDiagramWizardOperator.COLLABORATION_DIAGRAM,
156: DIA_NAME);
157:
158: //checking diagram was opened
159: DiagramOperator dia = new DiagramOperator(DIA_NAME);
160:
161: DiagramElementOperator[] lines = new DiagramElementOperator[] {
162: new LifelineOperator(dia, "addresses", "Address"),
163: new LifelineOperator(dia, "self", "Customer") };
164:
165: //checking only required elements are present on diagram
166: if (!util.diagramHasExactElements(lines, dia)) {
167: fail("testCreateCollaborationDiagramFromOperation verification failed");
168: }
169:
170: }
171:
172: protected void setUp() {
173: if (isNotInitialized) {
174: Project.openProject(CDFSUtil.CDFS_XTEST_PROJECT_DIR + "/"
175: + JAVA_PROJECT_NAME);
176: UMLProject.createProject(PROJECT_NAME,
177: ProjectType.UML_JAVA_REVERSE_ENGINEERING,
178: new JavaProject(JAVA_PROJECT_NAME));
179: isNotInitialized = false;
180: }
181: }
182:
183: public void tearDown() {
184: closeAllModal();
185: org.netbeans.test.umllib.util.Utils.tearDown();
186: new EventTool().waitNoEvent(1000);
187:
188: try {
189: DiagramOperator d = new DiagramOperator("DG");
190: d.closeAllDocuments();
191: } catch (TimeoutExpiredException tee) {
192: }
193:
194: new EventTool().waitNoEvent(1000);
195: }
196:
197: }
|