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.session;
179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.io.ByteArrayInputStream;
199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.io.ByteArrayOutputStream;
209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.io.IOException;
219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.io.InputStream;
229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.net.InetAddress;
239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.net.SocketTimeoutException;
249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.Collections;
259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.HashMap;
269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport java.util.Map;
279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.apache.log4j.Logger;
299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.MockFtpServerException;
309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.command.Command;
319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.socket.StubServerSocket;
329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.socket.StubServerSocketFactory;
339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.socket.StubSocket;
349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.socket.StubSocketFactory;
359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.core.util.AssertFailedException;
369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairimport org.mockftpserver.test.AbstractTest;
379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair/**
399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * Tests for the DefaultSession class
409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @version $Revision$ - $Date$
429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair *
439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair * @author Chris Mair
449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair */
459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismairpublic final class DefaultSessionTest extends AbstractTest {
469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final Logger LOG = Logger.getLogger(DefaultSessionTest.class);
489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final String DATA = "sample data 123";
499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final int PORT = 197;
509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final String NAME1 = "name1";
519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final String NAME2 = "name2";
529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private static final Object VALUE = "value";
539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private DefaultSession session;
559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private ByteArrayOutputStream outputStream;
569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private Map commandHandlerMap;
579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private StubSocket stubSocket;
589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private InetAddress clientHost;
599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Perform initialization before each test
629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @see org.mockftpserver.test.AbstractTest#setUp()
649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected void setUp() throws Exception {
669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        super.setUp();
679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        commandHandlerMap = new HashMap();
699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        outputStream = new ByteArrayOutputStream();
709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session = createDefaultSession("");
719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        clientHost = InetAddress.getLocalHost();
729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @see org.mockftpserver.test.AbstractTest#tearDown()
769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    protected void tearDown() throws Exception {
789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        super.tearDown();
799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the Constructor when the control socket is null
839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testConstructor_NullControlSocket() {
859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            new DefaultSession(null, commandHandlerMap);
879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the Constructor when the command handler Map is null
969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testConstructor_NullCommandHandlerMap() {
989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            new DefaultSession(stubSocket, null);
1009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
1019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
1029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
1039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
1049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
1059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the setClientDataPort() method
1099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSetClientDataPort() {
1119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket("");
1129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocketFactory stubSocketFactory = new StubSocketFactory(stubSocket);
1139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = stubSocketFactory;
1149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataPort(PORT);
1159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
1169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
1179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("data port", PORT, stubSocketFactory.requestedDataPort);
1189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the setClientDataPort() method after the session was in passive data mode
1229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSetClientDataPort_AfterPassiveConnectionMode() throws IOException {
1249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocket stubServerSocket = new StubServerSocket(PORT);
1259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocketFactory stubServerSocketFactory = new StubServerSocketFactory(stubServerSocket);
1269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.serverSocketFactory = stubServerSocketFactory;
1279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.switchToPassiveMode();
1299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertFalse("server socket closed", stubServerSocket.isClosed());
1309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNotNull("passiveModeDataSocket", session.passiveModeDataSocket);
1319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataPort(PORT);
1329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        // Make sure that any passive mode connection info is cleared out
1349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertTrue("server socket closed", stubServerSocket.isClosed());
1359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("passiveModeDataSocket should be null", session.passiveModeDataSocket);
1369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the setClientHost() method
1409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSetClientHost() throws Exception {
1429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket("");
1439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocketFactory stubSocketFactory = new StubSocketFactory(stubSocket);
1449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = stubSocketFactory;
1459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
1469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
1479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("client host", clientHost, stubSocketFactory.requestedHost);
1489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the openDataConnection(), setClientDataPort() and setClientDataHost() methods
1529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testOpenDataConnection() {
1549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket("");
1559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocketFactory stubSocketFactory = new StubSocketFactory(stubSocket);
1569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = stubSocketFactory;
1579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        // Use default client data port
1599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
1609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
1619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("data port", DefaultSession.DEFAULT_CLIENT_DATA_PORT, stubSocketFactory.requestedDataPort);
1629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("client host", clientHost, stubSocketFactory.requestedHost);
1639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        // Set client data port explicitly
1659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataPort(PORT);
1669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
1679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
1689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("data port", PORT, stubSocketFactory.requestedDataPort);
1699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("client host", clientHost, stubSocketFactory.requestedHost);
1709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the OpenDataConnection method, when in passive mode and no incoming connection is
1749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * initiated
1759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testOpenDataConnection_PassiveMode_NoConnection() throws IOException {
1779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocket stubServerSocket = new StubServerSocket(PORT);
1799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocketFactory stubServerSocketFactory = new StubServerSocketFactory(stubServerSocket);
1809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.serverSocketFactory = stubServerSocketFactory;
1819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.switchToPassiveMode();
1839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
1859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.openDataConnection();
1869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected MockFtpServerException");
1879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
1889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (MockFtpServerException expected) {
1899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
1909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            assertSame("cause", SocketTimeoutException.class, expected.getCause().getClass());
1919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
1929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
1939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
1949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
1959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the OpenDataConnection method, when the clientHost has not been set
1969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
1979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testOpenDataConnection_NullClientHost() {
1989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
1999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.openDataConnection();
2009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
2019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
2029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
2039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
2049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
2059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the readData() method
2099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testReadData() {
2119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket(DATA);
2129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = new StubSocketFactory(stubSocket);
2139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
2149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
2169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        byte[] data = session.readData();
2179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        LOG.info("data=[" + new String(data) + "]");
2189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("data", DATA.getBytes(), data);
2199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the readData() method after switching to passive mode
2239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testReadData_PassiveMode() throws IOException {
2259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket(DATA);
2269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocket stubServerSocket = new StubServerSocket(PORT, stubSocket);
2279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocketFactory stubServerSocketFactory = new StubServerSocketFactory(stubServerSocket);
2289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.serverSocketFactory = stubServerSocketFactory;
2299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.switchToPassiveMode();
2319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
2329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        byte[] data = session.readData();
2339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        LOG.info("data=[" + new String(data) + "]");
2349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("data", DATA.getBytes(), data);
2359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the closeDataConnection() method
2399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testCloseDataConnection() {
2419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket(DATA);
2429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = new StubSocketFactory(stubSocket);
2439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
2459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
2469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.closeDataConnection();
2479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertTrue("client data socket should be closed", stubSocket.isClosed());
2489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the switchToPassiveMode() method
2529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSwitchToPassiveMode() throws IOException {
2549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocket stubServerSocket = new StubServerSocket(PORT);
2559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubServerSocketFactory stubServerSocketFactory = new StubServerSocketFactory(stubServerSocket);
2569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.serverSocketFactory = stubServerSocketFactory;
2579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("passiveModeDataSocket starts out null", session.passiveModeDataSocket);
2599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        int port = session.switchToPassiveMode();
2609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertSame("passiveModeDataSocket", stubServerSocket, session.passiveModeDataSocket);
2619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("port", PORT, port);
2629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the getServerHost() method
2669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetServerHost() {
2689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("host", DEFAULT_HOST, session.getServerHost());
2699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the getClientHost() method when the session is not yet started
2739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetClientHost_NotRunning() {
2759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("null", session.getClientHost());
2769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the parseCommand() method
2809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testParseCommand() {
2829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        Command command = session.parseCommand("LIST");
2839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command name", "LIST", command.getName());
2849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command parameters", EMPTY, command.getParameters());
2859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        command = session.parseCommand("USER user123");
2879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command name", "USER", command.getName());
2889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command parameters", array("user123"), command.getParameters());
2899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        command = session.parseCommand("PORT 127,0,0,1,17,37");
2919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command name", "PORT", command.getName());
2929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("command parameters", new String[] { "127", "0", "0", "1", "17", "37" }, command
2939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair                .getParameters());
2949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
2959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
2969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
2979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the parseCommand() method, passing in an empty command String
2989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
2999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testParseCommand_EmptyCommandString() {
3009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
3019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.parseCommand("");
3029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
3039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
3059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
3069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the sendData() method, as well as the openDataConnection() and closeDataConnection()
3119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSendData() {
3139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = createTestSocket("1234567890 abcdef");
3149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.socketFactory = new StubSocketFactory(stubSocket);
3159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setClientDataHost(clientHost);
3179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.openDataConnection();
3189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.sendData(DATA.getBytes(), DATA.length());
3199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        LOG.info("output=[" + outputStream.toString() + "]");
3209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("output", DATA, outputStream.toString());
3219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the SendData() method, passing in a null byte[]
3259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSendData_Null() {
3279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
3299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.sendData(null, 1);
3309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
3319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
3339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
3349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the SendReply(int,String) method, passing in an invalid reply code
3399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSendReply_InvalidReplyCode() {
3419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
3439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.sendReply(-66, "text");
3449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
3459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
3479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
3489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the getAttribute() and setAttribute() methods
3539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetAndSetAttribute() {
3559d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("name does not exist yet", session.getAttribute(NAME1));
3569d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setAttribute(NAME1, VALUE);
3579d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setAttribute(NAME2, null);
3589d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("NAME1", VALUE, session.getAttribute(NAME1));
3599d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("NAME2", session.getAttribute(NAME2));
3609d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("no such name", session.getAttribute("noSuchName"));
3619d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3629d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3639d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3649d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the getAttribute() method, passing in a null name
3659d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3669d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetAttribute_Null() {
3679d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
3689d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.getAttribute(null);
3699d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
3709d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3719d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
3729d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
3739d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3749d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3759d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3769d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3779d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the setAttribute() method, passing in a null name
3789d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3799d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testSetAttribute_NullName() {
3809d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
3819d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.setAttribute(null, VALUE);
3829d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
3839d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3849d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
3859d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
3869d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
3879d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3889d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3899d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
3909d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the removeAttribute()
3919d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
3929d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testRemoveAttribute() {
3939d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.removeAttribute("noSuchName");      // do nothing
3949d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setAttribute(NAME1, VALUE);
3959d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.removeAttribute(NAME1);
3969d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertNull("NAME1", session.getAttribute(NAME1));
3979d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
3989d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
3999d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
4009d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the removeAttribute() method, passing in a null name
4019d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
4029d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testRemoveAttribute_Null() {
4039d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        try {
4049d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            session.removeAttribute(null);
4059d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            fail("Expected AssertFailedException");
4069d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
4079d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        catch (AssertFailedException expected) {
4089d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair            LOG.info("Expected: " + expected);
4099d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        }
4109d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
4119d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
4129d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
4139d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Test the getAttributeNames()
4149d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
4159d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    public void testGetAttributeNames() {
4169d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("No names yet", Collections.EMPTY_SET, session.getAttributeNames());
4179d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setAttribute(NAME1, VALUE);
4189d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("1", Collections.singleton(NAME1), session.getAttributeNames());
4199d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        session.setAttribute(NAME2, VALUE);
4209d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        assertEquals("2", set(NAME1, NAME2), session.getAttributeNames());
4219d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
4229d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
4239d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    // -------------------------------------------------------------------------
4249d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    // Internal Helper Methods
4259d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    // -------------------------------------------------------------------------
4269d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
4279d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
4289d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Create and return a DefaultSession object that reads from an InputStream with the specified
4299d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * contents and writes to the predefined outputStrean ByteArrayOutputStream. Also, save the
4309d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * StubSocket being used in the stubSocket attribute.
4319d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
4329d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param inputStreamContents - the contents of the input stream
4339d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the DefaultSession
4349d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
4359d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private DefaultSession createDefaultSession(String inputStreamContents) {
4369d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubSocket = createTestSocket(inputStreamContents);
4379d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        return new DefaultSession(stubSocket, commandHandlerMap);
4389d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
4399d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
4409d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    /**
4419d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * Create and return a StubSocket that reads from an InputStream with the specified contents and
4429d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * writes to the predefined outputStrean ByteArrayOutputStream.
4439d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     *
4449d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @param inputStreamContents - the contents of the input stream
4459d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     * @return the StubSocket
4469d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair     */
4479d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    private StubSocket createTestSocket(String inputStreamContents) {
4489d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        InputStream inputStream = new ByteArrayInputStream(inputStreamContents.getBytes());
4499d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        StubSocket stubSocket = new StubSocket(inputStream, outputStream);
4509d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        stubSocket._setLocalAddress(DEFAULT_HOST);
4519d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair        return stubSocket;
4529d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair    }
4539d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair
4549d9aece7b2c2865253fdd2946a4d11a4f642c5aechrismair}
455