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
Over 2 million developers have joined DZone.
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

  • Ingesting Fixed-Width Mainframe Files Into Delta Lake: The Details Nobody Writes Down
  • Building Enterprise-Grade Real-Time IoT Dashboards with Vue 3, MQTT, and Kafka
  • From AI Chaos to Control: Building Enterprise-Grade LLM Gateways With MuleSoft Anypoint
  • Ujorm3: A New Lightweight ORM for JavaBeans and Records
  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 user avatar
Krishna Prasad
·
Dec. 13, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
17.4K Views

Join the DZone community and get the full member experience.

Join For Free
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

The likes didn't load as expected. Please refresh the page and try again.

  • 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