3
3
import org .junit .Before ;
4
4
import org .junit .BeforeClass ;
5
5
import org .junit .Test ;
6
+ import org .slf4j .Logger ;
7
+ import org .slf4j .LoggerFactory ;
6
8
9
+ import com .ericsson .ei .handlers .test .ObjectHandlerTest ;
7
10
import com .ericsson .ei .mongodbhandler .MongoDBHandler ;
8
11
12
+ import de .flapdoodle .embed .mongo .MongodExecutable ;
13
+ import de .flapdoodle .embed .mongo .MongodProcess ;
14
+ import de .flapdoodle .embed .mongo .MongodStarter ;
15
+ import de .flapdoodle .embed .mongo .config .IMongodConfig ;
16
+ import de .flapdoodle .embed .mongo .config .MongodConfigBuilder ;
17
+ import de .flapdoodle .embed .mongo .config .Net ;
18
+ import de .flapdoodle .embed .mongo .distribution .Version ;
19
+ import de .flapdoodle .embed .process .runtime .Network ;
20
+
9
21
import static org .junit .Assert .assertTrue ;
10
22
import static org .junit .Assert .assertEquals ;
11
23
15
27
16
28
public class MongoDBHandlerTest {
17
29
18
- static MongoDBHandler mongoDBHandler = new MongoDBHandler ();
30
+ static Logger log = (Logger ) LoggerFactory .getLogger (MongoDBHandlerTest .class );
31
+
32
+ static MongodExecutable mongodExecutable = null ;
33
+ static MongoDBHandler mongoDBHandler = null ;
19
34
20
35
static String host = "localhost" ;
21
36
static int port = 27017 ;
@@ -26,9 +41,32 @@ public class MongoDBHandlerTest {
26
41
String updateInput = "{\" id\" :\" eventId\" ,\" type\" :\" eventType11\" ,\" test_cases\" : [{\" event_id\" : \" testcaseid1\" , \" test_data\" : \" testcase2data\" },{\" event_id\" : \" testcaseid3\" , \" test_data\" : \" testcase3data\" }]}" ;
27
42
static String condition = "{\" test_cases.event_id\" : \" testcaseid1\" }" ;
28
43
44
+ public static void setUpEmbeddedMongo () throws Exception {
45
+ System .setProperty ("mongodb.port" , "" +port );
46
+
47
+ MongodStarter starter = MongodStarter .getDefaultInstance ();
48
+
49
+ String bindIp = "localhost" ;
50
+
51
+ IMongodConfig mongodConfig = new MongodConfigBuilder ()
52
+ .version (Version .Main .PRODUCTION )
53
+ .net (new Net (bindIp , port , Network .localhostIsIPv6 ()))
54
+ .build ();
55
+
56
+
57
+ try {
58
+ mongodExecutable = starter .prepare (mongodConfig );
59
+ MongodProcess mongod = mongodExecutable .start ();
60
+ } catch (Exception e ) {
61
+ log .info (e .getMessage (),e );
62
+ }
63
+ }
64
+
29
65
@ BeforeClass
30
- public static void init ()
66
+ public static void init () throws Exception
31
67
{
68
+ setUpEmbeddedMongo ();
69
+ mongoDBHandler = new MongoDBHandler ();
32
70
mongoDBHandler .createConnection (host ,port );
33
71
assertTrue (mongoDBHandler .insertDocument (dataBaseName , collectionName , input ));
34
72
}
@@ -62,5 +100,7 @@ public void testUpdateDocument(){
62
100
public static void dropCollection ()
63
101
{
64
102
assertTrue (mongoDBHandler .dropDocument (dataBaseName , collectionName , condition ));
103
+ if (mongodExecutable != null )
104
+ mongodExecutable .stop ();
65
105
}
66
106
}
0 commit comments