1/* 2 * Copyright 2008 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.fake.command 17 18import org.mockftpserver.core.command.Command 19import org.mockftpserver.core.command.CommandHandler 20import org.mockftpserver.core.command.CommandNames 21import org.mockftpserver.core.command.ReplyCodes 22import org.mockftpserver.core.session.SessionKeys 23 24/** 25 * Tests for AcctCommandHandler 26 * 27 * @version $Revision$ - $Date$ 28 * 29 * @author Chris Mair 30 */ 31class AcctCommandHandlerTest extends AbstractFakeCommandHandlerTest { 32 33 def USERNAME = "user123" 34 def ACCOUNT_NAME = "account123" 35 36 boolean testNotLoggedIn = false 37 38 void testHandleCommand() { 39 handleCommand([ACCOUNT_NAME]) 40 assertSessionReply(ReplyCodes.ACCT_OK, ['acct', USERNAME]) 41 assertAccountNameInSession(true) 42 } 43 44 void testHandleCommand_UsernameNotSetInSession() { 45 session.removeAttribute(SessionKeys.USERNAME) 46 testHandleCommand_MissingRequiredSessionAttribute() 47 assertAccountNameInSession(false) 48 } 49 50 void testHandleCommand_MissingAccountNameParameter() { 51 testHandleCommand_MissingRequiredParameter([]) 52 assertAccountNameInSession(false) 53 } 54 55 //------------------------------------------------------------------------- 56 // Abstract and Overridden Methods 57 //------------------------------------------------------------------------- 58 59 void setUp() { 60 super.setUp() 61 session.setAttribute(SessionKeys.USERNAME, USERNAME) 62 } 63 64 CommandHandler createCommandHandler() { 65 new AcctCommandHandler() 66 } 67 68 Command createValidCommand() { 69 return new Command(CommandNames.ACCT, [ACCOUNT_NAME]) 70 } 71 72 //------------------------------------------------------------------------- 73 // Helper Methods 74 //------------------------------------------------------------------------- 75 76 /** 77 * Assert that the account name is stored in the session, depending on the value of isAccountNameInSession. 78 * @param isAccountNameInSession - true if the account name is expected in the session; false if it is not expected 79 */ 80 private void assertAccountNameInSession(boolean isAccountNameInSession) { 81 def expectedValue = isAccountNameInSession ? ACCOUNT_NAME : null 82 assert session.getAttribute(SessionKeys.ACCOUNT_NAME) == expectedValue 83 } 84 85}