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

package complete.common;

import java.io.*;
import junit.framework.*;
import org.netbeans.junit.*;
import org.netbeans.jemmy.TestOut;
import org.netbeans.jemmy.operators.JButtonOperator;
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.modules.vcscore.*;
import org.netbeans.jellytools.modules.vcsgeneric.wizard.*;
import org.netbeans.jellytools.properties.*;
import org.netbeans.test.oo.gui.jelly.SearchResults;
import org.netbeans.test.oo.gui.jelly.vcscore.SearchVCSFilesystem;


/** XTest / JUnit test class performing availability check of all basic features
 * of Generic VCS module.
 * @author Jiri Kovalsky
 * @version 1.0
 */
public class Availability extends JellyTestCase {
    
    public static String VERSIONING_MENU = "Versioning";
    public static String MOUNT_MENU = VERSIONING_MENU + "|Mount Version Control|Generic VCS";
    public static String FIND_SERVICE = "Find...";
    public static String UNMOUNT_MENU = "File|Unmount Filesystem";
    
    /** Constructor required by JUnit.
     * @param testName Method name to be used as testcase.
     */
    public Availability(String testName) {
        super(testName);
    }
    
    /** Method used for explicit test suite definition. This suite contains following test cases:
     * testUnmount, testPopupMenu, testRuntimeTab and testFindService.
     * @return Availability test suite.
     */
    public static junit.framework.Test suite() {
        TestSuite suite = new NbTestSuite();
        suite.addTest(new Availability("testVersioningMenu"));
        suite.addTest(new Availability("testUnmount"));
        suite.addTest(new Availability("testPopupMenu"));
        suite.addTest(new Availability("testFindService"));
        suite.addTest(new Availability("testRuntimeTab"));
        suite.addTest(new Availability("testToolbar"));
        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());
    }
    
    /** Method called before each testcase. Sets default timeouts, redirects system
     * output and maps main components.
     */
    protected void setUp() {
        org.netbeans.jemmy.JemmyProperties.setCurrentOutput(org.netbeans.jemmy.TestOut.getNullOutput());
    }
    
    /** Method will create a file and capture the screen.
     */
    private void captureScreen(Exception exc) throws Exception {
        File dumpFile, excFile;
        try {
            dumpFile = new File(getWorkDirPath() + "/dump.png");
            excFile = new File(getWorkDirPath() + "/exception.txt");
            dumpFile.getParentFile().mkdirs();
            dumpFile.createNewFile();
            PrintWriter writer = new PrintWriter(new FileWriter(excFile));
            exc.printStackTrace(writer);
            writer.flush();
            writer.close();
        } catch(IOException e) { throw new Exception("Error: Can't create dump file."); }
        PNGEncoder.captureScreen(dumpFile.getAbsolutePath());
    }
    
    /** Checks that "Versioning" main menu contains item for mounting Generic VCS filesystem.
     * @throws Exception any unexpected exception thrown during test.
     */
    public void testVersioningMenu() throws Exception {
        try {
            System.out.print(".. Testing versioning menu ..");
            new ActionNoBlock(MOUNT_MENU, null).perform();
            VCSWizardProfile wizard = new VCSWizardProfile();
            wizard.cancel();
            System.out.println(". done !");
        } catch (Exception e) {
            captureScreen(e);
            long oldTimeout = org.netbeans.jemmy.JemmyProperties.getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
            org.netbeans.jemmy.JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 2000);
            try { new VCSWizardProfile().cancel(); } catch (org.netbeans.jemmy.TimeoutExpiredException te) {}
            org.netbeans.jemmy.JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", oldTimeout);
            throw e;
        }
    }
    
    /** Unmounts the filesystem mounted in testVersioningMenu test case.
     * throws Exception Any unexpected exception thrown during test.
     */
    public void testUnmount() throws Exception {
        try {
            System.out.print(".. Testing unmount action ..");
            new File(getWorkDirPath()).mkdirs();
            new ActionNoBlock(MOUNT_MENU, null).perform();
            VCSWizardProfile wizard = new VCSWizardProfile();
            wizard.setProfile(Utilities.isUnix() ? VCSWizardProfile.EMPTY_UNIX : VCSWizardProfile.EMPTY_WIN);
            wizard.setWorkingDirectory(getWorkDirPath());
            wizard.finish();
            Thread.sleep(2000);
            String filesystem = "Empty " + getWorkDirPath();
            Node filesystemNode = new Node(new ExplorerOperator().repositoryTab().getRootNode(), filesystem);
            new UnmountFSAction().perform(filesystemNode);
            Thread.currentThread().sleep(5000);
            assertTrue("Error: Unable to unmount filesystem.", !filesystemNode.isPresent());
            System.out.println(". done !");
        } catch (Exception e) {
            captureScreen(e);
            long oldTimeout = org.netbeans.jemmy.JemmyProperties.getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
            org.netbeans.jemmy.JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 2000);
            try { new VCSWizardProfile().cancel(); } catch (org.netbeans.jemmy.TimeoutExpiredException te) {}
            try { new UnmountFSAction().perform(new Node(new ExplorerOperator().repositoryTab().getRootNode(), "Empty " + getWorkDirPath())); }
            catch (Exception te) {}
            org.netbeans.jemmy.JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", oldTimeout);
            throw e;
        }
    }
    
    /** Checks that popup menu contains all of item appropriate for mounted Generic VCS filesystem.
     * @throws Exception any unexpected exception thrown during test.
     */
    public void testPopupMenu() throws Exception {
        try {
            System.out.print(".. Testing popup menu ..");
            new File(getWorkDirPath()).mkdirs();
            new ActionNoBlock(MOUNT_MENU, null).perform();
            VCSWizardProfile wizard = new VCSWizardProfile();
            wizard.setProfile(Utilities.isUnix() ? VCSWizardProfile.EMPTY_UNIX : VCSWizardProfile.EMPTY_WIN);
            wizard.setWorkingDirectory(getWorkDirPath());
            wizard.finish();
            Thread.sleep(2000);
            String filesystem = "Empty " + getWorkDirPath();
            Node filesystemNode = new Node(new ExplorerOperator().repositoryTab().getRootNode(), filesystem);
            new Action(null, "Empty|Refresh Recursively").perform(filesystemNode);
            new NbDialogOperator("Retrieving...").closeByButton();
            String[] commands = new String[] {"Refresh", "Check In", "Check Out", "Lock", "Unlock", "Add", "Remove"};
            for (int i=0; i
... 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.