185efb15529d45e32fea8de03c38a968c157c8262chrismair/* 285efb15529d45e32fea8de03c38a968c157c8262chrismair * Copyright 2007 the original author or authors. 385efb15529d45e32fea8de03c38a968c157c8262chrismair * 485efb15529d45e32fea8de03c38a968c157c8262chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 585efb15529d45e32fea8de03c38a968c157c8262chrismair * you may not use this file except in compliance with the License. 685efb15529d45e32fea8de03c38a968c157c8262chrismair * You may obtain a copy of the License at 785efb15529d45e32fea8de03c38a968c157c8262chrismair * 885efb15529d45e32fea8de03c38a968c157c8262chrismair * http://www.apache.org/licenses/LICENSE-2.0 985efb15529d45e32fea8de03c38a968c157c8262chrismair * 1085efb15529d45e32fea8de03c38a968c157c8262chrismair * Unless required by applicable law or agreed to in writing, software 1185efb15529d45e32fea8de03c38a968c157c8262chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1285efb15529d45e32fea8de03c38a968c157c8262chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1385efb15529d45e32fea8de03c38a968c157c8262chrismair * See the License for the specific language governing permissions and 1485efb15529d45e32fea8de03c38a968c157c8262chrismair * limitations under the License. 1585efb15529d45e32fea8de03c38a968c157c8262chrismair */ 1685efb15529d45e32fea8de03c38a968c157c8262chrismairpackage org.mockftpserver.stub.command; 1785efb15529d45e32fea8de03c38a968c157c8262chrismair 1885efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.Command; 1985efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.CommandNames; 2085efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.core.command.ReplyCodes; 2185efb15529d45e32fea8de03c38a968c157c8262chrismairimport org.mockftpserver.stub.command.AppeCommandHandler; 2285efb15529d45e32fea8de03c38a968c157c8262chrismair 2385efb15529d45e32fea8de03c38a968c157c8262chrismair/** 2485efb15529d45e32fea8de03c38a968c157c8262chrismair * Tests for the AppeCommandHandler class 2585efb15529d45e32fea8de03c38a968c157c8262chrismair * 2685efb15529d45e32fea8de03c38a968c157c8262chrismair * @version $Revision$ - $Date$ 2785efb15529d45e32fea8de03c38a968c157c8262chrismair * 2885efb15529d45e32fea8de03c38a968c157c8262chrismair * @author Chris Mair 2985efb15529d45e32fea8de03c38a968c157c8262chrismair */ 3085efb15529d45e32fea8de03c38a968c157c8262chrismairpublic final class AppeCommandHandlerTest extends AbstractCommandHandlerTest { 3185efb15529d45e32fea8de03c38a968c157c8262chrismair 3285efb15529d45e32fea8de03c38a968c157c8262chrismair private AppeCommandHandler commandHandler; 3385efb15529d45e32fea8de03c38a968c157c8262chrismair 3485efb15529d45e32fea8de03c38a968c157c8262chrismair /** 3585efb15529d45e32fea8de03c38a968c157c8262chrismair * Perform initialization before each test 3685efb15529d45e32fea8de03c38a968c157c8262chrismair * 3785efb15529d45e32fea8de03c38a968c157c8262chrismair * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp() 3885efb15529d45e32fea8de03c38a968c157c8262chrismair */ 3985efb15529d45e32fea8de03c38a968c157c8262chrismair protected void setUp() throws Exception { 4085efb15529d45e32fea8de03c38a968c157c8262chrismair super.setUp(); 4185efb15529d45e32fea8de03c38a968c157c8262chrismair commandHandler = new AppeCommandHandler(); 4285efb15529d45e32fea8de03c38a968c157c8262chrismair commandHandler.setReplyTextBundle(replyTextBundle); 4385efb15529d45e32fea8de03c38a968c157c8262chrismair } 4485efb15529d45e32fea8de03c38a968c157c8262chrismair 4585efb15529d45e32fea8de03c38a968c157c8262chrismair /** 4685efb15529d45e32fea8de03c38a968c157c8262chrismair * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 4785efb15529d45e32fea8de03c38a968c157c8262chrismair */ 4885efb15529d45e32fea8de03c38a968c157c8262chrismair public void testHandleCommand() throws Exception { 4985efb15529d45e32fea8de03c38a968c157c8262chrismair final String DATA = "ABC"; 5085efb15529d45e32fea8de03c38a968c157c8262chrismair 5185efb15529d45e32fea8de03c38a968c157c8262chrismair session.sendReply(ReplyCodes.SEND_DATA_INITIAL_OK, replyTextFor(ReplyCodes.SEND_DATA_INITIAL_OK)); 5285efb15529d45e32fea8de03c38a968c157c8262chrismair session.openDataConnection(); 5385efb15529d45e32fea8de03c38a968c157c8262chrismair session.readData(); 5485efb15529d45e32fea8de03c38a968c157c8262chrismair control(session).setReturnValue(DATA.getBytes()); 5585efb15529d45e32fea8de03c38a968c157c8262chrismair session.closeDataConnection(); 5685efb15529d45e32fea8de03c38a968c157c8262chrismair session.sendReply(ReplyCodes.SEND_DATA_FINAL_OK, replyTextFor(ReplyCodes.SEND_DATA_FINAL_OK)); 5785efb15529d45e32fea8de03c38a968c157c8262chrismair replay(session); 5885efb15529d45e32fea8de03c38a968c157c8262chrismair 5985efb15529d45e32fea8de03c38a968c157c8262chrismair Command command = new Command(CommandNames.APPE, array(FILENAME1)); 6085efb15529d45e32fea8de03c38a968c157c8262chrismair commandHandler.handleCommand(command, session); 6185efb15529d45e32fea8de03c38a968c157c8262chrismair verify(session); 6285efb15529d45e32fea8de03c38a968c157c8262chrismair 6385efb15529d45e32fea8de03c38a968c157c8262chrismair verifyNumberOfInvocations(commandHandler, 1); 6485efb15529d45e32fea8de03c38a968c157c8262chrismair verifyTwoDataElements(commandHandler.getInvocation(0), AppeCommandHandler.PATHNAME_KEY, FILENAME1, 6585efb15529d45e32fea8de03c38a968c157c8262chrismair AppeCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 6685efb15529d45e32fea8de03c38a968c157c8262chrismair } 6785efb15529d45e32fea8de03c38a968c157c8262chrismair 6885efb15529d45e32fea8de03c38a968c157c8262chrismair /** 6985efb15529d45e32fea8de03c38a968c157c8262chrismair * Test the handleCommand() method, when no pathname parameter has been specified 7085efb15529d45e32fea8de03c38a968c157c8262chrismair */ 7185efb15529d45e32fea8de03c38a968c157c8262chrismair public void testHandleCommand_MissingPathnameParameter() throws Exception { 7285efb15529d45e32fea8de03c38a968c157c8262chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.APPE, EMPTY); 7385efb15529d45e32fea8de03c38a968c157c8262chrismair } 7485efb15529d45e32fea8de03c38a968c157c8262chrismair 7585efb15529d45e32fea8de03c38a968c157c8262chrismair} 76