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 org.openide.filesystems;

import org.openide.util.actions.SystemAction;
import org.openide.util.Queue;
import org.openide.util.NbBundle;
import org.openide.util.enum.QueueEnumeration;
//import org.openide.filesystems.hidden.*;

import junit.framework.*;

import java.beans.*;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.Iterator;
import javax.swing.SwingUtilities;
import javax.swing.event.EventListenerList;

/**
 *
 * @author  rm111737
 * @version 
 */


public class FileSystemTestHid extends TestBaseHid {
    private static String[] resources = new String [] {
        "atleastone"
    };
        
    public FileSystemTestHid(java.lang.String testName) {
        super(testName);
    }
    private static int abacus = 0;
    
    
    protected String[] getResources (String testName) {
        return resources;
    }    
    public void testAddFileStatusListener () {
        if (!(this.testedFS instanceof TestUtilHid.StatusFileSystem))
            return;
        FileStatusListener[]  fsListeners =  new FileStatusListener [10];
        abacus = 0;

        for (int i = 0; i < fsListeners.length; i++) {
            fsListeners[i] = createFileStatusListener ();
            this.testedFS.addFileStatusListener(fsListeners[i]);
        }
        this.testedFS.fireFileStatusChanged(new FileStatusEvent (this.testedFS, true, true) );
        fsAssert("failure: not all FileStstausListeners invoked: " + abacus,  abacus == fsListeners.length);

        abacus = 0;        
        this.testedFS.removeFileStatusListener(fsListeners[0]);
        this.testedFS.fireFileStatusChanged(new FileStatusEvent (this.testedFS, true, true) );        
        fsAssert("failure: not all FileStstausListeners invoked",  abacus == (fsListeners.length -1));
    }

    
    public void testAddVetoableChangeListener () {
        VetoableChangeListener[]  vListeners =  new VetoableChangeListener[10];
        abacus = 0;

        for (int i = 0; i < vListeners.length; i++) {
            vListeners[i] = createVetoableChangeListener ();
            this.testedFS.addVetoableChangeListener(vListeners[i]);            
        }
        try {
            this.testedFS.fireVetoableChange("test", "old", "new");
        } catch (PropertyVetoException pex) {
            fsFail("unexpected veto exception");
        }
        fsAssert("failure: not all VetoableChangeListeners invoked",  abacus == vListeners.length);
        
        abacus = 0;        
        this.testedFS.removeVetoableChangeListener(vListeners[0]);
        try {
            this.testedFS.fireVetoableChange("test", "old", "new");        
        } catch (PropertyVetoException pex) {
            fsFail("unexpected veto exception");            
        }            
        fsAssert("failure: not all VetoableChangeListeners invoked",  abacus == (vListeners.length -1));
    }
    
    private FileStatusListener createFileStatusListener () {
        return new FileStatusListener () {
            public void annotationChanged (FileStatusEvent ev) {
                abacus++;
            }
        };

    }

    private VetoableChangeListener createVetoableChangeListener () {
        return new VetoableChangeListener  () {
            public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
                    abacus++;            
            }
        };

    }
    
    public void testFsfileFolderCreated() throws IOException {
        FileSystem fs = this.testedFS;
        FileObject root = fs.getRoot ();
        if (!fs.isReadOnly () && !root.isReadOnly()) {
            root.getChildren();
            registerDefaultListener (fs);            
            root.createFolder("testtset");
            fileFolderCreatedAssert ("unexpecetd event count",1);
        }
    }
    
    public void testFsfileDataCreated() throws IOException {
        FileSystem fs = this.testedFS;
        FileObject root = fs.getRoot ();
        if (!fs.isReadOnly () && !root.isReadOnly()) {
            root.getChildren();
            registerDefaultListener (fs);            
            FileObject newF = root.createData("testfile","txe");
            fileDataCreatedAssert ("unexpecetd event count",1);            
        }
        
    }

    public void testFsfileRenamed() throws IOException {
        FileSystem fs = this.testedFS;
        FileObject root = fs.getRoot ();
        if (!fs.isReadOnly () && !root.isReadOnly()) {
            root.getChildren();
            registerDefaultListener (fs);            
            FileObject newF = root.createData("testfile","txe");
            FileLock fLock = newF.lock();            
            try {
                newF.rename(fLock,"obscure","uni");                               
            } finally {
                fLock.releaseLock();               
            }

            fileRenamedAssert("unexpecetd event count",1);                                    
        }
        
    }

    public void testFsfileDeleted() throws IOException {
        FileSystem fs = this.testedFS;
        FileObject root = fs.getRoot ();
        if (!fs.isReadOnly () && !root.isReadOnly()) {
            root.getChildren();
            registerDefaultListener (fs);            
            FileObject newF = root.createData("testfile","txe");
            FileLock fLock = newF.lock();            
            try {
                newF.delete(fLock);                               
            } finally {
                fLock.releaseLock();               
            }

            fileDeletedAssert("unexpecetd event count",1);                                    
        }
        
    }
    
    /** Test of isValid method, of class org.openide.filesystems.FileSystem. */
    public void testIsValid() {        
        Repository r = new Repository(new LocalFileSystem ());
        // 
        fsAssert("file system, which is not assigned to the repository, should be invalid", 
        !testedFS.isValid());
        
        // assign to empty repository -> become valid
        r.addFileSystem(testedFS);
        if (!testedFS.getSystemName().equals(""))
            fsAssert("assign to empty repository -> become valid" , testedFS.isValid());
        
        // remove from repo -> become invalid
        r.removeFileSystem(testedFS);
        fsAssert("remove from repo -> become invalid", !testedFS.isValid());
    }
    
    /** Test of setHidden method, of class org.openide.filesystems.FileSystem. */
    /*public void testSetHidden() {
        System.out.println("testSetHidden");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of isHidden method, of class org.openide.filesystems.FileSystem. */
    /*public void testIsHidden() {
        System.out.println("testIsHidden");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of isPersistent method, of class org.openide.filesystems.FileSystem. */
    /*public void testIsPersistent() {
        System.out.println("testIsPersistent");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of getSystemName method, of class org.openide.filesystems.FileSystem. */
    /*public void testGetSystemName() {
        System.out.println("testGetSystemName");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of setSystemName method, of class org.openide.filesystems.FileSystem. */
    /*public void testSetSystemName() {
        System.out.println("testSetSystemName");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of isDefault method, of class org.openide.filesystems.FileSystem. */
    /*public void testIsDefault() {
        System.out.println("testIsDefault");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of find method, of class org.openide.filesystems.FileSystem. */
    /*public void testFind() {
        System.out.println("testFind");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of getActions method, of class org.openide.filesystems.FileSystem. */
    /*public void testGetActions() {
        System.out.println("testGetActions");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of toString method, of class org.openide.filesystems.FileSystem. */
    /*public void testToString() {
        System.out.println("testToString");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of prepareEnvironment method, of class org.openide.filesystems.FileSystem. */
    /*public void testPrepareEnvironment() {
        System.out.println("testPrepareEnvironment");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of getStatus method, of class org.openide.filesystems.FileSystem. */
    /*public void testGetStatus() {
        System.out.println("testGetStatus");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of getCapability method, of class org.openide.filesystems.FileSystem. */
    /*public void testGetCapability() {
        System.out.println("testGetCapability");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of setCapability method, of class org.openide.filesystems.FileSystem. */
    /*public void testSetCapability() {
        System.out.println("testSetCapability");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of runAtomicAction method, of class org.openide.filesystems.FileSystem. */
    /*public void testRunAtomicAction() {
        System.out.println("testRunAtomicAction");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of addFileStatusListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testAddFileStatusListener() {
        System.out.println("testAddFileStatusListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of removeFileStatusListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testRemoveFileStatusListener() {
        System.out.println("testRemoveFileStatusListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of fireFileStatusChanged method, of class org.openide.filesystems.FileSystem. */
    /*public void testFireFileStatusChanged() {
        System.out.println("testFireFileStatusChanged");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of addVetoableChangeListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testAddVetoableChangeListener() {
        System.out.println("testAddVetoableChangeListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of removeVetoableChangeListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testRemoveVetoableChangeListener() {
        System.out.println("testRemoveVetoableChangeListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of fireVetoableChange method, of class org.openide.filesystems.FileSystem. */
    /*public void testFireVetoableChange() {
        System.out.println("testFireVetoableChange");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of addPropertyChangeListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testAddPropertyChangeListener() {
        System.out.println("testAddPropertyChangeListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of removePropertyChangeListener method, of class org.openide.filesystems.FileSystem. */
    /*public void testRemovePropertyChangeListener() {
        System.out.println("testRemovePropertyChangeListener");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of firePropertyChange method, of class org.openide.filesystems.FileSystem. */
    /*public void testFirePropertyChange() {
        System.out.println("testFirePropertyChange");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of addNotify method, of class org.openide.filesystems.FileSystem. */
    /*public void testAddNotify() {
        System.out.println("testAddNotify");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/
    
    /** Test of removeNotify method, of class org.openide.filesystems.FileSystem. */
    /*public void testRemoveNotify() {
        System.out.println("testRemoveNotify");
        
        // Add your test code below by replacing the default call to fail.
        fail("The test case is empty.");
    }*/    
}
... 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.