StouCommandHandlerTest.groovy revision 5aee6e3edf4d3d8decff73d2a5a26cebdd0572f5
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 */ 16package org.mockftpserver.fake.command 17 18import org.mockftpserver.core.command.Command 19import org.mockftpserver.core.command.CommandHandler 20import org.mockftpserver.core.command.CommandNames 21 22/** 23 * Tests for StouCommandHandler 24 * 25 * @version $Revision$ - $Date$ 26 * 27 * @author Chris Mair 28 */ 29class StouCommandHandlerTest extends AbstractStoreFileCommandHandlerTest { 30 31 def expectedBaseName 32 33 void testHandleCommand_SpecifyBaseFilename() { 34 setCurrentDirectory(DIR) 35 expectedBaseName = FILENAME 36 testHandleCommand([expectedBaseName], 'stou', CONTENTS) 37 } 38 39 void testHandleCommand_UseDefaultBaseFilename() { 40 setCurrentDirectory(DIR) 41 expectedBaseName = 'Temp' 42 testHandleCommand([expectedBaseName], 'stou', CONTENTS) 43 } 44 45 void testHandleCommand_AbsolutePath() { 46 expectedBaseName = FILENAME 47 testHandleCommand([FILE], 'stou', CONTENTS) 48 } 49 50 //------------------------------------------------------------------------- 51 // Helper Methods 52 //------------------------------------------------------------------------- 53 54 CommandHandler createCommandHandler() { 55 new StouCommandHandler() 56 } 57 58 Command createValidCommand() { 59 return new Command(CommandNames.STOU, []) 60 } 61 62 void setUp() { 63 super.setUp() 64 session.dataToRead = CONTENTS.bytes 65 } 66 67 protected String verifyOutputFile() { 68 def names = fileSystem.listNames(DIR) 69 def filename = names.find {name -> name.startsWith(expectedBaseName) } 70 assert filename 71 return p(DIR, filename) 72 } 73 74}