43
43
import static org .assertj .core .api .Assertions .assertThat ;
44
44
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
45
45
import static org .mockito .ArgumentMatchers .anyLong ;
46
- import static org .mockito .ArgumentMatchers .anyString ;
47
46
import static org .mockito .ArgumentMatchers .eq ;
48
47
import static org .mockito .ArgumentMatchers .isA ;
49
48
import static org .mockito .ArgumentMatchers .startsWith ;
50
49
import static org .mockito .BDDMockito .given ;
51
50
import static org .mockito .Mockito .atLeastOnce ;
52
51
import static org .mockito .Mockito .mock ;
53
- import static org .mockito .Mockito .never ;
54
52
import static org .mockito .Mockito .times ;
55
53
import static org .mockito .Mockito .verify ;
56
54
import static org .mockito .Mockito .verifyZeroInteractions ;
59
57
* Tests for {@link JdbcOperationsSessionRepository}.
60
58
*
61
59
* @author Vedran Pavic
60
+ * @author Craig Andrews
62
61
* @since 1.2.0
63
62
*/
64
63
public class JdbcOperationsSessionRepositoryTests {
@@ -340,23 +339,6 @@ public void saveUpdatedAddSingleAttribute() {
340
339
verifyZeroInteractions (this .jdbcOperations );
341
340
}
342
341
343
- @ Test
344
- public void saveUpdatedAddSingleAttributeSetTwice () {
345
- JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
346
- new MapSession ());
347
- session .setAttribute ("testName" , "testValue" );
348
- session .setAttribute ("testName" , "testValue" );
349
-
350
- this .repository .save (session );
351
-
352
- assertThat (session .isNew ()).isFalse ();
353
- assertPropagationRequiresNew ();
354
- verify (this .jdbcOperations , times (1 )).update (
355
- startsWith ("INSERT INTO SPRING_SESSION_ATTRIBUTES(" ),
356
- isA (PreparedStatementSetter .class ));
357
- verifyZeroInteractions (this .jdbcOperations );
358
- }
359
-
360
342
@ Test
361
343
public void saveUpdatedAddMultipleAttributes () {
362
344
JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
@@ -430,6 +412,19 @@ public void saveUpdatedRemoveSingleAttribute() {
430
412
verifyZeroInteractions (this .jdbcOperations );
431
413
}
432
414
415
+ @ Test
416
+ public void saveUpdatedRemoveNonExistingAttribute () {
417
+ JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
418
+ new MapSession ());
419
+ session .removeAttribute ("testName" );
420
+
421
+ this .repository .save (session );
422
+
423
+ assertThat (session .isNew ()).isFalse ();
424
+ assertPropagationRequiresNew ();
425
+ verifyZeroInteractions (this .jdbcOperations );
426
+ }
427
+
433
428
@ Test
434
429
public void saveUpdatedRemoveMultipleAttributes () {
435
430
JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
@@ -450,56 +445,70 @@ public void saveUpdatedRemoveMultipleAttributes() {
450
445
verifyZeroInteractions (this .jdbcOperations );
451
446
}
452
447
453
- @ Test
454
- public void saveUpdatedAddThenRemoveSingleAttribute () {
448
+ @ Test // gh-1070
449
+ public void saveUpdatedAddAndModifyAttribute () {
455
450
JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
456
451
new MapSession ());
457
- session .setAttribute ("testName" , "testValue " );
458
- session .removeAttribute ("testName" );
452
+ session .setAttribute ("testName" , "testValue1 " );
453
+ session .setAttribute ("testName" , "testValue2 " );
459
454
460
455
this .repository .save (session );
461
456
462
457
assertThat (session .isNew ()).isFalse ();
463
458
assertPropagationRequiresNew ();
464
- verify (this .jdbcOperations , never () ).update (
465
- anyString ( ),
459
+ verify (this .jdbcOperations ).update (
460
+ startsWith ( "INSERT INTO SPRING_SESSION_ATTRIBUTES(" ),
466
461
isA (PreparedStatementSetter .class ));
467
462
verifyZeroInteractions (this .jdbcOperations );
468
463
}
469
464
470
- @ Test
471
- public void saveUpdatedModifyThenRemoveSingleAttribute () {
465
+ @ Test // gh-1070
466
+ public void saveUpdatedAddAndRemoveAttribute () {
472
467
JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
473
468
new MapSession ());
474
469
session .setAttribute ("testName" , "testValue" );
470
+ session .removeAttribute ("testName" );
471
+
472
+ this .repository .save (session );
473
+
474
+ assertThat (session .isNew ()).isFalse ();
475
+ assertPropagationRequiresNew ();
476
+ verifyZeroInteractions (this .jdbcOperations );
477
+ }
478
+
479
+ @ Test // gh-1070
480
+ public void saveUpdatedModifyAndRemoveAttribute () {
481
+ JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
482
+ new MapSession ());
483
+ session .setAttribute ("testName" , "testValue1" );
475
484
session .clearChangeFlags ();
476
- session .setAttribute ("testName" , "testValueModifed " );
485
+ session .setAttribute ("testName" , "testValue2 " );
477
486
session .removeAttribute ("testName" );
478
487
479
488
this .repository .save (session );
480
489
481
490
assertThat (session .isNew ()).isFalse ();
482
491
assertPropagationRequiresNew ();
483
- verify (this .jdbcOperations , times ( 1 ) ).update (
492
+ verify (this .jdbcOperations ).update (
484
493
startsWith ("DELETE FROM SPRING_SESSION_ATTRIBUTES WHERE" ),
485
494
isA (PreparedStatementSetter .class ));
486
495
verifyZeroInteractions (this .jdbcOperations );
487
496
}
488
497
489
- @ Test
490
- public void saveUpdatedRemoveThenModifySingleAttribute () {
498
+ @ Test // gh-1070
499
+ public void saveUpdatedRemoveAndAddAttribute () {
491
500
JdbcOperationsSessionRepository .JdbcSession session = this .repository .new JdbcSession ("primaryKey" ,
492
501
new MapSession ());
493
- session .setAttribute ("testName" , "testValue " );
502
+ session .setAttribute ("testName" , "testValue1 " );
494
503
session .clearChangeFlags ();
495
504
session .removeAttribute ("testName" );
496
- session .setAttribute ("testName" , "testValueModifed " );
505
+ session .setAttribute ("testName" , "testValue2 " );
497
506
498
507
this .repository .save (session );
499
508
500
509
assertThat (session .isNew ()).isFalse ();
501
510
assertPropagationRequiresNew ();
502
- verify (this .jdbcOperations , times ( 1 ) ).update (
511
+ verify (this .jdbcOperations ).update (
503
512
startsWith ("UPDATE SPRING_SESSION_ATTRIBUTES SET" ),
504
513
isA (PreparedStatementSetter .class ));
505
514
verifyZeroInteractions (this .jdbcOperations );
0 commit comments