1c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/* 2c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Copyright 2008 the original author or authors. 3c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 4c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 5c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * you may not use this file except in compliance with the License. 6c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * You may obtain a copy of the License at 7c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 8c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * http://www.apache.org/licenses/LICENSE-2.0 9c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 10c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Unless required by applicable law or agreed to in writing, software 11c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * distributed under the License is distributed on an "AS IS" BASIS, 12c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * See the License for the specific language governing permissions and 14c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * limitations under the License. 15c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 16c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairpackage org.mockftpserver.fake.filesystem 17c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 18c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport java.text.SimpleDateFormat 19c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairimport org.mockftpserver.test.AbstractGroovyTest 20c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 21c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair/** 22c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * Tests for UnixDirectoryListingFormatter 23c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 24c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @version $Revision$ - $Date$ 25c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * 26c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair * @author Chris Mair 27c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair */ 28c1de24f1bfa6699e54b069e300af5e4246b34a34chrismairclass UnixDirectoryListingFormatterTest extends AbstractGroovyTest { 29c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 30c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final FILE_NAME = "def.txt" 31c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final FILE_PATH = "/dir/$FILE_NAME" 32c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final DIR_NAME = "etc" 33c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final DIR_PATH = "/dir/$DIR_NAME" 34c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final OWNER = 'owner123' 35c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final GROUP = 'group456' 36c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final SIZE = 11L 37c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final LAST_MODIFIED = new Date() 38c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final FILE_PERMISSIONS = new Permissions('rw-r--r--') 39c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair static final DIR_PERMISSIONS = new Permissions('rwxr-xr-x') 40c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 41c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair private formatter 42c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair private dateFormat 43c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair private lastModifiedFormatted 44c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 45c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // "-rw-rw-r-- 1 ftp ftp 254 Feb 23 2007 robots.txt" 46c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // "-rw-r--r-- 1 ftp ftp 30014925 Apr 15 00:19 md5.sums.gz" 47c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // "-rwxr-xr-x 1 c096336 iawebgrp 5778 Dec 1 2005 FU_WyCONN_updateplanaccess.sql" 48c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // "drwxr-xr-x 2 c096336 iawebgrp 8192 Nov 7 2006 tmp" 49c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair // "drwxr-xr-x 39 ftp ftp 4096 Mar 19 2004 a" 50c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 51c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair void testFormat_File() { 52c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair def fileSystemEntry = new FileEntry(path: FILE_PATH, contents: '12345678901', lastModified: LAST_MODIFIED, 53c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair owner: OWNER, group: GROUP, permissions: FILE_PERMISSIONS) 54c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info(fileSystemEntry) 55c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair verifyFormat(fileSystemEntry, "-rw-r--r-- 1 owner123 group456 11 $lastModifiedFormatted def.txt") 56c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 57c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 58c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair void testFormat_File_Defaults() { 59c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair def fileSystemEntry = new FileEntry(path: FILE_PATH, contents: '12345678901', lastModified: LAST_MODIFIED) 60c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info(fileSystemEntry) 61c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair verifyFormat(fileSystemEntry, "-rwxrwxrwx 1 none none 11 $lastModifiedFormatted def.txt") 62c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 63c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 64c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair void testFormat_Directory() { 65c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair def fileSystemEntry = new DirectoryEntry(path: DIR_PATH, lastModified: LAST_MODIFIED, 66c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair owner: OWNER, group: GROUP, permissions: DIR_PERMISSIONS) 67c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info(fileSystemEntry) 68c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair verifyFormat(fileSystemEntry, "drwxr-xr-x 1 owner123 group456 0 $lastModifiedFormatted etc") 69c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 70c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 71c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair void testFormat_Directory_Defaults() { 72c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair def fileSystemEntry = new DirectoryEntry(path: DIR_PATH, lastModified: LAST_MODIFIED) 73c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info(fileSystemEntry) 74c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair verifyFormat(fileSystemEntry, "drwxrwxrwx 1 none none 0 $lastModifiedFormatted etc") 75c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 76c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 77c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair void setUp() { 78c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair super.setUp() 79c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair formatter = new UnixDirectoryListingFormatter() 80c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair dateFormat = new SimpleDateFormat(UnixDirectoryListingFormatter.DATE_FORMAT) 81c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair lastModifiedFormatted = dateFormat.format(LAST_MODIFIED) 82c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 83c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 84c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair private void verifyFormat(FileSystemEntry fileSystemEntry, String expectedResult) { 85c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair def result = formatter.format(fileSystemEntry) 86c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info("result= [$result]") 87c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair LOG.info("expected=[$expectedResult]") 88c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair assert result == expectedResult 89c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair } 90c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair 91c1de24f1bfa6699e54b069e300af5e4246b34a34chrismair}