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 EditFileInClassicEditorRemoveProperty
 *
 * 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.editing_properties_file;

import java.io.File;
import javax.swing.SwingUtilities;
import junit.textui.TestRunner;
import org.netbeans.jellytools.EditorOperator;
import org.netbeans.jellytools.JellyTestCase;
import org.netbeans.jellytools.nodes.FilesystemNode;
import org.netbeans.jemmy.QueueTool;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.properties.jelly2tests.operators.PropertiesEditorOperator;


/**
 *
 * @author  Petr Felenda - QA Engineer ( petr.felenda@sun.com )
 */
public class EditFileInClassicEditorRemoveProperty extends JellyTestCase {
    
    
    /*
     * Definition of member variables and objects
     */
    private final String FILE_NAME = "testEditFileInClassicEditorRemoveProperty";
    
    
     /*
      * 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) {
        
        NbTestSuite nbTestSuite = new NbTestSuite();
        nbTestSuite.addTest(new EditFileInClassicEditorRemoveProperty());
        TestRunner.run(nbTestSuite);
    }
    
    
    /*
     * This static constructor have been using for starting this test from JUnit framework
     */
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new EditFileInClassicEditorRemoveProperty());
        return suite;
    }
    
    
    /**
     * Constructor - Creates new instance of this class
     */
    public EditFileInClassicEditorRemoveProperty() {
        super("testEditFileInClassicEditorRemoveProperty");
        
    }
    
    
    /**
     * This method contains body of test
     * @return void
     */
    public void testEditFileInClassicEditorRemoveProperty() {
        
        // Print test description to the Output window
        System.out.println();
        System.out.println("===================================================================================");
        System.out.println("=   Test :  Edit file in classic editor remove property                           =");
        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
         * Use propery file from previous case.
         */
        
        //create a node for the sampledir directory
        FilesystemNode filesystemNode = new FilesystemNode(System.getProperty( "xtest.workdir")+
        File.separator + "tmpdir");
        
        PropertiesEditorOperator propertiesEditorOperator = new PropertiesEditorOperator();
        propertiesEditorOperator.createNewPropertiesFileAndOpenInClassicEditor(filesystemNode, this.FILE_NAME);
        EditorOperator editorOperator = new EditorOperator(this.FILE_NAME);
        editorOperator.setCaretPosition(2,1);
        editorOperator.insert("\n#Comment of key1");
        editorOperator.insert("\n");
        editorOperator.insert("key1=value1\n");
        new org.netbeans.jellytools.actions.Action(null,"Save").performPopup(editorOperator.txtEditorPane());
        
        /*
         * 2nd step of testcase
         * Remove property.(typed in previous case)
         */
        SwingUtilities.invokeLater(new Runnable() {
            EditorOperator eo;
            public void run() {
                eo.deleteLine(2);
                eo.deleteLine(2);
                eo.deleteLine(2);
            }
            public Runnable setData(EditorOperator e) {
                eo=e;
                return this;
            }
        }.setData(editorOperator));
        
        try {
            Thread.currentThread().sleep(6000);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //new QueueTool().waitEmpty(5000);
        /*
         * 3th step of testcase
         * Save file. Use shortcut Ctrl-s
         */
        new org.netbeans.jellytools.actions.Action(null,"Save").performPopup(editorOperator.txtEditorPane());
        
        
        /*
         * Result
         * Should be accordingly removed property from previous case. If you create new file then you sould create new property.
         */
        try {
            propertiesEditorOperator.checkPropertiesFileIntegrityInClassicEditor(this.FILE_NAME);
            propertiesEditorOperator.openExistedPropertiesFile(filesystemNode.getPath()+"|"+this.FILE_NAME);
            propertiesEditorOperator.checkPropertiesInSheet(this.FILE_NAME, "", "", "",-1,1,0);
            //propertiesEditorOperator.checkPropertiesInSheet(this.FILE_NAME, "key1", "value1", "# Comment of key1",-1,1,0);
        } catch (Exception ex) {
            fail(ex);
        } finally {
        /*
         * Cleanup
         */
            propertiesEditorOperator.deletePropertiesFileFromExplorer(filesystemNode,this.FILE_NAME);
        }
    }
    
}
... 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.