StubSession.groovy revision 78795c9e5e3c55fc294f011bcc129b7aab0f49b7
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.core.session
17
18import java.net.InetAddress
19import java.util.Set
20
21/**
22 * Stub implementation of the {@link Session} interface for testing
23 *
24 * @version $Revision: $ - $Date: $
25 *
26 * @author Chris Mair
27 */
28class StubSession implements Session {
29
30     Map attributes = [:]
31     List sentReplies = [ ]
32
33    /**
34     * @see org.mockftpserver.core.session.Session#close()
35     */
36    public void close() {
37
38    }
39
40    /**
41     * @see org.mockftpserver.core.session.Session#closeDataConnection()
42     */
43    public void closeDataConnection() {
44
45    }
46
47    /**
48     * @see org.mockftpserver.core.session.Session#getAttribute(java.lang.String)
49     */
50    public Object getAttribute(String name) {
51        return attributes[name]
52    }
53
54    /**
55     * @see org.mockftpserver.core.session.Session#getAttributeNames()
56     */
57    public Set getAttributeNames() {
58        return attributes.keySet()
59    }
60
61    /**
62     * @see org.mockftpserver.core.session.Session#getClientHost()
63     */
64    public InetAddress getClientHost() {
65        return null
66    }
67
68    /**
69     * @see org.mockftpserver.core.session.Session#getServerHost()
70     */
71    public InetAddress getServerHost() {
72        return null
73    }
74
75    /**
76     * @see org.mockftpserver.core.session.Session#openDataConnection()
77     */
78    public void openDataConnection() {
79
80    }
81
82    /**
83     * @see org.mockftpserver.core.session.Session#readData()
84     */
85    public byte[] readData() {
86        return null
87    }
88
89    /**
90     * @see org.mockftpserver.core.session.Session#removeAttribute(java.lang.String)
91     */
92    public void removeAttribute(String name) {
93        attributes.remove(name)
94    }
95
96    /**
97     * @see org.mockftpserver.core.session.Session#sendData(byte[], int)
98     */
99    public void sendData(byte[] data, int numBytes) {
100
101    }
102
103    /**
104     * @see org.mockftpserver.core.session.Session#sendReply(int, java.lang.String)
105     */
106    public void sendReply(int replyCode, String replyText) {
107        sentReplies << [replyCode, replyText]
108    }
109
110    /**
111     * @see org.mockftpserver.core.session.Session#setAttribute(java.lang.String, java.lang.Object)
112     */
113    public void setAttribute(String name, Object value) {
114        attributes[name] = value
115    }
116
117    /**
118     * @see org.mockftpserver.core.session.Session#setClientDataHost(java.net.InetAddress)
119     */
120    public void setClientDataHost(InetAddress clientHost) {
121
122    }
123
124    /**
125     * @see org.mockftpserver.core.session.Session#setClientDataPort(int)
126     */
127    public void setClientDataPort(int clientDataPort) {
128
129    }
130
131    /**
132     * @see org.mockftpserver.core.session.Session#switchToPassiveMode()
133     */
134    public int switchToPassiveMode() {
135        return 0
136    }
137
138    /**
139     * @see java.lang.Runnable#run()
140     */
141    public void run() {
142
143    }
144
145    //-------------------------------------------------------------------------
146    // Stub-specific API - Helper methods not part of Session interface
147    //-------------------------------------------------------------------------
148
149    String toString() {
150        "StubSession[sentReplies=$sentReplies]"
151    }
152
153}
154