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 StatCommandHandler class
     23  *
     24  * @version $Revision$ - $Date$
     25  *
     26  * @author Chris Mair
     27  */
     28 public final class StatCommandHandlerTest extends AbstractCommandHandlerTestCase {
     29 
     30     private static final String RESPONSE_DATA = "status info 123.456";
     31     private static final String PATHNAME = "dir/file";
     32 
     33     private StatCommandHandler commandHandler;
     34 
     35     /**
     36      * Test the handleCommand() method, when no pathname parameter is specified
     37      */
     38     public void testHandleCommand_NoPathname() throws Exception {
     39 
     40         session.sendReply(ReplyCodes.STAT_SYSTEM_OK, formattedReplyTextFor(ReplyCodes.STAT_SYSTEM_OK, RESPONSE_DATA));
     41         replay(session);
     42 
     43         final Command COMMAND = new Command(CommandNames.STAT, EMPTY);
     44         commandHandler.setStatus(RESPONSE_DATA);
     45         commandHandler.handleCommand(COMMAND, session);
     46         verify(session);
     47 
     48         verifyNumberOfInvocations(commandHandler, 1);
     49         verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, null);
     50     }
     51 
     52     /**
     53      * Test the handleCommand() method, specifying a pathname parameter
     54      * @throws Exception
     55      */
     56     public void testHandleCommand_Pathname() throws Exception {
     57 
     58         session.sendReply(ReplyCodes.STAT_FILE_OK, formattedReplyTextFor(ReplyCodes.STAT_FILE_OK, RESPONSE_DATA));
     59         replay(session);
     60 
     61         final Command COMMAND = new Command(CommandNames.STAT, array(PATHNAME));
     62 
     63         commandHandler.setStatus(RESPONSE_DATA);
     64         commandHandler.handleCommand(COMMAND, session);
     65         verify(session);
     66 
     67         verifyNumberOfInvocations(commandHandler, 1);
     68         verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, PATHNAME);
     69     }
     70 
     71     /**
     72      * Test the handleCommand() method, when the replyCode is explicitly set
     73      */
     74     public void testHandleCommand_OverrideReplyCode() throws Exception {
     75 
     76         session.sendReply(200, replyTextFor(200));
     77         replay(session);
     78 
     79         final Command COMMAND = new Command(CommandNames.STAT, EMPTY);
     80         commandHandler.setStatus(RESPONSE_DATA);
     81         commandHandler.setReplyCode(200);
     82         commandHandler.handleCommand(COMMAND, session);
     83 
     84         verify(session);
     85 
     86         verifyNumberOfInvocations(commandHandler, 1);
     87         verifyOneDataElement(commandHandler.getInvocation(0), StatCommandHandler.PATHNAME_KEY, null);
     88     }
     89 
     90     /**
     91      * Perform initialization before each test
     92      *
     93      * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
     94      */
     95     protected void setUp() throws Exception {
     96         super.setUp();
     97         commandHandler = new StatCommandHandler();
     98         commandHandler.setReplyTextBundle(replyTextBundle);
     99     }
    100 
    101 }
    102