|
19 | 19 | import static org.mockito.ArgumentMatchers.*; |
20 | 20 | import static org.mockito.Mockito.*; |
21 | 21 |
|
| 22 | +import lombok.AccessLevel; |
22 | 23 | import lombok.Data; |
23 | 24 | import lombok.Getter; |
24 | 25 |
|
@@ -96,6 +97,7 @@ void setUp() { |
96 | 97 |
|
97 | 98 | KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>(); |
98 | 99 | mappingContext.getPersistentEntity(Sample.class); |
| 100 | + mappingContext.getPersistentEntity(Package.class); |
99 | 101 | mappingContext.getPersistentEntity(SampleWithAdditionalGetters.class); |
100 | 102 | mappingContext.getPersistentEntity(PersistentEntityJackson2ModuleUnitTests.PetOwner.class); |
101 | 103 | mappingContext.getPersistentEntity(Immutable.class); |
@@ -157,6 +159,41 @@ void resolvesReferenceToSubtypeCorrectly() throws IOException { |
157 | 159 | assertThat(petOwner.getPet()).isNotNull(); |
158 | 160 | } |
159 | 161 |
|
| 162 | + @Test |
| 163 | + void allowsUrlsForLinkableAssociation() throws Exception { |
| 164 | + |
| 165 | + when(converter.convert(UriTemplate.of("/homes/1").expand(), TypeDescriptor.valueOf(URI.class), |
| 166 | + TypeDescriptor.valueOf(Home.class))).thenReturn(new Home()); |
| 167 | + |
| 168 | + PersistentProperty<?> property = persistentEntities.getRequiredPersistentEntity(PetOwner.class) |
| 169 | + .getRequiredPersistentProperty("home"); |
| 170 | + |
| 171 | + when(associations.isLinkableAssociation(property)).thenReturn(true); |
| 172 | + |
| 173 | + PetOwner petOwner = mapper.readValue("{\"home\": \"/homes/1\" }", PetOwner.class); |
| 174 | + |
| 175 | + assertThat(petOwner).isNotNull(); |
| 176 | + assertThat(petOwner.getHome()).isInstanceOf(Home.class); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + void allowsUrlsForRenamedLinkableAssociation() throws IOException { |
| 181 | + |
| 182 | + when(converter.convert(UriTemplate.of("/packages/1").expand(), TypeDescriptor.valueOf(URI.class), |
| 183 | + TypeDescriptor.valueOf(Package.class))).thenReturn(new Package()); |
| 184 | + |
| 185 | + PersistentProperty<?> property = persistentEntities.getRequiredPersistentEntity(PetOwner.class) |
| 186 | + .getRequiredPersistentProperty("_package"); |
| 187 | + |
| 188 | + when(associations.isLinkableAssociation(property)).thenReturn(true); |
| 189 | + |
| 190 | + PetOwner petOwner = mapper.readValue("{\"package\":\"/packages/1\"}", PetOwner.class); |
| 191 | + |
| 192 | + assertThat(petOwner).isNotNull(); |
| 193 | + assertThat(petOwner.getPackage()).isNotNull(); |
| 194 | + } |
| 195 | + |
| 196 | + |
160 | 197 | @Test // DATAREST-1321 |
161 | 198 | void allowsNumericIdsForLookupTypes() throws Exception { |
162 | 199 |
|
@@ -260,8 +297,17 @@ static class PetOwner { |
260 | 297 |
|
261 | 298 | Pet pet; |
262 | 299 | Home home; |
| 300 | + |
| 301 | + @Getter(value = AccessLevel.NONE) |
| 302 | + @JsonProperty("package") Package _package; |
| 303 | + |
| 304 | + public Package getPackage() { |
| 305 | + return _package; |
| 306 | + } |
263 | 307 | } |
264 | 308 |
|
| 309 | + static class Package {} |
| 310 | + |
265 | 311 | @JsonTypeInfo(include = JsonTypeInfo.As.PROPERTY, use = JsonTypeInfo.Id.MINIMAL_CLASS) |
266 | 312 | static class Pet {} |
267 | 313 |
|
|
0 commit comments