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.

Configuration.

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

captura-de-ecra%cc%83-2017-01-28-as-19-50-48

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.

 Logs.
captura-de-ecra%cc%83-2017-01-28-as-20-05-42
 captura-de-ecra%cc%83-2017-01-28-as-20-07-32
fongo-scheduled-job‘ – is a maven project, so it should be fairly simple to import and build it.
Hope it’s helpful for someone!
Advertisements

Sample project using Spring Boot and MongoDB(Fongo) and test repository with NoSqlUnit

Hi, this is the initial 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 NoSqlUnit – a helper library for tests.
For a cleaner document object, we use Lombok.

You can read more about Fongo in here.
You can read more about NoSqlUnit in here.
You can read more about Spring-data-mongo in here.
You can read more about Lombok in here.

User document.

User repository.

Sample data to load using NoSqlUnit.

Sample test.

Configuration

fongo-hello-world‘ – is a maven project, so it should be fairly simple to import and build it. Run the test on class ‘UserRepositoryTest’.
Hope it’s helpful for someone!