Skip to content

Commit 21a1ac1

Browse files
author
Vasile Baluta
committed
update tests tear down
1 parent 50f1d46 commit 21a1ac1

File tree

8 files changed

+52
-28
lines changed

8 files changed

+52
-28
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
package com.ericsson.ei.controller;
33

4+
import com.ericsson.ei.controller.model.QueryResponse;
45
import org.springframework.http.ResponseEntity;
56
import org.springframework.web.bind.annotation.RequestMapping;
67
import org.springframework.web.bind.annotation.RequestMethod;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
package com.ericsson.ei.controller;
33

4+
import com.ericsson.ei.controller.model.QueryResponse;
45
import org.springframework.http.ResponseEntity;
56
import org.springframework.web.bind.annotation.RequestMapping;
67
import org.springframework.web.bind.annotation.RequestMethod;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package com.ericsson.ei.controller;
33

44
import javax.validation.Valid;
5+
import com.ericsson.ei.controller.model.RuleCheckBody;
56
import org.springframework.http.ResponseEntity;
67
import org.springframework.web.bind.annotation.RequestBody;
78
import org.springframework.web.bind.annotation.RequestMapping;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface SubscriptionController {
2626
*
2727
*/
2828
@RequestMapping(value = "", method = RequestMethod.GET)
29-
public ResponseEntity<List<String>> getSubscriptions();
29+
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptions();
3030

3131
/**
3232
* Takes the subscription rules, the name for subscription and the user name of the person registering this subscription and saves the subscription in subscription database. The name needs to be unique.
@@ -36,34 +36,34 @@ public interface SubscriptionController {
3636
public ResponseEntity<?> createSubscription(
3737
@Valid
3838
@RequestBody
39-
List<String> string);
39+
List<com.ericsson.ei.controller.model.Subscription> subscription);
4040

4141
/**
4242
* Modify an existing Subscription.
4343
*
4444
*/
4545
@RequestMapping(value = "", method = RequestMethod.PUT)
46-
public ResponseEntity<SubscriptionResponse> updateSubscriptions(
46+
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> updateSubscriptions(
4747
@Valid
4848
@RequestBody
49-
List<String> string);
49+
List<com.ericsson.ei.controller.model.Subscription> subscription);
5050

5151
/**
5252
* Returns the subscription rules for given subscription name.
5353
*
5454
*/
5555
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
56-
public ResponseEntity<List<String>> getSubscriptionById(
56+
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptionById(
5757
@PathVariable(required = false)
58-
java.lang.String subscriptionName);
58+
String subscriptionName);
5959

6060
/**
6161
* Removes the subscription from the database.
6262
*
6363
*/
6464
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.DELETE)
65-
public ResponseEntity<SubscriptionResponse> deleteSubscriptionById(
65+
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> deleteSubscriptionById(
6666
@PathVariable(required = false)
67-
java.lang.String subscriptionName);
67+
String subscriptionName);
6868

6969
}

src/test/java/com/ericsson/ei/flowtests/FlowTestConfigs.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public void tearDown() {
7979
// the connection is closed we just receive the
8080
// exception and go on
8181
}
82+
83+
if (testsFactory != null)
84+
testsFactory.shutdown();
85+
if (mongoClient != null)
86+
mongoClient.close();
8287
}
8388

8489
void createExchange(final String exchangeName, final String queueName) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public class ObjectHandlerTest {
7171
private static MongodForTestsFactory testsFactory;
7272
static MongoClient mongoClient = null;
7373

74-
7574
static MongoDBHandler mongoDBHandler = new MongoDBHandler();
7675

7776
static JmesPathInterface jmesPathInterface = new JmesPathInterface();
@@ -90,13 +89,12 @@ public class ObjectHandlerTest {
9089
static String event = "{\"meta\":{\"id\":\"eventId\"}}";
9190

9291
public static void setUpEmbeddedMongo() throws Exception {
93-
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
94-
mongoClient = testsFactory.newMongo();
92+
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
93+
mongoClient = testsFactory.newMongo();
9594
}
9695

9796
@BeforeClass
98-
public static void init() throws Exception
99-
{
97+
public static void init() throws Exception {
10098
setUpEmbeddedMongo();
10199
mongoDBHandler.setMongoClient(mongoClient);
102100
EventToObjectMapHandler eventToObjectMapHandler = mock(EventToObjectMapHandler.class);
@@ -106,7 +104,6 @@ public static void init() throws Exception
106104
objHandler.setCollectionName(collectionName);
107105
objHandler.setDatabaseName(dataBaseName);
108106
objHandler.setSubscriptionHandler(subscriptionHandler);
109-
110107

111108
try {
112109
String rulesString = FileUtils.readFileToString(new File(inputFilePath), "UTF-8");
@@ -128,8 +125,11 @@ public void test() {
128125
}
129126

130127
@AfterClass
131-
public static void dropCollection()
132-
{
128+
public static void dropCollection() {
133129
mongoDBHandler.dropDocument(dataBaseName, collectionName, condition);
130+
if (testsFactory != null)
131+
testsFactory.shutdown();
132+
if (mongoClient != null)
133+
mongoClient.close();
134134
}
135135
}

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.bson.Document;
2828
import org.bson.codecs.configuration.CodecRegistry;
2929
import org.bson.conversions.Bson;
30+
import org.junit.AfterClass;
3031
import org.junit.BeforeClass;
3132
import org.junit.Test;
3233
import org.junit.runner.RunWith;
@@ -68,7 +69,7 @@ public class QueryServiceTest {
6869

6970
@Autowired
7071
private ProcessAggregatedObject processAggregatedObject;
71-
72+
7273
@Autowired
7374
ObjectHandler objectHandler;
7475

@@ -111,15 +112,17 @@ public static void init() throws Exception {
111112
public void initMocks() {
112113
mongoDBHandler.setMongoClient(mongoClient);
113114
System.out.println("Database connected");
114-
//deleting all documents before inserting
115-
mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName).deleteMany(new BsonDocument());
115+
// deleting all documents before inserting
116+
mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName)
117+
.deleteMany(new BsonDocument());
116118
Document missedDocument = Document.parse(missedNotification);
117119
Document aggDocument = Document.parse(aggregatedObject);
118120
mongoClient.getDatabase(missedNotificationDataBaseName).getCollection(missedNotificationCollectionName)
119121
.insertOne(missedDocument);
120122
System.out.println("Document Inserted in missed Notification Database");
121-
122-
JsonNode preparedAggDocument = objectHandler.prepareDocumentForInsertion(aggDocument.getString("id"), aggregatedObject);
123+
124+
JsonNode preparedAggDocument = objectHandler.prepareDocumentForInsertion(aggDocument.getString("id"),
125+
aggregatedObject);
123126
aggDocument = Document.parse(preparedAggDocument.toString());
124127
mongoClient.getDatabase(aggregationDataBaseName).getCollection(aggregationCollectionName)
125128
.insertOne(aggDocument);
@@ -174,4 +177,12 @@ record = (ObjectNode) tempRecord;
174177
assertEquals(record.get("aggregatedObject").toString(), actual.toString());
175178
}
176179

180+
@AfterClass
181+
public static void tearDown() throws Exception {
182+
if (testsFactory != null)
183+
testsFactory.shutdown();
184+
if (mongoClient != null)
185+
mongoClient.close();
186+
}
187+
177188
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public static void init() throws Exception {
128128
@AfterClass
129129
public static void close() {
130130
testsFactory.shutdown();
131+
mongoClient.close();
131132
}
132133

133134
@PostConstruct
@@ -195,7 +196,8 @@ public void sendMailTest() {
195196

196197
@Test
197198
public void testRestPostTrigger() throws IOException {
198-
when(springRestTemplate.postDataMultiValue(url, mapNotificationMessage(), headerContentMediaType)).thenReturn(STATUS_OK);
199+
when(springRestTemplate.postDataMultiValue(url, mapNotificationMessage(), headerContentMediaType))
200+
.thenReturn(STATUS_OK);
199201
subscription.informSubscriber(aggregatedObject, new ObjectMapper().readTree(subscriptionData));
200202
verify(springRestTemplate, times(1)).postDataMultiValue(url, mapNotificationMessage(), headerContentMediaType);
201203
}
@@ -212,21 +214,24 @@ public void testQueryMissedNotificationEndPoint() throws Exception {
212214
String subscriptionName = new JSONObject(subscriptionData).getString("subscriptionName").replaceAll(REGEX, "");
213215
JSONObject input = new JSONObject(aggregatedObject);
214216
subscription.informSubscriber(aggregatedObject, new ObjectMapper().readTree(subscriptionData));
215-
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get(MISSED_NOTIFICATION_URL)
216-
.param("SubscriptionName", subscriptionName)).andReturn();
217+
MvcResult result = mockMvc
218+
.perform(
219+
MockMvcRequestBuilders.get(MISSED_NOTIFICATION_URL).param("SubscriptionName", subscriptionName))
220+
.andReturn();
217221
String response = result.getResponse().getContentAsString().replace("\\", "");
218222
assertEquals("{\"responseEntity\":\"[" + input.toString().replace("\\", "") + "]\"}", response);
219223
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
220224
}
221225

222226
private MultiValueMap<String, String> mapNotificationMessage() throws IOException {
223227
MultiValueMap<String, String> mapNotificationMessage = new LinkedMultiValueMap<>();
224-
ArrayNode arrNode = (ArrayNode) new ObjectMapper().readTree(subscriptionData).get("notificationMessageKeyValues");
228+
ArrayNode arrNode = (ArrayNode) new ObjectMapper().readTree(subscriptionData)
229+
.get("notificationMessageKeyValues");
225230
if (arrNode.isArray()) {
226231
for (final JsonNode objNode : arrNode) {
227-
mapNotificationMessage.add(objNode.get("formkey").toString().replaceAll(REGEX, ""),
228-
jmespath.runRuleOnEvent(objNode.get("formvalue").toString().replaceAll(REGEX, ""),
229-
aggregatedObject).toString().replaceAll(REGEX, ""));
232+
mapNotificationMessage.add(objNode.get("formkey").toString().replaceAll(REGEX, ""), jmespath
233+
.runRuleOnEvent(objNode.get("formvalue").toString().replaceAll(REGEX, ""), aggregatedObject)
234+
.toString().replaceAll(REGEX, ""));
230235
}
231236
}
232237
return mapNotificationMessage;

0 commit comments

Comments
 (0)