FTP Server Stub to be used in JUnit tests

A

Andrea Francia

Recently during the write of a specialized FTP Client in Java I found
some problem in writing automated tests for testing the main
functionalities.

So I used a sort of semi automated tests that required me to set up the
a local FTP Server with the particular configuration needed for the
specific test.

The project was finished without using a Ftp Server Stub, but I think
that a configurable Ftp Server Stub configurable via code could be
useful, may be for others developers or for me in the future.

So I investigated the feasibility creating an incomplete prototype of
Ftp Server Stub. Now, before commit myself in this work I would hear
some opinions on the possible usefullness of this project.

Do you think could be useful?
Do you know some other alternative?

The following example shows how the FtpServerStub could be used in a
JUnit test which test the downloadLatestFile() method which should
download the latest file matching the URL glob pattern.

public void testDownloadLatestFile() {
// prepare ftp server
FtpServerStub server = new FtpServerStub();
server.setPort(2121);
server.setFileSystemRoot(new Directory() {{

mkdir("data");
touch("data/list-1-jan-1970.txt")
.withModificationTime(0)
.withUtf8Content("BAD: this is not the latest!");

touch("data/list-1-jan-2000.txt")
.withModificationTime(946684800L)
.withUtf8Content("You downloaded the right one!");

touch("data/another-file.dat")
.withModificationTime(1199145600L) // newer that 1-jan-2000
.withUtf8Content("BAD: this does not matches the pattern!");
}});
server.start(); // start in a new thread

// execute the method under test
String result = Downloader.downloadLatestFile(
"ftp://127.0.0.1:2121/data/*.txt");

// verify the result
assertEquals(result, "You downloaded the right one!");
}
 
T

Tom Anderson

Recently during the write of a specialized FTP Client in Java I found some
problem in writing automated tests for testing the main functionalities.

So I used a sort of semi automated tests that required me to set up the a
local FTP Server with the particular configuration needed for the specific
test.

The project was finished without using a Ftp Server Stub, but I think that a
configurable Ftp Server Stub configurable via code could be useful, may be
for others developers or for me in the future.

So I investigated the feasibility creating an incomplete prototype of Ftp
Server Stub. Now, before commit myself in this work I would hear some
opinions on the possible usefullness of this project.

Do you think could be useful?

I think it's probably of limited use. If you made it general enough to be
used as an actual FTP server, it might be more use. FTP is not the big
player it once was, though.
Do you know some other alternative?

No.

You know what the real problem is, though? How are you going to unit-test
it? :)

tom
 
L

Lothar Kimmeringer

Tom said:
I think it's probably of limited use. If you made it general enough to be
used as an actual FTP server, it might be more use. FTP is not the big
player it once was, though.

I wish that would be true. Like OFTP via ISDN or X.400 you will
never get rid off FTP. At least the number of companies that
expect communication via OFTP using X.25-modems instead of ISDN
but that is enough trouble to install, especially with Java.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
A

Andrea Francia

Lothar said:
I wish that would be true. Like OFTP via ISDN or X.400 you will
never get rid off FTP. At least the number of companies that
expect communication via OFTP using X.25-modems instead of ISDN
but that is enough trouble to install, especially with Java.

As a far I can understand from the OFTP RFC () the OFTP and FTP protocol
are not related.

From http://www.ietf.org/rfc/rfc5024, chapter 1.1:
ODETTE-FTP is not to be confused as a variant of, or similar to, the
Internet FTP [FTP],
 
L

Lothar Kimmeringer

Andrea said:
As a far I can understand from the OFTP RFC () the OFTP and FTP protocol
are not related.

Who said so? But OFTP ist still in common use like FTP and X.400.
So speaking of FTP as "not the big player it once was" is simply
not true.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
T

Tom Anderson

Who said so? But OFTP ist still in common use like FTP and X.400. So
speaking of FTP as "not the big player it once was" is simply not true.

I didn't say it was extinct, or even endangered, i just said it wasn't a
big player any more, and i stand by that. Once upon a time, FTP was the
*only* way that software or ay other large dollop of bytes was distributed
over the internet, and that made it a major part of the interface to the
net. Nowadays, that just isn't the case. Are people building new apps with
FTP? No - it's a legacy protocol.

tom
 
L

Lothar Kimmeringer

Tom said:
I didn't say it was extinct, or even endangered, i just said it wasn't a
big player any more, and i stand by that. Once upon a time, FTP was the
*only* way that software or ay other large dollop of bytes was distributed
over the internet, and that made it a major part of the interface to the
net. Nowadays, that just isn't the case. Are people building new apps with
FTP? No - it's a legacy protocol.

If you limit your view of the "Net" as the World Wide Web and
private use you are correct and HTTP and P2P are more common.
When you regard data-transfer between companies you most likely
will be faced with FTP (everywhere), OFTP (automotive) and
X.400 (the rest). In the near past more and more AS2 is coming
up but mostly to replace X.400.

The US-american market might differ but AFAIK more in the way
that AS2 is more common because OFTP hasn't been used very much
in the past.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
T

Tom Anderson

If you limit your view of the "Net" as the World Wide Web and private
use you are correct and HTTP and P2P are more common. When you regard
data-transfer between companies you most likely will be faced with FTP
(everywhere), OFTP (automotive) and X.400 (the rest). In the near past
more and more AS2 is coming up but mostly to replace X.400.

I wasn't thinking of the web specifically, but i admit i was thinking of
apps used by the general public - B2C rather than B2B, if you like.

But still - are new apps being built using FTP by choice? If not, it's a
legacy protocol.

tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top