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; 214531116f8e675a208710e987bfe3b58faeb12db2chrismair 224531116f8e675a208710e987bfe3b58faeb12db2chrismair/** 234531116f8e675a208710e987bfe3b58faeb12db2chrismair * Tests for the SiteCommandHandler class 244531116f8e675a208710e987bfe3b58faeb12db2chrismair * 254531116f8e675a208710e987bfe3b58faeb12db2chrismair * @version $Revision$ - $Date$ 264531116f8e675a208710e987bfe3b58faeb12db2chrismair * 274531116f8e675a208710e987bfe3b58faeb12db2chrismair * @author Chris Mair 284531116f8e675a208710e987bfe3b58faeb12db2chrismair */ 294531116f8e675a208710e987bfe3b58faeb12db2chrismairpublic final class SiteCommandHandlerTest extends AbstractCommandHandlerTest { 304531116f8e675a208710e987bfe3b58faeb12db2chrismair 314531116f8e675a208710e987bfe3b58faeb12db2chrismair private static final String PARAMETERS1 = "abc def"; 324531116f8e675a208710e987bfe3b58faeb12db2chrismair private static final String PARAMETERS2 = "abc,23,def"; 334531116f8e675a208710e987bfe3b58faeb12db2chrismair 344531116f8e675a208710e987bfe3b58faeb12db2chrismair private SiteCommandHandler commandHandler; 354531116f8e675a208710e987bfe3b58faeb12db2chrismair private Command command1; 364531116f8e675a208710e987bfe3b58faeb12db2chrismair private Command command2; 374531116f8e675a208710e987bfe3b58faeb12db2chrismair 384531116f8e675a208710e987bfe3b58faeb12db2chrismair /** 394531116f8e675a208710e987bfe3b58faeb12db2chrismair * Test the handleCommand(Command,Session) method 404531116f8e675a208710e987bfe3b58faeb12db2chrismair * @throws Exception 414531116f8e675a208710e987bfe3b58faeb12db2chrismair */ 424531116f8e675a208710e987bfe3b58faeb12db2chrismair public void testHandleCommand() throws Exception { 434531116f8e675a208710e987bfe3b58faeb12db2chrismair session.sendReply(ReplyCodes.SITE_OK, replyTextFor(ReplyCodes.SITE_OK)); 444531116f8e675a208710e987bfe3b58faeb12db2chrismair session.sendReply(ReplyCodes.SITE_OK, replyTextFor(ReplyCodes.SITE_OK)); 454531116f8e675a208710e987bfe3b58faeb12db2chrismair replay(session); 464531116f8e675a208710e987bfe3b58faeb12db2chrismair 474531116f8e675a208710e987bfe3b58faeb12db2chrismair commandHandler.handleCommand(command1, session); 484531116f8e675a208710e987bfe3b58faeb12db2chrismair commandHandler.handleCommand(command2, session); 494531116f8e675a208710e987bfe3b58faeb12db2chrismair verify(session); 504531116f8e675a208710e987bfe3b58faeb12db2chrismair 514531116f8e675a208710e987bfe3b58faeb12db2chrismair verifyNumberOfInvocations(commandHandler, 2); 524531116f8e675a208710e987bfe3b58faeb12db2chrismair verifyOneDataElement(commandHandler.getInvocation(0), SiteCommandHandler.PARAMETERS_KEY, PARAMETERS1); 534531116f8e675a208710e987bfe3b58faeb12db2chrismair verifyOneDataElement(commandHandler.getInvocation(1), SiteCommandHandler.PARAMETERS_KEY, PARAMETERS2); 544531116f8e675a208710e987bfe3b58faeb12db2chrismair } 554531116f8e675a208710e987bfe3b58faeb12db2chrismair 564531116f8e675a208710e987bfe3b58faeb12db2chrismair /** 574531116f8e675a208710e987bfe3b58faeb12db2chrismair * Test the handleCommand() method, when no "parameters" parameter has been specified 584531116f8e675a208710e987bfe3b58faeb12db2chrismair */ 594531116f8e675a208710e987bfe3b58faeb12db2chrismair public void testHandleCommand_MissingParameters() throws Exception { 604531116f8e675a208710e987bfe3b58faeb12db2chrismair testHandleCommand_InvalidParameters(commandHandler, CommandNames.SITE, EMPTY); 614531116f8e675a208710e987bfe3b58faeb12db2chrismair } 624531116f8e675a208710e987bfe3b58faeb12db2chrismair 634531116f8e675a208710e987bfe3b58faeb12db2chrismair /** 644531116f8e675a208710e987bfe3b58faeb12db2chrismair * Perform initialization before each test 654531116f8e675a208710e987bfe3b58faeb12db2chrismair * @see org.mockftpserver.stub.command.AbstractCommandHandlerTest#setUp() 664531116f8e675a208710e987bfe3b58faeb12db2chrismair */ 674531116f8e675a208710e987bfe3b58faeb12db2chrismair protected void setUp() throws Exception { 684531116f8e675a208710e987bfe3b58faeb12db2chrismair super.setUp(); 694531116f8e675a208710e987bfe3b58faeb12db2chrismair commandHandler = new SiteCommandHandler(); 704531116f8e675a208710e987bfe3b58faeb12db2chrismair commandHandler.setReplyTextBundle(replyTextBundle); 714531116f8e675a208710e987bfe3b58faeb12db2chrismair command1 = new Command(CommandNames.SITE, array(PARAMETERS1)); 724531116f8e675a208710e987bfe3b58faeb12db2chrismair command2 = new Command(CommandNames.SITE, array(PARAMETERS2)); 734531116f8e675a208710e987bfe3b58faeb12db2chrismair } 744531116f8e675a208710e987bfe3b58faeb12db2chrismair} 75