Skip to content

Commit 93c88b7

Browse files
Added removing queried missed notification (#102)
1 parent edc8337 commit 93c88b7

File tree

5 files changed

+78
-51
lines changed

5 files changed

+78
-51
lines changed

src/main/java/com/ericsson/ei/controller/QueryMissedNotificationControllerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public ResponseEntity<QueryResponse> getQueryMissedNotifications(@RequestParam("
5151
List<String> response = processMissedNotification.processQueryMissedNotification(subscriptionName);
5252
queryResponse.setResponseEntity(response.toString());
5353
LOGGER.debug("The response is : " + response.toString());
54+
if(processMissedNotification.deleteMissedNotification(subscriptionName)) {
55+
LOGGER.debug("Missed notification with subscription name " + subscriptionName + " was successfully removed from database");
56+
}
5457
return new ResponseEntity<>(queryResponse, HttpStatus.OK);
5558
}
5659

src/main/java/com/ericsson/ei/queryservice/ProcessMissedNotification.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ProcessMissedNotification {
4949
* subscriptionName from the Missed Notification Object.
5050
*
5151
* @param subscriptionName
52-
* @return ArrayList
52+
* @return List
5353
*/
5454
public List<String> processQueryMissedNotification(String subscriptionName) {
5555
ObjectMapper mapper = new ObjectMapper();
@@ -75,6 +75,18 @@ public List<String> processQueryMissedNotification(String subscriptionName) {
7575

7676
}
7777

78+
/**
79+
* The method is responsible for the delete the missed notification using subscription name
80+
*
81+
* @param subscriptionName
82+
* @return boolean
83+
*/
84+
public boolean deleteMissedNotification(String subscriptionName) {
85+
String condition = "{\"subscriptionName\" : \"" + subscriptionName + "\"}";
86+
LOGGER.debug("The JSON condition for delete missed notification is : " + condition);
87+
return handler.dropDocument(missedNotificationDatabaseName, missedNotificationCollectionName, condition);
88+
}
89+
7890
@PostConstruct
7991
public void init() {
8092
LOGGER.debug("MissedNotification Database is : " + missedNotificationDatabaseName

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
@SpringBootTest(classes = App.class)
5454
public class QueryServiceTest {
5555

56+
private static final Logger LOG = (Logger) LoggerFactory.getLogger(QueryServiceTest.class);
57+
5658
@Value("${aggregated.collection.name}")
5759
private String aggregationCollectionName;
5860

@@ -69,13 +71,11 @@ public class QueryServiceTest {
6971
private ProcessAggregatedObject processAggregatedObject;
7072

7173
@Autowired
72-
ObjectHandler objectHandler;
74+
private ObjectHandler objectHandler;
7375

7476
@Autowired
7577
private ProcessMissedNotification processMissedNotification;
7678

77-
static Logger log = (Logger) LoggerFactory.getLogger(QueryServiceTest.class);
78-
7979
private static String aggregatedPath = "src/test/resources/AggregatedObject.json";
8080
private static String missedNotificationPath = "src/test/resources/MissedNotification.json";
8181
private static String aggregatedObject;
@@ -95,11 +95,11 @@ public static void setUpEmbeddedMongo() throws Exception {
9595
System.setProperty("spring.data.mongodb.port", port);
9696

9797
aggregatedObject = FileUtils.readFileToString(new File(aggregatedPath));
98-
log.debug("The aggregatedObject is : " + aggregatedObject);
98+
LOG.debug("The aggregatedObject is : " + aggregatedObject);
9999
missedNotification = FileUtils.readFileToString(new File(missedNotificationPath));
100-
log.debug("The missedNotification is : " + missedNotification);
100+
LOG.debug("The missedNotification is : " + missedNotification);
101101
} catch (Exception e) {
102-
log.error(e.getMessage(), e);
102+
LOG.error(e.getMessage(), e);
103103
e.printStackTrace();
104104
}
105105
}
@@ -112,22 +112,22 @@ public static void init() throws Exception {
112112
@PostConstruct
113113
public void initMocks() {
114114
mongoDBHandler.setMongoClient(mongoClient);
115-
log.debug("Database connected");
115+
LOG.debug("Database connected");
116116
// deleting all documents before inserting
117117
mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName)
118118
.deleteMany(new BsonDocument());
119119
Document missedDocument = Document.parse(missedNotification);
120120
Document aggDocument = Document.parse(aggregatedObject);
121121
mongoClient.getDatabase(missedNotificationDataBaseName).getCollection(missedNotificationCollectionName)
122122
.insertOne(missedDocument);
123-
log.debug("Document Inserted in missed Notification Database");
123+
LOG.debug("Document Inserted in missed Notification Database");
124124

125125
JsonNode preparedAggDocument = objectHandler.prepareDocumentForInsertion(aggDocument.getString("id"),
126126
aggregatedObject);
127127
aggDocument = Document.parse(preparedAggDocument.toString());
128128
mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName)
129129
.insertOne(aggDocument);
130-
log.debug("Document Inserted in Aggregated Object Database");
130+
LOG.debug("Document Inserted in Aggregated Object Database");
131131
}
132132

133133
@Test
@@ -136,9 +136,9 @@ public void processMissedNotificationTest() {
136136
.getCollection(missedNotificationCollectionName).find();
137137
Iterator itr = responseDB.iterator();
138138
String response = itr.next().toString();
139-
log.debug("The inserted doc is : " + response);
139+
LOG.debug("The inserted doc is : " + response);
140140
List<String> result = processMissedNotification.processQueryMissedNotification("Subscription_1");
141-
log.debug("The retrieved data is : " + result.toString());
141+
LOG.debug("The retrieved data is : " + result.toString());
142142
ObjectNode record = null;
143143
JsonNode actual = null;
144144

@@ -149,19 +149,33 @@ record = (ObjectNode) tempRecord;
149149
actual = new ObjectMapper().readTree(missedNotification).path("AggregatedObject");
150150

151151
} catch (Exception e) {
152-
log.error(e.getMessage(), e);
152+
LOG.error(e.getMessage(), e);
153153
}
154-
log.debug("The result is : " + record.toString());
154+
LOG.debug("The result is : " + record.toString());
155155
assertEquals(record.toString(), actual.toString());
156156
}
157157

158+
@Test
159+
public void deleteMissedNotificationTest() {
160+
Iterable<Document> responseDB = mongoClient.getDatabase(missedNotificationDataBaseName)
161+
.getCollection(missedNotificationCollectionName).find();
162+
Iterator itr = responseDB.iterator();
163+
String response = itr.next().toString();
164+
LOG.debug("The inserted doc is : " + response);
165+
boolean removed = processMissedNotification.deleteMissedNotification("Subscription_1");
166+
assertEquals(true, removed);
167+
Iterable<Document> responseDBAfter = mongoClient.getDatabase(missedNotificationDataBaseName)
168+
.getCollection(missedNotificationCollectionName).find();
169+
assertEquals(false, responseDBAfter.iterator().hasNext());
170+
}
171+
158172
@Test
159173
public void processAggregatedObjectTest() {
160174
Iterable<Document> responseDB = mongoClient.getDatabase(aggregationDataBaseName)
161175
.getCollection(aggregationCollectionName).find();
162176
Iterator itr = responseDB.iterator();
163177
String response = itr.next().toString();
164-
log.debug("The inserted doc is : " + response);
178+
LOG.debug("The inserted doc is : " + response);
165179
ArrayList<String> result = processAggregatedObject
166180
.processQueryAggregatedObject("6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43");
167181
ObjectNode record = null;
@@ -174,9 +188,9 @@ record = (ObjectNode) tempRecord;
174188
actual = new ObjectMapper().readTree(aggregatedObject);
175189

176190
} catch (Exception e) {
177-
log.error(e.getMessage(), e);
191+
LOG.error(e.getMessage(), e);
178192
}
179-
log.debug("The result is : " + record.toString());
193+
LOG.debug("The result is : " + record.toString());
180194
assertEquals(record.get("aggregatedObject").toString(), actual.toString());
181195
}
182196

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
{
2-
"subscriptionName" : "Subscription_1",
3-
"AggregatedObject" : {
4-
"fileInformation":[
5-
{
6-
"extension":"jar",
7-
"classifier":""
8-
}
9-
],
10-
"buildCommand":null,
11-
"testCaseExecutions":[
12-
{
13-
"testCaseFinishEventId":"11109351-41e0-474a-bc1c-f6e81e58a1c9",
14-
"testCaseStartedTime":1481875925916,
15-
"testCaseStartedEventId":"cb9d64b0-a6e9-4419-8b5d-a650c27c59ca",
16-
"testCaseFinishedTime":1481875935919,
17-
"testCase":
18-
{
19-
"conclusion":"SUCCESSFUL",
20-
"verdict":"PASSED",
21-
"tracker":"My Other Test Management System",
22-
"id":"TC5",
23-
"uri":"https://other-tm.company.com/testCase/TC5"
2+
"subscriptionName": "Subscription_1",
3+
"AggregatedObject": {
4+
"fileInformation": [
5+
{
6+
"extension": "jar",
7+
"classifier": ""
8+
}
9+
],
10+
"buildCommand": null,
11+
"testCaseExecutions": [
12+
{
13+
"testCaseFinishEventId": "11109351-41e0-474a-bc1c-f6e81e58a1c9",
14+
"testCaseStartedTime": 1481875925916,
15+
"testCaseStartedEventId": "cb9d64b0-a6e9-4419-8b5d-a650c27c59ca",
16+
"testCaseFinishedTime": 1481875935919,
17+
"testCase": {
18+
"conclusion": "SUCCESSFUL",
19+
"verdict": "PASSED",
20+
"tracker": "My Other Test Management System",
21+
"id": "TC5",
22+
"uri": "https://other-tm.company.com/testCase/TC5"
23+
}
24+
}
25+
],
26+
"id": "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43",
27+
"time": 1481875891763,
28+
"type": "ARTIFACT_1",
29+
"gav": {
30+
"groupId": "com.mycompany.myproduct",
31+
"artifactId": "sub-system",
32+
"version": "1.1.0"
2433
}
2534
}
26-
],
27-
"id":"6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43",
28-
"time":1481875891763,
29-
"type":"ARTIFACT_1",
30-
"gav":
31-
{
32-
"groupId":"com.mycompany.myproduct",
33-
"artifactId":"sub-system",
34-
"version":"1.1.0"
35-
}
36-
}
3735
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["{"subscriptionName" : "Subscription_1","AggregatedObject" : {"fileInformation":[{"extension":"jar","classifier":""}],"buildCommand":null,"testCaseExecutions":[{"testCaseFinishEventId":"11109351-41e0-474a-bc1c-f6e81e58a1c9","testCaseStartedTime":1481875925916,"testCaseStartedEventId":"cb9d64b0-a6e9-4419-8b5d-a650c27c59ca","testCaseFinishedTime":1481875935919,"testCase":{"conclusion":"SUCCESSFUL","verdict":"PASSED","tracker":"My Other Test Management System","id":"TC5","uri":"https://other-tm.company.com/testCase/TC5"}}],"id":"6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43","time":1481875891763,"type":"ARTIFACT_1","gav":{"groupId":"com.mycompany.myproduct","artifactId":"sub-system","version":"1.1.0"}}}"]
1+
["{"subscriptionName": "Subscription_1","AggregatedObject": {"fileInformation": [{"extension": "jar","classifier": ""}],"buildCommand": null,"testCaseExecutions": [{"testCaseFinishEventId": "11109351-41e0-474a-bc1c-f6e81e58a1c9","testCaseStartedTime": 1481875925916,"testCaseStartedEventId": "cb9d64b0-a6e9-4419-8b5d-a650c27c59ca","testCaseFinishedTime": 1481875935919,"testCase": {"conclusion": "SUCCESSFUL","verdict": "PASSED","tracker": "My Other Test Management System","id": "TC5","uri": "https://other-tm.company.com/testCase/TC5"}}],"id": "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43","time": 1481875891763,"type": "ARTIFACT_1","gav": {"groupId": "com.mycompany.myproduct","artifactId": "sub-system","version": "1.1.0"}}}"]

0 commit comments

Comments
 (0)