Home | History | Annotate | Download | only in command
      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.command
     17 
     18 import org.mockftpserver.core.command.Command
     19 import org.mockftpserver.core.command.CommandHandler
     20 import org.mockftpserver.core.command.CommandNames
     21 
     22 /**
     23  * Tests for StouCommandHandler
     24  *
     25  * @version $Revision$ - $Date$
     26  *
     27  * @author Chris Mair
     28  */
     29 class StouCommandHandlerTest extends AbstractStoreFileCommandHandlerTestCase {
     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     void testHandleCommand_NoWriteAccessToExistingFile() {
     51         // This command always stores a new (unique) file, so this test does not apply
     52     }
     53     //-------------------------------------------------------------------------
     54     // Helper Methods
     55     //-------------------------------------------------------------------------
     56 
     57     CommandHandler createCommandHandler() {
     58         new StouCommandHandler()
     59     }
     60 
     61     Command createValidCommand() {
     62         return new Command(CommandNames.STOU, [])
     63     }
     64 
     65     void setUp() {
     66         super.setUp()
     67         session.dataToRead = CONTENTS.bytes
     68     }
     69 
     70     protected String verifyOutputFile() {
     71         def names = fileSystem.listNames(DIR)
     72         def filename = names.find {name -> name.startsWith(expectedBaseName) }
     73         assert filename
     74         return p(DIR, filename)
     75     }
     76 
     77 }