|
1 | 1 | /*
|
2 |
| - * Copyright 2016 the original author or authors. |
| 2 | + * Copyright 2016-2017 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
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 | /**
|
@@ -138,17 +145,29 @@ public void shouldSkipWrongNestedProperties() {
|
138 | 145 | }
|
139 | 146 |
|
140 | 147 | /**
|
141 |
| - * @see DATAREST-910 |
| 148 | + * @see DATAREST-910, DATAREST-976 |
142 | 149 | */
|
143 | 150 | @Test
|
144 |
| - public void shouldSkipKnownAssociationProperties() { |
| 151 | + public void shouldSkipLinkableAssociationProperties() { |
145 | 152 |
|
146 |
| - Sort translatedSort = sortTranslator.translateSort(new Sort("refEmbedded.name"), |
| 153 | + Sort translatedSort = sortTranslator.translateSort(new Sort("association.name"), |
147 | 154 | mappingContext.getPersistentEntity(Plain.class));
|
148 | 155 |
|
149 | 156 | assertThat(translatedSort, is(nullValue()));
|
150 | 157 | }
|
151 | 158 |
|
| 159 | + /** |
| 160 | + * @see DATAREST-976 |
| 161 | + */ |
| 162 | + @Test |
| 163 | + public void shouldMapEmbeddableAssociationProperties() { |
| 164 | + |
| 165 | + Sort translatedSort = sortTranslator.translateSort(new Sort("refEmbedded.name"), |
| 166 | + mappingContext.getPersistentEntity(Plain.class)); |
| 167 | + |
| 168 | + assertThat(translatedSort.getOrderFor("refEmbedded.name"), is(notNullValue())); |
| 169 | + } |
| 170 | + |
152 | 171 | /**
|
153 | 172 | * @see DATAREST-910
|
154 | 173 | */
|
@@ -191,6 +210,7 @@ static class Plain {
|
191 | 210 | public String name;
|
192 | 211 | public Embedded embedded;
|
193 | 212 | @Reference public Embedded refEmbedded;
|
| 213 | + @Reference public AnotherRootEntity association; |
194 | 214 | }
|
195 | 215 |
|
196 | 216 | static class UnwrapEmbedded {
|
@@ -222,4 +242,9 @@ static class EmbeddedWithJsonProperty {
|
222 | 242 | }
|
223 | 243 |
|
224 | 244 | static interface SomeInterface {}
|
| 245 | + |
| 246 | + @RestResource |
| 247 | + static class AnotherRootEntity { |
| 248 | + public String name; |
| 249 | + } |
225 | 250 | }
|
0 commit comments