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

package complete.common;

import java.io.*;
import junit.framework.*;
import org.netbeans.junit.*;
import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.util.PNGEncoder;
import org.openide.util.Utilities;
import org.netbeans.jellytools.*;
import org.netbeans.jellytools.nodes.Node;
import org.netbeans.jellytools.actions.*;
import org.netbeans.jellytools.properties.*;
import org.netbeans.jellytools.modules.vcsgeneric.wizard.*;

/** XTest / JUnit test class performing check of all settings of filesystems mounted
 * using Generic VCS module.
 * @author Jiri Kovalsky
 * @version 1.0
 */
public class FilesystemSettings extends JellyTestCase {
    
    public static String VERSIONING_MENU = "Versioning";
    public static String MOUNT_MENU = VERSIONING_MENU + "|Mount Version Control|Generic VCS";
    public static String UNMOUNT_MENU = "File|Unmount Filesystem";
    
    /** Constructor required by JUnit.
     * @param testName Method name to be used as testcase.
     */
    public FilesystemSettings(String testName) {
        super(testName);
    }
    
    /** Method used for explicit test suite definition. This suite contains following test cases:
     * testUnmount, testPopupMenu, testRuntimeTab and testFindService.
     * @return GenericVCSAvailabilityTest test suite.
     */
    public static junit.framework.Test suite() {
        TestSuite suite = new NbTestSuite();
        suite.addTest(new FilesystemSettings("testAnnotationPattern"));
        suite.addTest(new FilesystemSettings("testCommandNotification"));
        suite.addTest(new FilesystemSettings("testProcessAllFiles"));
        suite.addTest(new FilesystemSettings("testIgnoredFiles"));
        suite.addTest(new FilesystemSettings("testBackupProperties"));
        suite.addTest(new FilesystemSettings("testRefreshTime"));
        suite.addTest(new FilesystemSettings("testHideShadowFiles"));
        return suite;
    }
    
    /** Use for internal test execution inside IDE.
     * @param args Command line arguments.
     */
    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(suite());
    }
    
    /** Mounts new filesystem using given profile.
     * @param profile Profile that should be used in wizard.
     * @throws Any unexpected exception thrown during test.
     */
    private void mountFilesystem(String profile, String workingDirectory) throws Exception {
        new ActionNoBlock(MOUNT_MENU, null).perform();
        VCSWizardProfile wizard = new VCSWizardProfile();
        wizard.setWorkingDirectory(workingDirectory);
//        wizard.checkOnlyCompatibleProfiles(false);
        wizard.setProfile(profile);
        Thread.sleep(1000);
        wizard.finish();
    }
    
    /** Creates new file or directory at given place.
     * @param name Name of directory or file to create.
     * @param isFile Should file be created or directory ?
     * @throws Any unexpected exception thrown during test.
     */
    public void createFile(String name, boolean isFile) throws Exception {
        if (isFile) {
            BufferedWriter writer = new BufferedWriter(new FileWriter(name));
            writer.write("/** This is testing file.\n */\n\n public class Testing_File {\n }\n");
            writer.flush();
            writer.close();
        }
        else new File(name).mkdirs();
    }

    /** Returns all of node's children as one String devided with commas.
     * @param node The node whose children should be returned in one String.
     * @return Collection of all children of given node.
     */
    private String getChildren(Node node) {
        String[] children = node.getChildren();
        String output = " [";
        int count = children.length;
        for(int i=0; i> ${fileName} $[? attribute][[Yes]][[No]] <<");
            property = new Property(sheet, "Refresh Time For Local Files [ms]");
            property.setValue("1000");
            Thread.sleep(1000);
            Node fileNode = new Node(filesystemNode, ">> A_File [No] <<");
            fileNode.select();
            new UnmountFSAction().perform(filesystemNode);
            System.out.println(". done !");
        } catch (Exception e) {
            new UnmountFSAction().perform(new Node(new ExplorerOperator().repositoryTab().getRootNode(), "Empty " + getWorkDirPath()));
            throw e;
        }
    }
    
    /** Checks whether "Command Notification" property works correctly.
     * @throws Any unexpected exception thrown during test.
     */
    public void testCommandNotification() throws Exception {
        try {
            System.out.print(".. Testing command notification property ..");
            String workingDirectory = getWorkDir().getAbsolutePath();
            String filesystem = "CVS " + workingDirectory;
            createFile(workingDirectory + File.separator + "A_File.java", true);
            mountFilesystem(Utilities.isUnix() ? VCSWizardProfile.CVS_UNIX : VCSWizardProfile.CVS_WIN_NT, workingDirectory);
            Thread.sleep(2000);
            Node filesystemNode = new Node(new ExplorerOperator().repositoryTab().getRootNode(), filesystem);
            Node fileNode = new Node(filesystemNode, "A_File");
            new Action(null, "CVS|Editing|Edit").perform(fileNode);
            new NbDialogOperator("Information").ok();
            new Action("View|Properties", null).perform(filesystemNode);
            PropertySheetOperator sheet = new PropertySheetOperator();
            Property commandNotification = new Property(sheet, "Command Notification");
            commandNotification.setValue("False");
            new Action(null, "CVS|Editing|Edit").perform(fileNode);
            long oldTimeout = JemmyProperties.getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
            JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 5000);
            try {
                new NbDialogOperator("Information").ok();
                JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", oldTimeout);
                fail("Command Notification property does not work.");
            } catch (org.netbeans.jemmy.TimeoutExpiredException e) {}
            JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", oldTimeout);
            new UnmountFSAction().perform(filesystemNode);
            System.out.println(". done !");
        } catch (Exception e) {
            new UnmountFSAction().perform(new Node(new ExplorerOperator().repositoryTab().getRootNode(), "CVS " + getWorkDir().getAbsolutePath()));
            throw e;
        }
    }

    /** Checks whether "Process All Files" property works correctly.
     * @throws Any unexpected exception thrown during test.
     */
    public void testProcessAllFiles() throws Exception {
        try {
            System.out.print(".. Testing process all files property ..");
            String workingDirectory = getWorkDir().getAbsolutePath();
            String filesystem = "Empty " + workingDirectory;
            createFile(workingDirectory + File.separator + "A_File.java", true);
            createFile(workingDirectory + File.separator + "A_File.class", true);
            mountFilesystem(Utilities.isUnix() ? VCSWizardProfile.EMPTY_UNIX : VCSWizardProfile.EMPTY_WIN, workingDirectory);
            Thread.sleep(2000);
            Node filesystemNode = new Node(new ExplorerOperator().repositoryTab().getRootNode(), filesystem);
            new Action("View|Properties", null).perform(filesystemNode);
            PropertySheetOperator sheet = new PropertySheetOperator();
            Property processAllFiles = new Property(sheet, "Process All Files");
            processAllFiles.setValue("True");
            Node fileNode = new Node(filesystemNode, "A_File");
            new Action(VERSIONING_MENU+"|Empty|Lock", null).perform(fileNode);
            RuntimeTabOperator explorer = new ExplorerOperator().runtimeTab();
            Node commandsHistory = new Node(explorer.getRootNode(), "VCS Commands|" + filesystem);
            commandsHistory.tree().expandPath(commandsHistory.getTreePath());
            int count = commandsHistory.getChildren().length;
            boolean found = false;
            for(int i=0; i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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