Skip to content

Commit

Permalink
feat: Migration Plugin needed
Browse files Browse the repository at this point in the history
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.7.1")
  • Loading branch information
QuadStingray committed Feb 7, 2025
1 parent b4982df commit 986aa14
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class RestaurantDemoSpec extends Specification with RestaurantDemoDatabaseFuncti
```shell
docker rm -f mongodb;
docker run -d --publish 27017:27017 --name mongodb mongocamp/mongodb:latest;
sbt test
sbt +test
```

## Supporters
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html
//crossScalaVersions := Seq("2.13.16")
crossScalaVersions := Seq("3.6.0", "2.13.16")

scalaVersion := crossScalaVersions.value.last
scalaVersion := crossScalaVersions.value.head

scalacOptions += "-deprecation"

Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

addSbtPlugin("dev.quadstingray" %% "sbt-json" % "0.7.1")

addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.7.1")


addDependencyTreePlugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import org.apache.lucene.search.MatchAllDocsQuery
class DocumentIncludesSuite extends FunSuite with DocumentIncludes {

test("mapToBson should convert Map to Bson") {
val map = Map("key" -> "value")
val map = Map("key" -> "value")
val bson = mapToBson(map)
assert(bson.isInstanceOf[Document])
assertEquals(bson.toBsonDocument.toJson(), "{\"key\":\"value\"}")
assertEquals(bson.asInstanceOf[Document].getString("key"), "value")
}

test("luceneQueryBson should convert Lucene Query to Bson") {
val query = new MatchAllDocsQuery()
val bson = luceneQueryBson(query)
val bson = luceneQueryBson(query)
assert(bson.isInstanceOf[Document])
}

Expand All @@ -27,55 +28,59 @@ class DocumentIncludesSuite extends FunSuite with DocumentIncludes {
javaMap.put("key", "value")
val document = documentFromJavaMap(javaMap)
assert(document.isInstanceOf[Document])
assertEquals(document.toBsonDocument.toJson(), "{\"key\":\"value\"}")
assertEquals(document.getString("key"), "value")
}

test("documentFromMutableMap should convert mutable.Map to Document") {
val mutableMap: collection.mutable.Map[String, Any] = collection.mutable.Map("key" -> "value")
val document = documentFromMutableMap(mutableMap)
val document = documentFromMutableMap(mutableMap)
assert(document.isInstanceOf[Document])
assertEquals(document.toBsonDocument.toJson(), "{\"key\":\"value\"}")
assertEquals(document.getString("key"), "value")
}

test("documentFromScalaMap should convert Map to Document") {
val map = Map("key" -> "value")
val map = Map("key" -> "value")
val document = documentFromScalaMap(map)
assert(document.isInstanceOf[Document])
assertEquals(document.toBsonDocument.toJson(), "{\"key\":\"value\"}")
assertEquals(document.getString("key"), "value")
}

test("documentFromDocument should convert org.bson.Document to Document") {
val bsonDoc = new org.bson.Document("key", "value")
val bsonDoc = new org.bson.Document("key", "value")
val document = documentFromDocument(bsonDoc)
assert(document.isInstanceOf[Document])
assertEquals(document.toBsonDocument.toJson(), "{\"key\":\"value\"}")
assertEquals(document.getString("key"), "value")
}

test("mapFromDocument should convert Document to Map") {
val document = Document("key" -> "value")
val map = mapFromDocument(document)
val map = mapFromDocument(document)
assert(map.isInstanceOf[Map[_, _]])
assertEquals(map("key"), "value")
}

test("mapListFromDocuments should convert List of Documents to List of Maps") {
val documents = List(Document("key" -> "value"))
val mapList = mapListFromDocuments(documents)
val mapList = mapListFromDocuments(documents)
assert(mapList.isInstanceOf[List[_]])
assertEquals(mapList.head("key"), "value")
}

test("stringToObjectId should convert String to ObjectId") {
val str = "507f1f77bcf86cd799439011"
val str = "507f1f77bcf86cd799439011"
val objectId = stringToObjectId(str)
assert(objectId.isInstanceOf[ObjectId])
assertEquals(objectId.toHexString, str)
}

test("documentToObjectId should extract ObjectId from Document") {
val objectId = new ObjectId()
val document = Document(DatabaseProvider.ObjectIdKey -> objectId)
val objectId = new ObjectId()
val document = Document(DatabaseProvider.ObjectIdKey -> objectId)
val extractedObjectId = documentToObjectId(document)
assertEquals(extractedObjectId, objectId)
}
}
}

0 comments on commit 986aa14

Please sign in to comment.