15
15
*/
16
16
package org .springframework .data .gemfire .repository .support ;
17
17
18
- import static org .assertj .core .api .Assertions .assertThat ;
18
+ import static java .util .Arrays .*;
19
+ import static org .assertj .core .api .Assertions .*;
19
20
20
- import java .util .Arrays ;
21
21
import java .util .Collections ;
22
22
import java .util .List ;
23
23
24
24
import javax .annotation .Resource ;
25
25
26
- import org .junit .Before ;
27
- import org .junit .Test ;
28
- import org .junit .runner .RunWith ;
29
-
30
26
import org .apache .geode .cache .GemFireCache ;
31
27
import org .apache .geode .cache .Region ;
32
28
import org .apache .geode .cache .RegionEvent ;
33
29
import org .apache .geode .cache .query .SelectResults ;
34
30
import org .apache .geode .cache .util .CacheListenerAdapter ;
35
-
31
+ import org .junit .Before ;
32
+ import org .junit .Test ;
33
+ import org .junit .runner .RunWith ;
36
34
import org .springframework .beans .factory .annotation .Autowired ;
37
35
import org .springframework .context .annotation .Bean ;
38
36
import org .springframework .data .domain .Page ;
54
52
*
55
53
* @author Oliver Gierke
56
54
* @author John Blum
55
+ * @author Jens Schauder
57
56
* @see org.junit.Test
58
57
* @see org.apache.geode.cache.GemFireCache
59
58
* @see org.apache.geode.cache.Region
@@ -71,11 +70,9 @@ public class SimpleGemfireRepositoryIntegrationTests {
71
70
72
71
static final String GEMFIRE_LOG_LEVEL = "warning" ;
73
72
74
- @ Autowired
75
- private GemfireTemplate template ;
73
+ @ Autowired private GemfireTemplate template ;
76
74
77
- @ Resource (name = "People" )
78
- private Region <?, ?> people ;
75
+ @ Resource (name = "People" ) private Region <?, ?> people ;
79
76
80
77
private RegionClearListener regionClearListener ;
81
78
@@ -91,8 +88,8 @@ public void setUp() {
91
88
92
89
GemfireMappingContext mappingContext = new GemfireMappingContext ();
93
90
94
- GemfirePersistentEntity <Person > personEntity =
95
- ( GemfirePersistentEntity < Person >) mappingContext .getPersistentEntity (Person .class );
91
+ GemfirePersistentEntity <Person > personEntity = ( GemfirePersistentEntity < Person >) mappingContext
92
+ .getPersistentEntity (Person .class );
96
93
97
94
EntityInformation <Person , Long > information = new PersistentEntityInformation <>(personEntity );
98
95
@@ -114,22 +111,16 @@ public void findAllPaged() {
114
111
115
112
assertThat (this .repository .count ()).isEqualTo (0 );
116
113
117
- List <Person > people = Arrays .asList (
118
- new Person (1L , "Jon" , "Doe" ),
119
- new Person (2L , "Jane" , "Doe" ),
120
- new Person (3L , "Cookie" , "Doe" ),
121
- new Person (4L , "Pie" , "Doe" ),
122
- new Person (5L , "Sour" , "Doe" )
123
- );
114
+ List <Person > people = asList (new Person (1L , "Jon" , "Doe" ), new Person (2L , "Jane" , "Doe" ),
115
+ new Person (3L , "Cookie" , "Doe" ), new Person (4L , "Pie" , "Doe" ), new Person (5L , "Sour" , "Doe" ));
124
116
125
117
people .forEach (person -> this .template .put (person .getId (), person ));
126
118
127
119
assertThat (this .repository .count ()).isEqualTo (5 );
128
120
129
121
Sort orderByFirstNameAscending = Sort .by ("firstname" ).ascending ();
130
122
131
- Page <Person > pageOne =
132
- this .repository .findAll (PageRequest .of (0 , 3 , orderByFirstNameAscending ));
123
+ Page <Person > pageOne = this .repository .findAll (PageRequest .of (0 , 3 , orderByFirstNameAscending ));
133
124
134
125
assertThat (pageOne ).isNotNull ();
135
126
assertThat (pageOne ).isNotEmpty ();
@@ -141,8 +132,7 @@ public void findAllPaged() {
141
132
assertThat (pageOne .getTotalPages ()).isEqualTo (2 );
142
133
assertThat (pageOne .getContent ()).containsExactly (people .get (2 ), people .get (1 ), people .get (0 ));
143
134
144
- Page <Person > pageTwo =
145
- this .repository .findAll (PageRequest .of (1 , 3 , Sort .by ("firstname" ).ascending ()));
135
+ Page <Person > pageTwo = this .repository .findAll (PageRequest .of (1 , 3 , Sort .by ("firstname" ).ascending ()));
146
136
147
137
assertThat (pageTwo ).isNotNull ();
148
138
assertThat (pageTwo ).isNotEmpty ();
@@ -166,17 +156,17 @@ public void findAllWithIds() {
166
156
this .template .put (carter .getId (), carter );
167
157
this .template .put (leroi .getId (), leroi );
168
158
169
- Iterable <Person > result = this .repository .findAllById (Arrays . asList (carter .getId (), leroi .getId ()));
159
+ Iterable <Person > result = this .repository .findAllById (asList (carter .getId (), leroi .getId ()));
170
160
171
161
assertThat (result ).isNotNull ();
172
162
assertThat (result ).hasSize (2 );
173
- assertThat (result ).containsAll (Arrays . asList (carter , leroi ));
163
+ assertThat (result ).containsAll (asList (carter , leroi ));
174
164
}
175
165
176
166
@ Test
177
167
public void findAllWithIdsReturnsNoMatches () {
178
168
179
- Iterable <Person > results = this .repository .findAllById (Arrays . asList (1L , 2L ));
169
+ Iterable <Person > results = this .repository .findAllById (asList (1L , 2L ));
180
170
181
171
assertThat (results ).isNotNull ();
182
172
assertThat (results ).isEmpty ();
@@ -192,7 +182,7 @@ public void findAllWithIdsReturnsPartialMatches() {
192
182
this .template .put (kurt .getId (), kurt );
193
183
this .template .put (eddie .getId (), eddie );
194
184
195
- Iterable <Person > results = this .repository .findAllById (Arrays . asList (0L , 1L , 2L , 4L ));
185
+ Iterable <Person > results = this .repository .findAllById (asList (0L , 1L , 2L , 4L ));
196
186
197
187
assertThat (results ).isNotNull ();
198
188
assertThat (results ).hasSize (2 );
@@ -208,7 +198,7 @@ public void queryRegion() {
208
198
assertThat (this .template .put (oliverGierke .getId (), oliverGierke )).isNull ();
209
199
210
200
SelectResults <Person > people = this .template .find ("SELECT * FROM /People p WHERE p.firstname = $1" ,
211
- oliverGierke .getFirstname ());
201
+ oliverGierke .getFirstname ());
212
202
213
203
assertThat (people .size ()).isEqualTo (1 );
214
204
assertThat (people .iterator ().next ()).isEqualTo (oliverGierke );
@@ -231,6 +221,26 @@ public void saveAndDeleteEntity() {
231
221
assertThat (this .repository .findAll ()).isEmpty ();
232
222
}
233
223
224
+ @ Test // DATAGEODE-387
225
+ public void deleteAllById () {
226
+
227
+ assertThat (this .repository .count ()).isEqualTo (0 );
228
+
229
+ List <Person > people = asList (new Person (1L , "Jon" , "Doe" ), new Person (2L , "Jane" , "Doe" ),
230
+ new Person (3L , "Cookie" , "Doe" ), new Person (4L , "Pie" , "Doe" ), new Person (5L , "Sour" , "Doe" ));
231
+
232
+ people .forEach (person -> this .template .put (person .getId (), person ));
233
+
234
+ assertThat (this .repository .count ()).isEqualTo (5 );
235
+
236
+ this .repository .deleteAllById (asList (1L , 2L ));
237
+
238
+ assertThat (this .repository .count ()).isEqualTo (3L );
239
+ assertThat (this .repository .findAll ()) //
240
+ .extracting (Person ::getFirstname ) //
241
+ .containsExactlyInAnyOrder ("Cookie" , "Pie" , "Sour" );
242
+ }
243
+
234
244
@ Test
235
245
public void saveEntities () {
236
246
@@ -240,7 +250,7 @@ public void saveEntities() {
240
250
Person jonBloom = new Person (2L , "Jon" , "Bloom" );
241
251
Person juanBlume = new Person (3L , "Juan" , "Blume" );
242
252
243
- this .repository .saveAll (Arrays . asList (johnBlum , jonBloom , juanBlume ));
253
+ this .repository .saveAll (asList (johnBlum , jonBloom , juanBlume ));
244
254
245
255
assertThat (this .template .getRegion ().size ()).isEqualTo (3 );
246
256
assertThat ((Person ) this .template .get (johnBlum .getId ())).isEqualTo (johnBlum );
0 commit comments