diff --git a/pom.xml b/pom.xml
index e80498c70..f59fa6aa7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.0.8.RELEASE
+ 2.5.5
@@ -25,12 +25,12 @@
false
${skipTests}
${skipTests}
- ${project.parent.version}
- 2.3.2.RELEASE
- 5.0.6.RELEASE
- 2.0.2.RELEASE
+ 2.5.5
+ 2.3.4.RELEASE
+ 5.5.2
+ 2.5.0
1
- 2.12.1
+ 2.12.5
@@ -111,7 +111,7 @@
com.github.ulisesbocchio
jasypt-spring-boot-starter
- 2.1.2
+ 3.0.4
@@ -136,6 +136,10 @@
com.vaadin.external.google
android-json
+
+ org.junit.jupiter
+ junit-jupiter
+
@@ -145,6 +149,23 @@
${springBootVersion}
compile
+
+
+ org.mongodb
+ mongodb-driver-sync
+ 4.3.2
+
+
+
+ org.mongodb
+ mongodb-driver-core
+ 4.3.2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
org.springframework.boot
@@ -204,7 +225,7 @@
junit
junit
- 4.13.1
+ 4.13.2
test
@@ -212,7 +233,7 @@
org.mockito
mockito-core
- 2.9.0
+ 3.9.0
test
@@ -246,13 +267,13 @@
org.apache.commons
commons-lang3
- 3.7
+ 3.12.0
org.apache.httpcomponents
httpcore
- 4.4.9
+ 4.4.14
@@ -285,7 +306,7 @@
org.projectlombok
lombok
- 1.18.6
+ 1.18.20
provided
@@ -335,7 +356,7 @@
de.flapdoodle.embed
de.flapdoodle.embed.mongo
- 2.0.0
+ 3.0.0
test
@@ -524,7 +545,7 @@
${skipUTs}
${forkCountTests}
true
- classes
+ methods
5
${someModule.test.includes}
diff --git a/src/functionaltests/java/com/ericsson/ei/rabbitmq/configuration/RabbitMQConfigurationTestSteps.java b/src/functionaltests/java/com/ericsson/ei/rabbitmq/configuration/RabbitMQConfigurationTestSteps.java
index 9ae88f7d6..a1762b947 100644
--- a/src/functionaltests/java/com/ericsson/ei/rabbitmq/configuration/RabbitMQConfigurationTestSteps.java
+++ b/src/functionaltests/java/com/ericsson/ei/rabbitmq/configuration/RabbitMQConfigurationTestSteps.java
@@ -74,7 +74,7 @@ public void connect_to_message_bus() throws Exception {
RabbitTemplate rabbitTemplate = rabbitAdmin.getRabbitTemplate();
rmqHandler.setRabbitTemplate(rabbitTemplate);
- rmqHandler.getContainer().setRabbitAdmin(rabbitAdmin);
+ rmqHandler.getContainer().setAmqpAdmin(rabbitAdmin);
rmqHandler.getContainer().setConnectionFactory(rmqHandler.getCachingConnectionFactory());
rmqHandler.getContainer().setQueueNames(rmqHandler.getRmqProperties().getQueueName());
assertEquals("Expected message bus to be up", true, amqpBroker.isRunning);
@@ -131,7 +131,7 @@ private RabbitAdmin createExchange(final RMQHandler rmqHandler) {
admin.getQueueProperties(queueName);
RabbitTemplate rabbitTemplate = admin.getRabbitTemplate();
rabbitTemplate.setExchange(exchangeName);
- rabbitTemplate.setQueue(queueName);
+ rabbitTemplate.setDefaultReceiveQueue(queueName);
rabbitTemplate.setRoutingKey(ROUTING_KEY_1);
return admin;
}
diff --git a/src/functionaltests/java/com/ericsson/ei/rabbitmq/connection/RabbitMQTestConnectionSteps.java b/src/functionaltests/java/com/ericsson/ei/rabbitmq/connection/RabbitMQTestConnectionSteps.java
index 755f880ce..c9ea9e45b 100644
--- a/src/functionaltests/java/com/ericsson/ei/rabbitmq/connection/RabbitMQTestConnectionSteps.java
+++ b/src/functionaltests/java/com/ericsson/ei/rabbitmq/connection/RabbitMQTestConnectionSteps.java
@@ -21,7 +21,7 @@
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
-import org.springframework.amqp.rabbit.support.CorrelationData;
+import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
@@ -98,7 +98,7 @@ public void connect_to_message_bus() throws Exception {
RabbitTemplate rabbitTemplate = rabbitAdmin.getRabbitTemplate();
rmqHandler.setRabbitTemplate(rabbitTemplate);
- rmqHandler.getContainer().setRabbitAdmin(rabbitAdmin);
+ rmqHandler.getContainer().setAmqpAdmin(rabbitAdmin);
rmqHandler.getContainer().setConnectionFactory(rmqHandler.getCachingConnectionFactory());
rmqHandler.getContainer().setQueueNames(rmqProperties.getQueueName());
assertEquals("Expected message bus to be up", true, amqpBroker.isRunning);
@@ -172,7 +172,7 @@ private RabbitAdmin createExchange(final RMQHandler rmqHandler) {
RabbitTemplate rabbitTemplate = admin.getRabbitTemplate();
rabbitTemplate.setExchange(exchangeName);
rabbitTemplate.setRoutingKey(DEFAULT_ROUTING_KEY);
- rabbitTemplate.setQueue(queueName);
+ rabbitTemplate.setDefaultReceiveQueue(queueName);
return admin;
}
diff --git a/src/functionaltests/java/com/ericsson/ei/utils/DataBaseManager.java b/src/functionaltests/java/com/ericsson/ei/utils/DataBaseManager.java
index 62f17a008..27835b516 100644
--- a/src/functionaltests/java/com/ericsson/ei/utils/DataBaseManager.java
+++ b/src/functionaltests/java/com/ericsson/ei/utils/DataBaseManager.java
@@ -11,8 +11,8 @@
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.stereotype.Component;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientURI;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
@@ -195,8 +195,7 @@ private List getDocumentsFromCollection(String collectionName) {
}
private MongoCollection getCollection(String collectionName) {
- MongoClientURI uri = new MongoClientURI(mongoProperties.getUri());
- mongoClient = new MongoClient(uri);
+ mongoClient = MongoClients.create(mongoProperties.getUri());
MongoDatabase db = mongoClient.getDatabase(database);
MongoCollection collection = db.getCollection(collectionName);
return collection;
diff --git a/src/functionaltests/java/com/ericsson/ei/utils/TestConfigs.java b/src/functionaltests/java/com/ericsson/ei/utils/TestConfigs.java
index 4466ae0ab..659852bd1 100644
--- a/src/functionaltests/java/com/ericsson/ei/utils/TestConfigs.java
+++ b/src/functionaltests/java/com/ericsson/ei/utils/TestConfigs.java
@@ -5,11 +5,14 @@
import org.apache.tomcat.util.codec.binary.Base64;
import org.apache.tomcat.util.codec.binary.StringUtils;
+import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.SocketUtils;
-import com.mongodb.MongoClient;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoCursor;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
@@ -51,9 +54,9 @@ protected static void startUpMongoClient() throws IOException {
}
try {
- MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
- mongoClient = testsFactory.newMongo();
- String port = "" + mongoClient.getAddress().getPort();
+ final ListDatabasesIterable list = mongoClient.listDatabases();
+ final MongoCursor iter = list.iterator();
+ final String port = "" + iter.getServerAddress().getPort();
System.setProperty("spring.data.mongodb.port", port);
LOGGER.debug("Started embedded Mongo DB for tests on port: " + port);
} catch (Exception e) {
diff --git a/src/integrationtests/java/com/ericsson/ei/integrationtests/flow/FlowStepsIT.java b/src/integrationtests/java/com/ericsson/ei/integrationtests/flow/FlowStepsIT.java
index 83a4b9ba3..45ac0e3b4 100644
--- a/src/integrationtests/java/com/ericsson/ei/integrationtests/flow/FlowStepsIT.java
+++ b/src/integrationtests/java/com/ericsson/ei/integrationtests/flow/FlowStepsIT.java
@@ -40,8 +40,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.mongodb.MongoClient;
-import com.mongodb.MongoClientURI;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
@@ -404,8 +404,7 @@ private JsonNode getNewestMailFromDatabase() throws Exception {
}
private void setupMailhogMongoDBHandler() {
- MongoClientURI uri = new MongoClientURI(mailHogUri);
- MongoClient mongoClient = new MongoClient(uri);
+ MongoClient mongoClient = MongoClients.create(mailHogUri);
mailhogMongoDBHandler = new MongoDBHandler();
mailhogMongoDBHandler.setMongoClient(mongoClient);
}
diff --git a/src/integrationtests/java/util/IntegrationTestBase.java b/src/integrationtests/java/util/IntegrationTestBase.java
index 187760912..51ede6c5a 100644
--- a/src/integrationtests/java/util/IntegrationTestBase.java
+++ b/src/integrationtests/java/util/IntegrationTestBase.java
@@ -13,21 +13,17 @@
*/
package util;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.annotation.PostConstruct;
@@ -52,6 +48,7 @@
import com.ericsson.ei.utils.HttpRequest.HttpMethod;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import lombok.Setter;
public abstract class IntegrationTestBase extends AbstractTestExecutionListener {
diff --git a/src/main/java/com/ericsson/ei/config/HttpSessionConfig.java b/src/main/java/com/ericsson/ei/config/HttpSessionConfig.java
index 91bf78d15..990de19c5 100644
--- a/src/main/java/com/ericsson/ei/config/HttpSessionConfig.java
+++ b/src/main/java/com/ericsson/ei/config/HttpSessionConfig.java
@@ -5,7 +5,7 @@
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.session.data.mongo.MongoOperationsSessionRepository;
+import org.springframework.session.data.mongo.MongoIndexedSessionRepository;
import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession;
import org.springframework.session.web.http.HttpSessionIdResolver;
@@ -20,8 +20,8 @@ public class HttpSessionConfig {
@Primary
@Bean
- public MongoOperationsSessionRepository mongoSessionRepository(MongoOperations mongoOperations) {
- MongoOperationsSessionRepository repository = new MongoOperationsSessionRepository(mongoOperations);
+ public MongoIndexedSessionRepository mongoIndexedSessionRepository(MongoOperations mongoOperations) {
+ MongoIndexedSessionRepository repository = new MongoIndexedSessionRepository(mongoOperations);
repository.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds);
return repository;
}
diff --git a/src/main/java/com/ericsson/ei/handlers/ObjectHandler.java b/src/main/java/com/ericsson/ei/handlers/ObjectHandler.java
index aa0f2d444..c8ce288b3 100644
--- a/src/main/java/com/ericsson/ei/handlers/ObjectHandler.java
+++ b/src/main/java/com/ericsson/ei/handlers/ObjectHandler.java
@@ -45,7 +45,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClientException;
-import com.mongodb.util.JSON;
import lombok.Getter;
import lombok.Setter;
@@ -118,7 +117,6 @@ public String insertObject(String aggregatedObject, RulesObject rulesObject, Str
BasicDBObject document = prepareDocumentForInsertion(id, aggregatedObject);
LOGGER.debug("ObjectHandler: Aggregated Object document to be inserted: {}",
document.toString());
-
mongoDbHandler.insertDocument(databaseName, aggregationsCollectionName, document.toString());
postInsertActions(aggregatedObject, rulesObject, event, id);
return aggregatedObject;
@@ -272,7 +270,7 @@ public String lockDocument(String id) {
if (result != null) {
LOGGER.debug("DB locked by {} thread", Thread.currentThread().getId());
documentLocked = false;
- return JSON.serialize(result);
+ return new BasicDBObject(result).toString();
}
// To Remove
LOGGER.debug("Waiting by {} thread", Thread.currentThread().getId());
diff --git a/src/main/java/com/ericsson/ei/handlers/RMQHandler.java b/src/main/java/com/ericsson/ei/handlers/RMQHandler.java
index d3671788a..af07232a8 100644
--- a/src/main/java/com/ericsson/ei/handlers/RMQHandler.java
+++ b/src/main/java/com/ericsson/ei/handlers/RMQHandler.java
@@ -38,7 +38,7 @@
import org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
-import org.springframework.amqp.rabbit.support.CorrelationData;
+import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -150,7 +150,7 @@ public RabbitTemplate rabbitMqTemplate() {
rabbitTemplate = new RabbitTemplate(connectionFactory());
}
- rabbitTemplate.setQueue(rmqProperties.getWaitlistQueueName());
+ rabbitTemplate.setDefaultReceiveQueue(rmqProperties.getWaitlistQueueName());
rabbitTemplate.setExchange(rmqProperties.getExchangeName());
rabbitTemplate.setRoutingKey(WAITLIST_BINDING_KEY);
rabbitTemplate.setConfirmCallback(new ConfirmCallback() {
diff --git a/src/main/java/com/ericsson/ei/jsonmerge/MergeHandler.java b/src/main/java/com/ericsson/ei/jsonmerge/MergeHandler.java
index 9536617e4..47080ff89 100644
--- a/src/main/java/com/ericsson/ei/jsonmerge/MergeHandler.java
+++ b/src/main/java/com/ericsson/ei/jsonmerge/MergeHandler.java
@@ -86,7 +86,7 @@ public String mergeObject(String id, String mergeId, RulesObject rules, String e
LOGGER.debug("AGGREGATED OBJECT : " + aggregatedObject);
if(aggregatedObject == null) {
return null;
- }
+ }
String mergeRule = getMergeRules(rules);
if (mergeRule != null && !mergeRule.isEmpty()) {
String updatedRule = replaceIdMarkerInRules(mergeRule, mergeId);
@@ -110,7 +110,6 @@ public String mergeObject(String id, String mergeId, RulesObject rules, String e
}
objectHandler.updateObject(mergedObject, rules, event, id);
}
-
return mergedObject;
}
diff --git a/src/main/java/com/ericsson/ei/jsonmerge/MergePrepare.java b/src/main/java/com/ericsson/ei/jsonmerge/MergePrepare.java
index c777b6445..42add1358 100644
--- a/src/main/java/com/ericsson/ei/jsonmerge/MergePrepare.java
+++ b/src/main/java/com/ericsson/ei/jsonmerge/MergePrepare.java
@@ -221,7 +221,7 @@ public String getMergePath(String originObject, String mergeRule, boolean skipPa
Object ruleJSONObject;
// condition to avoid un-necessary exception to print in the log
- if(mergeRule.startsWith("{")) {
+ if (mergeRule.startsWith("{")) {
ruleJSONObject = new JSONObject(mergeRule);
} else {
return getMergePathFromArrayMergeRules(originObject, mergeRule, stringObject);
diff --git a/src/main/java/com/ericsson/ei/mongo/MongoDBHandler.java b/src/main/java/com/ericsson/ei/mongo/MongoDBHandler.java
index df33e2177..fd78115f0 100644
--- a/src/main/java/com/ericsson/ei/mongo/MongoDBHandler.java
+++ b/src/main/java/com/ericsson/ei/mongo/MongoDBHandler.java
@@ -34,10 +34,7 @@
import com.ericsson.ei.handlers.DateUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mongodb.BasicDBObject;
-import com.mongodb.MongoClient;
import com.mongodb.MongoClientException;
-import com.mongodb.client.model.Updates;
-import com.mongodb.MongoClientURI;
import com.mongodb.MongoCommandException;
import com.mongodb.MongoConfigurationException;
import com.mongodb.MongoInterruptedException;
@@ -45,13 +42,17 @@
import com.mongodb.MongoSocketWriteException;
import com.mongodb.MongoWriteException;
import com.mongodb.client.FindIterable;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.Indexes;
+import com.mongodb.client.model.Updates;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
-import com.mongodb.util.JSON;
+import com.mongodb.client.MongoCursor;
import lombok.Getter;
import lombok.Setter;
@@ -153,7 +154,7 @@ public ArrayList getAllDocuments(String dataBaseName, String collectionN
if (collection != null) {
FindIterable foundResults = collection.find();
for (Document document : foundResults) {
- result.add(JSON.serialize(document));
+ result.add(new BasicDBObject(document).toString());
}
if (result.size() != 0) {
@@ -322,12 +323,16 @@ public void dropDatabase(String databaseName) {
*/
public boolean isMongoDBServerUp() {
try {
- mongoClient.getAddress();
+ final ListDatabasesIterable list = mongoClient.listDatabases();
+ MongoCursor iter = list.iterator();
+ while (iter.hasNext()) {
+ iter.getServerAddress();
+ break;
+ }
return true;
} catch (Exception e) {
return false;
}
-
}
private void createMongoClient() throws AbortExecutionException {
@@ -335,9 +340,7 @@ private void createMongoClient() throws AbortExecutionException {
throw new MongoConfigurationException(
"Failure to create MongoClient, missing config for spring.data.mongodb.uri:");
}
-
- MongoClientURI uri = new MongoClientURI(mongoProperties.getUri());
- mongoClient = new MongoClient(uri);
+ mongoClient = MongoClients.create(mongoProperties.getUri());
}
private ArrayList doFind(String dataBaseName, String collectionName,
@@ -360,7 +363,7 @@ private ArrayList doFind(String dataBaseName, String collectionName,
// Currently document.toJson() does not work here since something will add \\\ before
// all " later on, All get sometihng in mongoDB shoult redurn a JSON object and not a
// String.
- result.add(JSON.serialize(document));
+ result.add(new BasicDBObject(document).toString());
}
if (result.size() != 0) {
diff --git a/src/main/java/com/ericsson/ei/mongo/MongoUri.java b/src/main/java/com/ericsson/ei/mongo/MongoUri.java
index a9c1869f4..3249c1b76 100644
--- a/src/main/java/com/ericsson/ei/mongo/MongoUri.java
+++ b/src/main/java/com/ericsson/ei/mongo/MongoUri.java
@@ -18,7 +18,7 @@
import org.apache.commons.lang3.StringUtils;
-import com.mongodb.MongoClientURI;
+import com.mongodb.ConnectionString;
import com.mongodb.MongoConfigurationException;
public class MongoUri {
@@ -85,7 +85,7 @@ public static String getUriWithNewPassword(String uri, String newPassword) {
*/
public static String extractPasswordFromUri(String inputUri) {
String password = "";
- final MongoClientURI uri = new MongoClientURI(inputUri);
+ ConnectionString uri = new ConnectionString(inputUri);
final char[] passwordCharList = uri.getPassword();
if (passwordCharList != null) {
password = new String(passwordCharList);
diff --git a/src/test/java/com/ericsson/ei/controller/TestInformationControllerImpl.java b/src/test/java/com/ericsson/ei/controller/TestInformationControllerImpl.java
index c90964195..b9f03c0e2 100644
--- a/src/test/java/com/ericsson/ei/controller/TestInformationControllerImpl.java
+++ b/src/test/java/com/ericsson/ei/controller/TestInformationControllerImpl.java
@@ -24,6 +24,7 @@
import com.ericsson.ei.App;
import com.ericsson.ei.controller.model.ParseInstanceInfoEI;
+import com.ericsson.ei.encryption.Encryptor;
import com.ericsson.ei.utils.TestContextInitializer;
@TestPropertySource(properties = {
@@ -33,7 +34,7 @@
"rabbitmq.queue.suffix: TestInformationControllerImpl" })
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = App.class, loader = SpringBootContextLoader.class, initializers = TestContextInitializer.class)
-@WebMvcTest(value = InformationController.class, secure = false)
+@WebMvcTest(value = InformationController.class)
public class TestInformationControllerImpl extends ControllerTestBaseClass {
@MockBean
@@ -41,6 +42,9 @@ public class TestInformationControllerImpl extends ControllerTestBaseClass {
@MockBean
private InformationController infoController;
+
+ @MockBean
+ private Encryptor encryptor;
@Test
public void testResponseStatus() throws Throwable {
diff --git a/src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java b/src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java
index efa5d9817..f5b4e70f6 100644
--- a/src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java
+++ b/src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java
@@ -41,7 +41,7 @@
import com.ericsson.ei.waitlist.WaitListStorageHandler;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.rabbitmq.client.Channel;
@@ -206,7 +206,7 @@ private long countProcessedEvents(String database, String collection) throws Exc
}
MongoDatabase db = mongoClient.getDatabase(database);
MongoCollection table = db.getCollection(collection);
- return table.count();
+ return table.countDocuments();
}
protected void waitForEventsToBeProcessed(int eventsCount) throws Exception {
diff --git a/src/test/java/com/ericsson/ei/handlers/test/ObjectHandlerTest.java b/src/test/java/com/ericsson/ei/handlers/test/ObjectHandlerTest.java
index b776b7331..79e09c9d4 100644
--- a/src/test/java/com/ericsson/ei/handlers/test/ObjectHandlerTest.java
+++ b/src/test/java/com/ericsson/ei/handlers/test/ObjectHandlerTest.java
@@ -42,7 +42,7 @@
import com.ericsson.ei.test.utils.TestConfigs;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
diff --git a/src/test/java/com/ericsson/ei/mongo/MongoDBHandlerTest.java b/src/test/java/com/ericsson/ei/mongo/MongoDBHandlerTest.java
index bdfdfb6d0..a5aaa4c21 100644
--- a/src/test/java/com/ericsson/ei/mongo/MongoDBHandlerTest.java
+++ b/src/test/java/com/ericsson/ei/mongo/MongoDBHandlerTest.java
@@ -25,13 +25,15 @@
import java.util.ArrayList;
-import org.junit.After;
+import org.bson.Document;
import org.junit.Before;
import org.junit.Test;
import com.ericsson.ei.test.utils.TestConfigs;
-import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoCursor;
public class MongoDBHandlerTest {
@@ -72,12 +74,6 @@ public void testGetDocumentsOnCondition() {
assertTrue(documents.size() > 0);
}
- @Test
- public void testUpdateDocument() {
- final MongoQuery query = MongoCondition.idCondition("eventId");
- assertTrue("Document was not updated",
- mongoDBHandler.updateDocument(dataBaseName, collectionName, query, updateInput));
- }
@Test
public void testUpdateDocumentWrongId() {
@@ -87,18 +83,10 @@ public void testUpdateDocumentWrongId() {
}
@Test
- public void testIsMongoDBServerUp() {
- MongoClient client = mock(MongoClient.class);
- when(client.getAddress()).thenReturn(new ServerAddress());
- mongoDBHandler.setMongoClient(client);
- assertTrue(mongoDBHandler.isMongoDBServerUp());
-
- doThrow(Exception.class).when(client).getAddress();
- mongoDBHandler.setMongoClient(client);
- assertFalse(mongoDBHandler.isMongoDBServerUp());
-
- // Need to set a working client to enable cleanup
- mongoDBHandler.setMongoClient(TestConfigs.getMongoClient());
+ public void testUpdateDocument() {
+ final MongoQuery query = MongoCondition.idCondition("eventId");
+ assertTrue("Document was not updated",
+ mongoDBHandler.updateDocument(dataBaseName, collectionName, query, updateInput));
}
// Added test cases for EventToObjectMapHandler
@@ -114,13 +102,6 @@ public void updateEventToObjectMap() {
conditionForEventToObjectMap, updateInputForEventToObjectMap));
}
- @After
- public void dropCollection() {
- final MongoCondition idCondition = MongoCondition.idCondition("eventId");
- assertTrue(mongoDBHandler.dropDocument(dataBaseName, collectionName, idCondition));
- mongoDBHandler.dropCollection(dataBaseName, mapCollectionName);
- }
-
@Test
public void checkMongoDBStatusUp() {
assertEquals(mongoDBHandler.checkMongoDbStatus(dataBaseName), true);
@@ -132,4 +113,31 @@ public void checkMongoDBStatusDown() {
final MongoClient mongoclient = null;
assertEquals(mongoDB.checkMongoDbStatus(dataBaseName), false);
}
+
+ @Test
+ public void dropCollection() {
+ final MongoCondition idCondition = MongoCondition.idCondition("eventId");
+ assertTrue(mongoDBHandler.dropDocument(dataBaseName, collectionName, idCondition));
+ mongoDBHandler.dropCollection(dataBaseName, mapCollectionName);
+ }
+
+ @Test
+ public void testIsMongoDBServerUp() {
+ MongoClient client = mock(MongoClient.class);
+ Document document = mock(Document.class);
+ ListDatabasesIterable documents = mock(ListDatabasesIterable.class);;
+ ListDatabasesIterable list = client.listDatabases();
+ MongoCursor cursor= mock(MongoCursor.class);
+
+ when(client.listDatabases()).thenReturn(documents);
+ when(cursor.getServerAddress()).thenReturn(new ServerAddress());
+ assertTrue(mongoDBHandler.isMongoDBServerUp());
+
+ doThrow(Exception.class).when(documents);
+ mongoDBHandler.setMongoClient(null);
+ assertFalse(mongoDBHandler.isMongoDBServerUp());
+
+ //Need to set a working client to enable cleanup
+ mongoDBHandler.setMongoClient(TestConfigs.getMongoClient());
+ }
}
diff --git a/src/test/java/com/ericsson/ei/notifications/HttpRequestTest.java b/src/test/java/com/ericsson/ei/notifications/HttpRequestTest.java
index 35152758e..f79b9ae26 100644
--- a/src/test/java/com/ericsson/ei/notifications/HttpRequestTest.java
+++ b/src/test/java/com/ericsson/ei/notifications/HttpRequestTest.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.Base64;
+import org.bson.Document;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -38,9 +39,10 @@
import com.ericsson.eiffelcommons.subscriptionobject.RestPostSubscriptionObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.mongodb.MongoClient;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoCursor;
-import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
@TestPropertySource(properties = {
@@ -80,9 +82,9 @@ public class HttpRequestTest {
private HttpRequest httpRequest;
public static void setUpEmbeddedMongo() throws Exception {
- testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
- mongoClient = testsFactory.newMongo();
- String port = "" + mongoClient.getAddress().getPort();
+ ListDatabasesIterable list = mongoClient.listDatabases();
+ MongoCursor iter = list.iterator();
+ String port = "" + iter.getServerAddress().getPort();
System.setProperty("spring.data.mongodb.port", port);
}
diff --git a/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceRESTAPITest.java b/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceRESTAPITest.java
index 486e1e6fc..ed23eb443 100644
--- a/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceRESTAPITest.java
+++ b/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceRESTAPITest.java
@@ -50,6 +50,7 @@
import com.ericsson.ei.controller.AggregatedObjectControllerImpl;
import com.ericsson.ei.controller.EntryPointConstantsUtils;
import com.ericsson.ei.controller.FailedNotificationControllerImpl;
+import com.ericsson.ei.encryption.Encryptor;
import com.ericsson.ei.utils.TestContextInitializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -61,11 +62,14 @@
"rabbitmq.queue.suffix: QueryServiceRESTAPITest" })
@ContextConfiguration(classes = App.class, loader = SpringBootContextLoader.class, initializers = TestContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
-@WebMvcTest(value = AggregatedObjectController.class, secure = false)
+@WebMvcTest(value = AggregatedObjectController.class)
public class QueryServiceRESTAPITest {
@Autowired
private MockMvc mockMvc;
+
+ @MockBean
+ private Encryptor encryptor;
static JSONArray jsonArray = null;
diff --git a/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceTest.java b/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceTest.java
index f52874c24..6bb48fa36 100644
--- a/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceTest.java
+++ b/src/test/java/com/ericsson/ei/queryservice/test/QueryServiceTest.java
@@ -25,6 +25,7 @@
import org.apache.commons.io.FileUtils;
import org.bson.BsonDocument;
import org.bson.Document;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -48,7 +49,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.mongodb.BasicDBObject;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
@TestPropertySource(properties = {
"spring.data.mongodb.database: QueryServiceTest",
@@ -103,14 +104,6 @@ public void initMocks() throws Exception {
mongoClient.getDatabase(database).getCollection(failedNotificationCollectionName)
.insertOne(failedDocument);
LOG.debug("Document Inserted in failed notification Database");
-
- BasicDBObject preparedAggDocument = objectHandler.prepareDocumentForInsertion(
- aggDocument.getString("_id"),
- aggregatedObject);
- aggDocument = Document.parse(preparedAggDocument.toString());
- mongoClient.getDatabase(database).getCollection(aggregationCollectionName)
- .insertOne(aggDocument);
- LOG.debug("Document Inserted in Aggregated Object Database");
}
public void initializeData() throws Exception {
@@ -119,6 +112,21 @@ public void initializeData() throws Exception {
failedNotification = FileUtils.readFileToString(new File(FAILED_NOTIFICATION_PATH), "UTF-8");
LOG.debug("The failed notification is : " + failedNotification);
}
+
+ @Before
+ public void insertOneAggregation() {
+ Document aggDocument = Document.parse(aggregatedObject);
+ BasicDBObject preparedAggDocument = objectHandler.prepareDocumentForInsertion(
+ aggDocument.getString("_id"),
+ aggregatedObject);
+ aggDocument = Document.parse(preparedAggDocument.toString());
+ try {
+ mongoClient.getDatabase(database).getCollection(aggregationCollectionName).insertOne(aggDocument);
+ LOG.debug("Document Inserted in Aggregated Object Database");
+ } catch (Exception e) {
+ LOG.debug("Document already present in Aggregated Object Database");
+ }
+ }
@Test
public void processFailedNotificationTest() {
diff --git a/src/test/java/com/ericsson/ei/queryservice/test/TestProcessQueryParams.java b/src/test/java/com/ericsson/ei/queryservice/test/TestProcessQueryParams.java
index 221c7bbf5..62a90372b 100644
--- a/src/test/java/com/ericsson/ei/queryservice/test/TestProcessQueryParams.java
+++ b/src/test/java/com/ericsson/ei/queryservice/test/TestProcessQueryParams.java
@@ -28,6 +28,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ericsson.ei.App;
+import com.ericsson.ei.encryption.Encryptor;
import com.ericsson.ei.mongo.MongoQuery;
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
import com.ericsson.ei.queryservice.ProcessQueryParams;
@@ -57,6 +58,9 @@ public class TestProcessQueryParams {
@MockBean
private ProcessAggregatedObject processAggregatedObject;
+
+ @MockBean
+ private Encryptor encryptor;
@BeforeClass
public static void setUp() throws JSONException {
diff --git a/src/test/java/com/ericsson/ei/rules/TestRulesService.java b/src/test/java/com/ericsson/ei/rules/TestRulesService.java
index 853b10460..05bc667c0 100644
--- a/src/test/java/com/ericsson/ei/rules/TestRulesService.java
+++ b/src/test/java/com/ericsson/ei/rules/TestRulesService.java
@@ -23,7 +23,7 @@
import com.ericsson.ei.mongo.MongoDBHandler;
import com.ericsson.ei.test.utils.TestConfigs;
import com.ericsson.ei.utils.TestContextInitializer;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
@TestPropertySource(properties = {
"spring.data.mongodb.database: TestRulesService",
diff --git a/src/test/java/com/ericsson/ei/services/SubscriptionRestAPITest.java b/src/test/java/com/ericsson/ei/services/SubscriptionRestAPITest.java
index 072b53656..cca56193d 100644
--- a/src/test/java/com/ericsson/ei/services/SubscriptionRestAPITest.java
+++ b/src/test/java/com/ericsson/ei/services/SubscriptionRestAPITest.java
@@ -45,11 +45,12 @@
import com.ericsson.ei.controller.SubscriptionController;
import com.ericsson.ei.controller.model.Subscription;
+import com.ericsson.ei.encryption.Encryptor;
import com.ericsson.ei.exception.SubscriptionNotFoundException;
import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(SpringJUnit4ClassRunner.class)
-@WebMvcTest(value = SubscriptionController.class, secure = false)
+@WebMvcTest(value = SubscriptionController.class)
public class SubscriptionRestAPITest {
private static final String SUBSCRIPTION = "src/test/resources/subscription_single.json";
@@ -69,6 +70,8 @@ public class SubscriptionRestAPITest {
@MockBean
private SecurityContext securityContext;
+ @MockBean private Encryptor encryptor;
+
private ObjectMapper mapper = new ObjectMapper();
diff --git a/src/test/java/com/ericsson/ei/services/SubscriptionServiceTest.java b/src/test/java/com/ericsson/ei/services/SubscriptionServiceTest.java
index 4c035f034..c6450ed69 100644
--- a/src/test/java/com/ericsson/ei/services/SubscriptionServiceTest.java
+++ b/src/test/java/com/ericsson/ei/services/SubscriptionServiceTest.java
@@ -60,7 +60,7 @@
import com.ericsson.eiffelcommons.subscriptionobject.SubscriptionObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.BasicDBObject;
-import com.mongodb.MongoClient;
+import com.mongodb.client.MongoClient;
@TestPropertySource(properties = {
"spring.data.mongodb.database: SubscriptionServiceTest",
diff --git a/src/test/java/com/ericsson/ei/subscription/SubscriptionRepeatDbHandlerTest.java b/src/test/java/com/ericsson/ei/subscription/SubscriptionRepeatDbHandlerTest.java
index 745f5f231..b5294ef5e 100644
--- a/src/test/java/com/ericsson/ei/subscription/SubscriptionRepeatDbHandlerTest.java
+++ b/src/test/java/com/ericsson/ei/subscription/SubscriptionRepeatDbHandlerTest.java
@@ -33,7 +33,6 @@
import com.ericsson.ei.mongo.MongoDBHandler;
import com.ericsson.ei.utils.FunctionalTestBase;
import com.mongodb.BasicDBObject;
-import com.mongodb.util.JSON;
@TestPropertySource(properties = {
"spring.data.mongodb.database: SubscriptionRepeatDbHandlerTest",
@@ -76,7 +75,7 @@ public void addOneNewMatchedAggrIdToDatabase() {
subsRepeatDbHandler.addMatchedAggrObjToSubscriptionId(subscriptionId, requirementId, aggrObjId);
- BasicDBObject dbResult = (BasicDBObject) JSON.parse(mongoDBHandler
+ BasicDBObject dbResult = BasicDBObject.parse(mongoDBHandler
.find(subRepeatFlagDataBaseName,
subRepeatFlagCollectionName,
subscriptionQuery)
@@ -114,7 +113,7 @@ public void addTwoNewMatchedAggrIdToDatabase() {
subsRepeatDbHandler.addMatchedAggrObjToSubscriptionId(subscriptionId2, requirementId2, aggrObjId2);
- BasicDBObject dbResult = (BasicDBObject) JSON.parse(mongoDBHandler
+ BasicDBObject dbResult = BasicDBObject.parse(mongoDBHandler
.find(subRepeatFlagDataBaseName,
subRepeatFlagCollectionName,
subscriptionQuery2)
@@ -124,7 +123,7 @@ public void addTwoNewMatchedAggrIdToDatabase() {
assertEquals(subscriptionId2, dbResult.get("subscriptionId").toString());
String actual = dbResult.get("requirements").toString();
- String expected = "{ \"" + requirementId2 + "\" : [ \"" + aggrObjId2 + "\"]}";
+ String expected = "{\"" + requirementId2 + "\": [\"" + aggrObjId2 + "\"]}";
String msg = "\nACTUAL : |" + actual + "|\nEXPECTED: |" + expected + "|";
boolean result = true;
@@ -163,7 +162,7 @@ public void addTwoNewSameMatchedAggrIdToDatabase() {
e.printStackTrace();
}
- BasicDBObject dbResult = (BasicDBObject) JSON.parse(mongoDBHandler
+ BasicDBObject dbResult = BasicDBObject.parse(mongoDBHandler
.find(subRepeatFlagDataBaseName,
subRepeatFlagCollectionName,
subscriptionQuery)
@@ -175,7 +174,7 @@ public void addTwoNewSameMatchedAggrIdToDatabase() {
log.error("DB Content: " + dbResult.toString());
String actual = dbResult.get("requirements").toString();
- String expected = "{ \"0\" : [ \"" + aggrObjId + "\" , \"" + aggrObjId2 + "\"]}";
+ String expected = "{\"0\": [\"" + aggrObjId + "\", \"" + aggrObjId2 + "\"]}";
String msg = "\nACTUAL : |" + actual + "|\nEXPECTED: |" + expected + "|";
boolean result = true;
if (!expected.equals(actual)) {
diff --git a/src/test/java/com/ericsson/ei/test/utils/TestConfigs.java b/src/test/java/com/ericsson/ei/test/utils/TestConfigs.java
index c2a22527d..61723f19c 100644
--- a/src/test/java/com/ericsson/ei/test/utils/TestConfigs.java
+++ b/src/test/java/com/ericsson/ei/test/utils/TestConfigs.java
@@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.concurrent.TimeoutException;
+import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.BindingBuilder;
@@ -14,7 +15,10 @@
import org.springframework.util.SocketUtils;
import com.ericsson.ei.utils.AMQPBrokerManager;
-import com.mongodb.MongoClient;
+import com.mongodb.client.ListDatabasesIterable;
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCursor;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
@@ -74,10 +78,11 @@ private static synchronized void setUpEmbeddedMongo(String mongoUri) throws IOEx
}
try {
- testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
- mongoClient = testsFactory.newMongo();
- String port = String.valueOf(mongoClient.getAddress().getPort());
- setNewPortToMongoDBUriProperty(mongoUri, port);
+ mongoClient = MongoClients.create(mongoUri);
+ ListDatabasesIterable list = mongoClient.listDatabases();
+ MongoCursor iter = list.iterator();
+ String port = "" + iter.getServerAddress().getPort();
+ setNewPortToMongoDBUriProperty(mongoUri, port);
} catch (Exception e) {
LOGGER.error("Error setting new mongoDB uri property {}", e.getMessage(), e);
}
diff --git a/src/test/resources/FailedNotification.json b/src/test/resources/FailedNotification.json
index 503313868..2ef219df3 100644
--- a/src/test/resources/FailedNotification.json
+++ b/src/test/resources/FailedNotification.json
@@ -2,7 +2,7 @@
"subscriptionName": "Subscription_1",
"notificationMeta": "some_url",
"time": {
- "$date": "2019-08-29T06:29:00.000Z"
+ "$date": "2019-08-29T06:29:00Z"
},
"aggregatedObject": {
"fileInformation": [
diff --git a/src/test/resources/FailedNotificationOutput.json b/src/test/resources/FailedNotificationOutput.json
index 9e4b7a4fc..4ba9083b9 100644
--- a/src/test/resources/FailedNotificationOutput.json
+++ b/src/test/resources/FailedNotificationOutput.json
@@ -3,7 +3,7 @@
"subscriptionName": "Subscription_1",
"notificationMeta": "some_url",
"time": {
- "$date": "2019-08-29T06:29:00.000Z"
+ "$date": "2019-08-29T06:29:00Z"
},
"aggregatedObject": {
"fileInformation": [