1
+ /*
2
+ * Copyright (C) 2017/2019 Litote
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
+ * http://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.litote.kmongo.issues
18
+
19
+ import com.fasterxml.jackson.annotation.JsonIdentityInfo
20
+ import com.fasterxml.jackson.annotation.JsonIdentityReference
21
+ import com.fasterxml.jackson.annotation.ObjectIdGenerators
22
+ import org.junit.Test
23
+ import org.litote.kmongo.AllCategoriesKMongoBaseTest
24
+ import org.litote.kmongo.findOne
25
+ import org.litote.kmongo.save
26
+ import java.util.Collections
27
+ import kotlin.test.assertEquals
28
+
29
+ /* *
30
+ *
31
+ */
32
+ class Issue136WriteObjectRef : AllCategoriesKMongoBaseTest <Issue136WriteObjectRef .Data >() {
33
+
34
+ class Data (val entries : List <Entry >)
35
+
36
+ @JsonIdentityInfo(generator = ObjectIdGenerators .PropertyGenerator ::class , property = " uri" )
37
+ class Entry () {
38
+
39
+ constructor (uri: String ) : this () {
40
+ this .uri = uri
41
+ }
42
+
43
+ lateinit var uri: String
44
+
45
+ @JsonIdentityReference(alwaysAsId = true )
46
+ var contains: MutableSet <Entry > = Collections .synchronizedSet(HashSet ())
47
+
48
+ }
49
+
50
+ @Test
51
+ fun saveWithWriteObjectRefDoesNotFail () {
52
+ val entry = Entry (" http://litote.org/kmongo" )
53
+ col.save(Data (listOf (entry, entry)))
54
+ val data2 = col.findOne()
55
+ assertEquals(2 , data2!! .entries.size)
56
+ assertEquals(entry.uri, data2.entries.first().uri)
57
+ assertEquals(entry.uri, data2.entries.last().uri)
58
+ }
59
+ }
0 commit comments