ReinCommandHandlerTest.groovy revision 5303c6ae1dde5f399fe48803e677942fc4326344
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 23import org.mockftpserver.fake.UserAccount 24 25/** 26 * Tests for ReinCommandHandler 27 * 28 * @version $Revision$ - $Date$ 29 * 30 * @author Chris Mair 31 */ 32class ReinCommandHandlerTest extends AbstractFakeCommandHandlerTestCase { 33 34 boolean testNotLoggedIn = false 35 36 UserAccount userAccount 37 38 void testHandleCommand_AlreadyLoggedIn() { 39 session.setAttribute(SessionKeys.USER_ACCOUNT, userAccount) 40 assert isLoggedIn() 41 handleCommand([]) 42 assertSessionReply(ReplyCodes.REIN_OK, 'rein') 43 assert !isLoggedIn() 44 } 45 46 void testHandleCommand_NotLoggedIn() { 47 handleCommand([]) 48 assertSessionReply(ReplyCodes.REIN_OK, 'rein') 49 assert !isLoggedIn() 50 } 51 52 //------------------------------------------------------------------------- 53 // Helper Methods 54 //------------------------------------------------------------------------- 55 56 CommandHandler createCommandHandler() { 57 new ReinCommandHandler() 58 } 59 60 Command createValidCommand() { 61 return new Command(CommandNames.REIN, []) 62 } 63 64 void setUp() { 65 super.setUp() 66 userAccount = new UserAccount(username: 'user') 67 } 68 69 private boolean isLoggedIn() { 70 return session.getAttribute(SessionKeys.USER_ACCOUNT) != null 71 } 72}