File tree 2 files changed +68
-0
lines changed
main/kotlin/org/springframework/data/mongodb/core
test/kotlin/org/springframework/data/mongodb/core
2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2023 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org.springframework.data.mongodb.core
18
+
19
+ import com.mongodb.kotlin.client.MongoClient
20
+ import org.springframework.beans.DirectFieldAccessor
21
+
22
+ /* *
23
+ * Extension for [SimpleMongoClientDatabaseFactory] that accepts a [MongoClient].
24
+ *
25
+ * @author Christoph Strobl
26
+ * @since 4.2
27
+ */
28
+ fun SimpleMongoClientDatabaseFactory (client : MongoClient , database : String ): SimpleMongoClientDatabaseFactory =
29
+ SimpleMongoClientDatabaseFactory (
30
+ DirectFieldAccessor (client).getPropertyValue(" wrapped" ) as com.mongodb.client.MongoClient ,
31
+ database
32
+ )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2023 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org.springframework.data.mongodb.core
18
+
19
+ import com.mongodb.kotlin.client.MongoClient
20
+ import org.bson.Document
21
+ import org.junit.jupiter.api.Test
22
+ import org.springframework.data.mongodb.test.util.Assertions.assertThat
23
+
24
+ /* *
25
+ * @author Christoph Strobl
26
+ */
27
+ class SimpleMongoClientDatabaseFactoryExtensionTests {
28
+
29
+ @Test // GH-4393
30
+ fun `extension allows to create SimpleMongoClientDatabaseFactory with a Kotlin Driver instance` () {
31
+
32
+ val factory = SimpleMongoClientDatabaseFactory (MongoClient .create(), " test" )
33
+
34
+ assertThat(factory.mongoDatabase.runCommand(Document (" ping" , 1 ))).containsKey(" ok" )
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments