DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Marry MDC With Spring Integration
  • What Actually Breaks During Large-Scale S/4HANA Conversions (And How to Prevent It)
  • When Memory Overflows: Too Many ApplicationContexts in Spring Integration Tests
  • Integrate Spring With Open AI

Trending

  • How to Build a Scalable SaaS Product Architecture
  • Every Generation Fears the Machine. Here Is How the AI Job Panic Usually Ends
  • RAG Architecture Patterns: Proxy, Caching, and Routing
  • Why Spark Executors Leave Cores Idle on YARN: A Packing Model for Executor Sizing

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Spring FakeFtpServer to JUnit test a Spring Integration Flow

Using Spring FakeFtpServer to JUnit test a Spring Integration Flow

By 
Krishna Prasad
·
Dec. 13, 12 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
17.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in
for people in hurry, get the latest code and the steps in github .

to run the junit test, run “mvn test” and understand the test flow.

introduction: fakeftpserver

in this spring integration fakeftpserver example, i will demonstrate using spring fakeftpserver to junit test a spring integration flow. this is an interesting topic, and there are few articles on unit testing file transfers , which gives some insight on this topic.

in this blog, we will test a spring integration flow which checks for a list of files, apply a splitter to separate each file and start downloading them into a local location.  once the download is complete, it will delete the files on the ftp server. in my next blog, i will show how to do junit testing of spring integration flow with sftp server.

spring integration flow

spring integration fakeftpserver example

spring integration fakeftpserver example

in order to use fakeftpserver we need to have maven dependency as below,

<dependency>
<groupid>org.mockftpserver</groupid>
<artifactid>mockftpserver</artifactid>
<version>2.3</version>
<scope>test</scope>
</dependency>

the first step to this is to create a fakeftpserver before every test runs as below,

@before
public void setup() throws exception {
fakeftpserver = new fakeftpserver();
fakeftpserver.setservercontrolport(9999); // use any free port
filesystem filesystem = new unixfakefilesystem();
filesystem.add(new fileentry(file, contents));
fakeftpserver.setfilesystem(filesystem);
useraccount useraccount = new useraccount("user", "password", home_dir);
fakeftpserver.adduseraccount(useraccount);
fakeftpserver.start();
}

@after
public void teardown() throws exception {
fakeftpserver.stop();
}

finally run the junit test case as seen below,

    @autowired
private filedownloadutil downloadutil;
@test
public void testftpdownload() throws exception {
file file = new file("src/test/resources/output");
delete(file);
ftpclient client = new ftpclient();
client.connect("localhost", 9999);
client.login("user", "password");
string files[] = client.listnames("/dir");
client.help();
logger.debug("before delete" + files[0]);
assertequals(1, files.length);
downloadutil.downloadfilesfromremotedirectory();
logger.debug("after delete");
files = client.listnames("/dir");
client.help();
assertequals(0, files.length);
assertequals(1, file.list().length);
}

i hope this blog helped.



Spring Integration unit test Spring Framework Integration Flow (web browser) JUnit

Published at DZone with permission of Krishna Prasad. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Marry MDC With Spring Integration
  • What Actually Breaks During Large-Scale S/4HANA Conversions (And How to Prevent It)
  • When Memory Overflows: Too Many ApplicationContexts in Spring Integration Tests
  • Integrate Spring With Open AI

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook