|
17 | 17 |
|
18 | 18 | import static org.hamcrest.Matchers.*;
|
19 | 19 | import static org.junit.Assert.*;
|
| 20 | +import static org.mockito.Mockito.*; |
20 | 21 |
|
21 | 22 | import java.util.Collections;
|
22 | 23 | import java.util.List;
|
|
27 | 28 | import org.springframework.data.domain.Sort;
|
28 | 29 | import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
29 | 30 | import org.springframework.data.mapping.context.PersistentEntities;
|
| 31 | +import org.springframework.data.rest.core.annotation.RestResource; |
| 32 | +import org.springframework.data.rest.core.config.RepositoryRestConfiguration; |
| 33 | +import org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings; |
30 | 34 | import org.springframework.data.rest.webmvc.json.JacksonMappingAwareSortTranslator.SortTranslator;
|
| 35 | +import org.springframework.data.rest.webmvc.mapping.Associations; |
31 | 36 |
|
32 | 37 | import com.fasterxml.jackson.annotation.JsonProperty;
|
33 | 38 | import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
@@ -57,7 +62,9 @@ public void setUp() {
|
57 | 62 | mappingContext.getPersistentEntity(MultiUnwrapped.class);
|
58 | 63 |
|
59 | 64 | persistentEntities = new PersistentEntities(Collections.singleton(mappingContext));
|
60 |
| - sortTranslator = new SortTranslator(persistentEntities, objectMapper); |
| 65 | + |
| 66 | + sortTranslator = new SortTranslator(persistentEntities, objectMapper, new Associations( |
| 67 | + new PersistentEntitiesResourceMappings(persistentEntities), mock(RepositoryRestConfiguration.class))); |
61 | 68 | }
|
62 | 69 |
|
63 | 70 | @Test // DATAREST-883
|
@@ -119,15 +126,24 @@ public void shouldSkipWrongNestedProperties() {
|
119 | 126 | assertThat(translatedSort, is(nullValue()));
|
120 | 127 | }
|
121 | 128 |
|
122 |
| - @Test // DATAREST-910 |
| 129 | + @Test // DATAREST-910, DATAREST-976 |
123 | 130 | public void shouldSkipKnownAssociationProperties() {
|
124 | 131 |
|
125 |
| - Sort translatedSort = sortTranslator.translateSort(new Sort("refEmbedded.name"), |
| 132 | + Sort translatedSort = sortTranslator.translateSort(new Sort("association.name"), |
126 | 133 | mappingContext.getPersistentEntity(Plain.class));
|
127 | 134 |
|
128 | 135 | assertThat(translatedSort, is(nullValue()));
|
129 | 136 | }
|
130 | 137 |
|
| 138 | + @Test // DATAREST-976 |
| 139 | + public void shouldMapEmbeddableAssociationProperties() { |
| 140 | + |
| 141 | + Sort translatedSort = sortTranslator.translateSort(new Sort("refEmbedded.name"), |
| 142 | + mappingContext.getPersistentEntity(Plain.class)); |
| 143 | + |
| 144 | + assertThat(translatedSort.getOrderFor("refEmbedded.name"), is(notNullValue())); |
| 145 | + } |
| 146 | + |
131 | 147 | @Test // DATAREST-910
|
132 | 148 | public void shouldJacksonFieldNameForNestedFieldMapping() {
|
133 | 149 |
|
@@ -161,6 +177,7 @@ static class Plain {
|
161 | 177 | public String name;
|
162 | 178 | public Embedded embedded;
|
163 | 179 | @Reference public Embedded refEmbedded;
|
| 180 | + @Reference public AnotherRootEntity association; |
164 | 181 | }
|
165 | 182 |
|
166 | 183 | static class UnwrapEmbedded {
|
@@ -192,4 +209,9 @@ static class EmbeddedWithJsonProperty {
|
192 | 209 | }
|
193 | 210 |
|
194 | 211 | static interface SomeInterface {}
|
| 212 | + |
| 213 | + @RestResource |
| 214 | + static class AnotherRootEntity { |
| 215 | + public String name; |
| 216 | + } |
195 | 217 | }
|
0 commit comments