15
15
*/
16
16
package org .springframework .data .gemfire .repository .support ;
17
17
18
- import static org .assertj .core .api .Assertions .assertThat ;
19
-
20
- import java .util .Arrays ;
21
- import java .util .Collections ;
22
- import java .util .List ;
23
-
24
- import javax .annotation .Resource ;
25
-
26
- import org .junit .Before ;
27
- import org .junit .Test ;
28
- import org .junit .runner .RunWith ;
29
-
30
18
import org .apache .geode .cache .GemFireCache ;
31
19
import org .apache .geode .cache .Region ;
32
20
import org .apache .geode .cache .RegionEvent ;
33
21
import org .apache .geode .cache .query .SelectResults ;
34
22
import org .apache .geode .cache .util .CacheListenerAdapter ;
35
-
23
+ import org .junit .Before ;
24
+ import org .junit .Test ;
25
+ import org .junit .runner .RunWith ;
36
26
import org .springframework .beans .factory .annotation .Autowired ;
37
27
import org .springframework .context .annotation .Bean ;
38
28
import org .springframework .data .domain .Page ;
49
39
import org .springframework .test .context .ContextConfiguration ;
50
40
import org .springframework .test .context .junit4 .SpringRunner ;
51
41
42
+ import javax .annotation .Resource ;
43
+ import java .util .Collections ;
44
+ import java .util .List ;
45
+
46
+ import static java .util .Arrays .*;
47
+ import static org .assertj .core .api .Assertions .*;
48
+
52
49
/**
53
50
* Integration Tests for {@link SimpleGemfireRepository}.
54
51
*
55
52
* @author Oliver Gierke
56
53
* @author John Blum
54
+ * @author Jens Schauder
57
55
* @see org.junit.Test
58
56
* @see org.apache.geode.cache.GemFireCache
59
57
* @see org.apache.geode.cache.Region
@@ -92,7 +90,7 @@ public void setUp() {
92
90
GemfireMappingContext mappingContext = new GemfireMappingContext ();
93
91
94
92
GemfirePersistentEntity <Person > personEntity =
95
- (GemfirePersistentEntity <Person >) mappingContext .getPersistentEntity (Person .class );
93
+ (GemfirePersistentEntity <Person >) mappingContext .getPersistentEntity (Person .class );
96
94
97
95
EntityInformation <Person , Long > information = new PersistentEntityInformation <>(personEntity );
98
96
@@ -114,12 +112,12 @@ public void findAllPaged() {
114
112
115
113
assertThat (this .repository .count ()).isEqualTo (0 );
116
114
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" )
115
+ List <Person > people = asList (
116
+ new Person (1L , "Jon" , "Doe" ),
117
+ new Person (2L , "Jane" , "Doe" ),
118
+ new Person (3L , "Cookie" , "Doe" ),
119
+ new Person (4L , "Pie" , "Doe" ),
120
+ new Person (5L , "Sour" , "Doe" )
123
121
);
124
122
125
123
people .forEach (person -> this .template .put (person .getId (), person ));
@@ -129,7 +127,7 @@ public void findAllPaged() {
129
127
Sort orderByFirstNameAscending = Sort .by ("firstname" ).ascending ();
130
128
131
129
Page <Person > pageOne =
132
- this .repository .findAll (PageRequest .of (0 , 3 , orderByFirstNameAscending ));
130
+ this .repository .findAll (PageRequest .of (0 , 3 , orderByFirstNameAscending ));
133
131
134
132
assertThat (pageOne ).isNotNull ();
135
133
assertThat (pageOne ).isNotEmpty ();
@@ -142,7 +140,7 @@ public void findAllPaged() {
142
140
assertThat (pageOne .getContent ()).containsExactly (people .get (2 ), people .get (1 ), people .get (0 ));
143
141
144
142
Page <Person > pageTwo =
145
- this .repository .findAll (PageRequest .of (1 , 3 , Sort .by ("firstname" ).ascending ()));
143
+ this .repository .findAll (PageRequest .of (1 , 3 , Sort .by ("firstname" ).ascending ()));
146
144
147
145
assertThat (pageTwo ).isNotNull ();
148
146
assertThat (pageTwo ).isNotEmpty ();
@@ -166,17 +164,17 @@ public void findAllWithIds() {
166
164
this .template .put (carter .getId (), carter );
167
165
this .template .put (leroi .getId (), leroi );
168
166
169
- Iterable <Person > result = this .repository .findAllById (Arrays . asList (carter .getId (), leroi .getId ()));
167
+ Iterable <Person > result = this .repository .findAllById (asList (carter .getId (), leroi .getId ()));
170
168
171
169
assertThat (result ).isNotNull ();
172
170
assertThat (result ).hasSize (2 );
173
- assertThat (result ).containsAll (Arrays . asList (carter , leroi ));
171
+ assertThat (result ).containsAll (asList (carter , leroi ));
174
172
}
175
173
176
174
@ Test
177
175
public void findAllWithIdsReturnsNoMatches () {
178
176
179
- Iterable <Person > results = this .repository .findAllById (Arrays . asList (1L , 2L ));
177
+ Iterable <Person > results = this .repository .findAllById (asList (1L , 2L ));
180
178
181
179
assertThat (results ).isNotNull ();
182
180
assertThat (results ).isEmpty ();
@@ -192,7 +190,7 @@ public void findAllWithIdsReturnsPartialMatches() {
192
190
this .template .put (kurt .getId (), kurt );
193
191
this .template .put (eddie .getId (), eddie );
194
192
195
- Iterable <Person > results = this .repository .findAllById (Arrays . asList (0L , 1L , 2L , 4L ));
193
+ Iterable <Person > results = this .repository .findAllById (asList (0L , 1L , 2L , 4L ));
196
194
197
195
assertThat (results ).isNotNull ();
198
196
assertThat (results ).hasSize (2 );
@@ -208,7 +206,7 @@ public void queryRegion() {
208
206
assertThat (this .template .put (oliverGierke .getId (), oliverGierke )).isNull ();
209
207
210
208
SelectResults <Person > people = this .template .find ("SELECT * FROM /People p WHERE p.firstname = $1" ,
211
- oliverGierke .getFirstname ());
209
+ oliverGierke .getFirstname ());
212
210
213
211
assertThat (people .size ()).isEqualTo (1 );
214
212
assertThat (people .iterator ().next ()).isEqualTo (oliverGierke );
@@ -231,6 +229,31 @@ public void saveAndDeleteEntity() {
231
229
assertThat (this .repository .findAll ()).isEmpty ();
232
230
}
233
231
232
+ @ Test // DATAGEODE-387
233
+ public void deleteAllById () {
234
+
235
+ assertThat (this .repository .count ()).isEqualTo (0 );
236
+
237
+ List <Person > people = asList (
238
+ new Person (1L , "Jon" , "Doe" ),
239
+ new Person (2L , "Jane" , "Doe" ),
240
+ new Person (3L , "Cookie" , "Doe" ),
241
+ new Person (4L , "Pie" , "Doe" ),
242
+ new Person (5L , "Sour" , "Doe" )
243
+ );
244
+
245
+ people .forEach (person -> this .template .put (person .getId (), person ));
246
+
247
+ assertThat (this .repository .count ()).isEqualTo (5 );
248
+
249
+ this .repository .deleteAllById (asList (1L , 2L ));
250
+
251
+ assertThat (this .repository .count ()).isEqualTo (3L );
252
+ assertThat (this .repository .findAll ()) //
253
+ .extracting (Person ::getFirstname ) //
254
+ .containsExactlyInAnyOrder ("Cookie" , "Pie" , "Sour" );
255
+ }
256
+
234
257
@ Test
235
258
public void saveEntities () {
236
259
@@ -240,7 +263,7 @@ public void saveEntities() {
240
263
Person jonBloom = new Person (2L , "Jon" , "Bloom" );
241
264
Person juanBlume = new Person (3L , "Juan" , "Blume" );
242
265
243
- this .repository .saveAll (Arrays . asList (johnBlum , jonBloom , juanBlume ));
266
+ this .repository .saveAll (asList (johnBlum , jonBloom , juanBlume ));
244
267
245
268
assertThat (this .template .getRegion ().size ()).isEqualTo (3 );
246
269
assertThat ((Person ) this .template .get (johnBlum .getId ())).isEqualTo (johnBlum );
0 commit comments