38
38
import org .junit .Test ;
39
39
import org .slf4j .Logger ;
40
40
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 ;
42
49
import de .flapdoodle .embed .mongo .distribution .Version ;
43
50
import de .flapdoodle .embed .mongo .tests .MongodForTestsFactory ;
51
+ import de .flapdoodle .embed .process .runtime .Network ;
44
52
45
53
public class ObjectHandlerTest {
46
54
@@ -49,6 +57,7 @@ public class ObjectHandlerTest {
49
57
private ObjectHandler objHandler = new ObjectHandler ();
50
58
51
59
private MongodForTestsFactory testsFactory ;
60
+ private MongodExecutable mongodExecutable = null ;
52
61
private MongoClient mongoClient = null ;
53
62
54
63
private MongoDBHandler mongoDBHandler = new MongoDBHandler ();
@@ -70,8 +79,21 @@ public class ObjectHandlerTest {
70
79
71
80
public void setUpEmbeddedMongo () throws Exception {
72
81
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
+
75
97
} catch (Exception e ) {
76
98
log .error (e .getMessage (), e );
77
99
e .printStackTrace ();
@@ -116,8 +138,10 @@ public void dropCollection() {
116
138
mongoDBHandler .dropDocument (dataBaseName , collectionName , condition );
117
139
if (mongoClient != null )
118
140
mongoClient .close ();
119
- if (testsFactory != null )
120
- testsFactory .shutdown ();
141
+ if (mongodExecutable != null )
142
+ mongodExecutable .stop ();
143
+ // if (testsFactory != null)
144
+ // testsFactory.shutdown();
121
145
122
146
}
123
147
}
0 commit comments