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