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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  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

Krishna Prasad user avatar by
Krishna Prasad
·
Dec. 13, 12 · Interview
Like (0)
Save
Tweet
Share
15.67K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Using JSON Web Encryption (JWE)
  • Why It Is Important To Have an Ownership as a DevOps Engineer
  • How To Use Terraform to Provision an AWS EC2 Instance
  • How Do the Docker Client and Docker Servers Work?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: