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