|
17 | 17 | package org.mongodb.scala
|
18 | 18 |
|
19 | 19 | import java.util.concurrent.TimeUnit
|
20 |
| - |
21 | 20 | import _root_.scala.concurrent.duration.Duration
|
22 |
| - |
23 | 21 | import com.mongodb.{ MongoCredential => JMongoCredential }
|
24 |
| - |
| 22 | +import org.bson.BsonDocumentWrapper |
| 23 | +import org.bson.codecs.DocumentCodec |
25 | 24 | import org.mongodb.scala
|
26 |
| -import org.mongodb.scala.bson.BsonString |
| 25 | +import org.mongodb.scala.MongoClient.DEFAULT_CODEC_REGISTRY |
| 26 | +import org.mongodb.scala.bson._ |
27 | 27 | import org.mongodb.scala.model._
|
28 |
| -import org.scalatest.{ FlatSpec, Matchers } |
29 | 28 |
|
30 | 29 | class ScalaPackageSpec extends BaseSpec {
|
31 | 30 |
|
@@ -66,9 +65,9 @@ class ScalaPackageSpec extends BaseSpec {
|
66 | 65 |
|
67 | 66 | it should "be able to create Documents" in {
|
68 | 67 | val doc = Document("a" -> BsonString("1"))
|
69 |
| - val doc2 = org.mongodb.scala.bson.collection.Document("a" -> BsonString("1")) |
| 68 | + val doc2 = collection.Document("a" -> BsonString("1")) |
70 | 69 |
|
71 |
| - doc shouldBe a[org.mongodb.scala.bson.collection.immutable.Document] |
| 70 | + doc shouldBe a[collection.immutable.Document] |
72 | 71 | doc should equal(doc2)
|
73 | 72 | }
|
74 | 73 |
|
@@ -141,4 +140,33 @@ class ScalaPackageSpec extends BaseSpec {
|
141 | 140 | val javaCredential5 = JMongoCredential.createGSSAPICredential("userName")
|
142 | 141 | scalaCredential5 should equal(javaCredential5)
|
143 | 142 | }
|
| 143 | + |
| 144 | + it should "implicitly convert to org.bson.document with type fidelity" in { |
| 145 | + |
| 146 | + val bsonDocument = Document( |
| 147 | + "null" -> BsonNull(), |
| 148 | + "int32" -> BsonInt32(32), |
| 149 | + "int64" -> BsonInt64(Long.MaxValue), |
| 150 | + "decimal128" -> BsonDecimal128(128.1), |
| 151 | + "boolean" -> BsonBoolean(true), |
| 152 | + "date" -> BsonDateTime(123456789), |
| 153 | + "double" -> BsonDouble(1.1), |
| 154 | + "string" -> BsonString("String"), |
| 155 | + "minKey" -> BsonMinKey(), |
| 156 | + "maxKey" -> BsonMaxKey(), |
| 157 | + "javaScript" -> BsonJavaScript("function () {}"), |
| 158 | + "objectId" -> BsonObjectId(), |
| 159 | + "codeWithScope" -> BsonJavaScriptWithScope("function () {}", Document()), |
| 160 | + "regex" -> BsonRegularExpression("/(.*)/"), |
| 161 | + "symbol" -> BsonSymbol(Symbol("sym")), |
| 162 | + "timestamp" -> BsonTimestamp(), |
| 163 | + "undefined" -> BsonUndefined(), |
| 164 | + "binary" -> BsonBinary(Array[Byte](128.toByte)), |
| 165 | + "array" -> BsonArray(List("a", "b", "c")), |
| 166 | + "document" -> Document("a" -> 1, "b" -> List(1, 2, 3)) |
| 167 | + ) |
| 168 | + |
| 169 | + val document: org.bson.Document = bsonDocument |
| 170 | + BsonDocumentWrapper.asBsonDocument(document, DEFAULT_CODEC_REGISTRY) should equal(bsonDocument.underlying) |
| 171 | + } |
144 | 172 | }
|
0 commit comments