Skip to content

Commit 910d4b0

Browse files
author
Vasile Baluta
committed
change setuop of embedded mongo DB
1 parent 7128828 commit 910d4b0

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/test/java/com/ericsson/ei/handlers/test/ObjectHandlerTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@
3838
import org.junit.Test;
3939
import org.slf4j.Logger;
4040
import org.slf4j.LoggerFactory;
41-
41+
import org.springframework.util.SocketUtils;
42+
43+
import de.flapdoodle.embed.mongo.MongodExecutable;
44+
import de.flapdoodle.embed.mongo.MongodProcess;
45+
import de.flapdoodle.embed.mongo.MongodStarter;
46+
import de.flapdoodle.embed.mongo.config.IMongodConfig;
47+
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
48+
import de.flapdoodle.embed.mongo.config.Net;
4249
import de.flapdoodle.embed.mongo.distribution.Version;
4350
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
51+
import de.flapdoodle.embed.process.runtime.Network;
4452

4553
public class ObjectHandlerTest {
4654

@@ -49,6 +57,7 @@ public class ObjectHandlerTest {
4957
private ObjectHandler objHandler = new ObjectHandler();
5058

5159
private MongodForTestsFactory testsFactory;
60+
private MongodExecutable mongodExecutable = null;
5261
private MongoClient mongoClient = null;
5362

5463
private MongoDBHandler mongoDBHandler = new MongoDBHandler();
@@ -70,8 +79,21 @@ public class ObjectHandlerTest {
7079

7180
public void setUpEmbeddedMongo() throws Exception {
7281
try {
73-
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
74-
mongoClient = testsFactory.newMongo();
82+
// testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
83+
// mongoClient = testsFactory.newMongo();
84+
int port = SocketUtils.findAvailableTcpPort();
85+
86+
MongodStarter starter = MongodStarter.getDefaultInstance();
87+
88+
String bindIp = "localhost";
89+
90+
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION)
91+
.net(new Net(bindIp, port, Network.localhostIsIPv6())).build();
92+
93+
mongodExecutable = starter.prepare(mongodConfig);
94+
MongodProcess mongod = mongodExecutable.start();
95+
mongoClient = new MongoClient("localhost", port);
96+
7597
} catch (Exception e) {
7698
log.error(e.getMessage(), e);
7799
e.printStackTrace();
@@ -116,8 +138,10 @@ public void dropCollection() {
116138
mongoDBHandler.dropDocument(dataBaseName, collectionName, condition);
117139
if (mongoClient != null)
118140
mongoClient.close();
119-
if (testsFactory != null)
120-
testsFactory.shutdown();
141+
if (mongodExecutable != null)
142+
mongodExecutable.stop();
143+
// if (testsFactory != null)
144+
// testsFactory.shutdown();
121145

122146
}
123147
}

0 commit comments

Comments
 (0)