|
16 | 16 | */
|
17 | 17 | package com.ericsson.ei.handlers.test;
|
18 | 18 |
|
| 19 | +import static org.junit.Assert.assertEquals; |
19 | 20 | import static org.junit.Assert.assertTrue;
|
20 | 21 | 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; |
40 | 22 |
|
41 | 23 | import com.ericsson.ei.handlers.EventToObjectMapHandler;
|
42 | 24 | import com.ericsson.ei.handlers.ObjectHandler;
|
43 | 25 | import com.ericsson.ei.jmespath.JmesPathInterface;
|
44 |
| -import com.ericsson.ei.jsonmerge.MergeHandler; |
45 | 26 | import com.ericsson.ei.mongodbhandler.MongoDBHandler;
|
46 | 27 | 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; |
50 | 29 | import com.fasterxml.jackson.databind.JsonNode;
|
51 | 30 | import com.fasterxml.jackson.databind.ObjectMapper;
|
52 |
| -import com.fasterxml.jackson.databind.node.ObjectNode; |
53 | 31 | import com.mongodb.MongoClient;
|
54 | 32 |
|
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 | + |
61 | 42 | import de.flapdoodle.embed.mongo.distribution.Version;
|
62 | 43 | import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
|
63 |
| -import de.flapdoodle.embed.process.runtime.Network; |
64 | 44 |
|
65 | 45 | public class ObjectHandlerTest {
|
66 | 46 |
|
67 |
| - static Logger log = (Logger) LoggerFactory.getLogger(ObjectHandlerTest.class); |
| 47 | + final Logger log = (Logger) LoggerFactory.getLogger(ObjectHandlerTest.class); |
68 | 48 |
|
69 |
| - static ObjectHandler objHandler = new ObjectHandler(); |
| 49 | + private ObjectHandler objHandler = new ObjectHandler(); |
70 | 50 |
|
71 |
| - private static MongodForTestsFactory testsFactory; |
72 |
| - static MongoClient mongoClient = null; |
| 51 | + private MongodForTestsFactory testsFactory; |
| 52 | + private MongoClient mongoClient = null; |
73 | 53 |
|
74 |
| - static MongoDBHandler mongoDBHandler = new MongoDBHandler(); |
| 54 | + private MongoDBHandler mongoDBHandler = new MongoDBHandler(); |
75 | 55 |
|
76 |
| - static JmesPathInterface jmesPathInterface = new JmesPathInterface(); |
| 56 | + private JmesPathInterface jmesPathInterface = new JmesPathInterface(); |
77 | 57 |
|
78 |
| - static SubscriptionHandler subscriptionHandler = new SubscriptionHandler(); |
| 58 | + private SubscriptionHandler subscriptionHandler = new SubscriptionHandler(); |
79 | 59 |
|
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; |
83 | 63 |
|
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\"}}"; |
90 | 70 |
|
91 |
| - public static void setUpEmbeddedMongo() throws Exception { |
| 71 | + public void setUpEmbeddedMongo() throws Exception { |
92 | 72 | testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
|
93 | 73 | mongoClient = testsFactory.newMongo();
|
94 | 74 | }
|
95 | 75 |
|
96 |
| - @BeforeClass |
97 |
| - public static void init() throws Exception { |
| 76 | + @Before |
| 77 | + public void init() throws Exception { |
98 | 78 | setUpEmbeddedMongo();
|
99 | 79 | mongoDBHandler.setMongoClient(mongoClient);
|
100 | 80 | EventToObjectMapHandler eventToObjectMapHandler = mock(EventToObjectMapHandler.class);
|
@@ -124,8 +104,8 @@ public void test() {
|
124 | 104 | assertEquals(input, result.toString());
|
125 | 105 | }
|
126 | 106 |
|
127 |
| - @AfterClass |
128 |
| - public static void dropCollection() { |
| 107 | + @After |
| 108 | + public void dropCollection() { |
129 | 109 | mongoDBHandler.dropDocument(dataBaseName, collectionName, condition);
|
130 | 110 | if (testsFactory != null)
|
131 | 111 | testsFactory.shutdown();
|
|
0 commit comments