|
34 | 34 | import static junit.framework.TestCase.assertSame;
|
35 | 35 | import static junit.framework.TestCase.assertTrue;
|
36 | 36 | import static junit.framework.TestCase.fail;
|
37 |
| -import static org.junit.Assert.assertThrows; |
38 | 37 |
|
| 38 | +import java.util.Collections; |
39 | 39 | import java.util.List;
|
| 40 | +import java.util.Objects; |
40 | 41 |
|
41 | 42 | import org.junit.Before;
|
42 | 43 | import org.junit.Test;
|
43 | 44 |
|
44 | 45 | import com.google.gson.Gson;
|
45 | 46 |
|
46 | 47 | import redis.clients.jedis.Jedis;
|
47 |
| -import redis.clients.jedis.exceptions.JedisDataException; |
48 | 48 |
|
49 | 49 | public class ClientTest {
|
50 | 50 |
|
@@ -77,6 +77,63 @@ public FooBarObject() {
|
77 | 77 | }
|
78 | 78 | }
|
79 | 79 |
|
| 80 | + private static class Baz { |
| 81 | + private String quuz; |
| 82 | + private String grault; |
| 83 | + private String waldo; |
| 84 | + |
| 85 | + public Baz(final String quuz, final String grault, final String waldo) { |
| 86 | + this.quuz = quuz; |
| 87 | + this.grault = grault; |
| 88 | + this.waldo = waldo; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public boolean equals(Object o) { |
| 93 | + if (this == o) |
| 94 | + return true; |
| 95 | + if (o == null) |
| 96 | + return false; |
| 97 | + if (getClass() != o.getClass()) |
| 98 | + return false; |
| 99 | + Baz other = (Baz) o; |
| 100 | + |
| 101 | + return Objects.equals(quuz, other.quuz) && // |
| 102 | + Objects.equals(grault, other.grault) && // |
| 103 | + Objects.equals(waldo, other.waldo); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + private static class Qux { |
| 108 | + private String quux; |
| 109 | + private String corge; |
| 110 | + private String garply; |
| 111 | + private Baz baz; |
| 112 | + |
| 113 | + public Qux(final String quux, final String corge, final String garply, final Baz baz) { |
| 114 | + this.quux = quux; |
| 115 | + this.corge = corge; |
| 116 | + this.garply = garply; |
| 117 | + this.baz = baz; |
| 118 | + } |
| 119 | + |
| 120 | + @Override |
| 121 | + public boolean equals(Object o) { |
| 122 | + if (this == o) |
| 123 | + return true; |
| 124 | + if (o == null) |
| 125 | + return false; |
| 126 | + if (getClass() != o.getClass()) |
| 127 | + return false; |
| 128 | + Qux other = (Qux) o; |
| 129 | + |
| 130 | + return Objects.equals(quux, other.quux) && // |
| 131 | + Objects.equals(corge, other.corge) && // |
| 132 | + Objects.equals(garply, other.garply) && // |
| 133 | + Objects.equals(baz, other.baz); |
| 134 | + } |
| 135 | + } |
| 136 | + |
80 | 137 | private final Gson g = new Gson();
|
81 | 138 | private final JReJSON client = new JReJSON("localhost",6379);
|
82 | 139 | private final Jedis jedis = new Jedis("localhost",6379);
|
@@ -223,6 +280,81 @@ public void typeException() throws Exception {
|
223 | 280 | public void type1Exception() throws Exception {
|
224 | 281 | client.set( "foobar", new FooBarObject(), Path.ROOT_PATH);
|
225 | 282 | client.type( "foobar", new Path(".foo[1]"));
|
226 |
| - } |
| 283 | + } |
227 | 284 |
|
| 285 | + @Test |
| 286 | + public void testMultipleGetAtRootPathAllKeysExist() throws Exception { |
| 287 | + Baz baz1 = new Baz("quuz1", "grault1", "waldo1"); |
| 288 | + Baz baz2 = new Baz("quuz2", "grault2", "waldo2"); |
| 289 | + Qux qux1 = new Qux("quux1", "corge1", "garply1", baz1); |
| 290 | + Qux qux2 = new Qux("quux2", "corge2", "garply2", baz2); |
| 291 | + |
| 292 | + client.set("qux1", qux1); |
| 293 | + client.set("qux2", qux2); |
| 294 | + |
| 295 | + List<Qux> oneQux = client.mget(Qux.class, "qux1"); |
| 296 | + List<Qux> allQux = client.mget(Qux.class, "qux1", "qux2"); |
| 297 | + |
| 298 | + assertEquals(1, oneQux.size()); |
| 299 | + assertEquals(2, allQux.size()); |
| 300 | + |
| 301 | + assertEquals(qux1, oneQux.get(0)); |
| 302 | + |
| 303 | + Qux testQux1 = allQux.stream() // |
| 304 | + .filter(q -> q.quux.equals("quux1")) // |
| 305 | + .findFirst() // |
| 306 | + .orElseThrow(() -> new NullPointerException("")); |
| 307 | + Qux testQux2 = allQux.stream() // |
| 308 | + .filter(q -> q.quux.equals("quux2")) // |
| 309 | + .findFirst() // |
| 310 | + .orElseThrow(() -> new NullPointerException("")); |
| 311 | + |
| 312 | + assertEquals(qux1, testQux1); |
| 313 | + assertEquals(qux2, testQux2); |
| 314 | + } |
| 315 | + |
| 316 | + @Test |
| 317 | + public void testMultipleGetAtRootPathWithMissingKeys() throws Exception { |
| 318 | + Baz baz1 = new Baz("quuz1", "grault1", "waldo1"); |
| 319 | + Baz baz2 = new Baz("quuz2", "grault2", "waldo2"); |
| 320 | + Qux qux1 = new Qux("quux1", "corge1", "garply1", baz1); |
| 321 | + Qux qux2 = new Qux("quux2", "corge2", "garply2", baz2); |
| 322 | + |
| 323 | + client.set("qux1", qux1); |
| 324 | + client.set("qux2", qux2); |
| 325 | + |
| 326 | + List<Qux> allQux = client.mget(Qux.class, "qux1", "qux2", "qux3"); |
| 327 | + |
| 328 | + assertEquals(3, allQux.size()); |
| 329 | + assertNull(allQux.get(2)); |
| 330 | + allQux.removeAll(Collections.singleton(null)); |
| 331 | + assertEquals(2, allQux.size()); |
| 332 | + } |
| 333 | + |
| 334 | + @Test |
| 335 | + public void testMultipleGetWithPathPathAllKeysExist() throws Exception { |
| 336 | + Baz baz1 = new Baz("quuz1", "grault1", "waldo1"); |
| 337 | + Baz baz2 = new Baz("quuz2", "grault2", "waldo2"); |
| 338 | + Qux qux1 = new Qux("quux1", "corge1", "garply1", baz1); |
| 339 | + Qux qux2 = new Qux("quux2", "corge2", "garply2", baz2); |
| 340 | + |
| 341 | + client.set("qux1", qux1); |
| 342 | + client.set("qux2", qux2); |
| 343 | + |
| 344 | + List<Baz> allBaz = client.mget(new Path("baz"), Baz.class, "qux1", "qux2"); |
| 345 | + |
| 346 | + assertEquals(2, allBaz.size()); |
| 347 | + |
| 348 | + Baz testBaz1 = allBaz.stream() // |
| 349 | + .filter(b -> b.quuz.equals("quuz1")) // |
| 350 | + .findFirst() // |
| 351 | + .orElseThrow(() -> new NullPointerException("")); |
| 352 | + Baz testBaz2 = allBaz.stream() // |
| 353 | + .filter(q -> q.quuz.equals("quuz2")) // |
| 354 | + .findFirst() // |
| 355 | + .orElseThrow(() -> new NullPointerException("")); |
| 356 | + |
| 357 | + assertEquals(baz1, testBaz1); |
| 358 | + assertEquals(baz2, testBaz2); |
| 359 | + } |
228 | 360 | }
|
0 commit comments