19d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/*
29d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Copyright 2007 the original author or authors.
39d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
49d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Licensed under the Apache License, Version 2.0 (the "License");
59d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * you may not use this file except in compliance with the License.
69d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * You may obtain a copy of the License at
79d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
89d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *      http://www.apache.org/licenses/LICENSE-2.0
99d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Unless required by applicable law or agreed to in writing, software
119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * distributed under the License is distributed on an "AS IS" BASIS,
129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * See the License for the specific language governing permissions and
149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * limitations under the License.
159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpackage org.mockftpserver.stub.command;
179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.command.Command;
199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.command.CommandNames;
209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.command.ReplyCodes;
219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.stub.command.StorCommandHandler;
229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/**
249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Tests for the StorCommandHandler class
259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision$ - $Date$
279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair
299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic final class StorCommandHandlerTest extends AbstractCommandHandlerTest {
319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private StorCommandHandler commandHandler;
339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Perform initialization before each test
369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp()
389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected void setUp() throws Exception {
409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        super.setUp();
419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        commandHandler = new StorCommandHandler();
429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        commandHandler.setReplyTextBundle(replyTextBundle);
439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the handleCommand() method, as well as the getFileContents() and clearFileContents() methods
479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testHandleCommand() throws Exception {
499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        final String DATA = "ABC";
509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.sendReply(ReplyCodes.SEND_DATA_INITIAL_OK, replyTextFor(ReplyCodes.SEND_DATA_INITIAL_OK));
529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.readData();
549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        control(session).setReturnValue(DATA.getBytes());
559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.closeDataConnection();
569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.sendReply(ReplyCodes.SEND_DATA_FINAL_OK, replyTextFor(ReplyCodes.SEND_DATA_FINAL_OK));
579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        replay(session);
589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        Command command = new Command(CommandNames.STOR, array(FILENAME1));
609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        commandHandler.handleCommand(command, session);
619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        verify(session);
629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        verifyNumberOfInvocations(commandHandler, 1);
649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        verifyTwoDataElements(commandHandler.getInvocation(0), StorCommandHandler.PATHNAME_KEY, FILENAME1,
659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair                StorCommandHandler.FILE_CONTENTS_KEY, DATA.getBytes());
669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the handleCommand() method, when no pathname parameter has been specified
709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testHandleCommand_MissingPathnameParameter() throws Exception {
729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        testHandleCommand_InvalidParameters(commandHandler, CommandNames.STOR, EMPTY);
739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair}
76