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.core.command; 179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.ListResourceBundle; 199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.ResourceBundle; 209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.apache.log4j.Logger; 229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.easymock.MockControl; 239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.session.Session; 249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.util.AssertFailedException; 259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.stub.command.AbstractStubCommandHandler; 269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.AbstractTest; 279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/** 299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Tests for the AbstractCommandHandler class. The class name is prefixed with an underscore 309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * so that it is not filtered out by Maven's Surefire test plugin. 319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision$ - $Date$ 339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * 349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair 359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic final class _AbstractCommandHandlerTest extends AbstractTest { 379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Logger LOG = Logger.getLogger(_AbstractCommandHandlerTest.class); 399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String COMMAND_NAME = "abc"; 409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Object ARG = "123"; 419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Object[] ARGS = { ARG }; 429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Command COMMAND = new Command(COMMAND_NAME, EMPTY); 439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final Command COMMAND_WITH_ARGS = new Command(COMMAND_NAME, EMPTY); 449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final int REPLY_CODE1 = 777; 459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final int REPLY_CODE2 = 888; 469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final int REPLY_CODE3 = 999; 479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String REPLY_TEXT1 = "reply1 ... abcdef"; 489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String REPLY_TEXT2 = "abc {0} def"; 499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String REPLY_TEXT2_FORMATTED = "abc 123 def"; 509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String OVERRIDE_REPLY_TEXT = "overridden reply ... abcdef"; 519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String MESSAGE_KEY = "key.123"; 529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private static final String MESSAGE_TEXT = "message.123"; 539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private AbstractCommandHandler commandHandler; 559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private Session session; 569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private ResourceBundle replyTextBundle; 579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the handleCommand(Command,Session) method 609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testHandleCommand() throws Exception { 629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("before", 0, commandHandler.numberOfInvocations()); 639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, session); 649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("after", 1, commandHandler.numberOfInvocations()); 659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertTrue("locked", commandHandler.getInvocation(0).isLocked()); 669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the handleCommand(Command,Session) method, passing in a null Command 709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testHandleCommand_NullCommand() throws Exception { 729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(null, session); 749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the handleCommand(Command,Session) method, passing in a null Session 839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testHandleCommand_NullSession() throws Exception { 859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, null); 879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the numberOfInvocations(), addInvocationRecord() and clearInvocationRecord() methods 969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testInvocationHistory() throws Exception { 989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair control(session).expectAndDefaultReturn(session.getClientHost(), DEFAULT_HOST); 999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replay(session); 1009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("none", 0, commandHandler.numberOfInvocations()); 1029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, session); 1039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("1", 1, commandHandler.numberOfInvocations()); 1049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, session); 1059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("2", 2, commandHandler.numberOfInvocations()); 1069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.clearInvocations(); 1079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("cleared", 0, commandHandler.numberOfInvocations()); 1089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the getInvocation() method 1129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @throws Exception 1139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testGetInvocation() throws Exception { 1159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair control(session).expectAndDefaultReturn(session.getClientHost(), DEFAULT_HOST); 1169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replay(session); 1179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, session); 1199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND_WITH_ARGS, session); 1209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertSame("1", COMMAND, commandHandler.getInvocation(0).getCommand()); 1219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertSame("2", COMMAND_WITH_ARGS, commandHandler.getInvocation(1).getCommand()); 1229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the getInvocation() method, passing in an invalid index 1269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testGetInvocation_IndexOutOfBounds() throws Exception { 1289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.handleCommand(COMMAND, session); 1299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 1309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.getInvocation(2); 1319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected IndexOutOfBoundsException"); 1329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (IndexOutOfBoundsException expected) { 1349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 1359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the quotes utility method 1409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testQuotes() { 1429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("abc", "\"abc\"", AbstractStubCommandHandler.quotes("abc")); 1439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair assertEquals("<empty>", "\"\"", AbstractStubCommandHandler.quotes("")); 1449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the quotes utility method, passing in a null 1489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testQuotes_Null() { 1509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 1519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair AbstractStubCommandHandler.quotes(null); 1529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 1539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 1559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 1569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the assertValidReplyCode() method 1619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testAssertValidReplyCode() { 1639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair // These are valid, so expect no exceptions 1649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.assertValidReplyCode(1); 1659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.assertValidReplyCode(100); 1669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair // These are invalid 1689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair testAssertValidReplyCodeWithInvalid(0); 1699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair testAssertValidReplyCodeWithInvalid(-1); 1709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the assertValidReplyCode() method , passing in an invalid replyCode value 1749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair private void testAssertValidReplyCodeWithInvalid(int invalidReplyCode) { 1769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 1779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.assertValidReplyCode(invalidReplyCode); 1789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 1799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 1819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 1829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 1849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 1869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the sendReply() method, when no message arguments are specified 1879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 1889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testSendReply() { 1899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(REPLY_CODE1, REPLY_TEXT1); 1909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(REPLY_CODE1, MESSAGE_TEXT); 1919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(REPLY_CODE1, OVERRIDE_REPLY_TEXT); 1929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(REPLY_CODE3, null); 1939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replay(session); 1949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 1959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, REPLY_CODE1, null, null, null); 1969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, REPLY_CODE1, MESSAGE_KEY, null, null); 1979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, REPLY_CODE1, MESSAGE_KEY, OVERRIDE_REPLY_TEXT, null); 1989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, REPLY_CODE3, null, null, null); 1999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verify(session); 2019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 2049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the sendReply() method, passing in message arguments 2059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 2069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testSendReply_WithMessageArguments() { 2079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session.sendReply(REPLY_CODE1, REPLY_TEXT2_FORMATTED); 2089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replay(session); 2099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, REPLY_CODE1, null, REPLY_TEXT2, ARGS); 2119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair verify(session); 2139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 2169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the sendReply() method, passing in a null Session 2179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 2189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testSendReply_NullSession() { 2199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 2209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(null, REPLY_CODE1, REPLY_TEXT1, null, null); 2219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 2229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 2249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 2259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 2299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Test the sendReply() method, passing in an invalid replyCode 2309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 2319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void testSendReply_InvalidReplyCode() { 2329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair try { 2339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.sendReply(session, 0, REPLY_TEXT1, null, null); 2349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair fail("Expected AssertFailedException"); 2359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair catch (AssertFailedException expected) { 2379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair LOG.info("Expected: " + expected); 2389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair //------------------------------------------------------------------------- 2429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair // Test setup 2439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair //------------------------------------------------------------------------- 2449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair /** 2469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Perform initialization before each test 2479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @see org.mockftpserver.test.AbstractTest#setUp() 2489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */ 2499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair protected void setUp() throws Exception { 2509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair super.setUp(); 2519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair session = (Session) createMock(Session.class); 2529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair control(session).setDefaultMatcher(MockControl.ARRAY_MATCHER); 2539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler = new AbstractCommandHandler() { 2549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) throws Exception { 2559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair }; 2579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair replyTextBundle = new ListResourceBundle() { 2589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair protected Object[][] getContents() { 2599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair return new Object[][] { 2609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair { Integer.toString(REPLY_CODE1), REPLY_TEXT1 }, 2619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair { Integer.toString(REPLY_CODE2), REPLY_TEXT2 }, 2629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair { MESSAGE_KEY, MESSAGE_TEXT } 2639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair }; 2649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair }; 2669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair commandHandler.setReplyTextBundle(replyTextBundle); 2679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair } 2689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair 2699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair} 270