83
83
import com .mongodb .MongoException ;
84
84
import com .mongodb .MongoNamespace ;
85
85
import com .mongodb .ReadPreference ;
86
+ import com .mongodb .WriteConcern ;
86
87
import com .mongodb .client .AggregateIterable ;
87
88
import com .mongodb .client .FindIterable ;
88
89
import com .mongodb .client .MapReduceIterable ;
96
97
import com .mongodb .client .model .MapReduceAction ;
97
98
import com .mongodb .client .model .ReplaceOptions ;
98
99
import com .mongodb .client .model .UpdateOptions ;
100
+ import com .mongodb .client .result .DeleteResult ;
99
101
import com .mongodb .client .result .UpdateResult ;
100
102
101
103
/**
@@ -114,11 +116,13 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
114
116
@ Mock MongoClient mongo ;
115
117
@ Mock MongoDatabase db ;
116
118
@ Mock MongoCollection <Document > collection ;
119
+ @ Mock MongoCollection <Document > collectionWithWriteConcern ;
117
120
@ Mock MongoCursor <Document > cursor ;
118
121
@ Mock FindIterable <Document > findIterable ;
119
122
@ Mock AggregateIterable aggregateIterable ;
120
123
@ Mock MapReduceIterable mapReduceIterable ;
121
124
@ Mock UpdateResult updateResult ;
125
+ @ Mock DeleteResult deleteResult ;
122
126
123
127
Document commandResultDocument = new Document ();
124
128
@@ -141,6 +145,8 @@ public void setUp() {
141
145
when (collection .aggregate (any (List .class ), any ())).thenReturn (aggregateIterable );
142
146
when (collection .withReadPreference (any ())).thenReturn (collection );
143
147
when (collection .replaceOne (any (), any (), any (ReplaceOptions .class ))).thenReturn (updateResult );
148
+ when (collection .withWriteConcern (any ())).thenReturn (collectionWithWriteConcern );
149
+ when (collectionWithWriteConcern .deleteOne (any (Bson .class ), any ())).thenReturn (deleteResult );
144
150
when (findIterable .projection (any ())).thenReturn (findIterable );
145
151
when (findIterable .sort (any (org .bson .Document .class ))).thenReturn (findIterable );
146
152
when (findIterable .collation (any ())).thenReturn (findIterable );
@@ -731,6 +737,19 @@ public void findAndRemoveShouldUseCollationWhenPresent() {
731
737
assertThat (options .getValue ().getCollation ().getLocale (), is ("fr" ));
732
738
}
733
739
740
+ @ Test // DATAMONGO-2196
741
+ public void removeShouldApplyWriteConcern () {
742
+
743
+ Person person = new Person ();
744
+ person .id = "id-1" ;
745
+
746
+ template .setWriteConcern (WriteConcern .UNACKNOWLEDGED );
747
+ template .remove (person );
748
+
749
+ verify (collection ).withWriteConcern (eq (WriteConcern .UNACKNOWLEDGED ));
750
+ verify (collectionWithWriteConcern ).deleteOne (any (Bson .class ), any ());
751
+ }
752
+
734
753
@ Test // DATAMONGO-1518
735
754
public void findAndRemoveManyShouldUseCollationWhenPresent () {
736
755
0 commit comments