36
36
37
37
import static junit .framework .TestCase .*;
38
38
39
+ import java .util .Arrays ;
40
+ import java .util .Collections ;
39
41
import java .util .List ;
42
+ import java .util .Objects ;
40
43
41
44
public class ClientTest {
42
45
@@ -67,6 +70,63 @@ public FooBarObject() {
67
70
}
68
71
}
69
72
73
+ private static class Baz {
74
+ private String quuz ;
75
+ private String grault ;
76
+ private String waldo ;
77
+
78
+ public Baz (final String quuz , final String grault , final String waldo ) {
79
+ this .quuz = quuz ;
80
+ this .grault = grault ;
81
+ this .waldo = waldo ;
82
+ }
83
+
84
+ @ Override
85
+ public boolean equals (Object o ) {
86
+ if (this == o )
87
+ return true ;
88
+ if (o == null )
89
+ return false ;
90
+ if (getClass () != o .getClass ())
91
+ return false ;
92
+ Baz other = (Baz ) o ;
93
+
94
+ return Objects .equals (quuz , other .quuz ) && //
95
+ Objects .equals (grault , other .grault ) && //
96
+ Objects .equals (waldo , other .waldo );
97
+ }
98
+ }
99
+
100
+ private static class Qux {
101
+ private String quux ;
102
+ private String corge ;
103
+ private String garply ;
104
+ private Baz baz ;
105
+
106
+ public Qux (final String quux , final String corge , final String garply , final Baz baz ) {
107
+ this .quux = quux ;
108
+ this .corge = corge ;
109
+ this .garply = garply ;
110
+ this .baz = baz ;
111
+ }
112
+
113
+ @ Override
114
+ public boolean equals (Object o ) {
115
+ if (this == o )
116
+ return true ;
117
+ if (o == null )
118
+ return false ;
119
+ if (getClass () != o .getClass ())
120
+ return false ;
121
+ Qux other = (Qux ) o ;
122
+
123
+ return Objects .equals (quux , other .quux ) && //
124
+ Objects .equals (corge , other .corge ) && //
125
+ Objects .equals (garply , other .garply ) && //
126
+ Objects .equals (baz , other .baz );
127
+ }
128
+ }
129
+
70
130
private final Gson g = new Gson ();
71
131
private final JReJSON client = new JReJSON ("localhost" ,6379 );
72
132
private final Jedis jedis = new Jedis ("localhost" ,6379 );
@@ -196,4 +256,81 @@ public void type1Exception() throws Exception {
196
256
client .set ( "foobar" , new FooBarObject (), Path .ROOT_PATH );
197
257
client .type ( "foobar" , new Path (".foo[1]" ));
198
258
}
259
+
260
+ @ Test
261
+ public void testMultipleGetAtRootPathAllKeysExist () throws Exception {
262
+ Baz baz1 = new Baz ("quuz1" , "grault1" , "waldo1" );
263
+ Baz baz2 = new Baz ("quuz2" , "grault2" , "waldo2" );
264
+ Qux qux1 = new Qux ("quux1" , "corge1" , "garply1" , baz1 );
265
+ Qux qux2 = new Qux ("quux2" , "corge2" , "garply2" , baz2 );
266
+
267
+ client .set ("qux1" , qux1 );
268
+ client .set ("qux2" , qux2 );
269
+
270
+ List <Qux > oneQux = client .mget (Qux .class , "qux1" );
271
+ List <Qux > allQux = client .mget (Qux .class , "qux1" , "qux2" );
272
+
273
+ assertEquals (1 , oneQux .size ());
274
+ assertEquals (2 , allQux .size ());
275
+
276
+ assertEquals (qux1 , oneQux .get (0 ));
277
+
278
+ Qux testQux1 = allQux .stream () //
279
+ .filter (q -> q .quux .equals ("quux1" )) //
280
+ .findFirst () //
281
+ .orElseThrow (() -> new NullPointerException ("" ));
282
+ Qux testQux2 = allQux .stream () //
283
+ .filter (q -> q .quux .equals ("quux2" )) //
284
+ .findFirst () //
285
+ .orElseThrow (() -> new NullPointerException ("" ));
286
+
287
+ assertEquals (qux1 , testQux1 );
288
+ assertEquals (qux2 , testQux2 );
289
+ }
290
+
291
+ @ Test
292
+ public void testMultipleGetAtRootPathWithMissingKeys () throws Exception {
293
+ Baz baz1 = new Baz ("quuz1" , "grault1" , "waldo1" );
294
+ Baz baz2 = new Baz ("quuz2" , "grault2" , "waldo2" );
295
+ Qux qux1 = new Qux ("quux1" , "corge1" , "garply1" , baz1 );
296
+ Qux qux2 = new Qux ("quux2" , "corge2" , "garply2" , baz2 );
297
+
298
+ client .set ("qux1" , qux1 );
299
+ client .set ("qux2" , qux2 );
300
+
301
+ List <Qux > allQux = client .mget (Qux .class , "qux1" , "qux2" , "qux3" );
302
+
303
+ System .out .println (allQux );
304
+
305
+ assertEquals (3 , allQux .size ());
306
+ allQux .removeAll (Collections .singleton (null ));
307
+ assertEquals (2 , allQux .size ());
308
+ }
309
+
310
+ @ Test
311
+ public void testMultipleGetWithPathPathAllKeysExist () throws Exception {
312
+ Baz baz1 = new Baz ("quuz1" , "grault1" , "waldo1" );
313
+ Baz baz2 = new Baz ("quuz2" , "grault2" , "waldo2" );
314
+ Qux qux1 = new Qux ("quux1" , "corge1" , "garply1" , baz1 );
315
+ Qux qux2 = new Qux ("quux2" , "corge2" , "garply2" , baz2 );
316
+
317
+ client .set ("qux1" , qux1 );
318
+ client .set ("qux2" , qux2 );
319
+
320
+ List <Baz > allBaz = client .mget (new Path ("baz" ), Baz .class , "qux1" , "qux2" );
321
+
322
+ assertEquals (2 , allBaz .size ());
323
+
324
+ Baz testBaz1 = allBaz .stream () //
325
+ .filter (b -> b .quuz .equals ("quuz1" )) //
326
+ .findFirst () //
327
+ .orElseThrow (() -> new NullPointerException ("" ));
328
+ Baz testBaz2 = allBaz .stream () //
329
+ .filter (q -> q .quuz .equals ("quuz2" )) //
330
+ .findFirst () //
331
+ .orElseThrow (() -> new NullPointerException ("" ));
332
+
333
+ assertEquals (baz1 , testBaz1 );
334
+ assertEquals (baz2 , testBaz2 );
335
+ }
199
336
}
0 commit comments