14531116f8e675a208710e987bfe3b58faeb12db2chrismair/*
24531116f8e675a208710e987bfe3b58faeb12db2chrismair * Copyright 2007 the original author or authors.
34531116f8e675a208710e987bfe3b58faeb12db2chrismair *
44531116f8e675a208710e987bfe3b58faeb12db2chrismair * Licensed under the Apache License, Version 2.0 (the "License");
54531116f8e675a208710e987bfe3b58faeb12db2chrismair * you may not use this file except in compliance with the License.
64531116f8e675a208710e987bfe3b58faeb12db2chrismair * You may obtain a copy of the License at
74531116f8e675a208710e987bfe3b58faeb12db2chrismair *
84531116f8e675a208710e987bfe3b58faeb12db2chrismair *      http://www.apache.org/licenses/LICENSE-2.0
94531116f8e675a208710e987bfe3b58faeb12db2chrismair *
104531116f8e675a208710e987bfe3b58faeb12db2chrismair * Unless required by applicable law or agreed to in writing, software
114531116f8e675a208710e987bfe3b58faeb12db2chrismair * distributed under the License is distributed on an "AS IS" BASIS,
124531116f8e675a208710e987bfe3b58faeb12db2chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134531116f8e675a208710e987bfe3b58faeb12db2chrismair * See the License for the specific language governing permissions and
144531116f8e675a208710e987bfe3b58faeb12db2chrismair * limitations under the License.
154531116f8e675a208710e987bfe3b58faeb12db2chrismair */
164531116f8e675a208710e987bfe3b58faeb12db2chrismairpackage org.mockftpserver.stub.command;
174531116f8e675a208710e987bfe3b58faeb12db2chrismair
184531116f8e675a208710e987bfe3b58faeb12db2chrismairimport org.mockftpserver.core.command.Command;
194531116f8e675a208710e987bfe3b58faeb12db2chrismairimport org.mockftpserver.core.command.CommandNames;
204531116f8e675a208710e987bfe3b58faeb12db2chrismairimport org.mockftpserver.core.command.ReplyCodes;
214531116f8e675a208710e987bfe3b58faeb12db2chrismairimport org.mockftpserver.stub.command.StorCommandHandler;
224531116f8e675a208710e987bfe3b58faeb12db2chrismair
234531116f8e675a208710e987bfe3b58faeb12db2chrismair/**
244531116f8e675a208710e987bfe3b58faeb12db2chrismair * Tests for the StorCommandHandler class
254531116f8e675a208710e987bfe3b58faeb12db2chrismair *
264531116f8e675a208710e987bfe3b58faeb12db2chrismair * @version $Revision$ - $Date$
274531116f8e675a208710e987bfe3b58faeb12db2chrismair *
284531116f8e675a208710e987bfe3b58faeb12db2chrismair * @author Chris Mair
294531116f8e675a208710e987bfe3b58faeb12db2chrismair */
304531116f8e675a208710e987bfe3b58faeb12db2chrismairpublic final class StorCommandHandlerTest extends AbstractCommandHandlerTest {
314531116f8e675a208710e987bfe3b58faeb12db2chrismair
324531116f8e675a208710e987bfe3b58faeb12db2chrismair    private StorCommandHandler commandHandler;
334531116f8e675a208710e987bfe3b58faeb12db2chrismair
344531116f8e675a208710e987bfe3b58faeb12db2chrismair    /**
354531116f8e675a208710e987bfe3b58faeb12db2chrismair     * Perform initialization before each test
364531116f8e675a208710e987bfe3b58faeb12db2chrismair     *
374531116f8e675a208710e987bfe3b58faeb12db2chrismair     * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp()
384531116f8e675a208710e987bfe3b58faeb12db2chrismair     */
394531116f8e675a208710e987bfe3b58faeb12db2chrismair    protected void setUp() throws Exception {
404531116f8e675a208710e987bfe3b58faeb12db2chrismair        super.setUp();
414531116f8e675a208710e987bfe3b58faeb12db2chrismair        commandHandler = new StorCommandHandler();
424531116f8e675a208710e987bfe3b58faeb12db2chrismair        commandHandler.setReplyTextBundle(replyTextBundle);
434531116f8e675a208710e987bfe3b58faeb12db2chrismair    }
444531116f8e675a208710e987bfe3b58faeb12db2chrismair
454531116f8e675a208710e987bfe3b58faeb12db2chrismair    /**
464531116f8e675a208710e987bfe3b58faeb12db2chrismair     * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods
474531116f8e675a208710e987bfe3b58faeb12db2chrismair     */
484531116f8e675a208710e987bfe3b58faeb12db2chrismair    public void testHandleCommand() throws Exception {
494531116f8e675a208710e987bfe3b58faeb12db2chrismair        final String DATA = "ABC";
504531116f8e675a208710e987bfe3b58faeb12db2chrismair
514531116f8e675a208710e987bfe3b58faeb12db2chrismair        session.sendReply(ReplyCodes.SEND_DATA_INITIAL_OK, replyTextFor(ReplyCodes.SEND_DATA_INITIAL_OK));
524531116f8e675a208710e987bfe3b58faeb12db2chrismair        session.openDataConnection();
534531116f8e675a208710e987bfe3b58faeb12db2chrismair        session.readData();
544531116f8e675a208710e987bfe3b58faeb12db2chrismair        control(session).setReturnValue(DATA.getBytes());
554531116f8e675a208710e987bfe3b58faeb12db2chrismair        session.closeDataConnection();
564531116f8e675a208710e987bfe3b58faeb12db2chrismair        session.sendReply(ReplyCodes.SEND_DATA_FINAL_OK, replyTextFor(ReplyCodes.SEND_DATA_FINAL_OK));
574531116f8e675a208710e987bfe3b58faeb12db2chrismair        replay(session);
584531116f8e675a208710e987bfe3b58faeb12db2chrismair
594531116f8e675a208710e987bfe3b58faeb12db2chrismair        Command command = new Command(CommandNames.STOR, array(FILENAME1));
604531116f8e675a208710e987bfe3b58faeb12db2chrismair        commandHandler.handleCommand(command, session);
614531116f8e675a208710e987bfe3b58faeb12db2chrismair        verify(session);
624531116f8e675a208710e987bfe3b58faeb12db2chrismair
634531116f8e675a208710e987bfe3b58faeb12db2chrismair        verifyNumberOfInvocations(commandHandler, 1);
644531116f8e675a208710e987bfe3b58faeb12db2chrismair        verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1,
654531116f8e675a208710e987bfe3b58faeb12db2chrismair                StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes());
664531116f8e675a208710e987bfe3b58faeb12db2chrismair    }
674531116f8e675a208710e987bfe3b58faeb12db2chrismair
684531116f8e675a208710e987bfe3b58faeb12db2chrismair    /**
694531116f8e675a208710e987bfe3b58faeb12db2chrismair     * Test the handleCommand() method, when no pathname parameter has been specified
704531116f8e675a208710e987bfe3b58faeb12db2chrismair     */
714531116f8e675a208710e987bfe3b58faeb12db2chrismair    public void testHandleCommand_MissingPathnameParameter() throws Exception {
724531116f8e675a208710e987bfe3b58faeb12db2chrismair        testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY);
734531116f8e675a208710e987bfe3b58faeb12db2chrismair    }
744531116f8e675a208710e987bfe3b58faeb12db2chrismair
754531116f8e675a208710e987bfe3b58faeb12db2chrismair}
76