DATAREST-782 - Fixed build after Spring 4.2.5 update.

Upgraded to JSONPath 1.1.0 as 0.9 is not supported with Spring 4.2 anymore. Tweaked integration tests due to changed semantics and internals of JSONPath >= 1.0.
This commit is contained in:
Oliver Gierke
2016-03-17 21:29:20 +01:00
parent 2be6b2b6a9
commit 6075f3052a
16 changed files with 55 additions and 55 deletions

View File

@@ -37,7 +37,7 @@
<springdata.keyvalue>1.1.0.BUILD-SNAPSHOT</springdata.keyvalue>
<hibernate.version>4.3.10.Final</hibernate.version>
<jsonpath>0.9.1</jsonpath>
<jsonpath>1.1.0</jsonpath>
<bundlor.enabled>false</bundlor.enabled>
</properties>

View File

@@ -22,7 +22,6 @@ import org.springframework.data.rest.core.domain.Person;
import org.springframework.data.rest.core.domain.PersonRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
@@ -32,7 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepositoryTestsConfig.class)
@Transactional
public abstract class AbstractIntegrationTests {
@Autowired PersonRepository repository;

View File

@@ -42,7 +42,6 @@ import org.springframework.data.rest.core.event.BeforeLinkSaveEvent;
import org.springframework.data.rest.core.event.BeforeSaveEvent;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
@@ -52,7 +51,6 @@ import org.springframework.transaction.annotation.Transactional;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@Transactional
public class RepositoryEventIntegrationTests {
@Configuration

View File

@@ -42,17 +42,15 @@ import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.Re
import org.springframework.hateoas.core.EvoInflectorRelProvider;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* Integration tests for {@link RepositoryResourceMappings}.
*
* @author Oliver Gierke
* @author Greg Trunquist
* @author Greg Turnquist
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = JpaRepositoryConfig.class)
@Transactional
public class RepositoryResourceMappingsIntegrationTests {
@Autowired ListableBeanFactory factory;

View File

@@ -40,7 +40,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>

View File

@@ -15,17 +15,16 @@ package org.springframework.data.rest.tests;
* limitations under the License.
*/
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import net.minidev.json.JSONArray;
import java.util.Collections;
import java.util.Map;
import net.minidev.json.JSONArray;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -65,7 +64,7 @@ import com.jayway.jsonpath.JsonPath;
@ContextConfiguration(classes = RepositoryRestMvcConfiguration.class)
public abstract class AbstractWebIntegrationTests {
private static final String CONTENT_LINK_JSONPATH = "$._embedded.._links.%s.href[0]";
private static final String CONTENT_LINK_JSONPATH = "$._embedded.._links.%s.href";
@Autowired WebApplicationContext context;
@Autowired LinkDiscoverers discoverers;
@@ -117,8 +116,10 @@ public abstract class AbstractWebIntegrationTests {
String href = link.isTemplated() ? link.expand().getHref() : link.getHref();
MockHttpServletResponse response = mvc.perform(MockMvcRequestBuilders.request(HttpMethod.PATCH, href).//
content(payload.toString()).contentType(mediaType)).//
MockHttpServletResponse response = mvc
.perform(MockMvcRequestBuilders.request(HttpMethod.PATCH, href).//
content(payload.toString()).contentType(mediaType))
.//
andExpect(status().is2xxSuccessful()).//
andReturn().getResponse();
@@ -153,7 +154,8 @@ public abstract class AbstractWebIntegrationTests {
try {
String href = JsonPath.read(content, String.format(CONTENT_LINK_JSONPATH, rel)).toString();
String href = JsonPath.<JSONArray> read(content, String.format(CONTENT_LINK_JSONPATH, rel)).get(0).toString();
assertThat("Expected to find a link with rel" + rel + " in the content section of the response!", href,
is(expected ? notNullValue() : nullValue()));
@@ -247,4 +249,4 @@ public abstract class AbstractWebIntegrationTests {
protected MultiValueMap<String, String> getRootAndLinkedResources() {
return new LinkedMultiValueMap<String, String>(0);
}
}
}

View File

@@ -134,7 +134,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
if (searchLink != null) {
client.follow(searchLink).//
andExpect(client.hasLinkWithRel("self")).//
andExpect(jsonPath("$.domainType", is(nullValue()))); // DATAREST-549
andExpect(jsonPath("$.domainType").doesNotExist()); // DATAREST-549
}
}
}
@@ -182,7 +182,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
for (String linkedRel : linked.getValue()) {
// Find URIs pointing to linked resources
String jsonPath = String.format("$..%s._links.%s.href", linked.getKey(), linkedRel);
String jsonPath = String.format("$._embedded.%s[*]._links.%s.href", linked.getKey(), linkedRel);
String representation = resource.getContentAsString();
JSONArray uris = JsonPath.read(representation, jsonPath);

View File

@@ -19,6 +19,8 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import net.minidev.json.JSONArray;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -30,7 +32,6 @@ import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
import org.springframework.data.rest.tests.TestMvcClient;
import org.springframework.data.rest.webmvc.ProfileController;
import org.springframework.data.rest.webmvc.RestMediaTypes;
import org.springframework.data.rest.webmvc.alps.AlpsController;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.data.rest.webmvc.jpa.Item;
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
@@ -45,6 +46,8 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.jayway.jsonpath.JsonPath;
/**
* Integration tests for {@link AlpsController}.
*
@@ -146,9 +149,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
assertThat(itemsLink, is(notNullValue()));
client.follow(itemsLink, RestMediaTypes.ALPS_JSON)//
.andExpect(
jsonPath("$.alps.descriptors[?(@.id == 'item-representation')][0].href", endsWith("/profile/items")));
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)
.toString();
assertThat(href, endsWith("/profile/items"));
}
/**
@@ -162,12 +167,13 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
String jsonPath = "$.alps."; // Root
jsonPath += "descriptors[?(@.id == 'person-representation')]."; // Representation descriptor
jsonPath += "descriptors[?(@.name == 'father')][0]."; // First father descriptor
jsonPath += "descriptors[?(@.name == 'father')]."; // First father descriptor
jsonPath += "rt"; // Return type
client.follow(usersLink, RestMediaTypes.ALPS_JSON)//
.andExpect(jsonPath(jsonPath,
allOf(containsString(ProfileController.PROFILE_ROOT_MAPPING), endsWith("-representation"))));
String result = client.follow(usersLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString();
String rt = JsonPath.<JSONArray> read(result, jsonPath).get(0).toString();
assertThat(rt, allOf(containsString(ProfileController.PROFILE_ROOT_MAPPING), endsWith("-representation")));
}
/**
@@ -195,10 +201,14 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link profileLink = client.discoverUnique("profile");
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
client.follow(peopleLink)//
.andExpect(jsonPath(
"$.alps.descriptors[?(@.id == 'person-representation')].descriptors[?(@.name == 'gender')][0].doc.value",
is("Male, Female, Undefined")));
String result = client.follow(peopleLink).andReturn().getResponse().getContentAsString();
String value = JsonPath
.<JSONArray> read(result,
"$.alps.descriptors[?(@.id == 'person-representation')].descriptors[?(@.name == 'gender')].doc.value")
.get(0).toString();
assertThat(value, is("Male, Female, Undefined"));
}
/**
@@ -210,9 +220,13 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link profileLink = client.discoverUnique("profile");
Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses");
client.follow(groovyDomainObjectLink)//
.andExpect(jsonPath(
"$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')][0].descriptors[0].name",
is("name")));
String result = client.follow(groovyDomainObjectLink).andReturn().getResponse().getContentAsString();
String name = JsonPath
.<JSONArray> read(result,
"$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptors[0].name")
.get(0).toString();
assertThat(name, is("name"));
}
}

View File

@@ -694,10 +694,10 @@ public class JpaWebTests extends CommonWebTests {
MockHttpServletResponse response = client.request(client.discoverUnique("people"));
String jsonPath = String.format("$._embedded.people[?(@.firstName == '%s')][0]", name);
String jsonPath = String.format("$._embedded.people[?(@.firstName == '%s')]", name);
// Assert content inlined
Object john = JsonPath.read(response.getContentAsString(), jsonPath);
Object john = JsonPath.<JSONArray> read(response.getContentAsString(), jsonPath).get(0);
assertThat(john, is(notNullValue()));
assertThat(JsonPath.read(john, "$.firstName"), is(notNullValue()));

View File

@@ -225,7 +225,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(persistentEntityResource);
assertThat(JsonPath.read(result, "$_embedded.orders[*].lineItems"), is(notNullValue()));
assertThat(JsonPath.read(result, "$._embedded.orders[*].lineItems"), is(notNullValue()));
}
/**
@@ -251,7 +251,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$_embedded.father[*]._links.self"), is(notNullValue()));
assertThat(JsonPath.read(result, "$._embedded.father[*]._links.self"), is(notNullValue()));
}
/**
@@ -270,7 +270,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$_links.processed"), is(notNullValue()));
assertThat(JsonPath.read(result, "$._links.processed"), is(notNullValue()));
}
/**

View File

@@ -33,7 +33,6 @@
<groupId>com.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>${querydsl}</version>
<scope>test</scope>
</dependency>
<!-- Querydsl -->
@@ -76,7 +75,6 @@
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
<logOnlyOnError>true</logOnlyOnError>
<options>
<querydsl.excludedPackages>org.springframework.data.rest.tests.mongodb.groovy,groovy.lang</querydsl.excludedPackages>
</options>

View File

@@ -30,12 +30,6 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.tests.CommonWebTests;
import org.springframework.data.rest.tests.mongodb.Address;
import org.springframework.data.rest.tests.mongodb.Profile;
import org.springframework.data.rest.tests.mongodb.ProfileRepository;
import org.springframework.data.rest.tests.mongodb.Receipt;
import org.springframework.data.rest.tests.mongodb.User;
import org.springframework.data.rest.tests.mongodb.UserRepository;
import org.springframework.data.rest.webmvc.RestMediaTypes;
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
import org.springframework.hateoas.Link;

View File

@@ -45,7 +45,6 @@ import org.springframework.hateoas.hal.HalLinkDiscoverer;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletWebRequest;
@@ -62,7 +61,6 @@ import com.jayway.jsonpath.JsonPath;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class,
PersistentEntitySerializationTests.TestConfig.class })
@Transactional
public class PersistentEntitySerializationTests {
@Autowired ObjectMapper mapper;
@@ -114,7 +112,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(persistentEntityResource);
assertThat(JsonPath.read(result, "$_embedded.users[*].address"), is(notNullValue()));
assertThat(JsonPath.read(result, "$._embedded.users[*].address"), is(notNullValue()));
}
/**

View File

@@ -52,6 +52,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
/**
* @author Oliver Gierke
@@ -186,6 +187,8 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
try {
assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector), constraint.matcher);
} catch (PathNotFoundException e) {
assertThat(constraint.matcher.matches(null), is(true));
} catch (RuntimeException e) {
assertThat(e, constraint.matcher);
}

View File

@@ -38,7 +38,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
/**
@@ -50,7 +49,6 @@ import org.springframework.web.context.WebApplicationContext;
* @author Rob Winch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class,
RepositoryRestMvcConfiguration.class })
public class SecurityIntegrationTests extends AbstractWebIntegrationTests {

View File

@@ -65,7 +65,7 @@ public class ProjectionJacksonIntegrationTests {
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
String result = mapper.writeValueAsString(projection);
assertThat(JsonPath.read(result, "$firstname"), is((Object) "Dave"));
assertThat(JsonPath.read(result, "$.firstname"), is((Object) "Dave"));
}
/**
@@ -89,7 +89,7 @@ public class ProjectionJacksonIntegrationTests {
String result = mapper.writeValueAsString(resources);
assertThat(JsonPath.read(result, "$_embedded.customers[0].firstname"), is((Object) "Dave"));
assertThat(JsonPath.read(result, "$._embedded.customers[0].firstname"), is((Object) "Dave"));
}
static class Customer {