lordofthejars / nosql-unit

NoSQL Unit is a JUnit extension that helps you write NoSQL unit tests.
Other
383 stars 123 forks source link

Simultaneous engines using Spring Data #79

Closed jarandaf closed 11 years ago

jarandaf commented 11 years ago

How is it supposed to call the connectionIdentifier() method when trying to use Spring Data and simultaneous engines in the same test class? I did not find any straight way when using, for example, MongoDB and Neo4j. I tried instantiating both SpringGraphDatabaseServiceNeo4jRule and SpringMongoDbRule but they are not accessible outside their respective package (no modifier provided in class), so I can't use my own configuration and hence, neither set the connection identifiers. Any clues on that?

lordofthejars commented 11 years ago

Hello, first of all thank you very much for using NoSQLUnit.

You are right that there is not direct way to test polyglot persistence with Neo4j. Well in MongoDB there is no problem with connection identifier, and with Managed Neo4j either. The only problem is with Embedded Spring Neo4j.

I will add a better method to deal with that problem but as workaround you can instantiate the rule on your own:

new SpringGraphDatabaseServiceNeo4jRule(new Neo4jConfiguration())

and set the connection identifier in created Neo4jConfiguration instance.

jarandaf commented 11 years ago

It's not clear to me how I should specify the connection identifiers in both Spring Data MongoDB and Spring Data Neo4j approaches.

In the first case (Spring Data MongoDB), the docs say:

@Rule public MongoDbRule mongoDbRule = newMongoDbRule().defaultSpringMongoDb("test");

so the configuration is actually being already specified and I see no way to set the connection identifier.

In the second case (Spring Data Neo4j), I think it should exist a neo4j configuration builder class (like in MongoDB, since the configuration can not be done inline). And yes, your solution on the Neo4jRule does the trick but I think the class should be public, with no modifier there is no way to instantiate it outside its package.

Please, I would highly appreciate some further code snippets that solve this issue, in case I am wrong.

Thanks in advance!

lordofthejars commented 11 years ago

In case of Spring you can see http://www.lordofthejars.com/2013/01/testing-spring-data-mongodb.html where there is an example on how to use MongoDb with Spring without using defaultSpringMongoDb method, keep in mind that this methods are simply quick calls to other methods that you can call it from outside (in case of NoSQLUnit using MongoDbRuleBuilder https://github.com/lordofthejars/nosql-unit/blob/master/nosqlunit-mongodb/src/main/java/com/lordofthejars/nosqlunit/mongodb/MongoDbRule.java#L18)

So from the point of view of MongoDb there is no problem, and for Neo4j:

new SpringGraphDatabaseServiceNeo4jRule(new Neo4jConfiguration().setConnectionIdentifier(""));

And then you can use the approach explain it here: https://github.com/lordofthejars/nosql-unit#simultaneous-engines