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

package gui.updatecenterwizard;

import java.awt.Component;
import javax.swing.JComponent;
import junit.textui.TestRunner;
import org.netbeans.jellytools.Bundle;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.NbDialogOperator;
import org.netbeans.jellytools.WizardOperator;
import org.netbeans.jellytools.actions.Action;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.EventTool;
import org.netbeans.jemmy.JemmyException;
import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JCheckBoxOperator;
import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JLabelOperator;
import org.netbeans.jemmy.operators.JTableOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
import org.netbeans.jemmy.operators.JTreeOperator;
import org.netbeans.junit.NbTestSuite;

/**
 *
 * @author  lukas.hasik
 */
public class UpdateCenterWizardTests extends JellyTestCase {
    
    /** Creates a new instance of UpdateCenterWizardTests */
    public UpdateCenterWizardTests(String name) {
        super(name);
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        
        suite.addTest(new UpdateCenterWizardTests("testUnsuccesfullConnection"));        
        suite.addTest(new UpdateCenterWizardTests("testSuccesfullConnection"));

        
        return suite;
    }
    
    /** Use for execution inside IDE */
    public static void main(java.lang.String[] args) {
        // run whole suite
        //TestRunner.run(suite());
        // run only selected test case
        junit.textui.TestRunner.run(new UpdateCenterWizardTests("testSuccesfullConnection"));
    }
    
    public void setUp() {
        System.out.println("########  "+getName()+"  #######");
    }
    
    public void tearDown() {
    }
    
    /* opens Update Center wizard from main menu Tools | Update Center
     */
    private WizardOperator openUpdateCenterWizard() throws JemmyException {
        // "Tools"
        String toolsItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N
        WizardOperator updateCenterWizardOper = null;
        String updateCenterItem = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "CTL_Update");
        new Action(toolsItem+"|"+updateCenterItem, null).perform();
        // "Update Center Wizard"
        String updateCenterTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Wizard");
        updateCenterWizardOper = new WizardOperator(updateCenterTitle);
        
        return updateCenterWizardOper;
    }
    
    /* opens Update Center wizard 
     * set proxy to webcache:8080 !!! please change it correctly to your local settings, or comment the line marked with '// !!! proxy !!!'
     * connects to default update center
     */
    public void testSuccesfullConnection() {
        WizardOperator ucwizard = null;
        
        try {
            ucwizard = openUpdateCenterWizard();            
            // set proxy
            // Proxy Configuration...
            String buttonProxyConfLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "BNT_Proxy"); // !!! proxy !!! // NOI18N
            new JButtonOperator(ucwizard, buttonProxyConfLabel).pushNoBlock(); // !!! proxy !!!
            // Proxy Configuration
            String proxyConfDialogTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_ProxyDialog_Title"); // !!! proxy !!! // NOI18N
            NbDialogOperator proxyDialog = new NbDialogOperator(proxyConfDialogTitle);// !!! proxy !!!
            // Use Proxy check box
            new JCheckBoxOperator(proxyDialog).setSelected(true);// !!! proxy !!!
            // Proxy Host: text field
            new JTextFieldOperator(proxyDialog, 0).setText("webcache");// !!! proxy !!! // NOI18N
            // Proxy Port: text field
            new JTextFieldOperator(proxyDialog, 1).setText("8080");// !!! proxy !!! // NOI18N
            proxyDialog.ok();// !!! proxy !!!
            // "Next >"
            ucwizard.btNext().pushNoBlock();
            // wait connecting dialog appears
            // "Connecting"
            String connectingTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Connecting_Title");
            // wait at most 60 second until connecting dialog dismiss
            JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000);
            new NbDialogOperator(connectingTitle).waitClosed();
            //check that you are on second pane/step
            String secondStep = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "LAB_221"); //label 'Available Updates and New Modules:' is only on second pane
            new JLabelOperator(ucwizard, secondStep);
            //can close
            ucwizard.close();
            
        } catch (JemmyException e) {
            // close Update center dialog
            if(ucwizard != null) {
                ucwizard.close();
            }
            throw e;
        }
        
        
        
    }
    /* opens Update Center wizard 
     * set proxy to wrong values
     * connects to default update center 
     * and the connect fails
     */
    public void testUnsuccesfullConnection() {
        WizardOperator ucwizard = null;
        
        try {
            ucwizard = openUpdateCenterWizard();
            
            // set proxy
            // Proxy Configuration...
            String buttonProxyConfLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "BNT_Proxy"); // NOI18N
            new JButtonOperator(ucwizard, buttonProxyConfLabel).pushNoBlock();
            // Proxy Configuration
            String proxyConfDialogTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_ProxyDialog_Title"); // NOI18N
            NbDialogOperator proxyDialog = new NbDialogOperator(proxyConfDialogTitle);
            // Use Proxy check box
            new JCheckBoxOperator(proxyDialog).setSelected(true);
            // Proxy Host: text field
            new JTextFieldOperator(proxyDialog, 0).setText("nonexisting.cache"); // NOI18N
            // Proxy Port: text field
            new JTextFieldOperator(proxyDialog, 1).setText("80809999999999999999"); // NOI18N
            proxyDialog.ok();
            // "Next >"
            ucwizard.btNext().pushNoBlock();
            // wait connecting dialog appears
            // "Connecting"
            String connectingTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Connecting_Title");
            // wait at most 60 second until connecting dialog dismiss
            JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000);
            new NbDialogOperator(connectingTitle).waitClosed();
            //find Error dialog
            String errorTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Error");
            new NbDialogOperator(errorTitle).close();
            ucwizard.close();
            
        } catch (JemmyException e) {
            // close Update center dialog
            if(ucwizard != null) {
                ucwizard.close();
            }
            throw e;
        }
        
    }
    
    public void testProxyDialogPossibilities() {
        
    }
    
    public void testAddNewAUType() {
        
    }
    
    public void testBadAUUrl() {
        
    }
    
    public void testChangePropagation() {
        
    }
    
    public void testSecondPanelButtons() {
        
    }
    
    public void testAcceptLicence() {
        
    }
    
    public void testSkipDownloadStep() {
        
    }
    
    public void testIncludeCheckBox() {
        
    }
    
    public void testSaveCopy() {
        
    }
    
    public void testSaveCopyWithWrongName() {
        
    }
    
    public void testUninstallAndInstallAUModule() {
        
    }
    
    /** Test Update Center
     * - open Update Center Wizard from main menu Tools|Update Center
     * - set proxy and go next
     * - wait until connection dialog dismiss
     * - in modules tree select "Development Update Center|Web|Applet" node
     * - click right arrow button and go next
     * - accept license dialog
     * - wait until download is finished and finish the wizard
     */
    public void testUpdateCenter() {
        // "Tools"
        String toolsItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N
        WizardOperator updateCenterWizardOper = null;
        long oldWaitStateTime = JemmyProperties.getCurrentTimeout("ComponentOperator.WaitStateTimeout");
        try {
            // "Update Center"
            String updateCenterItem = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "CTL_Update");
            new Action(toolsItem+"|"+updateCenterItem, null).perform();
            // "Update Center Wizard"
            String updateCenterTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Wizard");
            updateCenterWizardOper = new WizardOperator(updateCenterTitle);
            // disable Forte for Java Update Center if any
            JTableOperator oper = new JTableOperator(updateCenterWizardOper);
            // check each row
            for(int i=0;i-1 && ((Boolean)oper.getValueAt(i, 0)).booleanValue()) { // NOI18N
                    oper.clickOnCell(i, 0);
                }
                // if Update Center matches "Sun ONE Studio" and it is enabled/checked then click to uncheck
                if(oper.getValueAt(i, 1).toString().indexOf("Sun")>-1 && ((Boolean)oper.getValueAt(i, 0)).booleanValue()) { // NOI18N
                    oper.clickOnCell(i, 0);
                }
            }
            
            // set proxy
            // Proxy Configuration...
            String buttonProxyConfLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "BNT_Proxy"); // NOI18N
            new JButtonOperator(updateCenterWizardOper, buttonProxyConfLabel).pushNoBlock();
            // Proxy Configuration
            String proxyConfDialogTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_ProxyDialog_Title"); // NOI18N
            NbDialogOperator proxyDialog = new NbDialogOperator(proxyConfDialogTitle);
            // Use Proxy check box
            new JCheckBoxOperator(proxyDialog).setSelected(true);
            // Proxy Host: text field
            new JTextFieldOperator(proxyDialog, 0).setText("webcache"); // NOI18N
            // Proxy Port: text field
            new JTextFieldOperator(proxyDialog, 1).setText("8080"); // NOI18N
            proxyDialog.ok();
            
            // "Next >"
            updateCenterWizardOper.btNext().pushNoBlock();
            // wait connecting dialog appears
            // "Connecting"
            String connectingTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Connecting_Title");
            // wait at most 60 second until connecting dialog dismiss
            JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", 60000);
            new NbDialogOperator(connectingTitle).waitClosed();
            // wait JTree generated on next page
            new EventTool().waitNoEvent(500);
            // select Web|Applet module
            JTreeOperator tree = new JTreeOperator(updateCenterWizardOper);
            // "Development Update Center
            String devUCLabel = Bundle.getString("org.netbeans.modules.updatecenters.resources.Bundle", "Services/AutoupdateType/autoupdate_xml_type.settings");
            new Node(tree, devUCLabel+"|Web|Applet").select(); // NOI18N
            // add to right panel (push button with tooltip "Add")
            new JButtonOperator(updateCenterWizardOper, new ComponentChooser() {
                final String addLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "HINT_Add"); // NOI18N
                public boolean checkComponent(Component comp) {
                    String tooltip = ((JComponent)comp).getToolTipText();
                    if(tooltip != null) {
                        return tooltip.equals(addLabel);
                    } else {
                        return false;
                    }
                }
                
                public String getDescription() {
                    return "JButton with tooltip equals "+addLabel;
                }
            }).push();
            // push "Next" button
            updateCenterWizardOper.btNext().pushNoBlock();
            // accept license agreement
            // "License Agreement"
            String licenceTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Licence_Title");
            // "Accept"
            String acceptLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Licence_Accept");
            new JButtonOperator(new NbDialogOperator(licenceTitle), acceptLabel).push();
            // wait 30 s until download is done
            JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000); // NOI18N
            // "Done."
            String doneLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "DownloadProgressPanel.jLabel1.doneText");
            new JLabelOperator(updateCenterWizardOper, doneLabel);
            updateCenterWizardOper.next();
            // accept certificate if requested
            if(!updateCenterWizardOper.btFinish().isEnabled()) {
                // "View Certificate..."
                String viewCertificateLable = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "BTN_View");
                new JButtonOperator(updateCenterWizardOper, viewCertificateLable).pushNoBlock();
                // click on "Accept" button in dialog
                String acceptCertificateLabel = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Certificate_Accept");
                // "Module Certificate"
                String certificateTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Certificate_Title");
                new JButtonOperator(new JDialogOperator(certificateTitle), acceptCertificateLabel).push();
            }
            // "Finish"
            updateCenterWizardOper.btFinish().push();
        } catch (JemmyException e) {
            // close possible error dialog
            // "Error"
            String errorTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Error");
            if(JDialogOperator.findJDialog(errorTitle, true, true) != null) {
                new NbDialogOperator(errorTitle).close();
            }
            // close Update center dialog
            if(updateCenterWizardOper != null) {
                updateCenterWizardOper.close();
            }
            throw e;
        } finally {
            // restore default timeout
            JemmyProperties.setCurrentTimeout("ComponentOperator.WaitStateTimeout", oldWaitStateTime);
        }
    }
}
... 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.