Home | History | Annotate | Download | only in command
      1 /*
      2  * Copyright 2007 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.stub.command;
     17 
     18 import org.mockftpserver.core.command.*;
     19 import org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
     20 
     21 /**
     22  * Tests for the StorCommandHandler class
     23  *
     24  * @author Chris Mair
     25  * @version $Revision$ - $Date$
     26  */
     27 public final class StorCommandHandlerTest extends AbstractCommandHandlerTestCase {
     28 
     29     private StorCommandHandler commandHandler;
     30 
     31     /**
     32      * Perform initialization before each test
     33      *
     34      * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
     35      */
     36     protected void setUp() throws Exception {
     37         super.setUp();
     38         commandHandler = new StorCommandHandler();
     39         commandHandler.setReplyTextBundle(replyTextBundle);
     40     }
     41 
     42     /**
     43      * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods
     44      */
     45     public void testHandleCommand() throws Exception {
     46         final String DATA = "ABC";
     47 
     48         session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK));
     49         session.openDataConnection();
     50         session.readData();
     51         control(session).setReturnValue(DATA.getBytes());
     52         session.closeDataConnection();
     53         session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK));
     54         replay(session);
     55 
     56         Command command = new Command(CommandNames.STOR, array(FILENAME1));
     57         commandHandler.handleCommand(command, session);
     58         verify(session);
     59 
     60         verifyNumberOfInvocations(commandHandler, 1);
     61         verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1,
     62                 StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes());
     63     }
     64 
     65     /**
     66      * Test the handleCommand() method, when no pathname parameter has been specified
     67      */
     68     public void testHandleCommand_MissingPathnameParameter() throws Exception {
     69         testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY);
     70     }
     71 
     72 }
     73