Hi all. There is a cool annotation @Sql, which allows to execute sql script before/after a test.

It may be good to have the same annotation for tests which use MongoDB. I'm thinking over a new annotation and a new test execution listener, that will run a MongoDB script before/after test, as @Sql annotation does.

For example:

@DataMongoTest
class MovieRepositoryTest {

    @Test
    @MongoInsert(scriptLocation = "movie.json", collection = "movies")
    void findById() {
      ....
    }
}

movie.json

{
  "_id": {
    "$oid": "573a1390f29313caabcd60e4"
  },
  "genres": [
    "Short",
    "Comedy",
    "Drama"
  ],
  "title": "The immigrant"
}

What do you think about it?

Comment From: sbrannen

The core Spring Framework does not have support for MongoDB.

However, the Spring Data MongoDB project provides extensive support for MongoDB in Spring applications.

So perhaps this issue should be moved to that repository.

/cc @odrotbohm, @mp911de

Comment From: mp911de

That's an generally interesting idea. I could think of other arrangements in the Data space such as setting up data in Couchbase, Elasicsearch and others. Could we leverage a general mechanism in the Spring Test context to evaluate annotations on test classes/methods from Spring Data?

In any case, let me take this to the data team.

Comment From: snicoll

I am going to close this as not related to the core framework.

@sleepo581 if you haven't done so already, please follow-up with the Spring Data project.