DATAREST-1256 - Upgraded to Spring HATEOAS 0.25.0.BUILD-SNAPSHOT.
Adapted RepositoryRestMvcConfiguration to now create a shared fallback ObjectMapper and avoid to register it as Spring Bean. Adapted test cases that previously were relying on such a bean being present. Adapted test cases to verify on the correct ALPS document structure (see spring-projects/spring-hateoas#665).
This commit is contained in:
@@ -69,7 +69,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
@Bean
|
||||
public LinkDiscoverer alpsLinkDiscoverer() {
|
||||
return new JsonPathLinkDiscoverer("$.descriptors[?(@.name == '%s')].href",
|
||||
return new JsonPathLinkDiscoverer("$.descriptor[?(@.name == '%s')].href",
|
||||
MediaType.valueOf("application/alps+json"));
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
client.follow(peopleLink, RestMediaTypes.ALPS_JSON)//
|
||||
.andExpect(jsonPath("$.alps.version").value("1.0"))//
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person")));
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].name", hasItems("people", "person")));
|
||||
}
|
||||
|
||||
@Test // DATAREST-638
|
||||
@@ -112,7 +112,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
client.follow(peopleLink)//
|
||||
.andExpect(jsonPath("$.alps.version").value("1.0"))//
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].name", hasItems("people", "person")));
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].name", hasItems("people", "person")));
|
||||
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
|
||||
// Exposes standard property
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("name")))
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("name")))
|
||||
// Does not expose explicitly @JsonIgnored property
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("owner"))))
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", not(hasItems("owner"))))
|
||||
// Does not expose properties pointing to non exposed types
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", not(hasItems("manager", "curator"))));
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", not(hasItems("manager", "curator"))));
|
||||
}
|
||||
|
||||
@Test // DATAREST-494
|
||||
@@ -140,7 +140,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
assertThat(itemsLink).isNotNull();
|
||||
|
||||
String result = client.follow(itemsLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString();
|
||||
String href = JsonPath.<JSONArray> read(result, "$.alps.descriptors[?(@.id == 'item-representation')].href").get(0)
|
||||
String href = JsonPath.<JSONArray> read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0)
|
||||
.toString();
|
||||
|
||||
assertThat(href, endsWith("/profile/items"));
|
||||
@@ -153,8 +153,8 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||
|
||||
String jsonPath = "$.alps."; // Root
|
||||
jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor
|
||||
jsonPath += "descriptors[?(@.name == 'father')]."; // First father descriptor
|
||||
jsonPath += "descriptor[?(@.id == 'person-representation')]."; // Representation descriptor
|
||||
jsonPath += "descriptor[?(@.name == 'father')]."; // First father descriptor
|
||||
jsonPath += "rt"; // Return type
|
||||
|
||||
String result = client.follow(usersLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString();
|
||||
@@ -171,7 +171,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
|
||||
// Exposes identifier if configured to
|
||||
.andExpect(jsonPath("$.alps.descriptors[*].descriptors[*].name", hasItems("id", "name")));
|
||||
.andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("id", "name")));
|
||||
}
|
||||
|
||||
@Test // DATAREST-683
|
||||
@@ -186,7 +186,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
String value = JsonPath
|
||||
.<JSONArray> read(result,
|
||||
"$.alps.descriptors[?(@.id == 'person-representation')].descriptors[?(@.name == 'gender')].doc.value")
|
||||
"$.alps.descriptor[?(@.id == 'person-representation')].descriptor[?(@.name == 'gender')].doc.value")
|
||||
.get(0).toString();
|
||||
|
||||
assertThat(value).isEqualTo("Male, Female, Undefined");
|
||||
@@ -202,7 +202,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
String name = JsonPath
|
||||
.<JSONArray> read(result,
|
||||
"$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptors[0].name")
|
||||
"$.alps.descriptor[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptor[0].name")
|
||||
.get(0).toString();
|
||||
|
||||
assertThat(name).isEqualTo("name");
|
||||
|
||||
@@ -26,11 +26,9 @@ import javax.persistence.ManyToOne;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -41,9 +39,16 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
@@ -69,11 +74,18 @@ public class DataRest262Tests {
|
||||
@Autowired ApplicationContext beanFactory;
|
||||
@Autowired JpaMetamodelMappingContext mappingContext;
|
||||
@Autowired AirportRepository repository;
|
||||
@Autowired @Qualifier("halObjectMapper") ObjectMapper mapper;
|
||||
|
||||
ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
|
||||
|
||||
this.mapper = beanFactory //
|
||||
.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) //
|
||||
.getObjectMapper() //
|
||||
.copy();
|
||||
|
||||
this.mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
@@ -87,9 +99,13 @@ public class DataRest262Tests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
@Ignore
|
||||
public void serializesLinksToNestedAssociations() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addHeader(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE);
|
||||
RequestAttributes attributes = new ServletRequestAttributes(request);
|
||||
RequestContextHolder.setRequestAttributes(attributes);
|
||||
|
||||
Airport first = new Airport();
|
||||
first.id = 1L;
|
||||
|
||||
@@ -112,9 +128,9 @@ public class DataRest262Tests {
|
||||
|
||||
String result = mapper.writeValueAsString(resource);
|
||||
|
||||
assertThat(JsonPath.<Object> read(result, "$_links.self")).isNotNull();
|
||||
assertThat(JsonPath.<Object> read(result, "$_links.airport")).isNotNull();
|
||||
assertThat(JsonPath.<Object> read(result, "$_links.originOrDestinationAirport")).isNotNull();
|
||||
assertThat(JsonPath.<Object> read(result, "$._links.self")).isNotNull();
|
||||
assertThat(JsonPath.<Object> read(result, "$._links.originOrDestinationAirport")).isNotNull();
|
||||
assertThat(JsonPath.<Object> read(result, "$.orgOrDstFlightPart._links.airport")).isNotNull();
|
||||
}
|
||||
|
||||
public interface AircraftMovementRepository extends CrudRepository<AircraftMovement, Long> {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.data.rest.webmvc.jpa.Order;
|
||||
import org.springframework.data.rest.webmvc.jpa.OrderRepository;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -50,18 +52,22 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class Jackson2DatatypeHelperIntegrationTests {
|
||||
|
||||
@Autowired PersistentEntities entities;
|
||||
@Autowired ObjectMapper objectMapper;
|
||||
@Autowired ApplicationContext context;
|
||||
|
||||
@Autowired PersonRepository people;
|
||||
@Autowired OrderRepository orders;
|
||||
@Autowired EntityManager em;
|
||||
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
Order order;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews"))));
|
||||
this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class)
|
||||
.getObjectMapper();
|
||||
|
||||
// Reset JPA to make sure the query returns a result with proxy references
|
||||
em.flush();
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
@@ -39,8 +38,6 @@ import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link PersistentEntityResourceAssembler}.
|
||||
*
|
||||
@@ -51,7 +48,6 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
|
||||
|
||||
@Autowired PersistentEntities entities;
|
||||
@Autowired EntityLinks entityLinks;
|
||||
@Autowired @Qualifier("objectMapper") ObjectMapper objectMapper;
|
||||
@Autowired Associations associations;
|
||||
|
||||
@Test // DATAREST-609
|
||||
|
||||
@@ -66,9 +66,10 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
@Autowired @Qualifier("resourceDescriptionMessageSourceAccessor") MessageSourceAccessor accessor;
|
||||
@Autowired RepositoryRestConfiguration configuration;
|
||||
@Autowired PersistentEntities entities;
|
||||
@Autowired @Qualifier("objectMapper") ObjectMapper objectMapper;
|
||||
@Autowired Associations associations;
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Configuration
|
||||
@Import(RepositoryRestMvcConfiguration.class)
|
||||
static class TestConfiguration extends RepositoryRestConfigurerAdapter {
|
||||
|
||||
Reference in New Issue
Block a user