1 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 ; 34 import java.io.IOException ; 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 47 public class GUICMPTest extends JellyTestCase { 48 49 public static final String EJB_PROJECT_NAME = "TestCMP"; 50 public static final String EJB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EJB_PROJECT_NAME; 51 52 public static final String BEAN_NAME = "Customer"; 53 public static final String CMP_FIELD_NAME = "testCMP"; 54 public static final String RETURN_TYPE = "int"; 55 public static final String NEW_GETTER_NAME = "getNewId"; 56 public static final String NEW_G_CMP_NAME = "newId"; 57 public static final String NEW_SETTER_NAME = "setNewLastName"; 58 public static final String NEW_S_CMP_NAME = "newLastName"; 59 60 61 62 public GUICMPTest(String 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 77 public static void main(java.lang.String [] args) { 78 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 { 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 checkFiles("testAddCMPField"); 103 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 { 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"); 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 { 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"); 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 { 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 new JButtonOperator(dialog,org.netbeans.jellytools.Bundle.getStringTrimmed("org.openide.Bundle", "CTL_NEXT")).push(); 171 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"); 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 } 188 } 189 190 public void testCloseProject(){ 191 ProjectSupport.closeProject(EJB_PROJECT_NAME); 192 } 193 194 private void checkFiles(String methodName) throws IOException { 195 Utils utils = new Utils(this); 196 String ddNames[] = { "ejb-jar.xml", "sun-cmp-mappings.xml"}; 197 utils.assertFiles(new File (EJB_PROJECT_PATH + File.separator + "src" + File.separator + "conf"), ddNames, methodName+"_"); 198 199 String classNames[] = { "CustomerBean.java", "CustomerLocalBusiness.java"}; 200 utils.assertFiles(new File (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 } 210 } 211 } 212 | Popular Tags |