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