DATAREST-516 - Fixed link to ALPS representation descriptors of associations.

Previously the link pointing to representation descriptors of associations neither pointed to the ALPS controller nor to the representation descriptor.
This commit is contained in:
Oliver Gierke
2015-04-13 12:18:24 +02:00
parent d70851cda8
commit 28e0ef76d1
2 changed files with 30 additions and 7 deletions

View File

@@ -149,7 +149,7 @@ public class RootResourceInformationToAlpsDescriptorConverter {
ResourceMetadata metadata = mappings.getMappingFor(type);
return descriptor().//
id(metadata.getItemResourceRel().concat("-representation")).//
id(getRepresentationDescriptorId(metadata)).//
href(entityLinks.linkFor(type).slash("schema").toString()).//
doc(getDocFor(metadata.getItemResourceDescription())).//
descriptors(buildPropertyDescriptors(type, metadata.getItemResourceRel())).//
@@ -348,9 +348,11 @@ public class RootResourceInformationToAlpsDescriptorConverter {
DescriptorBuilder builder = descriptor().//
name(mapping.getRel()).doc(getDocFor(mapping.getDescription()));
ResourceMetadata targetTypeMapping = mappings.getMappingFor(property.getActualType());
String localPath = targetTypeMapping.getRel().concat("#").concat(targetTypeMapping.getItemResourceRel());
Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(localPath).withSelfRel();
ResourceMetadata targetTypeMetadata = mappings.getMappingFor(property.getActualType());
String localPath = targetTypeMetadata.getRel().concat("#")
.concat(getRepresentationDescriptorId(targetTypeMetadata));
Link link = ControllerLinkBuilder.linkTo(AlpsController.class).slash(AlpsController.ALPS_ROOT_MAPPING)
.slash(localPath).withSelfRel();
builder.//
type(Type.SAFE).//
@@ -415,6 +417,10 @@ public class RootResourceInformationToAlpsDescriptorConverter {
}
}
private static String getRepresentationDescriptorId(ResourceMetadata metadata) {
return metadata.getItemResourceRel().concat("-representation");
}
private static String prefix(HttpMethod method) {
switch (method) {

View File

@@ -36,7 +36,6 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@@ -138,8 +137,26 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
assertThat(usersLink, is(notNullValue()));
mvc.perform(get(usersLink.getHref())).andDo(MockMvcResultHandlers.print())
.andExpect(jsonPath("$.descriptors[?(@.id == 'item-representation')].href", is(notNullValue())));
mvc.perform(get(usersLink.getHref())).andExpect(
jsonPath("$.descriptors[?(@.id == 'item-representation')].href", is(notNullValue())));
}
/**
* @see DATAREST-516
*/
@Test
public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
Link profileLink = discoverUnique("/", "profile");
Link usersLink = discoverUnique(profileLink.getHref(), "people");
String jsonPath = "$."; // Root
jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor
jsonPath += "descriptors[?(@.name == 'father')][0]."; // First father descriptor
jsonPath += "rt"; // Return type
mvc.perform(get(usersLink.getHref())).andExpect(
jsonPath(jsonPath, allOf(containsString("alps"), endsWith("-representation"))));
}
private Link discoverUnique(String href, String rel) throws Exception {