@@ -56,6 +56,8 @@ class WriteModelStrategyTest {
56
56
new ReplaceOneDefaultStrategy ();
57
57
private static final ReplaceOneBusinessKeyStrategy REPLACE_ONE_BUSINESS_KEY_STRATEGY =
58
58
new ReplaceOneBusinessKeyStrategy ();
59
+ private static final UpdateOneDefaultStrategy UPDATE_ONE_DEFAULT_STRATEGY =
60
+ new UpdateOneDefaultStrategy ();
59
61
private static final UpdateOneTimestampsStrategy UPDATE_ONE_TIMESTAMPS_STRATEGY =
60
62
new UpdateOneTimestampsStrategy ();
61
63
private static final UpdateOneBusinessKeyTimestampStrategy
@@ -231,6 +233,31 @@ void testReplaceOneBusinessKeyStrategyPartialWithValidSinkDocument() {
231
233
"replacement expected to be done in upsert mode" );
232
234
}
233
235
236
+ @ Test
237
+ @ DisplayName (
238
+ "when sink document is valid for UpdateOneDefaultStrategy then correct UpdateOneModel" )
239
+ void testUpdateOneDefaultStrategyWithValidSinkDocument () {
240
+ WriteModel <BsonDocument > result =
241
+ UPDATE_ONE_DEFAULT_STRATEGY .createWriteModel (new SinkDocument (null , VALUE_DOC .clone ()));
242
+ assertTrue (result instanceof UpdateOneModel , "result expected to be of type UpdateOneModel" );
243
+
244
+ UpdateOneModel <BsonDocument > writeModel = (UpdateOneModel <BsonDocument >) result ;
245
+
246
+ BsonDocument setValuesDocument = VALUE_DOC .clone ();
247
+ setValuesDocument .remove ("_id" );
248
+ BsonDocument expectedSetDocument = new BsonDocument ("$set" , setValuesDocument );
249
+
250
+ assertEquals (
251
+ expectedSetDocument ,
252
+ writeModel .getUpdate (),
253
+ "replacement doc not matching what is expected" );
254
+ assertTrue (
255
+ writeModel .getFilter () instanceof BsonDocument ,
256
+ "filter expected to be of type BsonDocument" );
257
+ assertEquals (ID_FILTER , writeModel .getFilter ());
258
+ assertTrue (writeModel .getOptions ().isUpsert (), "update expected to be done in upsert mode" );
259
+ }
260
+
234
261
@ Test
235
262
@ DisplayName (
236
263
"when sink document is valid for UpdateOneTimestampsStrategy then correct UpdateOneModel" )
@@ -412,6 +439,10 @@ void testIEmptyOrMissingSinkDocumentData() {
412
439
() ->
413
440
REPLACE_ONE_BUSINESS_KEY_PARTIAL_STRATEGY .createWriteModel (
414
441
SINK_DOCUMENT_EMPTY )),
442
+ () ->
443
+ assertThrows (
444
+ DataException .class ,
445
+ () -> UPDATE_ONE_DEFAULT_STRATEGY .createWriteModel (SINK_DOCUMENT_EMPTY )),
415
446
() ->
416
447
assertThrows (
417
448
DataException .class ,
0 commit comments