|
15 | 15 | */ |
16 | 16 | package org.socialsignin.spring.data.dynamodb.repository.support; |
17 | 17 |
|
| 18 | +import org.junit.Assert; |
18 | 19 | import org.junit.Before; |
19 | 20 | import org.junit.Test; |
20 | 21 | import org.junit.runner.RunWith; |
| 22 | +import org.mockito.ArgumentCaptor; |
21 | 23 | import org.mockito.Mock; |
22 | 24 | import org.mockito.Mockito; |
23 | 25 | import org.mockito.junit.MockitoJUnitRunner; |
|
28 | 30 | import org.springframework.dao.EmptyResultDataAccessException; |
29 | 31 |
|
30 | 32 | import java.util.Optional; |
| 33 | +import java.util.Random; |
31 | 34 |
|
32 | 35 | import static org.junit.Assert.assertEquals; |
| 36 | +import static org.mockito.ArgumentMatchers.anyLong; |
| 37 | +import static org.mockito.Mockito.verify; |
33 | 38 | import static org.mockito.Mockito.when; |
34 | 39 |
|
35 | 40 |
|
@@ -87,16 +92,32 @@ public void setUp() { |
87 | 92 | when(entityWithCompositeIdInformation.getRangeKey(testPlaylistId)).thenReturn("playlist1"); |
88 | 93 | when(entityWithCompositeIdInformation.isRangeKeyAware()).thenReturn(true); |
89 | 94 |
|
90 | | - repoForEntityWithOnlyHashKey = new SimpleDynamoDBCrudRepository<User, Long>(entityWithSimpleIdInformation, |
| 95 | + repoForEntityWithOnlyHashKey = new SimpleDynamoDBCrudRepository<>(entityWithSimpleIdInformation, |
91 | 96 | dynamoDBOperations,mockEnableScanPermissions); |
92 | | - repoForEntityWithHashAndRangeKey = new SimpleDynamoDBCrudRepository<Playlist, PlaylistId>( |
| 97 | + repoForEntityWithHashAndRangeKey = new SimpleDynamoDBCrudRepository<>( |
93 | 98 | entityWithCompositeIdInformation, dynamoDBOperations,mockEnableScanPermissions); |
94 | 99 |
|
95 | 100 | when(dynamoDBOperations.load(User.class, 1l)).thenReturn(testUser); |
96 | 101 | when(dynamoDBOperations.load(Playlist.class, "michael", "playlist1")).thenReturn(testPlaylist); |
97 | 102 |
|
98 | 103 | } |
99 | 104 |
|
| 105 | + @Test |
| 106 | + public void deleteById() { |
| 107 | + final long id = new Random().nextLong(); |
| 108 | + User testResult = new User(); |
| 109 | + testResult.setId(Long.toString(id)); |
| 110 | + |
| 111 | + when(entityWithSimpleIdInformation.getHashKey(id)).thenReturn(id); |
| 112 | + when(dynamoDBOperations.load(User.class, id)).thenReturn(testResult); |
| 113 | + |
| 114 | + repoForEntityWithOnlyHashKey.deleteById(id); |
| 115 | + |
| 116 | + ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class); |
| 117 | + Mockito.verify(dynamoDBOperations).delete(captor.capture()); |
| 118 | + Assert.assertEquals(Long.toString(id), captor.getValue().getId()); |
| 119 | + } |
| 120 | + |
100 | 121 | /** |
101 | 122 | * @see DATAJPA-177 |
102 | 123 | */ |
|
0 commit comments