160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair/* 260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Copyright 2007 the original author or authors. 360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * 460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Licensed under the Apache License, Version 2.0 (the "License"); 560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * you may not use this file except in compliance with the License. 660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * You may obtain a copy of the License at 760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * 860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * http://www.apache.org/licenses/LICENSE-2.0 960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * 1060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Unless required by applicable law or agreed to in writing, software 1160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * distributed under the License is distributed on an "AS IS" BASIS, 1260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * See the License for the specific language governing permissions and 1460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * limitations under the License. 1560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair */ 1660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairpackage org.mockftpserver.stub.command; 1760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 1860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairimport org.mockftpserver.core.command.AbstractCommandHandlerTest; 1960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairimport org.mockftpserver.core.command.Command; 2060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairimport org.mockftpserver.core.command.CommandNames; 2160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairimport org.mockftpserver.core.command.ReplyCodes; 2260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 2360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair/** 2460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Tests for the StorCommandHandler class 2560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * 2660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * @author Chris Mair 2760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * @version $Revision$ - $Date$ 2860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair */ 2960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismairpublic final class StorCommandHandlerTest extends AbstractCommandHandlerTest { 3060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 3160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair private StorCommandHandler commandHandler; 3260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 3360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair /** 3460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Perform initialization before each test 3560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * 3660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * @see org.mockftpserver.core.command.AbstractCommandHandlerTest#setUp() 3760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair */ 3860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair protected void setUp() throws Exception { 3960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair super.setUp(); 4060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair commandHandler = new StorCommandHandler(); 4160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair commandHandler.setReplyTextBundle(replyTextBundle); 4260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair } 4360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 4460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair /** 4560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods 4660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair */ 4760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair public void testHandleCommand() throws Exception { 4860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair final String DATA = "ABC"; 4960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 5060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK)); 5160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair session.openDataConnection(); 5260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair session.readData(); 5360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair control(session).setReturnValue(DATA.getBytes()); 5460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair session.closeDataConnection(); 5560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK)); 5660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair replay(session); 5760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 5860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair Command command = new Command(CommandNames.STOR, array(FILENAME1)); 5960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair commandHandler.handleCommand(command, session); 6060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair verify(session); 6160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 6260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair verifyNumberOfInvocations(commandHandler, 1); 6360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1, 6460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes()); 6560b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair } 6660b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 6760b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair /** 6860b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair * Test the handleCommand() method, when no pathname parameter has been specified 6960b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair */ 7060b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair public void testHandleCommand_MissingPathnameParameter() throws Exception { 7160b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY); 7260b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair } 7360b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair 7460b81e2faf8511148f0d1e8f296e0b40ce9c7971chrismair} 75