1 18 package org.drftpd.tests; 19 20 import java.io.FileInputStream ; 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.io.StringWriter ; 24 import java.net.InetAddress ; 25 import java.net.Socket ; 26 import java.util.Collections ; 27 import java.util.Properties ; 28 29 import javax.net.ServerSocketFactory; 30 import javax.net.SocketFactory; 31 32 import net.sf.drftpd.Bytes; 33 import net.sf.drftpd.event.Event; 34 import net.sf.drftpd.master.BaseFtpConnection; 35 import net.sf.drftpd.master.ConnectionManager; 36 import net.sf.drftpd.master.FtpRequest; 37 import net.sf.drftpd.master.SlaveManagerImpl; 38 import net.sf.drftpd.master.command.CommandManager; 39 import net.sf.drftpd.master.command.plugins.DataConnectionHandler; 40 import net.sf.drftpd.master.config.FtpConfig; 41 import net.sf.drftpd.master.usermanager.NoSuchUserException; 42 import net.sf.drftpd.master.usermanager.User; 43 import net.sf.drftpd.master.usermanager.UserManager; 44 import net.sf.drftpd.remotefile.LinkedRemoteFile; 45 import net.sf.drftpd.remotefile.StaticRemoteFile; 46 47 51 public class DummyBaseFtpConnection extends BaseFtpConnection { 52 53 private InetAddress _clientAddress; 54 private UserManager _userManager; 55 private DummyServerSocketFactory _serverSocketFactory; 56 private DummySocketFactory _socketFactory; 57 private StringWriter _out; 58 private FtpConfig config; 59 60 private DataConnectionHandler _dch; 61 62 public DummyBaseFtpConnection(DataConnectionHandler dch) { 63 _dch = dch; 64 _socketFactory = new DummySocketFactory(); 65 _serverSocketFactory = new DummyServerSocketFactory(_socketFactory); 66 67 currentDirectory = new LinkedRemoteFile(null); 68 currentDirectory.addFile(new StaticRemoteFile(Collections.EMPTY_LIST, "testfile", "drftpd", "drftpd", Bytes.parseBytes("10M"), System.currentTimeMillis())); 69 _out = new StringWriter (); 70 out = new PrintWriter (_out); 71 } 72 public void setRequest(FtpRequest request) { 73 this.request = request; 74 } 75 78 protected void dispatchFtpEvent(Event event) { 79 throw new UnsupportedOperationException (); 80 } 81 82 public InetAddress getClientAddress() { 83 if(_clientAddress == null) throw new NullPointerException (); 84 return _clientAddress; 85 } 86 public void setClientAddress(InetAddress clientAddress) { 87 _clientAddress = clientAddress; 88 } 89 90 public CommandManager getCommandManager() { 91 throw new UnsupportedOperationException (); 92 } 93 94 public FtpConfig getConfig() { 95 if ( config == null ) { 96 Properties p = new Properties (); 97 try { 98 p.load(new FileInputStream ("drftpd.conf")); 99 } catch (Exception e) { 100 throw new RuntimeException (e); 101 } 102 try { 103 config = new FtpConfig(p,"drftpd.conf", null); 104 } catch (IOException e) { 105 throw new RuntimeException (e); 106 } 107 } 108 return config; 109 } 110 111 public ConnectionManager getConnectionManager() { 112 return _cm; 113 } 114 115 public Socket getControlSocket() { 116 return new DummySocket(); 117 } 118 119 public DataConnectionHandler getDataConnectionHandler() { 120 return _dch; 121 } 122 123 public char getDirection() { 124 throw new UnsupportedOperationException (); 125 126 } 127 128 public long getLastActive() { 129 throw new UnsupportedOperationException (); 130 131 } 132 133 public SlaveManagerImpl getSlaveManager() { 134 throw new UnsupportedOperationException (); 135 136 } 137 138 public char getTransferDirection() { 139 throw new UnsupportedOperationException (); 140 } 141 142 public User getUser() throws NoSuchUserException { 143 throw new UnsupportedOperationException (); 144 } 145 146 public void setUserManager(UserManager um) { 147 _userManager = um; 148 } 149 150 153 public User getUserNull() { 154 return super.getUserNull(); 155 } 156 157 protected boolean hasPermission(FtpRequest request) { 158 throw new UnsupportedOperationException (); 159 } 160 161 public boolean isAuthenticated() { 162 throw new UnsupportedOperationException (); 163 } 164 165 public boolean isExecuting() { 166 throw new UnsupportedOperationException (); 167 } 168 169 172 public void reset() { 173 throw new UnsupportedOperationException (); 174 } 175 176 public void resetState() { 177 } 178 179 182 public void run() { 183 throw new UnsupportedOperationException (); 184 } 185 186 189 public void service(FtpRequest request, PrintWriter out) 190 throws IOException { 191 throw new UnsupportedOperationException (); 192 } 193 194 197 public void setControlSocket(Socket socket) { 198 throw new UnsupportedOperationException (); 199 } 200 201 204 public void setCurrentDirectory(LinkedRemoteFile file) { 205 throw new UnsupportedOperationException (); 206 } 207 208 public void setUser(User user) { 209 super.setUser(user); 210 } 211 212 215 public void start() { 216 throw new UnsupportedOperationException (); 217 } 218 219 222 public String status() { 223 return "dummy status string"; 224 } 225 226 229 public void stop() { 230 throw new UnsupportedOperationException (); 231 } 232 233 236 public void stop(String message) { 237 throw new UnsupportedOperationException (); 238 } 239 240 243 public String toString() { 244 throw new UnsupportedOperationException (); 245 } 246 247 250 public int hashCode() { 251 throw new UnsupportedOperationException (); 252 } 253 254 257 public boolean equals(Object obj) { 258 throw new UnsupportedOperationException (); 259 } 260 261 protected Object clone() throws CloneNotSupportedException { 262 throw new UnsupportedOperationException (); 263 } 264 265 public ServerSocketFactory getServerSocketFactory() { 266 return _serverSocketFactory; 267 } 268 public DummyServerSocketFactory getDummySSF() { 269 return _serverSocketFactory; 270 } 271 272 public StringWriter getDummyOut() { 273 return _out; 274 } 275 276 public SocketFactory getSocketFactory() { 277 return _socketFactory; 278 } 279 280 public void setConnectionManager(ConnectionManager manager) { 281 _cm = manager; 282 } 283 284 } 285 | Popular Tags |