@@ -549,42 +549,23 @@ public void testReplaceOne() {
549
549
550
550
DbDoc doc = this .collection .getOne ("existingId" );
551
551
assertNotNull (doc );
552
- assertEquals (new Integer ( 2 ) , ((JsonNumber ) doc .get ("a" )).getInteger ());
552
+ assertEquals (2 , ((JsonNumber ) doc .get ("a" )).getInteger ());
553
553
554
- res = this .collection .replaceOne ("notExistingId" , "{\" _id\" :\" existingId\" ,\" a\" :3}" );
555
- assertEquals (0 , res .getAffectedItemsCount ());
556
-
557
- res = this .collection .replaceOne ("" , "{\" _id\" :\" existingId\" ,\" a\" :3}" );
558
- assertEquals (0 , res .getAffectedItemsCount ());
559
-
560
- /*
561
- * FR5.1 The id of the document must remain immutable:
562
- *
563
- * Use a collection with some documents
564
- * Fetch a document
565
- * Modify _id: _new_id_ and modify any other field of the document
566
- * Call replaceOne() giving original ID and modified document: expect affected = 1
567
- * Fetch the document again, ensure other document modifications took place
568
- * Ensure no document with _new_id_ was added to the collection
569
- */
570
- this .collection .remove ("1=1" ).execute ();
571
- assertEquals (0 , this .collection .count ());
572
- this .collection .add ("{\" _id\" :\" id1\" ,\" a\" :1}" ).execute ();
573
-
574
- doc = this .collection .getOne ("id1" );
575
- assertNotNull (doc );
576
- ((JsonString ) doc .get ("_id" )).setValue ("id2" );
577
- ((JsonNumber ) doc .get ("a" )).setValue ("2" );
578
- res = this .collection .replaceOne ("id1" , doc );
579
- assertEquals (1 , res .getAffectedItemsCount ());
580
-
581
- doc = this .collection .getOne ("id1" );
582
- assertNotNull (doc );
583
- assertEquals ("id1" , ((JsonString ) doc .get ("_id" )).getString ());
584
- assertEquals (new Integer (2 ), ((JsonNumber ) doc .get ("a" )).getInteger ());
554
+ // Original behavior changed by Bug#32770013.
555
+ assertThrows (XDevAPIError .class , "Replacement document has an _id that is different than the matched document\\ ." , new Callable <Void >() {
556
+ public Void call () throws Exception {
557
+ CollectionModifyTest .this .collection .replaceOne ("nonExistingId" , "{\" _id\" :\" existingId\" ,\" a\" :3}" );
558
+ return null ;
559
+ }
560
+ });
585
561
586
- doc = this .collection .getOne ("id2" );
587
- assertNull (doc );
562
+ // Original behavior changed by Bug#32770013.
563
+ assertThrows (XDevAPIError .class , "Replacement document has an _id that is different than the matched document\\ ." , new Callable <Void >() {
564
+ public Void call () throws Exception {
565
+ CollectionModifyTest .this .collection .replaceOne ("" , "{\" _id\" :\" existingId\" ,\" a\" :3}" );
566
+ return null ;
567
+ }
568
+ });
588
569
589
570
/*
590
571
* FR5.2 The id of the document must remain immutable:
@@ -596,6 +577,10 @@ public void testReplaceOne() {
596
577
* Fetch the document again, ensure other document modifications took place
597
578
* Ensure the number of documents in the collection is unaltered
598
579
*/
580
+ this .collection .remove ("true" ).execute ();
581
+ assertEquals (0 , this .collection .count ());
582
+ this .collection .add ("{\" _id\" :\" id1\" ,\" a\" :1}" ).execute ();
583
+
599
584
doc = this .collection .getOne ("id1" );
600
585
assertNotNull (doc );
601
586
doc .remove ("_id" );
0 commit comments