|
51 | 51 |
|
52 | 52 | import org.springframework.data.annotation.Id; |
53 | 53 | import org.springframework.data.annotation.PersistenceConstructor; |
| 54 | +import org.springframework.data.jdbc.core.mapping.AggregateReference; |
54 | 55 | import org.springframework.data.jdbc.core.mapping.JdbcMappingContext; |
55 | 56 | import org.springframework.data.mapping.PersistentPropertyPath; |
56 | 57 | import org.springframework.data.relational.core.mapping.Embedded; |
|
71 | 72 | * @author Maciej Walkowiak |
72 | 73 | * @author Bastian Wilhelm |
73 | 74 | * @author Christoph Strobl |
| 75 | + * @author Myeonghyeon Lee |
74 | 76 | */ |
75 | 77 | public class EntityRowMapperUnitTests { |
76 | 78 |
|
@@ -129,6 +131,21 @@ public void namingStrategyGetsHonoredForConstructor() throws SQLException { |
129 | 131 | .containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha"); |
130 | 132 | } |
131 | 133 |
|
| 134 | + @Test // DATAJDBC-427 |
| 135 | + public void simpleWithReferenceGetProperlyExtracted() throws SQLException { |
| 136 | + |
| 137 | + ResultSet rs = mockResultSet(asList("id", "name", "trivial_id"), // |
| 138 | + ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L); |
| 139 | + rs.next(); |
| 140 | + |
| 141 | + WithReference extracted = createRowMapper(WithReference.class).mapRow(rs, 1); |
| 142 | + |
| 143 | + assertThat(extracted) // |
| 144 | + .isNotNull() // |
| 145 | + .extracting(e -> e.id, e -> e.name, e -> e.trivialId) // |
| 146 | + .containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L)); |
| 147 | + } |
| 148 | + |
132 | 149 | @Test // DATAJDBC-113 |
133 | 150 | public void simpleOneToOneGetsProperlyExtracted() throws SQLException { |
134 | 151 |
|
@@ -159,6 +176,21 @@ public void immutableOneToOneGetsProperlyExtracted() throws SQLException { |
159 | 176 | .containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 24L, "beta"); |
160 | 177 | } |
161 | 178 |
|
| 179 | + @Test // DATAJDBC-427 |
| 180 | + public void immutableWithReferenceGetsProperlyExtracted() throws SQLException { |
| 181 | + |
| 182 | + ResultSet rs = mockResultSet(asList("id", "name", "trivial_id"), // |
| 183 | + ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", 100L); |
| 184 | + rs.next(); |
| 185 | + |
| 186 | + WithReferenceImmutable extracted = createRowMapper(WithReferenceImmutable.class).mapRow(rs, 1); |
| 187 | + |
| 188 | + assertThat(extracted) // |
| 189 | + .isNotNull() // |
| 190 | + .extracting(e -> e.id, e -> e.name, e -> e.trivialId) // |
| 191 | + .containsExactly(ID_FOR_ENTITY_NOT_REFERENCING_MAP, "alpha", AggregateReference.to(100L)); |
| 192 | + } |
| 193 | + |
162 | 194 | // TODO add additional test for multilevel embeddables |
163 | 195 | @Test // DATAJDBC-111 |
164 | 196 | public void simpleEmbeddedGetsProperlyExtracted() throws SQLException { |
@@ -440,6 +472,26 @@ static class Trivial { |
440 | 472 | String name; |
441 | 473 | } |
442 | 474 |
|
| 475 | + @EqualsAndHashCode |
| 476 | + @NoArgsConstructor |
| 477 | + @AllArgsConstructor |
| 478 | + @Getter |
| 479 | + static class WithReference { |
| 480 | + |
| 481 | + @Id Long id; |
| 482 | + String name; |
| 483 | + AggregateReference<Trivial, Long> trivialId; |
| 484 | + } |
| 485 | + |
| 486 | + @Wither |
| 487 | + @RequiredArgsConstructor |
| 488 | + static class WithReferenceImmutable { |
| 489 | + |
| 490 | + @Id private final Long id; |
| 491 | + private final String name; |
| 492 | + private final AggregateReference<TrivialImmutable, Long> trivialId; |
| 493 | + } |
| 494 | + |
443 | 495 | static class OneToOne { |
444 | 496 |
|
445 | 497 | @Id Long id; |
|
0 commit comments