blob: 730179842aefd19dc9859fd9e157aa46ac486a83 [file] [log] [blame]
chrismair00dc7bd2014-05-11 21:21:28 +00001/*
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 */
16package org.mockftpserver.stub.command;
17
18import org.easymock.MockControl;
19import org.mockftpserver.core.command.*;
20import org.mockftpserver.core.command.AbstractCommandHandlerTestCase;
21
22/**
23 * Tests for the ListCommandHandler class
24 *
25 * @author Chris Mair
26 * @version $Revision$ - $Date$
27 */
28public final class ListCommandHandlerTest extends AbstractCommandHandlerTestCase {
29
30 private ListCommandHandler commandHandler;
31
32 /**
33 * Test the handleCommand() method
34 *
35 * @throws Exception
36 */
37 public void testHandleCommand() throws Exception {
38 final String DIR_LISTING = " directory listing\nabc.txt\ndef.log\n";
39 final String DIR_LISTING_TRIMMED = DIR_LISTING.trim();
40 ((ListCommandHandler) commandHandler).setDirectoryListing(DIR_LISTING);
41
42 for (int i = 0; i < 2; i++) {
43 session.sendReply(ReplyCodes.TRANSFER_DATA_INITIAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_INITIAL_OK));
44 session.openDataConnection();
45 byte[] bytes = DIR_LISTING_TRIMMED.getBytes();
46 session.sendData(bytes, bytes.length);
47 control(session).setMatcher(MockControl.ARRAY_MATCHER);
48 session.closeDataConnection();
49 session.sendReply(ReplyCodes.TRANSFER_DATA_FINAL_OK, replyTextFor(ReplyCodes.TRANSFER_DATA_FINAL_OK));
50 }
51 replay(session);
52
53 Command command1 = new Command(CommandNames.LIST, array(DIR1));
54 Command command2 = new Command(CommandNames.LIST, EMPTY);
55 commandHandler.handleCommand(command1, session);
56 commandHandler.handleCommand(command2, session);
57 verify(session);
58
59 verifyNumberOfInvocations(commandHandler, 2);
60 verifyOneDataElement(commandHandler.getInvocation(0), ListCommandHandler.PATHNAME_KEY, DIR1);
61 verifyOneDataElement(commandHandler.getInvocation(1), ListCommandHandler.PATHNAME_KEY, null);
62 }
63
64 /**
65 * Perform initialization before each test
66 *
67 * @see org.mockftpserver.core.command.AbstractCommandHandlerTestCase#setUp()
68 */
69 protected void setUp() throws Exception {
70 super.setUp();
71 commandHandler = new ListCommandHandler();
72 commandHandler.setReplyTextBundle(replyTextBundle);
73 }
74
75}