DATAREST-683 - ALPS documents are now correctly nested.

We now wrap the ALPS descriptors into a root ALPS JSON node.
This commit is contained in:
Oliver Gierke
2015-11-06 16:01:34 +01:00
parent a93f68e227
commit cc7bc7aa79
3 changed files with 27 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.data.rest.webmvc.alps;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.converter.Converter;
@@ -91,7 +92,8 @@ public class AlpsJsonHttpMessageConverter extends MappingJackson2HttpMessageConv
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
return body instanceof RootResourceInformation ? converter.convert((RootResourceInformation) body) : body;
return body instanceof RootResourceInformation
? Collections.singletonMap("alps", converter.convert((RootResourceInformation) body)) : body;
}
/*

View File

@@ -92,8 +92,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
client.follow(peopleLink, RestMediaTypes.ALPS_JSON)//
.andExpect(jsonPath("$.version").value("1.0"))//
.andExpect(jsonPath("$.descriptors[*].name", hasItems("people", "person")));
.andExpect(jsonPath("$.alps.version").value("1.0"))//
.andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person")));
}
/**
@@ -106,8 +106,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
client.follow(peopleLink)//
.andExpect(jsonPath("$.version").value("1.0"))//
.andExpect(jsonPath("$.descriptors[*].name", hasItems("people", "person")));
.andExpect(jsonPath("$.alps.version").value("1.0"))//
.andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person")));
}
@@ -122,11 +122,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
// Exposes standard property
.andExpect(jsonPath("$.descriptors[*].descriptors[*].name", hasItems("name")))
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("name")))
// Does not expose explicitly @JsonIgnored property
.andExpect(jsonPath("$.descriptors[*].descriptors[*].name", not(hasItems("owner"))))
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("owner"))))
// Does not expose properties pointing to non exposed types
.andExpect(jsonPath("$.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator"))));
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator"))));
}
/**
@@ -141,7 +141,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
assertThat(itemsLink, is(notNullValue()));
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
.andExpect(jsonPath("$.descriptors[?(@.id == 'item-representation')][0].href", endsWith("/profile/items")));
.andExpect(
jsonPath("$.alps.descriptors[?(@.id == 'item-representation')][0].href", endsWith("/profile/items")));
}
/**
@@ -153,7 +154,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link profileLink = client.discoverUnique("profile");
Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
String jsonPath = "$."; // Root
String jsonPath = "$.alps."; // Root
jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor
jsonPath += "descriptors[?(@.name == 'father')][0]."; // First father descriptor
jsonPath += "rt"; // Return type
@@ -174,6 +175,6 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
// Exposes identifier if configured to
.andExpect(jsonPath("$.descriptors[*].descriptors[*].name", hasItems("id", "name")));
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("id", "name")));
}
}

View File

@@ -50,6 +50,7 @@ public class Person {
private Person father;
@Description("Timestamp this person object was created") private Date created;
private int age, height, weight;
private Gender gender;
public Person() {}
@@ -146,4 +147,16 @@ public class Person {
public void setWeight(int weight) {
this.weight = weight;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public static enum Gender {
MALE, FEMALE, UNDEFINED;
}
}