alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package gui.wizards;

import java.io.PrintStream;
import java.io.PrintWriter;

import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.OptionsOperator;
import org.netbeans.jellytools.SetupWizardOperator;
import org.netbeans.jellytools.TreeTableOperator;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.jellytools.properties.Property;
import org.netbeans.jellytools.properties.PropertySheetOperator;

import org.netbeans.jemmy.ComponentSearcher;
import org.netbeans.jemmy.EventTool;
import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.TestOut;
import org.netbeans.jemmy.operators.JCheckBoxOperator;
import org.netbeans.jemmy.operators.JComboBoxOperator;
import org.netbeans.jemmy.operators.JLabelOperator;
import org.netbeans.jemmy.operators.JTableOperator;
import org.netbeans.jemmy.operators.JTreeOperator;

import org.netbeans.junit.NbTestSuite;

/**
 * This is the test suite for the Setup Wizard of NetBeans.
 *
 * @author  juhrik@netbeans.org, mmirilovic@netbeans.org
 */

public class SetupWizardTest extends JellyTestCase {
    
    //    private static final String EMPTY_STRING = "";
    //    private static final String "|" = "|";
    //    private static final String EXCLAM_MARK = "!";
    private static final String STR_TRUE = "True";
    private static final String STR_FALSE = "False";
    //    private static final String PROXY_PORT = java.util.ResourceBundle.getBundle("gui/wizards/Bundle").getString("PORT");
    //    private static final String PROXY_HOST = java.util.ResourceBundle.getBundle("gui/wizards/Bundle").getString("HOST");
    //    private static final String HASH_STRING = java.util.ResourceBundle.getBundle("gui/wizards/Bundle").getString("Str_Hashes");
    //    private static final String WIZARD_FAIL = java.util.ResourceBundle.getBundle("gui/wizards/Bundle").getString("Wizard_Fail");
    //    private static final String ERROR_TITLE = Bundle.getString("org.openide.Bundle", "NTF_ErrorTitle");
    
    protected static PrintStream err;
    protected static PrintStream log;
    
    private static final String CAPTION = "=========================== ";
    
    private static SetupWizardOperator setupWizardOperator;
    
    
    /** The Constructor - it is Called for Each of Test Methods.
     *extends NbTestCase
     *@param name the test method name - it must start with "test" prefix and the test method must exist
     */
    public SetupWizardTest(String name) {
        super(name);
    }
    
    /**Static method for Test suite. The tests are added to the suite.
     *@return the test suite
     */
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new SetupWizardTest("testInvokeSetupWizard"));
        suite.addTest(new SetupWizardTest("testProxyEnabling"));
        suite.addTest(new SetupWizardTest("testProxyDisabling"));
        suite.addTest(new SetupWizardTest("testProxySettings"));
        suite.addTest(new SetupWizardTest("testSwitchToSDI"));
        suite.addTest(new SetupWizardTest("testSwitchToMDI"));
//        suite.addTest(new SetupWizardTest("testExternalWebBrowser"));
        suite.addTest(new SetupWizardTest("testSwingHTMLBrowser"));
//        suite.addTest(new SetupWizardTest("testExternalCommandLineWebBrowser"));
        suite.addTest(new SetupWizardTest("testSecondPanelCheck"));
        suite.addTest(new SetupWizardTest("testDescriptionsCheck"));
//        suite.addTest(new SetupWizardTest("testDisableModule"));          // TODO
//        suite.addTest(new SetupWizardTest("testEnableModule"));           // TODO
//        suite.addTest(new SetupWizardTest("testDisableModuleBranch"));    // TODO
//        suite.addTest(new SetupWizardTest("testEnableModuleBranch"));     // TODO
        suite.addTest(new SetupWizardTest("testThirdPanelCheck"));
        suite.addTest(new SetupWizardTest("testSetPeriodOfUCCheck"));
        suite.addTest(new SetupWizardTest("testLastPanelSettings"));
        return suite;
    }
    
    
    public void setUp() {
//        err = System.out;
        err = getLog();
        log = getRef();
        
        JemmyProperties.getProperties().setOutput(new TestOut(null, new PrintWriter(err, true), new PrintWriter(err, true), null));
        new EventTool().waitNoEvent(1000);
        
        System.out.println(CAPTION + getName());
        
/*        if(!getName().equals("testInvokeSetupWizard")){
            try{
                setupWizardOperator = findSetupWizard();
            } catch (Exception exc) {
                failTest(exc, "It isn't possible invoke Setup Wizard, action causes EXCEPTION: "+exc.getMessage());
            }
        }
        
*/    }
    
    public void tearDown() {
        if(setupWizardOperator != null && setupWizardOperator.isShowing())
            setupWizardOperator.cancel();

        closeAllModal();
    }
    
    
    /**
     * Invoke the Setup Wizard, calls SetupWizardOperator.invoke().
     */
    public void testInvokeSetupWizard() {
        try {
            if(SetupWizardOperator.invoke()==null)
                fail("Setup Wizard isn't opened after pushing Tools | Setup WIzard.");
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Test enables the proxy in opened Setup Wizard and checks that it is possible to change proxy port and name
     */
    public void testProxyEnabling() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Use HTTP Proxy Server, set proxy checkbox to true
            setupWizardOperator.checkUseHTTPProxyServer(true);
            
            boolean proxyServerNameEnabled = setupWizardOperator.txtProxyServerName().isEditable();
            boolean proxyServerPortEnabled = setupWizardOperator.txtPort().isEditable();
            
            if(!proxyServerNameEnabled || !proxyServerPortEnabled)
                fail("Proxy Server Name("+(proxyServerPortEnabled?"enabled":"disabled")+") or Port("+(proxyServerPortEnabled?"enabled":"disabled")+") textfield is disabled, but it should be enabled.");
                
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Disables the proxy in opened Setup Wizard and checks that it is not possible to change proxy port and name
     */
    public void testProxyDisabling() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Use HTTP Proxy Server, set proxy checkbox to false
            setupWizardOperator.checkUseHTTPProxyServer(false);
            
            boolean proxyServerNameEnabled = setupWizardOperator.txtProxyServerName().isEditable();
            boolean proxyServerPortEnabled = setupWizardOperator.txtPort().isEditable();
            
            if(!proxyServerNameEnabled || !proxyServerPortEnabled)
                fail("Proxy Server Name("+(proxyServerPortEnabled?"enabled":"disabled")+") or Port("+(proxyServerPortEnabled?"enabled":"disabled")+") textfield is enabled, but it should be disabled.");
                
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Tests to set the Proxy Port and Proxy Name to the correct value.
     * Finally it finishes the Setup Wizard.
     */
    public void testProxySettings() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Use HTTP Proxy Server, set proxy checkbox to true
            setupWizardOperator.checkUseHTTPProxyServer(true);
            
            //Set Proxy Host, Port
            setupWizardOperator.setProxyServerName("webcache.uk");
            setupWizardOperator.setPort("8080");
            
            //Finish the setup wizard
            setupWizardOperator.finish();
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and switches to the SDI mode.
     * Finally it finishes the Setup Wizard.
     */
    public void testSwitchToSDI() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Multiple Smaller Windows Mode ("SDI")
            setupWizardOperator.separateWindowsMode();
            
            new EventTool().waitNoEvent(1000);
            
            boolean sdiRadioButtonIsSelected = setupWizardOperator.rbSeparateWindowsMode().isSelected();
            boolean mdiRadioButtonIsSelected = setupWizardOperator.rbCompactWindowsMode().isSelected();
            
            if(!sdiRadioButtonIsSelected || mdiRadioButtonIsSelected)
                fail("SDI Mode ("+(sdiRadioButtonIsSelected?"selected":"unselected")+") or MDI Mode ("+(mdiRadioButtonIsSelected?"selected":"unselected")+").");
                
                //Finish the setup wizard
                setupWizardOperator.finish();
                
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and switches to the MDI mode.
     * Finally it finishes the Setup Wizard.
     */
    public void testSwitchToMDI() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Full Screen Mode ("MDI")
            setupWizardOperator.compactWindowsMode();
            
            new EventTool().waitNoEvent(1000);
            
            boolean sdiRadioButtonIsSelected = setupWizardOperator.rbSeparateWindowsMode().isSelected();
            boolean mdiRadioButtonIsSelected = setupWizardOperator.rbCompactWindowsMode().isSelected();
            
            if(sdiRadioButtonIsSelected || !mdiRadioButtonIsSelected)
                fail("SDI Mode ("+(sdiRadioButtonIsSelected?"selected":"unselected")+") or MDI Mode ("+(mdiRadioButtonIsSelected?"selected":"unselected")+").");
                
                //Finish the setup wizard
                setupWizardOperator.finish();
                
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and selects the External Browser(Windows)
     * Finally it finishes the Setup Wizard.
     */
    public void testExternalWebBrowser() {
        try {
            setupWizardOperator = findSetupWizard();
            
            String extBrowser;
            
            if(System.getProperty("os.name").startsWith("Windows")){
                //External Browser (Windows)
                extBrowser = Bundle.getString("org.netbeans.modules.extbrowser.Bundle", "Services/Browsers/WinWebBrowser.settings");
            }else{
                //External Browser (Unix)
                extBrowser = Bundle.getString("org.netbeans.modules.extbrowser.Bundle", "Services/Browsers/UnixWebBrowser.settings");
            }
            
            setupWizardOperator.selectWebBrowser(extBrowser);
            new EventTool().waitNoEvent(500);
            
            String comboString = (String)setupWizardOperator.cboWebBrowser().getSelectedItem();
            
            if(!comboString.equals(extBrowser))
                fail("Browser: [" + extBrowser + "] should be selected, but selected browser is ["+comboString+"]!");
            
            //Finish the setup wizard
            setupWizardOperator.finish();
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and selects the Swing HTML Browser
     * Finally it finishes the Setup Wizard.
     */
    public void testSwingHTMLBrowser() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Swing HTML Browser
            String swingBrowser = Bundle.getString("org.netbeans.core.ui.Bundle", "Services/Browsers/SwingBrowser.ser");
            setupWizardOperator.selectWebBrowser(swingBrowser);
            new EventTool().waitNoEvent(500);
            
            String comboString = (String)setupWizardOperator.cboWebBrowser().getSelectedItem();
            
            if(!comboString.equals(swingBrowser))
                fail("Browser: [" + swingBrowser + "] should be selected, but selected browser is ["+comboString+"]!");
            
            //Finish the setup wizard
            setupWizardOperator.finish();
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and selects the External Browser(Command Line)
     * Finally it finishes the Setup Wizard.
     */
    public void testExternalCommandLineWebBrowser() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //External Browser (Command Line)
            String extCmdLine = Bundle.getString("org.netbeans.modules.extbrowser.Bundle", "Services/Browsers/SimpleExtBrowser.settings");
            setupWizardOperator.selectWebBrowser(extCmdLine);
            new EventTool().waitNoEvent(500);
            
            String comboString = (String)setupWizardOperator.cboWebBrowser().getSelectedItem();
            
            if(!comboString.equals(extCmdLine))
                fail("Browser: [" + extCmdLine + "] should be selected, but selected browser is ["+comboString+"]!");
            
            //Finish the setup wizard
            setupWizardOperator.finish();
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Opens Setup Wizard, finds it and presses the Next button.
     * Then the test checks whether the step of the wizard is correct(2nd step must be set).
     */
    public void testSecondPanelCheck() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //General NetBeans Settings
            checkStepLabel(Bundle.getString("org.netbeans.core.ui.Bundle", "LBL_IDEPanelName"));
            
            //Press Next button
            setupWizardOperator.next();
            
            new EventTool().waitNoEvent(3000);
            
            //Module Installation
            checkStepLabel(Bundle.getString("org.netbeans.core.ui.Bundle", "LBL_SetupWizardModuleInstallation"));
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Test first collapses all nodes in the tree of the second panel.
     * Then the tree is fully expanded, all nodes are selected to False
     * Tree is again fully collapsed and all groups of modules are selectsed (set to True)
     */
    public void testDescriptionsCheck() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Press Next button
            setupWizardOperator.next();
            
            JTreeOperator treeOperator = new TreeTableOperator((javax.swing.JTable) new JTableOperator(setupWizardOperator).getSource()).tree();
            
            expandWholeTree(treeOperator, true);
            
            expandWholeTree(treeOperator, false);
            
            setTreeSelected(STR_FALSE);
            setTreeSelected(STR_TRUE);
            
            setupWizardOperator.cancel();
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Finds out the module group that contains more than 2 modules and sets the 2nd module of the group disabled
     */
    public void testDisableModule() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Press Next button
            setupWizardOperator.next();
            
            // collapse tree
            JTableOperator tableOperator = new JTableOperator(setupWizardOperator);
            JTreeOperator treeOperator = new TreeTableOperator((javax.swing.JTable) tableOperator.getSource()).tree();
            
            expandWholeTree(treeOperator, false);
            
            String[] nodesNames = getNodesNames(tableOperator);
            
            for(int i = 1; i < nodesNames.length; i++){
                Node n = new Node(treeOperator, nodesNames[i]);
                if(n.getChildren().length > 2){
                    n.expand();
                    setModuleSelected(tableOperator, n.getChildren()[1], STR_FALSE);
                    n.collapse();
                    break;
                }
                n.collapse();
            }
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Finds out the module group that contains more than 2 modules and sets the 2nd module of the group enabled.
     * It tests that the module is selected as well.
     */
    public void testEnableModule() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //Press Next button
            setupWizardOperator.next();
            
            JTableOperator tableOperator = new JTableOperator(setupWizardOperator);
//            JTreeOperator treeOperator = new TreeTableOperator((javax.swing.JTable) tableOperator.getSource()).tree();
            
            String[] nodesNames = getNodesNames(tableOperator);
            
            for(int i = 1; i 2){
                    n.expand();

                    if(!getModuleSelected(tableOperator, i+2).equals(STR_FALSE))
                        fail("Module\\" + n.getChildren()[1] + " should be False!");
                    
                    setModuleSelected(tableOperator, n.getChildren()[1], STR_TRUE);
                    new EventTool().waitNoEvent(1000);
                    
                    if(!getModuleSelected(tableOperator, i+2).equals(STR_TRUE))
                        fail("Module\\" + n.getChildren()[1] + " should be True!");
                    
                    n.collapse();
                    break;
                }
                n.collapse();
            }
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Disables the branch of modules
     */
    public void testDisableModuleBranch() {
        workWithModuleBranch(false);
    }
    
    /**
     * Enables the branch of modules disabled in the previous test
     */
    public void testEnableModuleBranch() {
        workWithModuleBranch(true);
    }
    
    /**
     * First the Next button is pressed.
     * Then the step of the wizard is checked(it must be in tits 3rd step)
     */
    public void testThirdPanelCheck() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //General NetBeans Settings
            checkStepLabel(Bundle.getString("org.netbeans.core.ui.Bundle", "LBL_IDEPanelName"));
            
            //push Next, Next
            setupWizardOperator.next();
            setupWizardOperator.next();
            
            new EventTool().waitNoEvent(3000);
            
            //Update Center
            checkStepLabel(Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Settings_Name"));
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * Sets each of the period for Update Center Check. Finishes the wizard and tests whether the change is propagated in Tools|Options
     */
    public void testSetPeriodOfUCCheck() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //push Next, Next
            setupWizardOperator.next();
            setupWizardOperator.next();
            
            JComboBoxOperator jcbo = new JComboBoxOperator(setupWizardOperator);
            int itemCount = jcbo.getItemCount();
            String lastSelected = "";
            for(int i = 0; i < itemCount; i++){
                jcbo.setSelectedIndex(i);
                
                if(jcbo.getSelectedItem().toString().equals(lastSelected))
                    fail("Cannot select item in JComboBox!");
                
                lastSelected = jcbo.getSelectedItem().toString();
            }
            //finally set Every Startup
            jcbo.setSelectedIndex(0);
            //Finish setup wizard
            setupWizardOperator.finish();
            
            //Start options
            OptionsOperator options = OptionsOperator.invoke();
            new EventTool().waitNoEvent(3000);
            
            //IDE Configuration
            String firstLevel = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration");
            //System
            String secondLevel = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/System");
            //Update Center
            String updateCenter = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Settings_Name");
            
            options.selectOption(firstLevel + "|" + secondLevel + "|" + updateCenter);
            new EventTool().waitNoEvent(1000);
            
            //do it twice because of first time doesn't assure the invocation
            options.selectOption(firstLevel + "|" + secondLevel + "|" + updateCenter);
            
            PropertySheetOperator propertySheet = new PropertySheetOperator(options);
            //Check Period
            String checkPeriod = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "PROP_Period");
            Property property = new Property(propertySheet, checkPeriod);
            new EventTool().waitNoEvent(100);
            String st = property.getValue();
            new EventTool().waitNoEvent(100);
            property = new Property(propertySheet, checkPeriod);
            new EventTool().waitNoEvent(100);
            st = property.getValue();
            String everyStartup = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_PeriodEditor_Startup");
            
            if(!st.equals(everyStartup))
                fail("Every Startup should be set in Options!");
            
            options.close();
            
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    /**
     * All checkboxes in last panel of the wizard are deselected and the wizard is finished.
     * Then it is reopened again and the it is checked that the checkboxes are equal to their previous values.
     */
    public void testLastPanelSettings() {
        try {
            setupWizardOperator = findSetupWizard();
            
            //push Next, Next
            setupWizardOperator.next();
            setupWizardOperator.next();
            
            //Show Dialog Before Automatic Update Check.
            JCheckBoxOperator jchbo = new JCheckBoxOperator(setupWizardOperator, Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle","AutoCheckInfo.jCheckBox1.text"));
            jchbo.setSelected(false);
            //Show Check Results Even If No Update Available.
            jchbo = new JCheckBoxOperator(setupWizardOperator, Bundle.getString("org.netbeans.modules.autoupdate.Bundle","AutoCheckInfo.jCheckBox2.text"));
            new EventTool().waitNoEvent(100);
            jchbo.setSelected(false);
            new EventTool().waitNoEvent(100);
            setAllAUtypesSelected(false);
            new EventTool().waitNoEvent(100);
            setupWizardOperator.finish();
            
            setupWizardOperator = findSetupWizard();
            
            //push Next, Next
            setupWizardOperator.next();
            setupWizardOperator.next();
            
            //Show Dialog Before Automatic Update Check.
            jchbo = new JCheckBoxOperator(setupWizardOperator, Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle","AutoCheckInfo.jCheckBox1.text"));
            if(jchbo.isSelected())
                fail("Checkbox \"Show Dialog Before Automatic Update Check\" should be deselected!");
            
            //Show Check Results Even If No Update Available.
            jchbo = new JCheckBoxOperator(setupWizardOperator, Bundle.getString("org.netbeans.modules.autoupdate.Bundle","AutoCheckInfo.jCheckBox2.text"));
            if(jchbo.isSelected())
                fail("Checkbox \"Show Check Results Even If No Update Available\" should be deselected!");
            
            JTableOperator servers_table = new JTableOperator(setupWizardOperator);
            int rowCount = servers_table.getRowCount();
            for(int line = 0; line < rowCount; line++){
                Boolean b = (Boolean)(servers_table.getValueAt(line, 0));
                
                if(b.booleanValue())
                    fail("Update center on\\" + line + ". line should be deselected!");
            }
            
            setupWizardOperator.finish();
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    
    /**
     * Get nodes names.
     * @param treeTableOperator operator for tree table
     * @return nodes names
     */
    private String[] getNodesNames(JTableOperator treeTableOperator) {
        String[] nodesNames = new String[treeTableOperator.getRowCount()];
        for(int i = 1; i < treeTableOperator.getRowCount(); i++){
            nodesNames[i] = treeTableOperator.getValueAt(i, 0).toString();
        }
        return nodesNames;
    }
    
    
    /**
     * Expand or Collapse whole tree.
     * @param treeOperator operator for tree table
     * @param expand if true - each node will be expanded, if false each one will be collapsed
     */
    private void expandWholeTree(JTreeOperator treeOperator, boolean expand){
        Node rootNode = new Node(treeOperator, "");
        
        // expand whole tree
        for (int i = 0; i < rootNode.getChildren().length; i++){
            Node node = new Node(treeOperator, rootNode.getChildren()[i]);
            if(expand)
                node.expand();
            else
                node.collapse();
        }
        
        new EventTool().waitNoEvent(1000);
    }
    
    
    /**
     * Work with module branch, enable or disable module node and check subnodes status.
     * @param enable if TRUE - enable module branch, if FALSE - disable module branch
     */
    private void workWithModuleBranch(boolean enable){
        String value = enable?STR_TRUE:STR_FALSE;
        
        try {
            setupWizardOperator = findSetupWizard();
            
            //Press Next button
            setupWizardOperator.next();
            
            JTableOperator tableOperator = new JTableOperator(setupWizardOperator);
            String[] nodesNames = getNodesNames(tableOperator);
            
            for(int i = 1; i2){
                    n.expand();
                    setModuleSelected(tableOperator, i, value);
                    for(int j = 0; j < n.getChildren().length; j++){
                        String actualValue = getModuleSelected(tableOperator, i+j);
                        
                        if(!actualValue.equals(value))
                            fail("Module is ["+actualValue+"], but it should be ["+value+"] !");
                    }
                    n.collapse();
                    break;
                }
                n.collapse();
            }
        } catch (Exception exc) {
            failTest(exc, "Test fails and causes EXCEPTION: "+exc.getMessage());
        }
    }
    
    
    /**
     * Finds Setup Wizard and (de)selects all Update centers - it is supposed that Wizard is opened on its 3rd panel
     *@param selected true - select all Update Centers, false - deselect all Update Centers
     */
    public void setAllAUtypesSelected(boolean selected){
        JTableOperator servers_table = new JTableOperator(setupWizardOperator);
        int linesCount = servers_table.getRowCount();
        for(int line = 0; line < linesCount; line++){
            servers_table.setValueAt(new Boolean(selected),line, 1);
        }
    }
    
    /**
     * Recognizes whether the module at appropriate row position is selected/deselected
     * @param row the table row value of the module
     * @return the "True", "False" or empty string - empty if the value is null
     */
    public String getModuleSelected(JTableOperator tableOperator, int row){
        
//        tableOperator = new JTableOperator(setupWizardOperator);
        
//err.println(CAPTION + " ROW=["+row+"] < ROW COUNT=["+tableOperator.getRowCount()+"]");
        if(tableOperator.getRowCount() > row){
            new EventTool().waitNoEvent(100);
            
            if(tableOperator.getValueAt(row, 1) != null){
                tableOperator.clearSelection();
                tableOperator.selectCell(row, 1);
                
                new EventTool().waitNoEvent(100);
                if(JComboBoxOperator.findJComboBox(tableOperator.getContainer(ComponentSearcher.getTrueChooser("")), ComponentSearcher.getTrueChooser("")) != null){
                    JComboBoxOperator jci = new JComboBoxOperator(setupWizardOperator);
                    return jci.getSelectedItem().toString();
                }

/*                try{
                    JCheckBoxOperator jci = new JCheckBoxOperator(setupWizardOperator);
                    return jci.isSelected()?STR_TRUE:STR_FALSE;
                }catch(Exception exc){
                    err.println(CAPTION+" No ComboBox found on row"+row);
                }
*/                
            }
        }
//err.println(CAPTION + " ROW=["+row+"] is NULL");
        return null;
    }
    
    /**Recognizes whether the module with the appropriate name is selected/deselected
     *@param name the module name
     *@return the "True", "False" or empty string - empty if the value is null
     */
    public String getModuleSelected(JTableOperator tableOperator, String name){
        int row = 0;
        while(tableOperator.getRowCount() > row){
            new EventTool().waitNoEvent(100);
            if(tableOperator.getValueAt(row, 0).toString().equals(name)){
                tableOperator.clearSelection();
                tableOperator.selectCell(row, 1);
                new EventTool().waitNoEvent(100);
                if(JComboBoxOperator.findJComboBox(tableOperator.getContainer(ComponentSearcher.getTrueChooser("")), ComponentSearcher.getTrueChooser("")) != null){
                    JComboBoxOperator jci = new JComboBoxOperator(setupWizardOperator);
                    return jci.getSelectedItem().toString();
                }
            }
            row++;
        }
        return null;
    }
    
    /**
     * Sets all the modules and groups in the tree (de)selected - it is supposed that the second panel of Setup Wizard is opened
     *@param true_or_false the value must be string "True" or "False"
     */
    public void setTreeSelected(String true_or_false){
        JTableOperator tableOperator = new JTableOperator(setupWizardOperator);
        for(int i = 0; i < tableOperator.getRowCount(); i++){
            new EventTool().waitNoEvent(500);
            setModuleSelected(tableOperator, i, true_or_false);
        }
    }
    
    /**
     * Sets the module or the module group at appropriate position (de)selected
     * @param row the table row value of the module
     * @param value "True" or "False"
     */
    public void setModuleSelected(JTableOperator tableOperator, int row, String value){
        if(getModuleSelected(tableOperator, row)==null || getModuleSelected(tableOperator, row).equals(value))
            return;
        
        if(tableOperator.getRowCount()>row){
            new EventTool().waitNoEvent(100);
            if(tableOperator.getValueAt(row, 1) != null){
                tableOperator.clearSelection();
                tableOperator.selectCell(row, 1);
                new EventTool().waitNoEvent(100);
                if(JComboBoxOperator.findJComboBox(tableOperator.getContainer(ComponentSearcher.getTrueChooser("")), ComponentSearcher.getTrueChooser("")) != null){
                    JComboBoxOperator jci = new JComboBoxOperator(setupWizardOperator);
                    jci.selectItem(value);
                }
            }
        }
    }
    
    /**
     * Sets the module or the module group with appropriate name (de)selected
     *@param name the module name
     *@param value "True" or "False"
     */
    public void setModuleSelected(JTableOperator tableOperator, String name, String value){
        if(getModuleSelected(tableOperator, name) == null || getModuleSelected(tableOperator, name).equals(value))
            return;
        
        int row = 0;
        while(tableOperator.getRowCount()>row){
            new EventTool().waitNoEvent(100);
            if(tableOperator.getValueAt(row, 0).toString().equals(name)){
                tableOperator.clearSelection();
                tableOperator.selectCell(row, 1);
                new EventTool().waitNoEvent(100);
                if(JComboBoxOperator.findJComboBox(tableOperator.getContainer(ComponentSearcher.getTrueChooser("")), ComponentSearcher.getTrueChooser("")) != null){
                    JComboBoxOperator jci = new JComboBoxOperator(setupWizardOperator);
                    jci.selectItem(value);
                    return;
                }
            }
            row++;
        }
    }
    
    /**
     * Finds the Setup wizard (the window with the title Setup Wizard)
     *@return instance of SetupWizardOperator for Setup Wizard
     */
    public SetupWizardOperator findSetupWizard(){
        
        String waitDialogTimeout = "DialogWaiter.WaitDialogTimeout";
        long findTimeout = JemmyProperties.getCurrentTimeout(waitDialogTimeout);
        JemmyProperties.setCurrentTimeout(waitDialogTimeout, 3000);
        
        try{
            setupWizardOperator = new SetupWizardOperator();
        }catch(org.netbeans.jemmy.TimeoutExpiredException exception){
            setupWizardOperator = SetupWizardOperator.invoke();
        }
        
        JemmyProperties.setCurrentTimeout(waitDialogTimeout, findTimeout);
        
        return setupWizardOperator;
    }
    
    /**
     * Checks whether the wizard has the appropriate text in its Step Label(the title on the most top part of the wizard)
     *@param label the text with which the Step Label is compared
     */
    public void checkStepLabel(String label){
//        javax.swing.JLabel jLabel = JLabelOperator.waitJLabel(setupWizardOperator.getContainer(ComponentSearcher.getTrueChooser("")), ComponentSearcher.getTrueChooser(""),1);
//        String textLabel = jLabel.getText();
        
        JLabelOperator jLabelOperator = new JLabelOperator(setupWizardOperator,1);
        
        String textLabel = jLabelOperator.getText();
        
        if(!textLabel.equals(label))
            fail("Panel [" + label + "] should be selected, but selected panel is ["+textLabel+"]!");
    }
    
    
    /**
     * Print full stack trace to log files, get message and log to test results if test fails.
     * @param exc Exception logged to description
     * @param message written to test results
     */
    protected void failTest(Exception exc, String message) {
        err.println("################################");
        if(exc!=null) exc.printStackTrace(err);
        err.println("################################");
        fail(message);
    }
    
    
    /** Use for execution inside IDE */
    public static void main(java.lang.String[] args) {
        // run whole suite
        junit.textui.TestRunner.run(suite());
        // run only selected test case
        // junit.textui.TestRunner.run(new SetupWizardTest("testLastPanelSettings"));
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.