Sample project using Spring Boot, MongoDB(Fongo) with a scheduled maintenance job and test repository with NoSqlUnit

Hi, this is the another post of a series where i’ll be publishing some samples showing how to work with MongoDB documents with Java.
This post sample consists on a project that uses spring-boot with spring-data-mongo repository, Fongo(an in-memory mongodb representation) and a schedule maintenance job to delete user records.
We will also use NoSqlUnit – a helper library for tests.
For a cleaner document object, we use Lombok.

You can read more about scheduling-tasks in here.

This project uses the same structure of the one in my previous post.

User document.

User repository.

Scheduled tasks.


At this point we can run the app and what the logs to see the scheduled job in action.


Having the app running if we run the test ‘testCountAllUsersNotUpdatedOnLast24Hours’
we can check that all users from the dataset ‘five-users.json’ are loaded and when the schedule job runs it deletes all the five records. All records have the property ‘lastUpdated’ with values that exceed more than 24 hours from now.

Sample data to load using NoSqlUnit.

Sample test.

fongo-scheduled-job‘ – is a maven project, so it should be fairly simple to import and build it.
Hope it’s helpful for someone!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s