DATAREST-261 - Fixed RepositoryRelProvider registration.
We now register a RepositoryRelProvider that hadn't been exported before so that clients using a RelProvider will automatically see potentially customized rels for repositories. Changed RepositoryRelProvider to lazily depend on the ResourceMappings as will be requested eagerly for injection into the configuration class itself.
This commit is contained in:
@@ -45,6 +45,7 @@ import org.springframework.data.rest.core.invoke.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.mapping.ResourceDescription;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.support.DomainObjectMerger;
|
||||
import org.springframework.data.rest.core.support.RepositoryRelProvider;
|
||||
import org.springframework.data.rest.core.util.UUIDConverter;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResourceHandlerMethodArgumentResolver;
|
||||
@@ -132,6 +133,11 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
return new Repositories(beanFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RepositoryRelProvider repositoryRelProvider(ObjectFactory<ResourceMappings> resourceMappings) {
|
||||
return new RepositoryRelProvider(resourceMappings);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier
|
||||
public DefaultFormattingConversionService defaultConversionService() {
|
||||
@@ -418,7 +424,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
Repositories repositories = repositories();
|
||||
RepositoryRestConfiguration config = config();
|
||||
|
||||
return new ResourceMappings(config, repositories, getDefaultedRelProvider());
|
||||
return new ResourceMappings(config, repositories);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -270,8 +270,13 @@ public abstract class AbstractWebIntegrationTests {
|
||||
protected void assertJsonPathDoesntExist(String path, MockHttpServletResponse response) throws Exception {
|
||||
|
||||
try {
|
||||
JsonPath.read(response.getContentAsString(), path);
|
||||
fail(path + " should have failed");
|
||||
|
||||
Object result = JsonPath.read(response.getContentAsString(), path);
|
||||
|
||||
if (result != null) {
|
||||
fail("Was expecting to find no value for path " + path + " but got " + result.toString());
|
||||
}
|
||||
|
||||
} catch (InvalidPathException e) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.webmvc.AbstractWebIntegrationTests;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -60,6 +61,7 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Autowired TestDataPopulator loader;
|
||||
@Autowired ResourceMappings mappings;
|
||||
@Autowired RelProvider relProvider;
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -429,6 +431,14 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
|
||||
mvc.perform(post(link.getHref()).content("{}").contentType(MediaType.APPLICATION_JSON)).//
|
||||
andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-261
|
||||
*/
|
||||
@Test
|
||||
public void relProviderDetectsCustomizedMapping() {
|
||||
assertThat(relProvider.getCollectionResourceRelFor(Person.class), is("people"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the {@link Person} resource the given link points to contains siblings with the given names.
|
||||
@@ -440,7 +450,7 @@ public class JpaWebTests extends AbstractWebIntegrationTests {
|
||||
private void assertSiblingNames(Link link, String... siblingNames) throws Exception {
|
||||
|
||||
String responseBody = request(link).getContentAsString();
|
||||
List<String> persons = JsonPath.read(responseBody, "$._embedded.persons[*].firstName");
|
||||
List<String> persons = JsonPath.read(responseBody, "$._embedded.people[*].firstName");
|
||||
|
||||
assertThat(persons, hasSize(siblingNames.length));
|
||||
assertThat(persons, hasItems(siblingNames));
|
||||
|
||||
Reference in New Issue
Block a user