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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration
  • How to Migrate From JUnit 4 to JUnit 5 Step by Step
  • Testing Asynchronous Operations in Spring With JUnit 5 and Byteman
  • Testing Asynchronous Operations in Spring With JUnit and Byteman

Trending

  • The Full-Stack Developer's Blind Spot: Why Data Cleansing Shouldn't Be an Afterthought
  • Performing and Managing Incremental Backups Using pg_basebackup in PostgreSQL 17
  • Concourse CI/CD Pipeline: Webhook Triggers
  • Automatic Code Transformation With OpenRewrite
  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.1K 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.

Related

  • Spring Boot - Microservice- JaxRS Jersey - HATEOAS - JerseyTest - Integration
  • How to Migrate From JUnit 4 to JUnit 5 Step by Step
  • Testing Asynchronous Operations in Spring With JUnit 5 and Byteman
  • Testing Asynchronous Operations in Spring With JUnit and Byteman

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!