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.
 */

/*
 * File CustomizeBigPropertiesFile.java
 *
 * Created on 19. brezen 2002, 11:07
 *
 * Description :
 *
 * This is autometed test for netBenas34 version. Test has been
 * writed in Jelly2 ( see testtools.netbeans.org )
 *
 */

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

import java.awt.Container;
import java.lang.Exception;
import java.lang.InterruptedException;
import java.lang.Runnable;
import java.lang.Thread;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.EditorWindowOperator;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.NbDialogOperator;
import org.netbeans.jellytools.RepositoryTabOperator;
import org.netbeans.jellytools.TopComponentOperator;
import org.netbeans.jellytools.actions.CloseViewAction;
import org.netbeans.jellytools.actions.SaveAction;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jemmy.ComponentChooser;
import org.netbeans.jemmy.EventTool;
import org.netbeans.jemmy.operators.ComponentOperator;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.properties.jelly2tests.operators.PropertiesEditorOperator;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.Repository;


/**
 *
 * @author  Petr Felenda - QA Engineer ( petr.felenda@sun.com )
 */
public class CustomizeBigPropertiesFile extends JellyTestCase {
    
    /*
     * Definition of member variables and objects
     */
    private final String FILE_NAME = "big_file";
    private final String KEY = "key";
    private final String VALUE = "value";
    private final String COMMENT = "Comment of key";
    private final int count = 2;
    private final int[] indexes = new int[] {2};//    }{12,512,780,42,444,55,678,1,333,48};
    
    
    /*
     * Main method for starting test from IDE.
     * There must 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) {
        
        junit.textui.TestRunner.run(suite());
    }
    
    
    /*
     * This static constructor have been using for starting this test from JUnit framework
     */
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new CustomizeBigPropertiesFile());
        return suite;
    }
    
    
    /**
     * Constructor - Creates new instance of this class
     */
    public CustomizeBigPropertiesFile() {
        super("testCustomizeBigPropertiesFile");
    }
    
    
    /**
     *  This is body of test. Each step of testcase are described in testspec
     * on http://properties.netbeans.org/qa
     */
    public void testCustomizeBigPropertiesFile() throws Exception {
        
        // Print test description to the Output window
        System.out.println();
        System.out.println("===================================================================================");
        System.out.println("=   Test :  Customize big properties file                                         =");
        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("===================================================================================");
        
        
        /*
         * 1st step of testcase
         * Open big properties file with 5 thousands rows in it.
         */
        
        
        PropertiesEditorOperator propertiesEditorOperator = new PropertiesEditorOperator();
        // this only find filesystem in repository
        FileSystem[] fileSystems = Repository.getDefault().toArray();
        String fileSystemName = null;
        
        for ( int ii = 0; ii < fileSystems.length; ii++ ) {
            FileObject file = fileSystems[ii].findResource("data");
            if (file != null) {
                System.out.println("> Used Filesystem = "+fileSystems[ii].getDisplayName());
                fileSystemName = fileSystems[ii].getDisplayName();
            }
        }
        
        if ( fileSystemName == null )
            throw new Exception("Must be mounted .../data repository in explorer !");
        
        String path = fileSystemName.concat("|data|"+FILE_NAME);
        propertiesEditorOperator.openExistedPropertiesFile(path);
        
        /*
         * 2nd step of testcase
         * Add some properties to this file. Use 'Add property' button in
         * properties file' or popup menu from explorer or properties window.
         */
        
        // start time measurement  --> this code will be added later
        long time=System.currentTimeMillis();
        try {
            
            for ( int ii = 0; ii <= count; ii++ ) {
                propertiesEditorOperator.propertiesEditorClickNewPropertyButton(this.FILE_NAME);
                propertiesEditorOperator.newPropertyDialogFill(this.FILE_NAME, this.KEY.concat(String.valueOf(ii)), this.VALUE.concat(String.valueOf(ii)), this.COMMENT.concat(String.valueOf(ii)));
                propertiesEditorOperator.newPropertyDialogClickCloseButton();
            }
            
        /*
         * 3th step of testcase
         * Remove some properties.
         */
            for (int i=0;i < indexes.length;i++) {
                System.out.println(">>  Selecting row : "+indexes[i]);
                propertiesEditorOperator.selectPropertiesFileItem(this.FILE_NAME, indexes[i]);
                propertiesEditorOperator.propertiesEditorClickRemovePropertyButton(this.FILE_NAME);
                propertiesEditorOperator.questionDialogClickOkButton();
                
            }
        } finally {
            
        /*
         * Result
         * All actions should be done in adequate time. Maximum time for each
         * action is 3 sec.
         */
            // stop time measuement --> this code will be added later
            time=System.currentTimeMillis()-time;
            System.out.println("Time: "+time+" ms. Maximum time = "+(3000*indexes.length)+" ms.");
            
        /*
         * Clean up
         */
            TopComponentOperator tco = new TopComponentOperator(FILE_NAME);
            tco.saveDocument();
            new EventTool().waitNoEvent(10000);
            tco.close();
            //propertiesEditorOperator.questionDialogClickDiscardButton();
            /*new Thread() {
                public void run() {
                    NbDialogOperator nbDialogOperator = new NbDialogOperator("Question");
                    nbDialogOperator.no();
                }
            }.start();*/
            System.out.println("Closed discard.");
        }
    }
    
}
... 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.