28
28
@ DomainModel (annotatedClasses = Book .class )
29
29
class DeletionIntegrationTests extends AbstractMutationQueryIntegrationTests {
30
30
31
- @ InjectMongoCollection (Book .COLLECTION_NAME )
31
+ @ InjectMongoCollection (Book .COLLECTION )
32
32
private static MongoCollection <BsonDocument > mongoCollection ;
33
33
34
34
private static final List <Book > testingBooks = List .of (
35
- new Book (1 , "War and Peace" , 1869 ),
36
- new Book (2 , "Crime and Punishment" , 1866 ),
37
- new Book (3 , "Anna Karenina" , 1877 ),
38
- new Book (4 , "The Brothers Karamazov" , 1880 ),
39
- new Book (5 , "War and Peace" , 2025 ));
35
+ new Book (1 , "War and Peace" , 1869 , true ),
36
+ new Book (2 , "Crime and Punishment" , 1866 , false ),
37
+ new Book (3 , "Anna Karenina" , 1877 , false ),
38
+ new Book (4 , "The Brothers Karamazov" , 1880 , false ),
39
+ new Book (5 , "War and Peace" , 2025 , false ));
40
40
41
41
@ BeforeEach
42
42
void beforeEach () {
@@ -45,71 +45,154 @@ void beforeEach() {
45
45
}
46
46
47
47
@ Test
48
- void testSimpleDeletion () {
49
- getSessionFactoryScope ()
50
- .inTransaction (
51
- session -> assertMutationQuery (
52
- "delete from Book where title = :title" ,
53
- q -> q .setParameter ("title" , "War and Peace" ),
54
- 2 ,
48
+ void testDeletionWithNonZeroMutationCount () {
49
+ assertMutationQuery (
50
+ "delete from Book where title = :title" ,
51
+ q -> q .setParameter ("title" , "War and Peace" ),
52
+ 2 ,
53
+ """
54
+ {
55
+ "delete": "books",
56
+ "deletes": [
57
+ {
58
+ "limit": 0,
59
+ "q": {
60
+ "title": {
61
+ "$eq": "War and Peace"
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ """ ,
68
+ mongoCollection ,
69
+ List .of (
70
+ BsonDocument .parse (
71
+ """
72
+ {
73
+ "_id": 2,
74
+ "title": "Crime and Punishment",
75
+ "outOfStock": false,
76
+ "publishYear": 1866,
77
+ "isbn13": {"$numberLong": "0"},
78
+ "discount": {"$numberDouble": "0"},
79
+ "price": {"$numberDecimal": "0.0"}
80
+ }
81
+ """ ),
82
+ BsonDocument .parse (
83
+ """
84
+ {
85
+ "_id": 3,
86
+ "title": "Anna Karenina",
87
+ "outOfStock": false,
88
+ "publishYear": 1877,
89
+ "isbn13": {"$numberLong": "0"},
90
+ "discount": {"$numberDouble": "0"},
91
+ "price": {"$numberDecimal": "0.0"}
92
+ }
93
+ """ ),
94
+ BsonDocument .parse (
95
+ """
96
+ {
97
+ "_id": 4,
98
+ "title": "The Brothers Karamazov",
99
+ "outOfStock": false,
100
+ "publishYear": 1880,
101
+ "isbn13": {"$numberLong": "0"},
102
+ "discount": {"$numberDouble": "0"},
103
+ "price": {"$numberDecimal": "0.0"}
104
+ }
105
+ """ )));
106
+ }
107
+
108
+ @ Test
109
+ void testDeletionWithZeroMutationCount () {
110
+ assertMutationQuery (
111
+ "delete from Book where publishYear < :year" ,
112
+ q -> q .setParameter ("year" , 1850 ),
113
+ 0 ,
114
+ """
115
+ {
116
+ "delete": "books",
117
+ "deletes": [
118
+ {
119
+ "limit": 0,
120
+ "q": {
121
+ "publishYear": {
122
+ "$lt": 1850
123
+ }
124
+ }
125
+ }
126
+ ]
127
+ }
128
+ """ ,
129
+ mongoCollection ,
130
+ List .of (
131
+ BsonDocument .parse (
132
+ """
133
+ {
134
+ "_id": 1,
135
+ "title": "War and Peace",
136
+ "outOfStock": true,
137
+ "publishYear": 1869,
138
+ "isbn13": {"$numberLong": "0"},
139
+ "discount": {"$numberDouble": "0"},
140
+ "price": {"$numberDecimal": "0.0"}
141
+ }
142
+ """ ),
143
+ BsonDocument .parse (
144
+ """
145
+ {
146
+ "_id": 2,
147
+ "title": "Crime and Punishment",
148
+ "outOfStock": false,
149
+ "publishYear": 1866,
150
+ "isbn13": {"$numberLong": "0"},
151
+ "discount": {"$numberDouble": "0"},
152
+ "price": {"$numberDecimal": "0.0"}
153
+ }
154
+ """ ),
155
+ BsonDocument .parse (
156
+ """
157
+ {
158
+ "_id": 3,
159
+ "title": "Anna Karenina",
160
+ "outOfStock": false,
161
+ "publishYear": 1877,
162
+ "isbn13": {"$numberLong": "0"},
163
+ "discount": {"$numberDouble": "0"},
164
+ "price": {"$numberDecimal": "0.0"}
165
+ }
166
+ """ ),
167
+ BsonDocument .parse (
168
+ """
169
+ {
170
+ "_id": 4,
171
+ "title": "The Brothers Karamazov",
172
+ "outOfStock": false,
173
+ "publishYear": 1880,
174
+ "isbn13": {"$numberLong": "0"},
175
+ "discount": {"$numberDouble": "0"},
176
+ "price": {"$numberDecimal": "0.0"}
177
+ }
178
+ """ ),
179
+ BsonDocument .parse (
55
180
"""
56
181
{
57
- "delete": "books",
58
- "deletes": [
59
- {
60
- "limit": 0,
61
- "q": {
62
- "title": {
63
- "$eq": "War and Peace"
64
- }
65
- }
66
- }
67
- ]
182
+ "_id": 5,
183
+ "title": "War and Peace",
184
+ "outOfStock": false,
185
+ "publishYear": 2025,
186
+ "isbn13": {"$numberLong": "0"},
187
+ "discount": {"$numberDouble": "0"},
188
+ "price": {"$numberDecimal": "0.0"}
68
189
}
69
- """ ,
70
- mongoCollection ,
71
- List .of (
72
- BsonDocument .parse (
73
- """
74
- {
75
- "_id": 2,
76
- "title": "Crime and Punishment",
77
- "outOfStock": false,
78
- "publishYear": 1866,
79
- "isbn13": {"$numberLong": "0"},
80
- "discount": {"$numberDouble": "0"},
81
- "price": {"$numberDecimal": "0.0"}
82
- }
83
- """ ),
84
- BsonDocument .parse (
85
- """
86
- {
87
- "_id": 3,
88
- "title": "Anna Karenina",
89
- "outOfStock": false,
90
- "publishYear": 1877,
91
- "isbn13": {"$numberLong": "0"},
92
- "discount": {"$numberDouble": "0"},
93
- "price": {"$numberDecimal": "0.0"}
94
- }
95
- """ ),
96
- BsonDocument .parse (
97
- """
98
- {
99
- "_id": 4,
100
- "title": "The Brothers Karamazov",
101
- "outOfStock": false,
102
- "publishYear": 1880,
103
- "isbn13": {"$numberLong": "0"},
104
- "discount": {"$numberDouble": "0"},
105
- "price": {"$numberDecimal": "0.0"}
106
- }
107
- """ ))));
190
+ """ )));
108
191
}
109
192
110
193
@ Test
111
- void testAffectedTableNames () {
112
- assertAffectedTableNames (
194
+ void testAffectedTable () {
195
+ assertAffectedTable (
113
196
"""
114
197
delete from Book where title = :title
115
198
""" ,
0 commit comments