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