1 19 package org.netbeans.test.jsf; 20 21 import java.awt.event.KeyEvent ; 22 import java.io.IOException ; 23 import java.util.List ; 24 import javax.swing.text.Document ; 25 import org.netbeans.jellytools.JellyTestCase; 26 import org.netbeans.jellytools.NbDialogOperator; 27 import org.netbeans.jellytools.NewFileWizardOperator; 28 import org.netbeans.jellytools.NewProjectWizardOperator; 29 import org.netbeans.jellytools.Bundle; 30 import org.netbeans.jellytools.EditorOperator; 31 import org.netbeans.jellytools.NewWebProjectNameLocationStepOperator; 32 import org.netbeans.jellytools.ProjectsTabOperator; 33 import org.netbeans.jellytools.actions.ActionNoBlock; 34 import org.netbeans.jellytools.actions.Action; 35 import org.netbeans.jellytools.actions.EditAction; 36 import org.netbeans.jellytools.actions.OpenAction; 37 import org.netbeans.jellytools.modules.form.ComponentPaletteOperator; 38 import org.netbeans.jellytools.modules.web.nodes.WebPagesNode; 39 import org.netbeans.jellytools.nodes.SourcePackagesNode; 40 import org.netbeans.jemmy.JemmyProperties; 41 import org.netbeans.jemmy.TimeoutExpiredException; 42 import org.netbeans.jemmy.operators.JTableOperator; 43 import org.netbeans.jellytools.nodes.Node; 44 import org.netbeans.jellytools.nodes.SourcePackagesNode; 45 import org.netbeans.jemmy.operators.JButtonOperator; 46 import org.netbeans.jemmy.operators.JCheckBoxOperator; 47 import org.netbeans.jemmy.operators.JListOperator; 48 import org.netbeans.jemmy.operators.JTreeOperator; 49 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 50 import org.netbeans.junit.NbTestSuite; 51 import org.netbeans.junit.ide.ProjectSupport; 52 import org.netbeans.modules.editor.NbEditorUtilities; 53 61 62 67 public class JsfFunctionalTest extends JellyTestCase{ 68 69 public static final String PROJECT_NAME = "myjsfproject"; 70 public static final String WELCOME_JSP = "welcomeJSF.jsp"; 71 public static final String INDEX_JSP = "index.jsp"; 72 public static final String FROM_ACTION = "FromAction"; 73 public static final String FROM_ACTION1 = "FromAction1"; 74 public static final String FROM_OUTCOME = "FromOutcome"; 75 public static final String DESCRIPTION = "Description"; 76 77 public JsfFunctionalTest(String name) { 78 super(name); 79 } 80 81 public static NbTestSuite suite() { 82 NbTestSuite suite = new NbTestSuite(); 83 suite.addTest(new JsfFunctionalTest("testCreateWebProjectWithJSF")); 84 suite.addTest(new JsfFunctionalTest("testManagedBeanWizard")); 85 suite.addTest(new JsfFunctionalTest("testManagedBeanDelete")); 86 suite.addTest(new JsfFunctionalTest("testAddManagedBean")); 87 suite.addTest(new JsfFunctionalTest("testAddNavigationRule")); 88 suite.addTest(new JsfFunctionalTest("testAddNavigationCase")); 89 suite.addTest(new JsfFunctionalTest("testAddNavigationCaseWithNewRule")); 90 suite.addTest(new JsfFunctionalTest("testAddJSFToProject")); 91 suite.addTest(new JsfFunctionalTest("testJSFPalette")); 92 return suite; 93 } 94 95 public void setUp() { 96 System.out.println("### "+getName()+" ###"); 97 } 98 99 102 public static void main(java.lang.String [] args) { 103 junit.textui.TestRunner.run(suite()); 104 } 105 106 public void testCreateWebProjectWithJSF() throws IOException { 107 String web = Bundle.getStringTrimmed( 109 "org.netbeans.modules.web.core.Bundle", 110 "OpenIDE-Module-Display-Category"); 111 String webApplication = Bundle.getStringTrimmed( 113 "org.netbeans.modules.web.project.ui.wizards.Bundle", 114 "Templates/Project/Web/emptyWeb.xml"); 115 NewProjectWizardOperator nop = NewProjectWizardOperator.invoke(); 116 nop.selectCategory(web); 117 nop.selectProject(webApplication); 118 nop.next(); 119 NewWebProjectNameLocationStepOperator lop = new NewWebProjectNameLocationStepOperator(); 120 lop.setProjectName(PROJECT_NAME); 121 lop.setProjectLocation(getDataDir().getCanonicalPath()); 122 lop.next(); 123 NewProjectWizardOperator frameworkStep = new NewProjectWizardOperator(); 124 new JTableOperator(frameworkStep).selectCell(0, 0);; 126 frameworkStep.finish(); 127 String openingProjectsTitle = Bundle.getString( 129 "org.netbeans.modules.project.ui.Bundle", 130 "LBL_Opening_Projects_Progress"); 131 try { 132 JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000); 134 new NbDialogOperator(openingProjectsTitle).waitClosed(); 135 } catch (TimeoutExpiredException e) { 136 } 138 ProjectSupport.waitScanFinished(); 139 WebPagesNode webPages = new WebPagesNode(PROJECT_NAME); 141 Node welcomeJSF = new Node(webPages, "welcomeJSF.jsp"); 142 new OpenAction().perform(welcomeJSF); 143 new EditorOperator("welcomeJSF.jsp").close(); 144 Node facesconfig = new Node(webPages, "WEB-INF|faces-config.xml"); 145 new OpenAction().perform(facesconfig); 146 new EditorOperator("faces-config.xml"); 148 } 149 150 151 public void testManagedBeanWizard(){ 152 NewFileWizardOperator projectWizard = NewFileWizardOperator.invoke(); 153 String filetype = Bundle.getStringTrimmed( 154 "org/netbeans/modules/web/jsf/resources/Bundle", 155 "Templates/JSP_Servlet/JSFManagedBean.java"); 156 projectWizard.selectCategory("Web"); 157 projectWizard.selectFileType(filetype); 158 projectWizard.next(); 159 NewJSFBeanStepOperator bean = new NewJSFBeanStepOperator(); 160 bean.setClassName("MyManagedBean"); 161 bean.selectScope("session"); 162 bean.cboPackage().getTextField().setText("mypackage"); 163 bean.finish(); 164 new EditorOperator("MyManagedBean.java").close(); 166 EditorOperator facesEditor = new EditorOperator("faces-config.xml"); 167 String expected = "<managed-bean>"; 168 assertTrue("faces-config.xml should contain "+expected, facesEditor.contains(expected)); 169 expected = "<managed-bean-name>MyManagedBean</managed-bean-name>"; 170 assertTrue("faces-config.xml should contain "+expected, facesEditor.contains(expected)); 171 expected = "<managed-bean-class>mypackage.MyManagedBean</managed-bean-class>"; 172 assertTrue("faces-config.xml should contain "+expected, facesEditor.contains(expected)); 173 expected = "<managed-bean-scope>session</managed-bean-scope>"; 174 assertTrue("faces-config.xml should contain "+expected, facesEditor.contains(expected)); 175 176 186 } 187 188 189 public void testManagedBeanDelete() { 190 Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "mypackage|MyManagedBean.java"); 191 new ActionNoBlock(null, "Refactor|Safely Delete...").perform(node); 192 NbDialogOperator safeDeleteDialog = new NbDialogOperator("Safe Delete"); 193 new JButtonOperator(safeDeleteDialog, "Refactor").push(); 194 node.waitNotPresent(); 195 EditorOperator facesEditor = new EditorOperator("faces-config.xml"); 197 202 } 205 206 207 public void testAddManagedBean(){ 208 EditorOperator editor = new EditorOperator("faces-config.xml"); 209 Action addBeanAction = new ActionNoBlock(null, "JavaServer Faces|Add Managed Bean..."); 210 addBeanAction.perform(editor); 211 AddManagedBeanOperator addBeanOper = new AddManagedBeanOperator(); 212 addBeanOper.setBeanName("SecondBean"); 213 addBeanOper.setBeanClass("mypackage.MyManagedBean"); 214 addBeanOper.selectScope("application"); 215 addBeanOper.setBeanDescription(DESCRIPTION); 216 addBeanOper.add(); 217 232 } 233 234 235 public void testAddNavigationRule() throws IOException { 236 EditorOperator editor = new EditorOperator("faces-config.xml"); 237 Action addRule = new ActionNoBlock(null, "JavaServer Faces|Add Navigation Rule..."); 238 addRule.perform(editor); 239 AddNavigationRuleDialogOperator rule = new AddNavigationRuleDialogOperator(); 240 rule.setRuleFromView("/"+WELCOME_JSP); 241 rule.setRuleDescription(DESCRIPTION); 242 rule.add(); 243 editor.save(); 244 Document document = editor.txtEditorPane().getDocument(); 246 254 } 255 256 257 public void testAddNavigationCase() throws IOException { 258 EditorOperator editor = new EditorOperator("faces-config.xml"); 259 Action addCase = new ActionNoBlock(null, "JavaServer Faces|Add Navigation Case..."); 260 addCase.perform(editor); 261 AddNavigationCaseDialogOperator caseOper = new AddNavigationCaseDialogOperator(); 262 caseOper.selectFromView("/"+WELCOME_JSP); 263 caseOper.selectToView("/"+WELCOME_JSP); 264 caseOper.setFromAction(FROM_ACTION); 265 caseOper.setFromOutcome(FROM_OUTCOME); 266 caseOper.setRuleDescription(DESCRIPTION); 267 caseOper.add(); 268 editor.save(); 269 Document document = editor.txtEditorPane().getDocument(); 271 281 } 284 285 286 public void testAddNavigationCaseWithNewRule() throws IOException { 287 EditorOperator editor = new EditorOperator("faces-config.xml"); 288 Action addCase = new ActionNoBlock(null, "JavaServer Faces|Add Navigation Case..."); 289 addCase.perform(editor); 290 AddNavigationCaseDialogOperator caseOper = new AddNavigationCaseDialogOperator(); 291 caseOper.cboFromView().getTextField().setText("/"+INDEX_JSP); 292 caseOper.setFromAction(FROM_ACTION); 293 caseOper.setFromOutcome(FROM_OUTCOME); 294 caseOper.setRuleDescription(DESCRIPTION); 295 caseOper.checkRedirect(true); 296 caseOper.cboToView().getTextField().setText("/"+INDEX_JSP); 297 caseOper.add(); 298 editor.save(); 299 Document document = editor.txtEditorPane().getDocument(); 301 312 } 315 316 317 public void testAddJSFToProject() throws IOException { 318 String web = Bundle.getStringTrimmed( 320 "org.netbeans.modules.web.core.Bundle", 321 "OpenIDE-Module-Display-Category"); 322 String webApplication = Bundle.getStringTrimmed( 324 "org.netbeans.modules.web.project.ui.wizards.Bundle", 325 "Templates/Project/Web/emptyWeb.xml"); 326 NewProjectWizardOperator nop = NewProjectWizardOperator.invoke(); 327 nop.selectCategory(web); 328 nop.selectProject(webApplication); 329 nop.next(); 330 NewWebProjectNameLocationStepOperator lop = new NewWebProjectNameLocationStepOperator(); 331 lop.setProjectName(PROJECT_NAME+"2"); 332 lop.setProjectLocation(getDataDir().getCanonicalPath()); 333 lop.finish(); 334 String openingProjectsTitle = Bundle.getString( 336 "org.netbeans.modules.project.ui.Bundle", 337 "LBL_Opening_Projects_Progress"); 338 try { 339 JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000); 341 new NbDialogOperator(openingProjectsTitle).waitClosed(); 342 } catch (TimeoutExpiredException e) { 343 } 345 346 ProjectsTabOperator.invoke().getProjectRootNode(PROJECT_NAME+"2").properties(); 349 String projectPropertiesTitle = Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.customizer.Bundle", "LBL_Customizer_Title"); 351 NbDialogOperator propertiesDialogOper = new NbDialogOperator(projectPropertiesTitle); 352 new Node(new JTreeOperator(propertiesDialogOper), "Frameworks").select(); 354 new JButtonOperator(propertiesDialogOper, "Add").pushNoBlock(); 355 NbDialogOperator addFrameworkOper = new NbDialogOperator("Add a Framework"); 356 new JListOperator(addFrameworkOper).selectItem("JSF"); 358 addFrameworkOper.ok(); 359 new JCheckBoxOperator(propertiesDialogOper, "Validate XML").setSelected(false); 360 new JCheckBoxOperator(propertiesDialogOper, "Verify Objects").setSelected(true); 361 propertiesDialogOper.ok(); 363 364 WebPagesNode webPages = new WebPagesNode(PROJECT_NAME+"2"); 366 Node welcomeJSF = new Node(webPages, "welcomeJSF.jsp"); 367 Node facesconfig = new Node(webPages, "WEB-INF|faces-config.xml"); 368 webPages.setComparator(new DefaultStringComparator(true, true)); 369 Node webXML = new Node(webPages, "WEB-INF|web.xml"); 370 new EditAction().performAPI(webXML); 371 EditorOperator webXMLEditor = new EditorOperator("web.xml"); 372 webXMLEditor.select("validateXml"); 373 assertTrue("Validate XML should be false.", webXMLEditor.getText(webXMLEditor.getLineNumber()+1).indexOf("false") > -1); 374 webXMLEditor.select("verifyObjects"); 375 assertTrue("Verify Objects should be true.", webXMLEditor.getText(webXMLEditor.getLineNumber()+1).indexOf("true") > -1); 376 webXMLEditor.close(); 377 } 378 379 380 public void testJSFPalette() { 381 EditorOperator editorOper = new EditorOperator(INDEX_JSP); 382 ComponentPaletteOperator paletteOper = new ComponentPaletteOperator(); 383 JCheckBoxOperator htmlCategoryOper = new JCheckBoxOperator(paletteOper, "HTML"); 385 if(htmlCategoryOper.isSelected()) { 386 htmlCategoryOper.push(); 387 } 388 JCheckBoxOperator jsfCategoryOper = new JCheckBoxOperator(paletteOper, "JSF"); 390 if(!jsfCategoryOper.isSelected()) { 391 jsfCategoryOper.push(); 392 } 393 paletteOper.selectComponent("JSF Form"); 394 paletteOper.pushKey(KeyEvent.VK_ENTER); 395 new NbDialogOperator("Insert JSF Form").ok(); 396 String expected = "<f:view>"; 397 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 398 expected = "<h:form>"; 399 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 400 expected = "</h:form>"; 401 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 402 expected = "</f:view>"; 403 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 404 405 paletteOper.selectComponent("JSF Data Table"); 406 paletteOper.pushKey(KeyEvent.VK_ENTER); 407 new NbDialogOperator("Insert JSF Data Table").ok(); 408 expected = "<h:dataTable value=\"#{arrayOrCollectionOf}\" var=\"item\">"; 409 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 410 expected = "</h:dataTable>"; 411 assertTrue("index.jsp should contain "+expected+".", editorOper.contains(expected)); 412 } 413 } 414 | Popular Tags |