|
22 | 22 | import javax.annotation.PostConstruct;
|
23 | 23 |
|
24 | 24 | import org.apache.commons.io.FileUtils;
|
| 25 | +import org.bson.BsonDocument; |
25 | 26 | import org.bson.Document;
|
| 27 | +import org.bson.codecs.configuration.CodecRegistry; |
| 28 | +import org.bson.conversions.Bson; |
26 | 29 | import org.junit.BeforeClass;
|
27 | 30 | import org.junit.Test;
|
28 | 31 | import org.junit.runner.RunWith;
|
|
34 | 37 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
35 | 38 |
|
36 | 39 | import com.ericsson.ei.App;
|
| 40 | +import com.ericsson.ei.handlers.ObjectHandler; |
37 | 41 | import com.ericsson.ei.mongodbhandler.MongoDBHandler;
|
38 | 42 | import com.ericsson.ei.queryservice.ProcessAggregatedObject;
|
39 | 43 | import com.ericsson.ei.queryservice.ProcessMissedNotification;
|
@@ -63,6 +67,9 @@ public class QueryServiceTest {
|
63 | 67 |
|
64 | 68 | @Autowired
|
65 | 69 | private ProcessAggregatedObject processAggregatedObject;
|
| 70 | + |
| 71 | + @Autowired |
| 72 | + ObjectHandler objectHandler; |
66 | 73 |
|
67 | 74 | @Autowired
|
68 | 75 | private ProcessMissedNotification processMissedNotification;
|
@@ -103,11 +110,16 @@ public static void init() throws Exception {
|
103 | 110 | public void initMocks() {
|
104 | 111 | mongoDBHandler.setMongoClient(mongoClient);
|
105 | 112 | System.out.println("Database connected");
|
| 113 | + //deleting all documents before inserting |
| 114 | + mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName).deleteMany(new BsonDocument()); |
106 | 115 | Document missedDocument = Document.parse(missedNotification);
|
107 | 116 | Document aggDocument = Document.parse(aggregatedObject);
|
108 | 117 | mongoClient.getDatabase(missedNotificationDataBaseName).getCollection(missedNotificationCollectionName)
|
109 | 118 | .insertOne(missedDocument);
|
110 | 119 | System.out.println("Document Inserted in missed Notification Database");
|
| 120 | + |
| 121 | + JsonNode preparedAggDocument = objectHandler.prepareDocumentForInsertion(aggDocument.getString("id"), aggregatedObject); |
| 122 | + aggDocument = Document.parse(preparedAggDocument.toString()); |
111 | 123 | mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName)
|
112 | 124 | .insertOne(aggDocument);
|
113 | 125 | System.out.println("Document Inserted in Aggregated Object Database");
|
@@ -158,7 +170,7 @@ record = (ObjectNode) tempRecord;
|
158 | 170 | log.error(e.getMessage(), e);
|
159 | 171 | }
|
160 | 172 | log.info("The result is : " + record.toString());
|
161 |
| - assertEquals(record.toString(), actual.toString()); |
| 173 | + assertEquals(record.get("aggregatedObject").toString(), actual.toString()); |
162 | 174 | }
|
163 | 175 |
|
164 | 176 | }
|
0 commit comments