final File ftpHomeDirFile = new File("target/FTPBlobTest/ftptest");
ftpHomeDirFile.mkdirs();
ftpHomeDirFile.getParentFile().deleteOnExit();
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory factory = new ListenerFactory();
// mock up a user manager to validate user activemq:activemq and provide
// home dir options
context = new Mockery();
final UserManager userManager = context.mock(UserManager.class);
final User user = context.mock(User.class);
context.checking(new Expectations() {{
atLeast(1).of(userManager).authenticate(
with(any(UsernamePasswordAuthentication.class))); will(returnValue(user));
atLeast(1).of(userManager).getUserByName(userNamePass); will(returnValue(user));
atLeast(1).of(user).getHomeDirectory(); will(returnValue(ftpHomeDirFile.getParent()));
atLeast(1).of(user).getMaxIdleTime(); will(returnValue(20000));
atLeast(1).of(user).getName(); will(returnValue(userNamePass));
atLeast(1).of(user).authorize( with(any(AuthorizationRequest.class))); will(new CustomAction("return first passed in param") {
public Object invoke(Invocation invocation)
throws Throwable {
return invocation.getParameter(0);
}
});
}
});
serverFactory.setUserManager(userManager);
factory.setPort(0);
serverFactory.addListener(ftpServerListenerName, factory
.createListener());
server = serverFactory.createServer();
server.start();
int ftpPort = serverFactory.getListener(ftpServerListenerName)
.getPort();