Skip to content

Commit 57562f7

Browse files
author
Vasile Baluta
committed
more test fixes
1 parent 21a1ac1 commit 57562f7

File tree

6 files changed

+77
-91
lines changed

6 files changed

+77
-91
lines changed

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

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,85 +16,65 @@
1616
*/
1717
package com.ericsson.ei.handlers.test;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertTrue;
2021
import static org.mockito.Mockito.mock;
21-
import static org.junit.Assert.assertEquals;
22-
23-
import java.io.File;
24-
import java.io.IOException;
25-
26-
import javax.annotation.PostConstruct;
27-
28-
import com.ericsson.ei.subscriptionhandler.SubscriptionHandler;
29-
import org.apache.commons.io.FileUtils;
30-
import org.junit.AfterClass;
31-
import org.junit.Before;
32-
import org.junit.BeforeClass;
33-
import org.junit.Test;
34-
import org.mockito.InjectMocks;
35-
import org.mockito.Mock;
36-
import org.mockito.MockitoAnnotations;
37-
import org.slf4j.Logger;
38-
import org.slf4j.LoggerFactory;
39-
import org.springframework.beans.factory.annotation.Autowired;
4022

4123
import com.ericsson.ei.handlers.EventToObjectMapHandler;
4224
import com.ericsson.ei.handlers.ObjectHandler;
4325
import com.ericsson.ei.jmespath.JmesPathInterface;
44-
import com.ericsson.ei.jsonmerge.MergeHandler;
4526
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
4627
import com.ericsson.ei.rules.RulesObject;
47-
import com.ericsson.ei.rules.test.TestRulesObject;
48-
import com.fasterxml.jackson.core.JsonParseException;
49-
import com.fasterxml.jackson.databind.JsonMappingException;
28+
import com.ericsson.ei.subscriptionhandler.SubscriptionHandler;
5029
import com.fasterxml.jackson.databind.JsonNode;
5130
import com.fasterxml.jackson.databind.ObjectMapper;
52-
import com.fasterxml.jackson.databind.node.ObjectNode;
5331
import com.mongodb.MongoClient;
5432

55-
import de.flapdoodle.embed.mongo.MongodExecutable;
56-
import de.flapdoodle.embed.mongo.MongodProcess;
57-
import de.flapdoodle.embed.mongo.MongodStarter;
58-
import de.flapdoodle.embed.mongo.config.IMongodConfig;
59-
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
60-
import de.flapdoodle.embed.mongo.config.Net;
33+
import java.io.File;
34+
35+
import org.apache.commons.io.FileUtils;
36+
import org.junit.After;
37+
import org.junit.Before;
38+
import org.junit.Test;
39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
41+
6142
import de.flapdoodle.embed.mongo.distribution.Version;
6243
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
63-
import de.flapdoodle.embed.process.runtime.Network;
6444

6545
public class ObjectHandlerTest {
6646

67-
static Logger log = (Logger) LoggerFactory.getLogger(ObjectHandlerTest.class);
47+
final Logger log = (Logger) LoggerFactory.getLogger(ObjectHandlerTest.class);
6848

69-
static ObjectHandler objHandler = new ObjectHandler();
49+
private ObjectHandler objHandler = new ObjectHandler();
7050

71-
private static MongodForTestsFactory testsFactory;
72-
static MongoClient mongoClient = null;
51+
private MongodForTestsFactory testsFactory;
52+
private MongoClient mongoClient = null;
7353

74-
static MongoDBHandler mongoDBHandler = new MongoDBHandler();
54+
private MongoDBHandler mongoDBHandler = new MongoDBHandler();
7555

76-
static JmesPathInterface jmesPathInterface = new JmesPathInterface();
56+
private JmesPathInterface jmesPathInterface = new JmesPathInterface();
7757

78-
static SubscriptionHandler subscriptionHandler = new SubscriptionHandler();
58+
private SubscriptionHandler subscriptionHandler = new SubscriptionHandler();
7959

80-
static private RulesObject rulesObject;
81-
static private final String inputFilePath = "src/test/resources/RulesHandlerOutput2.json";
82-
static private JsonNode rulesJson;
60+
private RulesObject rulesObject;
61+
private final String inputFilePath = "src/test/resources/RulesHandlerOutput2.json";
62+
private JsonNode rulesJson;
8363

84-
static String dataBaseName = "EventStorageDBbbb";
85-
static String collectionName = "SampleEvents";
86-
static String input = "{\"TemplateName\":\"ARTIFACT_1\",\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\":[{\"event_id\":\"testcaseid1\",\"test_data\":\"testcase1data\"},{\"event_id\":\"testcaseid2\",\"test_data\":\"testcase2data\"}]}";
87-
String updateInput = "{\"TemplateName\":\"ARTIFACT_1\",\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase2data\"},{\"event_id\" : \"testcaseid3\", \"test_data\" : \"testcase3data\"}]}";
88-
static String condition = "{\"_id\" : \"eventId\"}";
89-
static String event = "{\"meta\":{\"id\":\"eventId\"}}";
64+
private String dataBaseName = "EventStorageDBbbb";
65+
private String collectionName = "SampleEvents";
66+
private String input = "{\"TemplateName\":\"ARTIFACT_1\",\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\":[{\"event_id\":\"testcaseid1\",\"test_data\":\"testcase1data\"},{\"event_id\":\"testcaseid2\",\"test_data\":\"testcase2data\"}]}";
67+
private String updateInput = "{\"TemplateName\":\"ARTIFACT_1\",\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase2data\"},{\"event_id\" : \"testcaseid3\", \"test_data\" : \"testcase3data\"}]}";
68+
private String condition = "{\"_id\" : \"eventId\"}";
69+
private String event = "{\"meta\":{\"id\":\"eventId\"}}";
9070

91-
public static void setUpEmbeddedMongo() throws Exception {
71+
public void setUpEmbeddedMongo() throws Exception {
9272
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
9373
mongoClient = testsFactory.newMongo();
9474
}
9575

96-
@BeforeClass
97-
public static void init() throws Exception {
76+
@Before
77+
public void init() throws Exception {
9878
setUpEmbeddedMongo();
9979
mongoDBHandler.setMongoClient(mongoClient);
10080
EventToObjectMapHandler eventToObjectMapHandler = mock(EventToObjectMapHandler.class);
@@ -124,8 +104,8 @@ public void test() {
124104
assertEquals(input, result.toString());
125105
}
126106

127-
@AfterClass
128-
public static void dropCollection() {
107+
@After
108+
public void dropCollection() {
129109
mongoDBHandler.dropDocument(dataBaseName, collectionName, condition);
130110
if (testsFactory != null)
131111
testsFactory.shutdown();

src/test/java/com/ericsson/ei/mongoDBHandler/test/MongoDBHandlerTest.java

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,82 +16,79 @@
1616
*/
1717
package com.ericsson.ei.mongoDBHandler.test;
1818

19-
import org.junit.BeforeClass;
20-
import org.junit.Test;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
23-
import org.springframework.beans.factory.annotation.Autowired;
19+
import static org.junit.Assert.assertTrue;
2420

2521
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
2622
import com.mongodb.MongoClient;
2723

28-
import de.flapdoodle.embed.mongo.distribution.Version;
29-
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
30-
31-
import static org.junit.Assert.assertTrue;
32-
3324
import java.util.ArrayList;
3425

35-
import org.junit.AfterClass;
26+
import org.junit.After;
27+
import org.junit.Before;
28+
import org.junit.Test;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
import de.flapdoodle.embed.mongo.distribution.Version;
33+
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
3634

3735
public class MongoDBHandlerTest {
3836

39-
static Logger log = (Logger) LoggerFactory.getLogger(MongoDBHandlerTest.class);
37+
final Logger log = (Logger) LoggerFactory.getLogger(MongoDBHandlerTest.class);
4038

41-
@Autowired
42-
static MongoDBHandler mongoDBHandler;
39+
private MongoDBHandler mongoDBHandler;
4340

44-
private static MongodForTestsFactory testsFactory;
45-
static MongoClient mongoClient = null;
41+
private MongodForTestsFactory testsFactory;
42+
private MongoClient mongoClient = null;
4643

47-
static String dataBaseName = "EventStorageDBbbb";
48-
static String collectionName = "SampleEvents";
49-
static String input = "{\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase1data\"},{\"event_id\" : \"testcaseid2\", \"test_data\" : \"testcase2data\"}]}";
50-
String updateInput = "{\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase2data\"},{\"event_id\" : \"testcaseid3\", \"test_data\" : \"testcase3data\"}]}";
51-
static String condition = "{\"test_cases.event_id\" : \"testcaseid1\"}";
44+
private String dataBaseName = "EventStorageDBbbb";
45+
private String collectionName = "SampleEvents";
46+
private String input = "{\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase1data\"},{\"event_id\" : \"testcaseid2\", \"test_data\" : \"testcase2data\"}]}";
47+
private String updateInput = "{\"id\":\"eventId\",\"type\":\"eventType11\",\"test_cases\" : [{\"event_id\" : \"testcaseid1\", \"test_data\" : \"testcase2data\"},{\"event_id\" : \"testcaseid3\", \"test_data\" : \"testcase3data\"}]}";
48+
private String condition = "{\"test_cases.event_id\" : \"testcaseid1\"}";
5249

53-
public static void setUpEmbeddedMongo() throws Exception {
50+
public void setUpEmbeddedMongo() throws Exception {
5451
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
5552
mongoClient = testsFactory.newMongo();
5653
}
5754

58-
@BeforeClass
59-
public static void init() throws Exception
60-
{
55+
@Before
56+
public void init() throws Exception {
6157
setUpEmbeddedMongo();
6258
mongoDBHandler = new MongoDBHandler();
6359
mongoDBHandler.setMongoClient(mongoClient);
6460
assertTrue(mongoDBHandler.insertDocument(dataBaseName, collectionName, input));
6561
}
6662

6763
@Test
68-
public void testGetDocuments(){
64+
public void testGetDocuments() {
6965
ArrayList<String> documents = mongoDBHandler.getAllDocuments(dataBaseName, collectionName);
7066
assertTrue(documents.size() > 0);
7167
}
7268

7369
@Test
74-
public void testGetDocumentsOnCondition(){
70+
public void testGetDocumentsOnCondition() {
7571
ArrayList<String> documents = mongoDBHandler.find(dataBaseName, collectionName, condition);
7672
assertTrue(documents.size() > 0);
7773
}
7874

79-
// @Test
80-
// TODO fix this test case
81-
// public void testGetDocumentOnCondition(){
82-
// ArrayList<String> documents = mongoDBHandler.getDocumentsOnCondition(dataBaseName, collectionName, condition);
83-
// String document = documents.get(0);
84-
// assertEquals(document, input);
85-
// }
75+
// @Test
76+
// TODO fix this test case
77+
// public void testGetDocumentOnCondition(){
78+
// ArrayList<String> documents =
79+
// mongoDBHandler.getDocumentsOnCondition(dataBaseName, collectionName,
80+
// condition);
81+
// String document = documents.get(0);
82+
// assertEquals(document, input);
83+
// }
8684

8785
@Test
88-
public void testUpdateDocument(){
86+
public void testUpdateDocument() {
8987
assertTrue(mongoDBHandler.updateDocument(dataBaseName, collectionName, input, updateInput));
9088
}
9189

92-
@AfterClass
93-
public static void dropCollection()
94-
{
90+
@After
91+
public void dropCollection() {
9592
assertTrue(mongoDBHandler.dropDocument(dataBaseName, collectionName, condition));
9693
testsFactory.shutdown();
9794
mongoClient.close();

src/test/java/com/ericsson/ei/queryservice/test/QueryServiceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public class QueryServiceTest {
9292
public static void setUpEmbeddedMongo() throws Exception {
9393
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
9494
mongoClient = testsFactory.newMongo();
95+
String port = "" + mongoClient.getAddress().getPort();
96+
System.setProperty("mongodb.port", port);
9597

9698
try {
9799
aggregatedObject = FileUtils.readFileToString(new File(aggregatedPath));

src/test/java/com/ericsson/ei/rules/test/TestRulesService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class TestRulesService {
4545
public static void setMongoDB() throws IOException, JSONException {
4646
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
4747
mongoClient = testsFactory.newMongo();
48+
String port = "" + mongoClient.getAddress().getPort();
49+
System.setProperty("mongodb.port", port);
4850
}
4951

5052
@PostConstruct
@@ -69,7 +71,8 @@ public void prepareAggregatedObject() {
6971
extractionRules_test = FileUtils.readFileToString(new File(RULES), "UTF-8");
7072
aggregatedResult = FileUtils.readFileToString(new File(AGGREGATED_RESULT_OBJECT), "UTF-8");
7173
expectedAggObject = new JSONArray(aggregatedResult);
72-
String result = ruleCheckService.prepareAggregatedObject(new JSONArray(extractionRules_test), new JSONArray(jsonInput));
74+
String result = ruleCheckService.prepareAggregatedObject(new JSONArray(extractionRules_test),
75+
new JSONArray(jsonInput));
7376
JSONArray actualAggObject = new JSONArray(result);
7477
assertEquals(expectedAggObject.toString(), actualAggObject.toString());
7578
} catch (Exception e) {

src/test/java/com/ericsson/ei/subscription/SubscriptionServiceTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public static void setMongoDB() throws IOException, JSONException {
7474
String readFileToString = FileUtils.readFileToString(new File(subscriptionJsonPath), "UTF-8");
7575
jsonArray = new JSONArray(readFileToString);
7676
mongoClient = testsFactory.newMongo();
77+
String port = "" + mongoClient.getAddress().getPort();
78+
System.setProperty("mongodb.port", port);
7779

7880
ArrayList<String> list = new ArrayList<String>();
7981
for (int i = 0; i < jsonArray.length(); i++) {

src/test/java/com/ericsson/ei/subscriptionhandler/test/SubscriptionHandlerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public class SubscriptionHandlerTest {
113113
public static void setUpEmbeddedMongo() throws JSONException, IOException {
114114
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
115115
mongoClient = testsFactory.newMongo();
116+
String port = "" + mongoClient.getAddress().getPort();
117+
System.setProperty("mongodb.port", port);
116118
aggregatedObject = FileUtils.readFileToString(new File(aggregatedPath), "UTF-8");
117119
subscriptionData = FileUtils.readFileToString(new File(subscriptionPath), "UTF-8");
118120
url = new JSONObject(subscriptionData).getString("notificationMeta").replaceAll(REGEX, "");

0 commit comments

Comments
 (0)