|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
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-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.test.gui.web.warpackager;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.nodes.FolderNode;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.web.test.nodes.WARNode;
import org.netbeans.jellytools.OutputWindowOperator;
import org.netbeans.jellytools.NbDialogOperator;
import org.netbeans.jellytools.RuntimeTabOperator;
import org.netbeans.jellytools.ExplorerOperator;
import org.netbeans.jellytools.MainWindowOperator;
import org.netbeans.jemmy.operators.JRadioButtonOperator;
import org.netbeans.jellytools.actions.Action;
import org.netbeans.jellytools.actions.FilesystemsViewAction;
import org.netbeans.jellytools.actions.PropertiesAction;
import org.netbeans.jellytools.properties.Property;
import org.netbeans.jellytools.properties.TextFieldProperty;
import org.netbeans.jellytools.properties.PropertySheetTabOperator;
import org.netbeans.jellytools.properties.PropertySheetOperator;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.jemmy.operators.Operator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JCheckBoxOperator;
import org.netbeans.jemmy.operators.JComboBoxOperator;
import org.netbeans.jemmy.Waiter;
import org.netbeans.jemmy.Waitable;
import org.netbeans.jemmy.TimeoutExpiredException;
import java.awt.event.KeyEvent;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.EditorWindowOperator;
import org.netbeans.jemmy.operators.JEditorPaneOperator;
import java.util.HashSet;
import java.util.jar.JarFile;
import java.util.jar.JarEntry;
import java.util.Enumeration;
/* */
public class FilterProperty extends JellyTestCase {
private static String workDir = null;
private static String webModule = null;
private static String wmName = "wm2";
private static String fSep = System.getProperty("file.separator");
private static String iSep = "|";
private static String classes = null;
private static String from1 = null;
private static String from2 = null;
private static String from3 = null;
private static String to1 = null;
private static String to2 = null;
private static String to3 = null;
private static ExplorerOperator explorer = null;
private static String renameTitle = null;
private static String renameLabel = null;
private static String tempDir = null;
//constructor required by JUnit
public FilterProperty(java.lang.String testName) {
super(testName);
}
//method allowing to execute test directly
//from IDE for debugging
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
//method required by JUnit
public static junit.framework.Test suite() {
junit.framework.Test suite = new NbTestSuite(FilterProperty.class);
workDir = System.getProperty("warpackager.workdir").replace('/', fSep.charAt(0));
tempDir = System.getProperty("nbjunit.workdir");
renameTitle = Bundle.getStringTrimmed("org.openide.actions.Bundle", "CTL_RenameTitle");
renameLabel = Bundle.getStringTrimmed("org.openide.actions.Bundle", "CTL_RenameLabel");
explorer = ExplorerOperator.invoke();
explorer.selectPageFilesystems();
webModule = workDir + fSep + wmName;
return suite;
}
public void testCommonFilter1() {
String[] f1Content = { "META-INF/MANIFEST.MF", "html/wm2_html.html", "data/JApplet.html", "WEB-INF/classes/Servlet1.class", "images/wm2.gif", "WEB-INF/web.xml", "jsp/sample_jsp.jsp", "html/wm2.gif", "data/JApplet.class", "data/JApplet.form", "WEB-INF/classes/pkg/Servlet2.class"};
String testValue = "";
testCommonFilter(f1Content, testValue, "F1.war" );
}
public void testCommonFilter2() {
String[] f2Content = {"META-INF/MANIFEST.MF", "data/JApplet.html", "WEB-INF/classes/Servlet1.class", "images/wm2.gif", "html/wm2.gif", "html/wm2_html.html", "WEB-INF/web.xml", "jsp/sample_jsp.jsp", "data/JApplet.class", "WEB-INF/classes/pkg/Servlet2.class"};
String testValue = "";
testCommonFilter(f2Content, testValue, "F2.war" );
}
public void testCommonFilter3() {
String[] f3Content = {"META-INF/MANIFEST.MF", "images/wm2.gif", "WEB-INF/classes/Servlet1.java", "WEB-INF/classes/Servlet1.class", "data/JApplet.html", "html/wm2_html.html", "html/wm2.gif", "WEB-INF/web.xml", "jsp/sample_jsp.jsp", "data/JApplet.java", "data/JApplet.class", "data/JApplet.form", "WEB-INF/classes/pkg/Servlet2.java", "WEB-INF/classes/pkg/Servlet2.class"};
String testValue = "";
testCommonFilter(f3Content, testValue, "F3.war" );
}
public void testRegexpFilter() {
String[] f4Content = {"META-INF/MANIFEST.MF"};
String testValue = ".*\\.txt";
testREFilter(f4Content, testValue, "F4.war" , false);
}
public void testNegativeRegexpFilter() {
String[] f5Content = {"META-INF/MANIFEST.MF", "html/wm2_html.html", "data/JApplet.html", "WEB-INF/classes/Servlet1.java", "WEB-INF/classes/Servlet1.class", "html/wm2.gif", "images/wm2.gif", "WEB-INF/web.xml", "jsp/sample_jsp.jsp", "data/JApplet.java", "data/JApplet.class", "data/JApplet.form", "WEB-INF/classes/pkg/Servlet2.java", "WEB-INF/classes/pkg/Servlet2.class"};
String testValue = ".*\\.txt";
testREFilter(f5Content, testValue, "F5.war", true);
}
public void testWrongRegexp() {
String regexp = "*.txt";
FolderNode node1 = null;
try {
System.out.println("Check mounts");
node1 = new FolderNode(webModule + "|WEB-INF");
} catch (Exception e) {
fail("Please check that all mounts are done properly");
e.printStackTrace();
}
try {
node1.select();
(new PropertiesAction()).performPopup(node1);
}catch(Exception e) {
fail("Exception while try to rename WAR via popup: " + e);
}
String tab = "Archive"; //NOI18N
String propName = Bundle.getString("org.netbeans.modules.web.war.Bundle", "PROP_Filter");
PropertySheetOperator pso = new PropertySheetOperator("Properties of WEB-INF"); //NOI18N
PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, tab);
Property filter = new Property(psto,propName);
filter.openEditor();
NbDialogOperator dialog = new NbDialogOperator(propName);
JRadioButtonOperator jrb = new JRadioButtonOperator(dialog,"Regular Expression",0); //NOI18N
jrb.changeSelection(true);
JCheckBoxOperator jcb = new JCheckBoxOperator (dialog, "Negative", 0);
jcb.changeSelection(false);
JTextFieldOperator jtf = new JTextFieldOperator(dialog, 0);
String oldValue = jtf.getText();
jtf.setText("");
jtf.typeText(regexp,0);
if(!jtf.getText().equals(regexp)) {
fail("Can't set value(" + jtf.getText() + ") of filter property to " + regexp);
}
dialog.ok();
filter.openEditor();
dialog = new NbDialogOperator(propName);
jtf = new JTextFieldOperator(dialog, 0);
if(!jtf.getText().equals(oldValue)) {
fail("Value of regexp changed to " + jtf.getText());
}
dialog.ok();
//PASS
}
public void testCancelRegexp() {
String regexp = "someValue";
FolderNode node1 = null;
try {
System.out.println("Check mounts");
node1 = new FolderNode(webModule + "|WEB-INF");
} catch (Exception e) {
fail("Please check that all mounts are done properly");
e.printStackTrace();
}
try {
node1.select();
(new PropertiesAction()).performPopup(node1);
}catch(Exception e) {
fail("Exception while try to rename WAR via popup: " + e);
}
String tab = "Archive"; //NOI18N
String propName = Bundle.getString("org.netbeans.modules.web.war.Bundle", "PROP_Filter");
PropertySheetOperator pso = new PropertySheetOperator("Properties of WEB-INF"); //NOI18N
PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, tab);
Property filter = new Property(psto,propName);
filter.openEditor();
NbDialogOperator dialog = new NbDialogOperator(propName);
JRadioButtonOperator jrb = new JRadioButtonOperator(dialog,"Regular Expression",0); //NOI18N
jrb.changeSelection(true);
//JCheckBoxOperator jcb = new JCheckBoxOperator (dialog, "Negative", 0);
//jcb.changeSelection(false);
JTextFieldOperator jtf = new JTextFieldOperator(dialog, 0);
String oldValue = jtf.getText();
jtf.setText("");
jtf.typeText(regexp,0);
if(!jtf.getText().equals(regexp)) {
fail("Can't set value(" + jtf.getText() + ") of filter property to " + regexp);
}
dialog.cancel();
filter.openEditor();
dialog = new NbDialogOperator(propName);
jtf = new JTextFieldOperator(dialog, 0);
if(!jtf.getText().equals(oldValue)) {
fail("Value of regexp changed to " + jtf.getText());
}
dialog.ok();
//PASS
}
public void testCancelCommon() {
FolderNode node1 = null;
try {
System.out.println("Check mounts");
node1 = new FolderNode(webModule + "|WEB-INF");
} catch (Exception e) {
fail("Please check that all mounts are done properly");
e.printStackTrace();
}
try {
node1.select();
(new PropertiesAction()).performPopup(node1);
}catch(Exception e) {
fail("Exception while try to rename WAR via popup: " + e);
}
String tab = "Archive"; //NOI18N
String propName = Bundle.getString("org.netbeans.modules.web.war.Bundle", "PROP_Filter");
PropertySheetOperator pso = new PropertySheetOperator("Properties of WEB-INF"); //NOI18N
PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, tab);
Property filter = new Property(psto,propName);
filter.openEditor();
NbDialogOperator dialog = new NbDialogOperator(propName);
JRadioButtonOperator jrb = new JRadioButtonOperator(dialog,"Common Filter",0); //NOI18N
jrb.changeSelection(true);
JComboBoxOperator jcb = new JComboBoxOperator(dialog, 0);
int oldVal = jcb.getSelectedIndex();
if(oldVal!=2) {
jcb.setSelectedIndex(2);
}else{
jcb.setSelectedIndex(1);
}
dialog.cancel();
filter.openEditor();
dialog = new NbDialogOperator(propName);
jcb = new JComboBoxOperator(dialog, 0);
if(oldVal!=jcb.getSelectedIndex()) {
fail("Common Filter changes was not discarded after cancel");
}
dialog.ok();
//PASS
}
private void testREFilter(String[] expectedContent, String testValue, String name, boolean negative) {
FolderNode node1 = null;
try {
System.out.println("Check mounts");
node1 = new FolderNode(webModule + "|WEB-INF");
} catch (Exception e) {
fail("Please check that all mounts are done properly");
e.printStackTrace();
}
try {
node1.select();
(new PropertiesAction()).performPopup(node1);
}catch(Exception e) {
fail("Exception while try to rename WAR via popup: " + e);
}
String tab = "Archive"; //NOI18N
String propName = Bundle.getString("org.netbeans.modules.web.war.Bundle", "PROP_Filter");
PropertySheetOperator pso = new PropertySheetOperator("Properties of WEB-INF"); //NOI18N
PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, tab);
Property filter = new Property(psto,propName);
filter.openEditor();
NbDialogOperator dialog = new NbDialogOperator(propName);
JRadioButtonOperator jrb = new JRadioButtonOperator(dialog,"Regular Expression",0); //NOI18N
jrb.changeSelection(true);
JTextFieldOperator jtf = new JTextFieldOperator(dialog, 0);
if(!jtf.getText().equals(testValue)) {
jtf.setText("");
jtf.typeText(testValue,0);
}
JCheckBoxOperator jcb = new JCheckBoxOperator (dialog, "Negative", 0);
jcb.changeSelection(!negative); //WORKAROUND of strange jemmy problem
jcb.changeSelection(negative);
try {
Thread.sleep(10000);
}catch(Exception e) {
}
if(!jtf.getText().equals(testValue)) {
fail("Can't set value(" + jtf.getText() + ") of filter property to " + testValue);
}
dialog.ok();
try {
Thread.sleep(20000);
}catch(Exception e) {
}
exportWARFile(webModule + "|WEB-INF",tempDir + fSep + name);
HashSet content = getWARContent(tempDir + fSep + name);
if(content.remove("WEB-INF/sun-web.xml")) { //Remove server-specific data
System.out.println("S1S AS specific sun-web.xml was added");
}
if(content.size() != expectedContent.length) {
fail(content.size() + " files exported instead of " + expectedContent.length);
}
for(int i=0; i< expectedContent.length;i++) {
if(!content.contains(expectedContent[i])) {
fail("Item " + expectedContent[i] + " not found in exported WAR ");
}
}
//PASS
}
private void testCommonFilter(String[] expectedContent, String testValue, String name) {
FolderNode node1 = null;
try {
System.out.println("Check mounts");
node1 = new FolderNode(webModule + "|WEB-INF");
} catch (Exception e) {
fail("Please check that all mounts are done properly");
e.printStackTrace();
}
try {
node1.select();
(new PropertiesAction()).performPopup(node1);
}catch(Exception e) {
fail("Exception while try to rename WAR via popup: " + e);
}
String tab = "Archive"; //NOI18N
String propName = Bundle.getString("org.netbeans.modules.web.war.Bundle", "PROP_Filter");
PropertySheetOperator pso = new PropertySheetOperator("Properties of WEB-INF"); //NOI18N
PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, tab);
Property filter = new Property(psto,propName);
filter.openEditor();
NbDialogOperator dialog = new NbDialogOperator(propName);
JRadioButtonOperator jrb = new JRadioButtonOperator(dialog,"Common Filter",0); //NOI18N
jrb.changeSelection(true);
JComboBoxOperator jcb = new JComboBoxOperator(dialog, 0);
//jcb.pushComboButton();
if(!jcb.getSelectedItem().toString().equals(testValue)) {
int length = jcb.getItemCount(); //WORKWAROUND for jcb.setSelectedItem(testValue);
for(int i = 0;i
|