|
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; |
46 | 47 | import static org.mockito.ArgumentMatchers.eq;
|
47 | 48 | import static org.mockito.ArgumentMatchers.isA;
|
48 | 49 | import static org.mockito.ArgumentMatchers.startsWith;
|
49 | 50 | import static org.mockito.BDDMockito.given;
|
50 | 51 | import static org.mockito.Mockito.atLeastOnce;
|
51 | 52 | import static org.mockito.Mockito.mock;
|
| 53 | +import static org.mockito.Mockito.never; |
52 | 54 | import static org.mockito.Mockito.times;
|
53 | 55 | import static org.mockito.Mockito.verify;
|
54 | 56 | import static org.mockito.Mockito.verifyZeroInteractions;
|
@@ -338,6 +340,23 @@ public void saveUpdatedAddSingleAttribute() {
|
338 | 340 | verifyZeroInteractions(this.jdbcOperations);
|
339 | 341 | }
|
340 | 342 |
|
| 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 | + |
341 | 360 | @Test
|
342 | 361 | public void saveUpdatedAddMultipleAttributes() {
|
343 | 362 | JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey",
|
@@ -431,6 +450,61 @@ public void saveUpdatedRemoveMultipleAttributes() {
|
431 | 450 | verifyZeroInteractions(this.jdbcOperations);
|
432 | 451 | }
|
433 | 452 |
|
| 453 | + @Test |
| 454 | + public void saveUpdatedAddThenRemoveSingleAttribute() { |
| 455 | + JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", |
| 456 | + new MapSession()); |
| 457 | + session.setAttribute("testName", "testValue"); |
| 458 | + session.removeAttribute("testName"); |
| 459 | + |
| 460 | + this.repository.save(session); |
| 461 | + |
| 462 | + assertThat(session.isNew()).isFalse(); |
| 463 | + assertPropagationRequiresNew(); |
| 464 | + verify(this.jdbcOperations, never()).update( |
| 465 | + anyString(), |
| 466 | + isA(PreparedStatementSetter.class)); |
| 467 | + verifyZeroInteractions(this.jdbcOperations); |
| 468 | + } |
| 469 | + |
| 470 | + @Test |
| 471 | + public void saveUpdatedModifyThenRemoveSingleAttribute() { |
| 472 | + JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", |
| 473 | + new MapSession()); |
| 474 | + session.setAttribute("testName", "testValue"); |
| 475 | + session.clearChangeFlags(); |
| 476 | + session.setAttribute("testName", "testValueModifed"); |
| 477 | + session.removeAttribute("testName"); |
| 478 | + |
| 479 | + this.repository.save(session); |
| 480 | + |
| 481 | + assertThat(session.isNew()).isFalse(); |
| 482 | + assertPropagationRequiresNew(); |
| 483 | + verify(this.jdbcOperations, times(1)).update( |
| 484 | + startsWith("DELETE FROM SPRING_SESSION_ATTRIBUTES WHERE"), |
| 485 | + isA(PreparedStatementSetter.class)); |
| 486 | + verifyZeroInteractions(this.jdbcOperations); |
| 487 | + } |
| 488 | + |
| 489 | + @Test |
| 490 | + public void saveUpdatedRemoveThenModifySingleAttribute() { |
| 491 | + JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey", |
| 492 | + new MapSession()); |
| 493 | + session.setAttribute("testName", "testValue"); |
| 494 | + session.clearChangeFlags(); |
| 495 | + session.removeAttribute("testName"); |
| 496 | + session.setAttribute("testName", "testValueModifed"); |
| 497 | + |
| 498 | + this.repository.save(session); |
| 499 | + |
| 500 | + assertThat(session.isNew()).isFalse(); |
| 501 | + assertPropagationRequiresNew(); |
| 502 | + verify(this.jdbcOperations, times(1)).update( |
| 503 | + startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"), |
| 504 | + isA(PreparedStatementSetter.class)); |
| 505 | + verifyZeroInteractions(this.jdbcOperations); |
| 506 | + } |
| 507 | + |
434 | 508 | @Test
|
435 | 509 | public void saveUpdatedLastAccessedTime() {
|
436 | 510 | JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey",
|
|
0 commit comments