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

/*
 * CreatingPropertiesFileFromMainWindow2.java
 *
 * Created on 18. September 2002
 */

package org.netbeans.properties.jelly2tests.suites.creating_properties_file;

import java.awt.Component;
import java.awt.Container;
import java.io.File;
import junit.textui.TestRunner;
import org.netbeans.jellytools.*;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jellytools.nodes.PropertiesNode;
import org.netbeans.jemmy.EventTool;
import org.netbeans.jemmy.operators.JTreeOperator;
import org.netbeans.junit.NbTestSuite;


/**
 *
 * @author  Petr Felenda - QA Engineer (petr.felenda@sun.com)
 */
public class CreatingPropertiesFileFromMainWindow2 extends JellyTestCase {
    
    /*
     * Definition of member variables and objects
     */
    final String FILE_NAME = "testCreatingPropertiesFileFromMainWindow2" ;
    final String SEPARATOR = "#";
    final String WORKDIR = System.getProperty( "xtest.workdir") + File.separator + "tmpdir";
    final String PACKAGE_PATH = "examples";
    //final String EDITOR_TITLE_NAME = "Source Editor";
    
    
    /*
     * Main method for starting test from IDE.
     * There should be mounted necessary jars in Filesystems ( in Explorer Window )
     * - jemmy.jar
     * - jelly2-nb.jar
     *  both jars have been downloaded from http://jellytools.netbeans.org
     *  @param String[] args - arguments are not processed
     */
    public static void main( String[] args) {
        
        NbTestSuite nbSuite = new NbTestSuite();
        for ( int ii = 1; ii <= 10; ii++ )
            nbSuite.addTest(new CreatingPropertiesFileFromMainWindow2());
        TestRunner.run(nbSuite);
    }
    
    
    /**
     * Constructor - Creates a new instance of this class
     */
    public CreatingPropertiesFileFromMainWindow2() {
        super("testCreatingPropertiesFileFromMainWindow2");
    }
    
    
    /**
     * This method contain body of test
     * @return void
     */
    public void testCreatingPropertiesFileFromMainWindow2() {
        
        /*
         * Print description of test to output window
         */
        System.out.println();
        System.out.println("================================================================================");
        System.out.println("=   Test :  Creating properties file from main window 2                        =");
        System.out.println("=   See testspec of properties module on web :                                 =");
        System.out.println("=   http://properties.netbeans.org/qa/testspecs/nb34/PropertiesTestSpec.html   =");
        System.out.println("================================================================================");
        
        //create a node for the WORKDIR directory
        FilesystemNode filesystemNode = new FilesystemNode( WORKDIR );
        filesystemNode.select();
        /*
         * 1st step of testcase ( here is used toolbar's icon for opening wizard )
         * There will be opened New Wizard from Main Window Toolbar ( icon 'New' from toolbar 'System' )
         */
        MainWindowOperator mainWindowOp = MainWindowOperator.getDefault();
        mainWindowOp.getToolbarButton(mainWindowOp.getToolbar("System"),"New").push();
        
        
        /*
         * 2nd step of testcase
         * Select from wizard Other|Properties File and click next button.
         */
        WizardOperator wo = new WizardOperator("New");
        JTreeOperator tree = new JTreeOperator(wo);
        tree.clickOnPath(tree.findPath("Other|Properties File","|"));
        wo.next();
        
        /*
         * 3rd step of testcase
         * Type name and select directory.
         */
        new TargetLocationStepOperator().setName(this.FILE_NAME);
        // It's not good use thw same varianble for two things but there are less rows in code
        tree = new JTreeOperator(wo);
        tree.clickOnPath( tree.findPath( this.WORKDIR ));// + this.SEPARATOR ));//+ this.PACKAGE_PATH, this.SEPARATOR));
        
        
        /*
         * 4th step of testcase
         * Confirm wizard
         */
        wo.finish();
        
        
        /*
         *  Result
         * Should be added new properties file to adequate place in explorer and opened in editor
         */
        new EventTool().waitNoEvent(2000);
        
        TopComponentOperator eo=new TopComponentOperator(this.FILE_NAME);
        System.out.println(">> File has been in Editor Window (Ok)");
        /*NbFrameOperator fo = new NbFrameOperator(this.EDITOR_TITLE_NAME);
        if ( findMyComponent( fo.getComponents(),"["+this.FILE_NAME) == null )
            fail("File not found in Editor window");
        else
            System.out.println(">> File has been in Editor Window (Ok)");*/
        
        System.out.println(">> Checking Explorer");
        
        /*
         * Cleanup and checking if file is rightly closed
         */
        PropertiesNode propNode = new PropertiesNode(filesystemNode, this.FILE_NAME);
        propNode.delete();
        
        NbDialogOperator dop = new NbDialogOperator(Bundle.getString("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle"));
        dop.yes();
        
        new EventTool().waitNoEvent(500);
        
        /*Component c;
         if ( (c = findMyComponent( fo.getComponents(),"["+this.FILE_NAME)) != null ) {
            System.out.println(">> "+ c.toString());
            fail("There is opened my file in Editor. This should be an issue.");
        } else
            System.out.println(">> Editor Window (Ok)");*/
    }
    
    
    
    /*
     * Find component in container
     */
    private Component findMyComponent(Container con, String findComponent) {
        Component comp = null;
        for ( int ii = 0; ii < con.getComponentCount(); ii++ ) {
            String str = con.getComponent(ii).toString().toLowerCase();
            int toIndex = str.indexOf('[');
            str = str.substring(0,toIndex);
            if ( str.indexOf("pane") > 0 || str.indexOf("view") > 0 || str.indexOf("renderer") > 0 || str.indexOf("container") > 0 || str.indexOf("component") > 0 ) {
                Container tmpC = (Container) con.getComponent(ii);
                if ( tmpC.getComponentCount() != 0 )
                    comp = findMyComponent( (Container) con.getComponent(ii), findComponent);
            }
            // if component is
            if ( comp != null )
                return comp;
            
            if ( con.getComponent(ii).toString().toLowerCase().indexOf(findComponent.toLowerCase()) > 0 )
                return con.getComponent(ii);
        }
        return null;
    }
    
    /*
     * Find comtainer in component
     */
    private Component findMyComponent(Component[] comps, String findComponent ){
        Component comp = null;
        for ( int ii = 0; ii < comps.length; ii++ ) {
            
            String str = comps[ii].toString().toLowerCase();
            int toIndex = str.indexOf('[');
            str = str.substring(0,toIndex);
            if ( str.indexOf("pane") > 0 )
                comp = findMyComponent( (Container) comps[ii] , findComponent);
            if ( comp != null )
                break;
        }
        
        return comp;
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new CreatingPropertiesFileFromMainWindow2());
        return suite;
    }
    
}
... 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.