Created
February 26, 2014 22:58
-
-
Save djegauth/9240595 to your computer and use it in GitHub Desktop.
MongoDB / Arquillian / NoSqlUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeploymentTest { | |
@Deployment | |
public static Archive<?> createDeployment() { | |
File[] libs = Maven | |
.resolver() | |
.loadPomFromFile("pom.xml") | |
.resolve("org.slf4j:slf4j-api:1.7.5", | |
"org.mongodb:mongo-java-driver:jar:2.11.2", | |
"com.lordofthejars:nosqlunit-mongodb:0.7.9", | |
"org.assertj:assertj-core:1.5.0", | |
"de.flapdoodle.embed:de.flapdoodle.embed.mongo:jar:1.41", | |
"org.jongo:jongo:1.0", | |
"com.fasterxml.jackson.datatype:jackson-datatype-joda:2.2.1", | |
"com.google.guava:guava:16.0", | |
"com.google.code.gson:gson:2.1",) | |
.withTransitivity().asFile(); | |
return ShrinkWrap.create(WebArchive.class, "test.war") | |
.addPackages(true, "com.test") | |
.addAsResource("com/test/service/initialUser.json", "com/test/service/initialUser.json") | |
.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) | |
.addAsLibraries(libs); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"user": [ | |
{ "_id" : { "$oid" : "5169aa28e4b0266f45f5a6e7" }, "name" : "Jérémie Gauthier" }, | |
{ "_id" : { "$oid" : "5175aff8e4b0ee583c98cde6" }, "name" : "djegauth" }, | |
{ "_id" : { "$oid" : "518043c9e4b008ed8f6e909f" }, "name" : "qsdf", "password" : "782dd27ea8e3b4f4095ffa38eeb4d20b59069077" }, | |
{ "_id" : { "$oid" : "51883928e4b0a36d741b41f5" }, "name" : "azerty" } | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>com.github.joelittlejohn.embedmongo</groupId> | |
<artifactId>embedmongo-maven-plugin</artifactId> | |
<version>0.1.10</version> | |
<executions> | |
<execution> | |
<id>start</id> | |
<goals> | |
<goal>start</goal> | |
</goals> | |
<configuration> | |
<port>27017</port> | |
<!-- optional, default 27017 --> | |
<!--<randomPort>true</randomPort> <!– optional, default is false, if true allocates a random port and overrides embedmongo.port –>--> | |
<version>2.2.3</version> | |
<!-- optional, default 2.2.1 --> | |
<databaseDirectory>${project.build.directory}\mongo-temp\mongotest</databaseDirectory> | |
<!-- optional, default is a new dir in java.io.tmpdir --> | |
<logging>none</logging> | |
<!-- optional (file|console|none), default console --> | |
<!--<logFile>${project.build.directory}/myfile.log</logFile> <!– optional, can be used when logging=file, default is ./embedmongo.log –>--> | |
<!--<logFileEncoding>utf-8</logFileEncoding> <!– optional, can be used when logging=file, default is utf-8 –>--> | |
<!--<proxyHost>myproxy.company.com</proxyHost> <!– optional, default is none –>--> | |
<!--<proxyPort>8080</proxyPort> <!– optional, default 80 –>--> | |
<!--<proxyUser>joebloggs</proxyUser> <!– optional, default is none –>--> | |
<!--<proxyPassword>pa55w0rd</proxyPassword> <!– optional, default is none –>--> | |
<!--<bindIp>127.0.0.1</bindIp> <!– optional, default is to listen on all interfaces –>--> | |
</configuration> | |
</execution> | |
<execution> | |
<id>stop</id> | |
<goals> | |
<goal>stop</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(Arquillian.class) | |
@UsingDataSet(locations = {"/com/test/service/initialUser.json"}, loadStrategy = LoadStrategyEnum.CLEAN_INSERT) | |
public class UserServiceIT extends DeploymentTest { | |
@ClassRule | |
public static ManagedMongoDb managedMongoDb = newManagedMongoDbRule() | |
.mongodPath("mongotest") | |
.build(); | |
@Rule | |
public MongoDbRule remoteMongoDbRule = new MongoDbRule(mongoDb() | |
.databaseName("dbtest") | |
.host("localhost") | |
.port(27017) | |
.build()); | |
@ConnectionManager | |
private Mongo mongo; | |
@Inject | |
@MongoDB | |
private UserService userService; | |
@Before | |
public void before() { | |
Jongo jongo = new Jongo(this.mongo.getDB("dbtest"), new JacksonMapper.Builder().build()); | |
userService.setJongo(jongo); | |
} | |
@Test | |
public void testGetUsers() { | |
List<User> users = userService.getUsers(); | |
assertThat(users).isNotNull().hasSize(4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment