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.vss_profile;

import java.io.*;
import junit.framework.*;
import org.netbeans.junit.*;
import org.netbeans.jemmy.JemmyProperties;
import org.netbeans.jemmy.TestOut;
import org.netbeans.jemmy.TimeoutExpiredException;
import org.netbeans.jemmy.util.PNGEncoder;
import org.netbeans.jemmy.operators.*;
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.vcsgeneric.vss.*;
import org.netbeans.jellytools.modules.vcscore.VCSCommandsOutputOperator;
import org.netbeans.modules.vcscore.cmdline.exec.ExternalCommand;
import javax.swing.text.*;
import java.awt.Color;

/** XTest / JUnit test class performing regular development testing on VSS filesystem.
 * @author Jiri Kovalsky
 * @version 1.0
 */
public class RegularDevelopment extends NbTestCase {
    
    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";
    public static String REFRESH = "VSS|Refresh";
    public static String REFRESH_RECURSIVELY = "VSS|Refresh Recursively";
    public static String CHECK_OUT = "VSS|Check Out";
    public static String CHECK_IN = "VSS|Check In";
    public static String DIFF = "VSS|Diff";
    public static String HISTORY = "VSS|History";
    public static String PROPERTIES = "VSS|Properties";
    public static String GET_LATEST_VERSION = "VSS|Get Latest Version";
    public static String UNDO_CHECK_OUT = "VSS|Undo Check Out";
    private static final Color MODIFIED_COLOR = new Color(160, 200, 255);
    private static final Color NEW_COLOR = new Color(180, 255, 180);
    private static final Color REMOVED_COLOR = new Color(255, 160, 180);
    public static String workingDirectory;
    public static String userName;
    
    /** Constructor required by JUnit.
     * @param testName Method name to be used as testcase.
     */
    public RegularDevelopment(String testName) {
        super(testName);
    }
    
    /** Method used for explicit test suite definition.
     * @return RegularDevelopment test suite.
     */
    public static junit.framework.Test suite() {
        TestSuite suite = new NbTestSuite();
        if (Utilities.isUnix()) return suite;
        String zipFile = "C:\\Program Files\\Microsoft Visual Studio\\vss.zip";
        if (!new File(zipFile).exists()) return suite; // This test suite can't run where zip with empty VSS repository is not prepared.
        suite.addTest(new RegularDevelopment("testCheckoutFile"));
        suite.addTest(new RegularDevelopment("testModifyFile"));
        suite.addTest(new RegularDevelopment("testViewDifferences"));
        suite.addTest(new RegularDevelopment("testCheckinFile"));
        suite.addTest(new RegularDevelopment("testViewHistory"));
        suite.addTest(new RegularDevelopment("testGetMissingFile"));
        suite.addTest(new RegularDevelopment("testUnlockFile"));
        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() throws Exception {
        String workingDir = getWorkDirPath();
        new File(workingDir).mkdirs();
        File outputFile = new File(workingDir + "/output.txt");
        outputFile.createNewFile();
        File errorFile = new File(workingDir + "/error.txt");
        errorFile.createNewFile();
        PrintWriter outputWriter = new PrintWriter(new FileWriter(outputFile));
        PrintWriter errorWriter = new PrintWriter(new FileWriter(errorFile));
        org.netbeans.jemmy.JemmyProperties.setCurrentOutput(new org.netbeans.jemmy.TestOut(System.in, outputWriter, errorWriter));
    }

    /** Method will create a file and capture the screen.
     */
    private void captureScreen(String reason) throws Exception {
        File file;
        try {
            file = new File(getWorkDirPath() + "/dump.png");
            file.getParentFile().mkdirs();
            file.createNewFile();
        } catch(IOException e) { throw new Exception("Error: Can't create dump file."); }
        PNGEncoder.captureScreen(file.getAbsolutePath());
        throw new Exception(reason);
    }
    
    /** Tries to checkout a file from VSS project repository.
     * @throws Exception any unexpected exception thrown during test.
     */
    public void testCheckoutFile() throws Exception {
        System.out.print(".. Testing checking out a file ..");
        String workingPath = getWorkDirPath();
        workingDirectory = workingPath.substring(0, workingPath.indexOf("RegularDevelopment")) + "RepositoryCreation" + File.separator + "testCreateProjects";
        String filesystem = "VSS " + workingDirectory + File.separator + "Work";
        Node filesystemNode = new Node(new ExplorerOperator().repositoryTab().getRootNode(), filesystem);
        Node A_FileNode = new Node( filesystemNode, "A_File [Current]");
        new Action(VERSIONING_MENU + "|" + CHECK_OUT, CHECK_OUT).perform(A_FileNode);
        Thread.sleep(2000);
        String children[] = filesystemNode.getChildren();
        int count = children.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.