|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.test.gui.web.servletexec.servlet23.filters.creation;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.JavaNode;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.ChooseTemplateStepOperator;
import org.netbeans.jellytools.TargetLocationStepOperator;
import org.netbeans.jellytools.NewObjectNameStepOperator;
import org.netbeans.jellytools.NewWizardOperator;
import org.netbeans.jellytools.EditorWindowOperator;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.NbDialogOperator;
import org.netbeans.jellytools.actions.NewTemplateAction;
import org.netbeans.test.gui.web.util.RepositoryNodeWaitable;
import org.netbeans.test.gui.web.util.EditorPageWaitable;
import org.netbeans.jemmy.Timeouts;
import org.netbeans.jemmy.Waitable;
import org.netbeans.jemmy.Waiter;
import org.netbeans.junit.NbTestSuite;
//NB import
import org.netbeans.web.test.util.Utils;
public class FiltersCreation extends JellyTestCase{
private static String newSimpleFilterMenuPath = null;
private static String newAdvancedFilterMenuPath = null;
private static String simpleFilterTreePath = null;
private static String advancedFilterTreePath = null;
private static String filterTreePath = null;
private static String compileFilterMenuPath = "Compile";
private static String wmName = "wm1";
private static String webInf = "WEB-INF";
private static String classes = "Classes";
private static String popupDefaultPackage = "filters|creation";
private static String mainDefaultPackage = "filters|creationMain";
private static String existing = "existing";
private static String nonexisting = "nonexisting";
private static String fSep = System.getProperty("file.separator");
private static String iSep = "|";
private static String workDir = null;
private static String webModule = null;
private static String pkg = null;
private static String pkgMain = null;
private static boolean first = true;
private static String afWizard = null;
private static String sfWizard = null;
private static String advancedFilterViaMain = "AdvancvedFilterViaMainMenu";
private static String simpleFilterViaMain = "SimpleFilterViaMainMenu";
private static String simpleFilterViaPopup = "SimpleFilterViaPopup";
private static String advancedFilterViaPopup = "AdvancvedFilterViaPopup";
private static String simplePopularFilter = "SimplePopularFilter";
private static String advancedPopularFilter = "AdvancvedPopularFilter";
private static String jspServlet = null;
private static String servlet = null;
private static String filters = null;
private static String sfName = null;
private static String afName = null;
public FiltersCreation(String testName) {
super(testName);
}
/** Use for execution inside IDE */
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
public static junit.framework.Test suite() {
workDir = System.getProperty("servletexec.workdir").replace('/', fSep.charAt(0));
webModule = workDir + fSep + wmName;
pkg = webModule + iSep + webInf + iSep + classes + iSep + popupDefaultPackage;
pkgMain = webModule + iSep + webInf + iSep + classes + iSep + mainDefaultPackage;
simpleFilterTreePath = jspServlet + iSep + filters + iSep + sfName;
advancedFilterTreePath = jspServlet + iSep + filters + iSep + afName;
newSimpleFilterMenuPath = "New" + iSep + simpleFilterTreePath;
newAdvancedFilterMenuPath = "New" + iSep + advancedFilterTreePath;
afWizard = "New Wizard - " + afName;
sfWizard = "New Wizard - " + sfName;
String wmc = System.getProperty("servletexec.mountcount");
int count = 0;
if(wmc != null) {
count = new Integer(wmc).intValue();
}
if(first) {
while(count >0) {
Utils.handleDialogAfterNewWebModule();
count--;
}
first = false;
}
Timeouts.initDefault("JMenuOperator.PushMenuTimeout",60000);
Timeouts.initDefault("ComponentOperator.WaitComponentTimeout",10000);
return new NbTestSuite(FiltersCreation.class);
}
/* Tests section */
public void testSimpleFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(simpleFilterViaMain);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + simpleFilterViaMain);
}
public void testAdvancedFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(advancedFilterViaMain);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + advancedFilterViaMain);
}
public void testSameNameSimpleFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(simplePopularFilter);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + simplePopularFilter);
node1.select();
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(simplePopularFilter);
if(wizard.btFinish().isEnabled()) {
wizard.cancel();
fail("Finish button isn't disabled, if SimpleFilter with same name already exist");
}
wizard.cancel();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
}
public void testSameNameAdvancedFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(advancedPopularFilter);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + advancedPopularFilter);
node1.select();
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
new TargetLocationStepOperator().setName(advancedPopularFilter);
if(wizard.btFinish().isEnabled()) {
wizard.cancel();
fail("Finish button isn't disabled, if AdvancedFilter with same name already exist");
}
wizard.cancel();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
}
public void testDefaultNameSimpleFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + "SimpleFilter");
}
public void testDefaultNameAdvancedFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + "AdvancedFilter");
}
public void testSecondDefaultNameSimpleFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new JavaNode(pkgMain + iSep + "SimpleFilter");
}catch(Exception e1) {
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
wizard.finish();
checkResultOfFilterCreation(pkgMain + iSep + "SimpleFilter");
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
}
node1.select();
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(simpleFilterTreePath);
wizard.next();
wizard.finish();
}catch(Exception e3) {
wizard.cancel();
e3.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + "SimpleFilter_1");
}
public void testSecondDefaultNameAdvancedFilterViaMain() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkgMain);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
new JavaNode(pkgMain + iSep + "AdvancedFilter");
}catch(Exception e1) {
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
wizard.finish();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + "AdvancedFilter");
}
node1.select();
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(advancedFilterTreePath);
wizard.next();
wizard.finish();
}catch(Exception e3) {
wizard.cancel();
e3.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkgMain + iSep + "AdvancedFilter_1");
}
//PopupSection
/*-------------------------------------------*/
public void testSimpleFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(simpleFilterTreePath);
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(simpleFilterViaPopup);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + simpleFilterViaPopup);
}
public void testAdvancedFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(advancedFilterTreePath);
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(advancedFilterViaPopup);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + advancedFilterViaPopup);
}
public void testSameNameSimpleFilterViaPopup() {
NewWizardOperator wizard = null;
FilesystemNode node1 = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(simpleFilterTreePath);
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(simplePopularFilter);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + simplePopularFilter);
try {
node1.select();
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(simplePopularFilter);
if(wizard.btFinish().isEnabled()) {
wizard.cancel();
fail("Finish button isn't disabled, if SimpleFilter with same name already exist");
}
wizard.cancel();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
}
public void testSameNameAdvancedFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(advancedFilterTreePath);
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(advancedPopularFilter);
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + advancedPopularFilter);
try {
node1.select();
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
new NewObjectNameStepOperator().setName(advancedPopularFilter);
if(wizard.btFinish().isEnabled()) {
wizard.cancel();
fail("Finish button isn't disabled, if AdvancedFilter with same name already exist");
}
wizard.cancel();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
}
public void testDefaultNameSimpleFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(simpleFilterTreePath);
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "SimpleFilter");
}
public void testDefaultNameAdvancedFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
try {
createPopup(advancedFilterTreePath);
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "AdvancedFilter");
}
public void testSecondDefaultNameSimpleFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
createPopup(simpleFilterTreePath);
try {
new JavaNode(pkg + iSep + "SimpleFilter");
}catch(Exception e) {
try {
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "SimpleFilter");
}
try {
node1.select();
node1.newFromTemplate(sfName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "SimpleFilter_1");
}
public void testSecondDefaultNameAdvancedFilterViaPopup() {
FilesystemNode node1 = null;
NewWizardOperator wizard = null;
try {
node1 = new FilesystemNode(pkg);
node1.select();
}catch(Exception e) {
e.printStackTrace();
fail("Please check, that all mounts are done properly");
}
createPopup(advancedFilterTreePath);
try {
new JavaNode(pkg + iSep + "AdvancedFilter");
}catch(Exception e) {
try {
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e1) {
wizard.cancel();
e1.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "AdvancedFilter");
}
try {
node1.select();
node1.newFromTemplate(afName);
wizard = new NewWizardOperator();
wizard.finish();
}catch(Exception e2) {
wizard.cancel();
e2.printStackTrace();
fail("Exception during filter creation");
}
checkResultOfFilterCreation(pkg + iSep + "AdvancedFilter_1");
}
/** Private methods section **/
private void checkResultOfFilterCreation(String explorerPath) {
String name = explorerPath.substring(explorerPath.lastIndexOf(iSep)+1);
//1)Check that it is created
RepositoryNodeWaitable rnw = new RepositoryNodeWaitable(explorerPath);
Waiter w1 = new Waiter(rnw);
try {
w1.waitAction(rnw);
} catch (Exception e) {
e.printStackTrace();
fail("Node in repository not created");
}
//2)Check that it is opened in the editor
EditorPageWaitable epw = new EditorPageWaitable(name);
Waiter w = new Waiter(epw);
try {
w.waitAction(epw);
} catch (Exception e) {
e.printStackTrace();
fail("Not opened in editor");
}
epw.getEditorOperator().close(false); //Close opened file
//3)Check that code is "compilable"
JavaNode node1 = new JavaNode(explorerPath);
node1.compile();
isFail(Utils.checkResultOfJavaFileCompilation(explorerPath));
}
private void createPopup(String treePath) {
NewWizardOperator wizard = null;
try {
new NewTemplateAction().performMenu();
wizard = new NewWizardOperator();
new ChooseTemplateStepOperator().selectTemplate(treePath);
wizard.next();
wizard.cancel();
}catch(Exception e) {
e.printStackTrace();
wizard.cancel(); //Just remove wrong wizard window
}
}
private void wa() {
try {
Thread.sleep(5000);
}catch(Exception e) {
}
}
private void isFail(String res) {
if(res != null) {
fail(res);
}
}
private void closeOldWizards() {
NbDialogOperator wizard = null;
try {
while(true) {
wizard = new NbDialogOperator("New Wizard");
wizard.cancel();
}
}catch(Exception e) {
//OK. no more wizards found
}
}
//This static block used to init variables, common for all tests
static{
try {
jspServlet = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet");
servlet = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet/Servlet.java");
filters = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet/Filters");
sfName = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet/Filters/SimpleFilter.java");
afName = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet/Filters/AdvancedFilter.java");
}catch(Exception e) {
e.printStackTrace();
fail("Error during static initialization. Check Bundle paths.");
}
}
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.