KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > cmp > GUICMPTest


1 /*
2 The contents of this file are subject to the terms of the Common Development
3 and Distribution License (the License). You may not use this file except in
4 compliance with the License.
5
6 You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7 or http://www.netbeans.org/cddl.txt.
8
9 When distributing Covered Code, include this CDDL Header Notice in each file
10 and include the License file at http://www.netbeans.org/cddl.txt.
11 If applicable, add the following below the CDDL Header, with the fields
12 enclosed by brackets [] replaced by your own identifying information:
13 "Portions Copyrighted [year] [name of copyright owner]"
14
15 The Original Software is NetBeans. The Initial Developer of the Original
16 Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17 Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.j2ee.cmp;
20
21 import junit.textui.TestRunner;
22 import org.netbeans.jellytools.Bundle;
23 import org.netbeans.jellytools.JellyTestCase;
24 import org.netbeans.jellytools.ProjectsTabOperator;
25 import org.netbeans.jellytools.TopComponentOperator;
26 import org.netbeans.jellytools.nodes.Node;
27 import org.netbeans.jemmy.TimeoutExpiredException;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29 import org.netbeans.jemmy.operators.JComboBoxOperator;
30 import org.netbeans.jemmy.operators.JTextFieldOperator;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.junit.ide.ProjectSupport;
33 import java.io.File JavaDoc;
34 import java.io.IOException JavaDoc;
35 import org.netbeans.jellytools.EditorOperator;
36 import org.netbeans.jellytools.EditorWindowOperator;
37 import org.netbeans.jellytools.NbDialogOperator;
38 import org.netbeans.jellytools.actions.Action;
39 import org.netbeans.jellytools.actions.ActionNoBlock;
40 import org.netbeans.jellytools.actions.OpenAction;
41 import org.netbeans.test.j2ee.lib.Utils;
42
43 /**
44  *
45  * @author blaha
46  */

47 public class GUICMPTest extends JellyTestCase {
48     
49     public static final String JavaDoc EJB_PROJECT_NAME = "TestCMP";
50     public static final String JavaDoc EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME;
51     
52     public static final String JavaDoc BEAN_NAME = "Customer";
53     public static final String JavaDoc CMP_FIELD_NAME = "testCMP";
54     public static final String JavaDoc RETURN_TYPE = "int";
55     public static final String JavaDoc NEW_GETTER_NAME = "getNewId";
56     public static final String JavaDoc NEW_G_CMP_NAME = "newId";
57     public static final String JavaDoc NEW_SETTER_NAME = "setNewLastName";
58     public static final String JavaDoc NEW_S_CMP_NAME = "newLastName";
59     
60     
61     /** Creates a new instance of GUICMPTest */
62     public GUICMPTest(String JavaDoc name) {
63         super(name);
64     }
65     
66     public static NbTestSuite suite() {
67         NbTestSuite suite = new NbTestSuite();
68         suite.addTest(new GUICMPTest("testOpenProjects"));
69         suite.addTest(new GUICMPTest("testAddCMPField"));
70         suite.addTest(new GUICMPTest("testRenameGetterMethod"));
71         suite.addTest(new GUICMPTest("testRenameSetterMethod"));
72         suite.addTest(new GUICMPTest("testDeleteCMPField"));
73         suite.addTest(new GUICMPTest("testCloseProject"));
74         return suite;
75     }
76     /** Use for execution inside IDE */
77     public static void main(java.lang.String JavaDoc[] args) {
78         // run whole suite
79
TestRunner.run(suite());
80     }
81     
82     public void testOpenProjects(){
83         ProjectSupport.openProject(EJB_PROJECT_PATH);
84         ProjectSupport.waitScanFinished();
85         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
86     }
87     
88     public void testAddCMPField() throws Exception JavaDoc{
89        Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
90                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
91                 + "|" + BEAN_NAME);
92        new ActionNoBlock(null,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddActionGroup")
93        + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCmpFieldAction")).perform(node);
94        NbDialogOperator dialog = new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle", "LBL_AddCmpFieldAction"));
95        new JTextFieldOperator(dialog).setText(CMP_FIELD_NAME);
96        new JComboBoxOperator(dialog).selectItem(RETURN_TYPE);
97        dialog.ok();
98        
99        new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
100        //saveProject();
101
checkFiles("testAddCMPField"); //check java files and DD
102

103        //check node in project tab
104
node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
105                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
106                 + "|" + BEAN_NAME + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity.Bundle", "LBL_CMPFields")
107                 + "|" + CMP_FIELD_NAME);
108     }
109     
110     public void testRenameGetterMethod() throws Exception JavaDoc{
111         Node beanNode = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
112                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
113                 + "|" + BEAN_NAME);
114         new OpenAction().performAPI(beanNode);
115         EditorOperator editor = new EditorWindowOperator().getEditor(BEAN_NAME);
116         editor.select(65, 36,40);
117         new ActionNoBlock(null,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Action")
118         + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Rename")).perform(editor);
119         NbDialogOperator dialog = new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Rename"));
120         new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
121         new JTextFieldOperator(dialog).setText(NEW_GETTER_NAME);
122         new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
123         TopComponentOperator refactorWin = new TopComponentOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Refactoring"));
124         new JButtonOperator(refactorWin,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_DoRefactor")).push();
125         
126         editor.close();
127         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
128         checkFiles("testRenameGetterMethod"); //check java files and DD
129
// check Node
130
Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
131                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
132                 + "|" + BEAN_NAME + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity.Bundle", "LBL_CMPFields")
133                 + "|" + NEW_G_CMP_NAME);
134     }
135     
136     public void testRenameSetterMethod() throws Exception JavaDoc{
137         Node beanNode = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
138                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
139                 + "|" + BEAN_NAME);
140         new OpenAction().performAPI(beanNode);
141         EditorOperator editor = new EditorWindowOperator().getEditor(BEAN_NAME);
142         editor.select(69, 26,36);
143         new ActionNoBlock(null,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Action")
144         + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Rename")).perform(editor);
145         NbDialogOperator dialog = new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Rename"));
146         new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
147         new JTextFieldOperator(dialog).setText(NEW_SETTER_NAME);
148         new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
149         TopComponentOperator refactorWin = new TopComponentOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_Refactoring"));
150         new JButtonOperator(refactorWin,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_DoRefactor")).push();
151         
152         editor.close();
153         new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
154         checkFiles("testRenameSetterMethod"); //check java files and DD
155
// check Node
156
Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
157                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
158                 + "|" + BEAN_NAME + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity.Bundle", "LBL_CMPFields")
159                 + "|" + NEW_S_CMP_NAME);
160     }
161     
162     public void testDeleteCMPField() throws Exception JavaDoc{
163         Node node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
164                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
165                 + "|" + BEAN_NAME + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity.Bundle", "LBL_CMPFields")
166                 + "|" + CMP_FIELD_NAME);
167         new ActionNoBlock(null,org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.editor.Bundle", "popup-remove-selection")).perform(node);
168        NbDialogOperator dialog = new NbDialogOperator(org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.refactoring.ui.Bundle", "LBL_SafeDel"));
169        // first panel
170
new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
171        // second panel
172
new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push();
173        
174        new org.netbeans.jemmy.EventTool().waitNoEvent(5000);
175        saveProject();
176        checkFiles("testDeleteCMPField"); //check java files and DD
177
// check Node
178
try{
179            node = new Node(new ProjectsTabOperator().getProjectRootNode(EJB_PROJECT_NAME),
180                 Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbjar.project.ui.Bundle", "LBL_node")
181                 + "|" + BEAN_NAME + "|" + org.netbeans.jellytools.Bundle.getStringTrimmed("org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity.Bundle", "LBL_CMPFields")
182                 + "|" + CMP_FIELD_NAME);
183            fail("Node isn't deleted!");
184   
185        }catch(TimeoutExpiredException timeE){
186            // It's OK, node is deleted
187
}
188     }
189     
190     public void testCloseProject(){
191         ProjectSupport.closeProject(EJB_PROJECT_NAME);
192     }
193     
194     private void checkFiles(String JavaDoc methodName) throws IOException JavaDoc{
195         Utils utils = new Utils(this);
196         String JavaDoc ddNames[] = { "ejb-jar.xml", "sun-cmp-mappings.xml"};
197         utils.assertFiles(new File JavaDoc(EJB_PROJECT_PATH + File.separator + "src" + File.separator + "conf"), ddNames, methodName+"_");
198
199         String JavaDoc classNames[] = { "CustomerBean.java", "CustomerLocalBusiness.java"};
200         utils.assertFiles(new File JavaDoc(EJB_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "cmp"), classNames, methodName+"_");
201     }
202     
203     private void saveProject(){
204         try{
205         Action saveAll = new Action("File|Save All", null);
206         saveAll.perform();
207         }catch(TimeoutExpiredException timeE){
208             // Save All action is disabled
209
}
210     }
211 }
212
Popular Tags