@@ -421,4 +421,101 @@ void testAutoIdWithTwoSameSubnodesWithSameIdSameNode(
421421 }
422422 );
423423 }
424+
425+ @ Test
426+ void testReplaceWithId (@ Autowired final CustomerWithIdIntegerNoAutoGenerateRepository customerRepository )
427+ {
428+ final CustomerWithIdIntegerNoAutoGenerate existingCustomer =
429+ new CustomerWithIdIntegerNoAutoGenerate (1 , TestData .FIRST_NAME , TestData .LAST_NAME );
430+ customerRepository .save (existingCustomer );
431+
432+ final CustomerWithIdIntegerNoAutoGenerate newCustomer =
433+ new CustomerWithIdIntegerNoAutoGenerate (1 , TestData .FIRST_NAME_ALTERNATIVE ,
434+ TestData .LAST_NAME_ALTERNATIVE );
435+ customerRepository .save (newCustomer );
436+
437+ TestUtil .doBeforeAndAfterRestartOfDatastore (
438+ this .configuration ,
439+ () -> {
440+ final List <CustomerWithIdIntegerNoAutoGenerate > loadedCustomer =
441+ TestUtil .iterableToList (customerRepository .findAll ());
442+
443+ Assertions .assertEquals (1 , loadedCustomer .size ());
444+ Assertions .assertEquals (TestData .FIRST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getFirstName ());
445+ Assertions .assertEquals (TestData .LAST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getLastName ());
446+ }
447+ );
448+ }
449+
450+ @ Test
451+ void testReplaceWithAutoId (@ Autowired final CustomerWithIdIntegerRepository customerRepository )
452+ {
453+ final CustomerWithIdInteger existingCustomer =
454+ new CustomerWithIdInteger (TestData .FIRST_NAME , TestData .LAST_NAME );
455+ customerRepository .save (existingCustomer );
456+ final Integer existingId = customerRepository .findAll ().iterator ().next ().getId ();
457+
458+ final CustomerWithIdInteger newCustomer = new CustomerWithIdInteger (existingId ,
459+ TestData .FIRST_NAME_ALTERNATIVE ,
460+ TestData .LAST_NAME_ALTERNATIVE );
461+ customerRepository .save (newCustomer );
462+
463+ TestUtil .doBeforeAndAfterRestartOfDatastore (
464+ this .configuration ,
465+ () -> {
466+ final List <CustomerWithIdInteger > loadedCustomer =
467+ TestUtil .iterableToList (customerRepository .findAll ());
468+
469+ Assertions .assertEquals (1 , loadedCustomer .size ());
470+ Assertions .assertEquals (TestData .FIRST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getFirstName ());
471+ Assertions .assertEquals (TestData .LAST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getLastName ());
472+ }
473+ );
474+ }
475+
476+ @ Test
477+ void testReplaceWithIdSaveAll (@ Autowired final CustomerWithIdIntegerNoAutoGenerateRepository customerRepository )
478+ {
479+ final CustomerWithIdIntegerNoAutoGenerate existingCustomer =
480+ new CustomerWithIdIntegerNoAutoGenerate (1 , TestData .FIRST_NAME , TestData .LAST_NAME );
481+ final CustomerWithIdIntegerNoAutoGenerate newCustomer =
482+ new CustomerWithIdIntegerNoAutoGenerate (1 , TestData .FIRST_NAME_ALTERNATIVE ,
483+ TestData .LAST_NAME_ALTERNATIVE );
484+ customerRepository .saveAll (List .of (existingCustomer , newCustomer ));
485+
486+ TestUtil .doBeforeAndAfterRestartOfDatastore (
487+ this .configuration ,
488+ () -> {
489+ final List <CustomerWithIdIntegerNoAutoGenerate > loadedCustomer =
490+ TestUtil .iterableToList (customerRepository .findAll ());
491+
492+ Assertions .assertEquals (1 , loadedCustomer .size ());
493+ Assertions .assertEquals (TestData .FIRST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getFirstName ());
494+ Assertions .assertEquals (TestData .LAST_NAME_ALTERNATIVE , loadedCustomer .get (0 ).getLastName ());
495+ }
496+ );
497+ }
498+
499+ @ Test
500+ void testAddTwoWithId (@ Autowired final CustomerWithIdIntegerNoAutoGenerateRepository customerRepository )
501+ {
502+ final CustomerWithIdIntegerNoAutoGenerate existingCustomer =
503+ new CustomerWithIdIntegerNoAutoGenerate (1 , TestData .FIRST_NAME , TestData .LAST_NAME );
504+ customerRepository .save (existingCustomer );
505+
506+ final CustomerWithIdIntegerNoAutoGenerate newCustomer =
507+ new CustomerWithIdIntegerNoAutoGenerate (2 , TestData .FIRST_NAME_ALTERNATIVE ,
508+ TestData .LAST_NAME_ALTERNATIVE );
509+ customerRepository .save (newCustomer );
510+
511+ TestUtil .doBeforeAndAfterRestartOfDatastore (
512+ this .configuration ,
513+ () -> {
514+ final List <CustomerWithIdIntegerNoAutoGenerate > loadedCustomer =
515+ TestUtil .iterableToList (customerRepository .findAll ());
516+
517+ Assertions .assertEquals (2 , loadedCustomer .size ());
518+ }
519+ );
520+ }
424521}
0 commit comments