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.PassCommandHandler; 229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/** 249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Tests for the PassCommandHandler class 259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision$ - $Date$ 279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair 299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic final class PassCommandHandlerTest extends AbstractCommandHandlerTest { 319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String PASSWORD1 = "password1"; 339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String PASSWORD2 = "password2"; 349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private PassCommandHandler commandHandler; 369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private Command command1; 379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private Command command2; 389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the handleCommand() method 419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testHandleCommand() throws Exception { 439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(ReplyCodes.PASS_OK, replyTextFor(ReplyCodes.PASS_OK)); 459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(ReplyCodes.PASS_OK, replyTextFor(ReplyCodes.PASS_OK)); 469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replay(session); 479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(command1, session); 499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(command2, session); 509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verify(session); 519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verifyNumberOfInvocations(commandHandler, 2); 539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verifyOneDataElement(commandHandler.getInvocation(0), PassCommandHandler.PASSWORD_KEY, PASSWORD1); 549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verifyOneDataElement(commandHandler.getInvocation(1), PassCommandHandler.PASSWORD_KEY, PASSWORD2); 559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the handleCommand() method, when no password parameter has been specified 599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testHandleCommand_MissingPasswordParameter() throws Exception { 619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.PASS, EMPTY); 629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Perform initialization before each test 669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp() 679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair protected void setUp() throws Exception { 699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair super.setUp(); 709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler = new PassCommandHandler(); 719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.setReplyTextBundle(replyTextBundle); 729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair command1 = new Command(CommandNames.PASS, array(PASSWORD1)); 739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair command2 = new Command(CommandNames.PASS, array(PASSWORD2)); 749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair} 77