Home | History | Annotate | Download | only in filesystem
      1 /*
      2  * Copyright 2008 the original author or authors.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package org.mockftpserver.fake.filesystem
     17 
     18 import java.lang.reflect.Constructor
     19 import org.mockftpserver.test.AbstractGroovyTestCase
     20 
     21 /**
     22  * Abstract test superclass for subclasses of AbstractFileSystemEntry
     23  *
     24  * @version $Revision$ - $Date$
     25  *
     26  * @author Chris Mair
     27  */
     28 public abstract class AbstractFileSystemEntryTestCase extends AbstractGroovyTestCase {
     29 
     30     protected static final PATH = "c:/test/dir"
     31     protected static final NEW_PATH = "d:/other/dir"
     32     protected static final USER = 'user77'
     33     protected static final GROUP = 'group88'
     34     protected static final PERMISSIONS = new Permissions('rwxrwx---')
     35     protected static final LAST_MODIFIED = new Date()
     36 
     37     void testConstructor_NoArgs() {
     38         AbstractFileSystemEntry entry = (AbstractFileSystemEntry) getImplementationClass().newInstance()
     39         assertNull("path", entry.getPath())
     40         entry.setPath(PATH)
     41         assert entry.getPath() == PATH
     42         assert isDirectory() == entry.isDirectory()
     43     }
     44 
     45     void testConstructor_Path() {
     46         Constructor constructor = getImplementationClass().getConstructor([String.class] as Class[])
     47         AbstractFileSystemEntry entry = (AbstractFileSystemEntry) constructor.newInstance([PATH] as Object[])
     48         LOG.info(entry.toString())
     49         assertEquals("path", PATH, entry.getPath())
     50         entry.setPath("")
     51         assert entry.getPath() == ""
     52         assert isDirectory() == entry.isDirectory()
     53     }
     54 
     55     void testLockPath() {
     56         def entry = createFileSystemEntry(PATH)
     57         entry.lockPath()
     58         shouldFail { entry.path = 'abc' }
     59         assert entry.path == PATH
     60     }
     61 
     62     void testGetName() {
     63         assert createFileSystemEntry('abc').name == 'abc'
     64         assert createFileSystemEntry('/abc').name == 'abc'
     65         assert createFileSystemEntry('/dir/abc').name == 'abc'
     66         assert createFileSystemEntry('\\abc').name == 'abc'
     67     }
     68 
     69     void testSetPermissionsFromString() {
     70         def entry = createFileSystemEntry('abc')
     71         final PERM = 'rw-r---wx'
     72         entry.setPermissionsFromString(PERM)
     73         assert entry.permissions == new Permissions(PERM)
     74     }
     75 
     76     protected AbstractFileSystemEntry createFileSystemEntry(String path) {
     77         def entry = (AbstractFileSystemEntry) getImplementationClass().newInstance()
     78         entry.setPath(path)
     79         return entry
     80     }
     81 
     82     /**
     83      * @return the subclass of AbstractFileSystemEntry to be tested
     84      */
     85     protected abstract Class getImplementationClass()
     86 
     87     /**
     88      * @return true if the class being tested represents a directory entry
     89      */
     90     protected abstract boolean isDirectory()
     91 
     92 }
     93