diff --git a/menas/pom.xml b/menas/pom.xml
index a6bb90831..c5c516d19 100644
--- a/menas/pom.xml
+++ b/menas/pom.xml
@@ -29,7 +29,7 @@
1.0.4
${project.basedir}/ui
${project.parent.basedir}/scalastyle-config.xml
- 2.2.0
+ 4.18.0
@@ -340,7 +340,7 @@
-Xfatal-warnings
-unchecked
- -deprecation
+ -deprecation:false
-feature
diff --git a/menas/src/test/scala/za/co/absa/enceladus/menas/integration/controllers/SchemaApiFeaturesIntegrationSuite.scala b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/controllers/SchemaApiFeaturesIntegrationSuite.scala
index b3416fb98..b81efb79b 100644
--- a/menas/src/test/scala/za/co/absa/enceladus/menas/integration/controllers/SchemaApiFeaturesIntegrationSuite.scala
+++ b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/controllers/SchemaApiFeaturesIntegrationSuite.scala
@@ -308,7 +308,8 @@ class SchemaApiFeaturesIntegrationSuite extends BaseRestApiTest with BeforeAndAf
val actual = response.getBody
val expected = UsedIn(Some(Seq(MenasReference(None, "dataset", 1))), Some(Seq()))
- assert(actual == expected)
+ val expectedMongo4_4 = UsedIn(Some(Seq(MenasReference(Some("dataset"), "dataset", 1))), Some(Seq()))
+ assert(actual == expectedMongo4_4)
}
}
"some version of the Schema is used by a enabled MappingTable" should {
@@ -325,7 +326,8 @@ class SchemaApiFeaturesIntegrationSuite extends BaseRestApiTest with BeforeAndAf
val actual = response.getBody
val expected = UsedIn(Some(Seq()), Some(Seq(MenasReference(None, "mapping", 1))))
- assert(actual == expected)
+ val expectedMongo4_4 = UsedIn(Some(Seq()), Some(Seq(MenasReference(Some("mapping_table"), "mapping", 1))))
+ assert(actual == expectedMongo4_4)
}
}
}
@@ -460,7 +462,8 @@ class SchemaApiFeaturesIntegrationSuite extends BaseRestApiTest with BeforeAndAf
val actual = response.getBody
val expected = UsedIn(Some(Seq(MenasReference(None, "dataset1", 1))), Some(Seq()))
- assert(actual == expected)
+ val expectedMongo4_4 = UsedIn(Some(Seq(MenasReference(Some("dataset"), "dataset1", 1))), Some(Seq()))
+ assert(actual == expectedMongo4_4)
}
}
"some version of the Schema is used by a enabled MappingTable" should {
@@ -478,7 +481,8 @@ class SchemaApiFeaturesIntegrationSuite extends BaseRestApiTest with BeforeAndAf
val actual = response.getBody
val expected = UsedIn(Some(Seq()), Some(Seq(MenasReference(None, "mapping1", 1))))
- assert(actual == expected)
+ val expectedMongo4_4 = UsedIn(Some(Seq()), Some(Seq(MenasReference(Some("mapping_table"), "mapping1", 1))))
+ assert(actual == expectedMongo4_4)
}
}
}
diff --git a/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbeddedMongo.scala b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbeddedMongo.scala
index ae2c0422f..948c87edb 100644
--- a/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbeddedMongo.scala
+++ b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbeddedMongo.scala
@@ -15,10 +15,10 @@
package za.co.absa.enceladus.menas.integration.mongo
-import de.flapdoodle.embed.mongo.config.{MongodConfigBuilder, Net}
import de.flapdoodle.embed.mongo.distribution.Version
-import de.flapdoodle.embed.mongo.{MongodExecutable, MongodStarter}
-import de.flapdoodle.embed.process.runtime.Network
+import de.flapdoodle.embed.mongo.transitions.{Mongod, RunningMongodProcess}
+import de.flapdoodle.reverse.TransitionWalker
+
import javax.annotation.{PostConstruct, PreDestroy}
import org.mongodb.scala.{MongoClient, MongoDatabase}
import org.slf4j.LoggerFactory
@@ -33,37 +33,22 @@ import za.co.absa.enceladus.menas.utils.implicits.codecRegistry
@Profile(Array("withEmbeddedMongo"))
class EmbeddedMongo {
private val logger = LoggerFactory.getLogger(this.getClass)
- private var mongodExecutable: MongodExecutable = _
- private var mongoPort: Int = _
-
- def getMongoUri: String = s"mongodb://localhost:$mongoPort/?ssl=false"
+ private var runningMongod: TransitionWalker.ReachedState[RunningMongodProcess] = _
- def getMongoPort: Int = mongoPort
+ def getMongoUri: String = f"mongodb://${runningMongod.current().getServerAddress}"
@Value("${menas.mongo.connection.database}")
val database: String = ""
@PostConstruct
def runDummyMongo(): Unit = {
- val starter = MongodStarter.getDefaultInstance
-
- synchronized {
- mongoPort = Network.getFreeServerPort()
- val mongodConfig = new MongodConfigBuilder()
- .version(Version.Main.V4_0)
- .net(new Net("localhost", mongoPort, Network.localhostIsIPv6()))
- .build()
-
- mongodExecutable = starter.prepare(mongodConfig)
- }
-
- mongodExecutable.start()
- logger.debug(s"*** mongod started at port $mongoPort")
+ runningMongod = Mongod.instance().start(Version.Main.V8_0)
+ logger.debug(s"*** mongod started at $getMongoUri")
}
@PreDestroy
def shutdownDummyMongo(): Unit = {
- mongodExecutable.stop()
+ runningMongod.close()
}
@Primary // will override non-primary MongoDatabase-typed bean when in scope - here: the 'defaultMongoDb' bean
@@ -71,5 +56,4 @@ class EmbeddedMongo {
def embeddedMongoDb: MongoDatabase = {
MongoClient(getMongoUri).getDatabase(database).withCodecRegistry(codecRegistry)
}
-
}
diff --git a/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbededMongoIntegrationSuite.scala b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbededMongoIntegrationSuite.scala
new file mode 100644
index 000000000..c4770e481
--- /dev/null
+++ b/menas/src/test/scala/za/co/absa/enceladus/menas/integration/mongo/EmbededMongoIntegrationSuite.scala
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2018 ABSA Group Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package za.co.absa.enceladus.menas.integration.mongo
+
+import org.junit.runner.RunWith
+import org.mongodb.scala.model.Filters.equal
+import org.mongodb.scala.model.Filters
+import org.mongodb.scala.model.Projections.{computed, fields, include}
+import org.mongodb.scala.{MongoCollection, MongoDatabase}
+import org.scalatest.wordspec.AnyWordSpec
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.ActiveProfiles
+import org.springframework.test.context.junit4.SpringRunner
+import za.co.absa.enceladus.menas.integration.TestContextManagement
+import za.co.absa.enceladus.model.menas.MenasReference
+
+import scala.concurrent.Await
+import scala.concurrent.duration.Duration
+
+@RunWith(classOf[SpringRunner])
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles(Array("withEmbeddedMongo"))
+class EmbededMongoIntegrationSuite extends AnyWordSpec with TestContextManagement {
+ @Autowired
+ val mongoDb: MongoDatabase = null
+
+ override def afterAll(): Unit = {
+ super.afterAll()
+ Await.result(mongoDb.drop().toFuture(), Duration.Inf)
+ }
+
+ s"mongo" can {
+ s"perform find" when {
+ s"version is above 4.4.1 or below 4.2.23" should {
+ s"populate or ignore computed field accordingly" in {
+
+ // Prior to v 4.4
+ // inlcuding field in find expression purely included it in result
+ // meaninig, original value / null value is preserved regardless of users wish to override it
+ // Since 4.4
+ // provided value is actually respected
+ // https://www.mongodb.com/docs/v4.4/release-notes/4.4-compatibility/#projection-compatibility-changes
+
+ val collection: MongoCollection[MenasReference] = mongoDb.getCollection[MenasReference]("TestMeCollection")
+ val sampleReference = MenasReference(None, "dedo jozef", 123)
+ val filter = Filters.and(equal("name", "dedo jozef"), equal("version", 123))
+ val mongoInsertQuery = collection.insertMany(Seq(sampleReference))
+ val mongoFindQuery = collection
+ .find[MenasReference](filter)
+ .projection(fields(include("name", "version"), computed("collection", "tato zlato")))
+
+ Await.result(mongoInsertQuery.toFuture(), Duration.Inf)
+ val actual = Await.result(mongoFindQuery.toFuture(), Duration.Inf)
+
+ val expectedV4_2_23orBefore = Seq(MenasReference(None, "dedo jozef", 123))
+ val expectedV4_4_1orAfter = Seq(MenasReference(Some("tato zlato"), "dedo jozef", 123))
+ assert(actual == expectedV4_4_1orAfter)
+ }
+ }
+ }
+ }
+}
diff --git a/utils/pom.xml b/utils/pom.xml
index 6aebcadd0..05d0c2c24 100644
--- a/utils/pom.xml
+++ b/utils/pom.xml
@@ -88,7 +88,7 @@
-Xfatal-warnings
-unchecked
- -deprecation
+ -deprecation:false
-feature