|
49 | 49 | import java.util.*; |
50 | 50 |
|
51 | 51 | import static org.hamcrest.Matchers.*; |
| 52 | +import static org.junit.Assert.assertEquals; |
52 | 53 | import static org.junit.Assert.assertThat; |
53 | 54 |
|
54 | 55 | /** |
@@ -589,4 +590,57 @@ public void readMapInMap() { |
589 | 590 | assertThat(find.isPresent(), is(true)); |
590 | 591 | assertThat(find.get().value, is(map)); |
591 | 592 | } |
| 593 | + |
| 594 | + @Test |
| 595 | + public void readMapInMapWithNull() { |
| 596 | + final MapInMapTestEntity entity = new MapInMapTestEntity(); |
| 597 | + final Map<String, Object> map = new HashMap<>(); |
| 598 | + Map<String, Object> nested = new HashMap<>(); |
| 599 | + nested.put("key1", "test"); |
| 600 | + nested.put("key2", null); |
| 601 | + map.put("nested", nested); |
| 602 | + entity.value = map; |
| 603 | + template.insert(entity); |
| 604 | + final Optional<MapInMapTestEntity> find = template.find(entity.id, MapInMapTestEntity.class); |
| 605 | + assertThat(find.isPresent(), is(true)); |
| 606 | + Map<String, Object> nestedResult = (Map<String, Object>) find.get().value.get("nested"); |
| 607 | + assertThat(nestedResult.size(), is(1)); |
| 608 | + assertThat(nestedResult.get("key1"), is("test")); |
| 609 | + } |
| 610 | + |
| 611 | + @Test |
| 612 | + public void readMapInMapWithArray() { |
| 613 | + final MapInMapTestEntity entity = new MapInMapTestEntity(); |
| 614 | + final Map<String, Object> map = new HashMap<>(); |
| 615 | + Map<String, Object> nested = new HashMap<>(); |
| 616 | + String[] nestedArray = {"test", null}; |
| 617 | + nested.put("key1", nestedArray); |
| 618 | + map.put("nested", nested); |
| 619 | + entity.value = map; |
| 620 | + template.insert(entity); |
| 621 | + final Optional<MapInMapTestEntity> find = template.find(entity.id, MapInMapTestEntity.class); |
| 622 | + assertThat(find.isPresent(), is(true)); |
| 623 | + Map<String, Object> nestedResult = (Map<String, Object>) find.get().value.get("nested"); |
| 624 | + assertThat(nestedResult.size(), is(1)); |
| 625 | + assertThat(((List<String>) nestedResult.get("key1")).size(), is(2)); |
| 626 | + assertEquals(Arrays.asList(nestedArray), nestedResult.get("key1")); |
| 627 | + } |
| 628 | + |
| 629 | + @Test |
| 630 | + public void readMapInMapWithCollection() { |
| 631 | + final MapInMapTestEntity entity = new MapInMapTestEntity(); |
| 632 | + final Map<String, Object> map = new HashMap<>(); |
| 633 | + Map<String, Object> nested = new HashMap<>(); |
| 634 | + Collection<String> nestedCollection = Arrays.asList("test", null); |
| 635 | + nested.put("key1", nestedCollection); |
| 636 | + map.put("nested", nested); |
| 637 | + entity.value = map; |
| 638 | + template.insert(entity); |
| 639 | + final Optional<MapInMapTestEntity> find = template.find(entity.id, MapInMapTestEntity.class); |
| 640 | + assertThat(find.isPresent(), is(true)); |
| 641 | + Map<String, Object> nestedResult = (Map<String, Object>) find.get().value.get("nested"); |
| 642 | + assertThat(nestedResult.size(), is(1)); |
| 643 | + assertThat(((List<String>) nestedResult.get("key1")).size(), is(2)); |
| 644 | + assertEquals(nestedCollection, nestedResult.get("key1")); |
| 645 | + } |
592 | 646 | } |
0 commit comments