DATAREST-1008 - Adapt to API changes in Spring Data Commons, Java 8 upgrades and Mockito 2.7.

This commit is contained in:
Oliver Gierke
2017-03-01 12:30:47 +01:00
parent 272dc179ad
commit b9957d1a6c
159 changed files with 2230 additions and 2220 deletions

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.rest.tests.TestMvcClient.*;
import org.junit.Test;
@@ -50,7 +49,7 @@ public class RepositoryControllerIntegrationTests extends AbstractControllerInte
@Test // DATAREST-333, DATAREST-330
public void headRequestReturnsNoContent() {
assertThat(controller.headForRepositories().getStatusCode(), is(HttpStatus.NO_CONTENT));
assertThat(controller.headForRepositories().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
@Test // DATAREST-160, DATAREST-333, DATAREST-463
@@ -58,14 +57,14 @@ public class RepositoryControllerIntegrationTests extends AbstractControllerInte
RepositoryLinksResource resource = controller.listRepositories().getBody();
assertThat(resource.getLinks(), hasSize(8));
assertThat(resource.getLinks()).hasSize(8);
assertThat(resource.hasLink("people"), is(true));
assertThat(resource.hasLink("orders"), is(true));
assertThat(resource.hasLink("addresses"), is(true));
assertThat(resource.hasLink("books"), is(true));
assertThat(resource.hasLink("authors"), is(true));
assertThat(resource.hasLink("receipts"), is(true));
assertThat(resource.hasLink("items"), is(true));
assertThat(resource.hasLink("people")).isTrue();
assertThat(resource.hasLink("orders")).isTrue();
assertThat(resource.hasLink("addresses")).isTrue();
assertThat(resource.hasLink("books")).isTrue();
assertThat(resource.hasLink("authors")).isTrue();
assertThat(resource.hasLink("receipts")).isTrue();
assertThat(resource.hasLink("items")).isTrue();
}
}

View File

@@ -15,13 +15,16 @@
*/
package org.springframework.data.rest.webmvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import static org.springframework.data.rest.tests.TestMvcClient.*;
import static org.springframework.http.HttpMethod.*;
import java.util.List;
import java.util.Optional;
import org.hamcrest.Matchers;
import org.junit.Test;
@@ -89,7 +92,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
RootResourceInformation information = getResourceInformation(Order.class);
PersistentEntityResource persistentEntityResource = PersistentEntityResource
.build(new Order(new Person()), entities.getPersistentEntity(Order.class)).build();
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
ResponseEntity<?> entity = controller.putItemResource(information, persistentEntityResource, 1L, assembler,
ETag.NO_ETAG, MediaType.APPLICATION_JSON_VALUE);
@@ -101,7 +104,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
public void exposesHeadForCollectionResourceIfExported() throws Exception {
ResponseEntity<?> entity = controller.headCollectionResource(getResourceInformation(Person.class),
new DefaultedPageable(null, false));
assertThat(entity.getStatusCode(), is(HttpStatus.NO_CONTENT));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
@@ -117,7 +120,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
ResponseEntity<?> entity = controller.headForItemResource(getResourceInformation(Address.class), address.id,
assembler);
assertThat(entity.getStatusCode(), is(HttpStatus.NO_CONTENT));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
@@ -153,7 +156,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
List<String> value = entity.getHeaders().get("Accept-Patch");
assertThat(value, hasSize(3));
assertThat(value).hasSize(3);
assertThat(value,
hasItems(//
RestMediaTypes.JSON_PATCH_JSON.toString(), //
@@ -168,7 +171,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
Order order = request.getInvoker().invokeSave(new Order(new Person()));
PersistentEntityResource persistentEntityResource = PersistentEntityResource
.build(new Order(new Person()), entities.getPersistentEntity(Order.class)).build();
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
assertThat(controller.putItemResource(request, persistentEntityResource, order.getId(), assembler, ETag.NO_ETAG,
MediaType.APPLICATION_JSON_VALUE).hasBody(), is(true));
@@ -179,7 +182,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
RootResourceInformation request = getResourceInformation(Order.class);
PersistentEntityResource persistentEntityResource = PersistentEntityResource
.build(new Order(new Person()), entities.getPersistentEntity(Order.class)).build();
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
assertThat(controller.putItemResource(request, persistentEntityResource, 1L, assembler, ETag.NO_ETAG,
MediaType.APPLICATION_JSON_VALUE).hasBody(), is(true));
@@ -190,7 +193,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
RootResourceInformation request = getResourceInformation(Order.class);
PersistentEntityResource persistentEntityResource = PersistentEntityResource
.build(new Order(new Person()), entities.getPersistentEntity(Order.class)).build();
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
assertThat(controller
.postCollectionResource(request, persistentEntityResource, assembler, MediaType.APPLICATION_JSON_VALUE)
@@ -202,7 +205,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
RootResourceInformation request = getResourceInformation(Order.class);
PersistentEntityResource persistentEntityResource = PersistentEntityResource
.build(new Order(new Person()), entities.getPersistentEntity(Order.class)).build();
.build(new Order(new Person()), entities.getRequiredPersistentEntity(Order.class)).build();
assertThat(controller.postCollectionResource(request, persistentEntityResource, assembler, null).hasBody(),
is(false));
@@ -220,32 +223,32 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
.createProjection(AddressProjection.class);
PersistentEntityResource resource = PersistentEntityResource
.build(addressProjection, entities.getPersistentEntity(Address.class)).build();
.build(addressProjection, entities.getRequiredPersistentEntity(Address.class)).build();
Mockito.when(assembler.toFullResource(Mockito.any(Object.class))).thenReturn(resource);
ResponseEntity<Resource<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
assembler, new HttpHeaders());
assertThat(entity.getHeaders().getETag(), is(notNullValue()));
assertThat(entity.getHeaders().getETag()).isNotNull();
}
@Test // DATAREST-724
public void deletesEntityWithCustomLookupCorrectly() throws Exception {
Address address = repository.save(new Address());
assertThat(repository.findOne(address.id), is(notNullValue()));
assertThat(repository.findOne(address.id)).isNotNull();
RootResourceInformation resourceInformation = getResourceInformation(Address.class);
RepositoryInvoker invoker = spy(resourceInformation.getInvoker());
doReturn(address).when(invoker).invokeFindOne("foo");
doReturn(Optional.of(address)).when(invoker).invokeFindOne("foo");
RootResourceInformation informationSpy = Mockito.spy(resourceInformation);
doReturn(invoker).when(informationSpy).getInvoker();
controller.deleteItemResource(informationSpy, "foo", ETag.from("0"));
assertThat(repository.findOne(address.id), is(nullValue()));
assertThat(repository.findOne(address.id)).isEmpty();
}
interface AddressProjection {}

View File

@@ -15,14 +15,14 @@
*/
package org.springframework.data.rest.webmvc;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.rest.tests.TestMvcClient.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.rest.core.mapping.ResourceMetadata;
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
import org.springframework.data.rest.tests.ResourceTester;
@@ -56,7 +56,7 @@ import org.springframework.util.MultiValueMap;
@Transactional
public class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests {
static final DefaultedPageable PAGEABLE = new DefaultedPageable(new PageRequest(0, 10), true);
static final DefaultedPageable PAGEABLE = new DefaultedPageable(PageRequest.of(0, 10), true);
@Autowired TestDataPopulator loader;
@Autowired RepositorySearchController controller;
@@ -101,12 +101,12 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
parameters.add("firstname", "John");
ResponseEntity<?> response = controller.executeSearch(resourceInformation, parameters, "firstname", PAGEABLE, null,
assembler, new HttpHeaders());
ResponseEntity<?> response = controller.executeSearch(resourceInformation, parameters, "firstname", PAGEABLE,
Sort.unsorted(), assembler, new HttpHeaders());
ResourceTester tester = ResourceTester.of(response.getBody());
PagedResources<Object> pagedResources = tester.assertIsPage();
assertThat(pagedResources.getContent().size(), is(1));
assertThat(pagedResources.getContent()).hasSize(1);
ResourceMetadata metadata = getMetadata(Person.class);
tester.withContentResource(new HasSelfLink(BASE.slash(metadata.getPath()).slash("{id}")));
@@ -165,9 +165,9 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
RootResourceInformation resourceInformation = getResourceInformation(Book.class);
ResponseEntity<?> result = controller.executeSearch(resourceInformation, parameters, "findByAuthorsContains",
PAGEABLE, null, assembler, new HttpHeaders());
PAGEABLE, Sort.unsorted(), assembler, new HttpHeaders());
assertThat(result.getBody(), is(instanceOf(Resources.class)));
assertThat(result.getBody()).isInstanceOf(Resources.class);
}
@Test // DATAREST-515
@@ -175,6 +175,6 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
RepositorySearchesResource searches = controller.listSearches(getResourceInformation(Person.class));
assertThat(searches.getDomainType(), is(typeCompatibleWith(Person.class)));
assertThat(searches.getDomainType()).isAssignableFrom(Person.class);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.rest.core.mapping.ResourceType.*;
import static org.springframework.http.HttpMethod.*;
@@ -44,13 +43,13 @@ public class RootResourceInformationIntegrationTests extends AbstractControllerI
public void getIsNotSupportedIfFindAllIsNotExported() {
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
assertThat(supportedMethods.getMethodsFor(COLLECTION), not(hasItem(GET)));
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(GET);
}
@Test // DATAREST-217
public void postIsNotSupportedIfSaveIsNotExported() {
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
assertThat(supportedMethods.getMethodsFor(COLLECTION), not(hasItem(POST)));
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(POST);
}
}

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.rest.webmvc.alps;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import net.minidev.json.JSONArray;
@@ -135,7 +137,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
Link profileLink = client.discoverUnique("profile");
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
assertThat(itemsLink, is(notNullValue()));
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)
@@ -158,7 +160,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
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")));
assertThat(rt).contains(ProfileController.PROFILE_ROOT_MAPPING).endsWith("-representation");
}
@Test // DATAREST-630
@@ -187,7 +189,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
"$.alps.descriptors[?(@.id == 'person-representation')].descriptors[?(@.name == 'gender')].doc.value")
.get(0).toString();
assertThat(value, is("Male, Female, Undefined"));
assertThat(value).isEqualTo("Male, Female, Undefined");
}
@Test // DATAREST-753
@@ -203,6 +205,6 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
"$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')].descriptors[0].name")
.get(0).toString();
assertThat(name, is("name"));
assertThat(name).isEqualTo("name");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
@@ -84,7 +83,7 @@ public class DataRest262Tests {
String payload = "{\"orgOrDstFlightPart\":{\"airport\":\"/api/airports/" + airport.id + "\"}}";
AircraftMovement result = mapper.readValue(payload, AircraftMovement.class);
assertThat(result.orgOrDstFlightPart.airport.id, is(airport.id));
assertThat(result.orgOrDstFlightPart.airport.id).isEqualTo(airport.id);
}
@Test // DATAREST-262
@@ -105,7 +104,7 @@ public class DataRest262Tests {
movement.originOrDestinationAirport = first;
movement.orgOrDstFlightPart = part;
JpaPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(AircraftMovement.class);
JpaPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(AircraftMovement.class);
Resource<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
withLink(new Link("/api/airports/" + movement.id)).//
@@ -113,9 +112,9 @@ public class DataRest262Tests {
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$_links.self"), is(notNullValue()));
assertThat(JsonPath.read(result, "$_links.airport"), is(notNullValue()));
assertThat(JsonPath.read(result, "$_links.originOrDestinationAirport"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$_links.self")).isNotNull();
assertThat(JsonPath.<Object> read(result, "$_links.airport")).isNotNull();
assertThat(JsonPath.<Object> read(result, "$_links.originOrDestinationAirport")).isNotNull();
}
public interface AircraftMovementRepository extends CrudRepository<AircraftMovement, Long> {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -96,8 +95,8 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
Link findBySortedLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
// Assert sort options advertised
assertThat(findBySortedLink.isTemplated(), is(true));
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
assertThat(findBySortedLink.isTemplated()).isTrue();
assertThat(findBySortedLink.getVariableNames()).contains("sort", "projection");
// Assert results returned as specified
client.follow(findBySortedLink.expand()).//

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import static org.springframework.data.rest.webmvc.util.TestUtils.*;
import static org.springframework.http.HttpHeaders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
@@ -149,7 +151,7 @@ public class JpaWebTests extends CommonWebTests {
MockHttpServletResponse orders = client.request(ordersLink);
Link creatorLink = assertHasContentLinkWithRel("creator", orders);
assertThat(client.request(creatorLink), is(notNullValue()));
assertThat(client.request(creatorLink)).isNotNull();
}
@Test // DATAREST-200
@@ -201,18 +203,18 @@ public class JpaWebTests extends CommonWebTests {
Link bilboLink = client.assertHasLinkWithRel("self", bilbo);
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), is("Bilbo"));
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), is("Baggins"));
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName")).isEqualTo("Bilbo");
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
MockHttpServletResponse frodo = patchAndGet(bilboLink, "{ \"firstName\" : \"Frodo\" }", MediaType.APPLICATION_JSON);
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), is("Frodo"));
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.lastName"), is("Baggins"));
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName")).isEqualTo("Frodo");
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
frodo = patchAndGet(bilboLink, "{ \"firstName\" : null }", MediaType.APPLICATION_JSON);
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), is(nullValue()));
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.lastName"), is("Baggins"));
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName")).isNull();
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
}
@Test // DATAREST-150
@@ -411,17 +413,17 @@ public class JpaWebTests extends CommonWebTests {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(orderLink.getHref());
String uri = builder.queryParam("projection", "summary").build().toUriString();
response = mvc.perform(get(uri)). //
andExpect(status().isOk()). //
andExpect(jsonPath("$.price", is(2.5))).//
andReturn().getResponse();
response = mvc.perform(get(uri))//
.andExpect(status().isOk())//
.andExpect(jsonPath("$.price", is(2.5)))//
.andReturn().getResponse();
assertJsonPathDoesntExist("$.lineItems", response);
}
@Test // DATAREST-261
public void relProviderDetectsCustomizedMapping() {
assertThat(relProvider.getCollectionResourceRelFor(Person.class), is("people"));
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo("people");
}
@Test // DATAREST-311
@@ -445,9 +447,9 @@ public class JpaWebTests extends CommonWebTests {
JSONArray personLinks = JsonPath.<JSONArray> read(responseBody, "$.links[?(@.rel=='person')].href");
assertThat(personLinks, hasSize(1));
assertThat(personLinks.get(0), is((Object) daenerysLink.getHref()));
assertThat(JsonPath.<JSONArray> read(responseBody, "$.content"), hasSize(0));
assertThat(personLinks).hasSize(1);
assertThat(personLinks.get(0)).isEqualTo((Object) daenerysLink.getHref());
assertThat(JsonPath.<JSONArray> read(responseBody, "$.content")).hasSize(0);
}
@Test // DATAREST-317
@@ -490,8 +492,8 @@ public class JpaWebTests extends CommonWebTests {
Link findBySortedLink = client.discoverUnique(searchLink, "find-by-sorted");
// Assert sort options advertised
assertThat(findBySortedLink.isTemplated(), is(true));
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
assertThat(findBySortedLink.isTemplated()).isTrue();
assertThat(findBySortedLink.getVariableNames()).contains("sort", "projection");
// Assert results returned as specified
client.follow(findBySortedLink.expand("title,desc")).//
@@ -575,8 +577,8 @@ public class JpaWebTests extends CommonWebTests {
.andReturn().getResponse();
Links links = Links.valueOf(response.getHeader("Link"));
assertThat(links.hasLink("self"), is(true));
assertThat(links.hasLink("person"), is(true));
assertThat(links.hasLink("self")).isTrue();
assertThat(links.hasLink("person")).isTrue();
}
@Test // DATAREST-883
@@ -585,8 +587,8 @@ public class JpaWebTests extends CommonWebTests {
Link findBySortedLink = client.discoverUnique("books", "search", "find-by-sorted");
// Assert sort options advertised
assertThat(findBySortedLink.isTemplated(), is(true));
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
assertThat(findBySortedLink.isTemplated()).isTrue();
assertThat(findBySortedLink.getVariableNames()).contains("sort", "projection");
// Assert results returned as specified
client.follow(findBySortedLink.expand("sales,desc")).//
@@ -606,7 +608,7 @@ public class JpaWebTests extends CommonWebTests {
Link findByLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
// Assert sort options advertised
assertThat(findByLink.isTemplated(), is(true));
assertThat(findByLink.isTemplated()).isTrue();
// Assert results returned as specified
client.follow(findByLink.expand("0", "10", "sales,desc")).//
@@ -635,8 +637,8 @@ public class JpaWebTests extends CommonWebTests {
Link findBySortedLink = client.discoverUnique(searchLink, "find-by-sorted");
// Assert sort options advertised
assertThat(findBySortedLink.isTemplated(), is(true));
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
assertThat(findBySortedLink.isTemplated()).isTrue();
assertThat(findBySortedLink.getVariableNames()).contains("sort", "projection");
// Assert results returned as specified
client.follow(findBySortedLink.expand("offer.price,desc")).//
@@ -682,8 +684,8 @@ public class JpaWebTests extends CommonWebTests {
String responseBody = client.request(link).getContentAsString();
List<String> persons = JsonPath.read(responseBody, "$._embedded.people[*].firstName");
assertThat(persons, hasSize(siblingNames.length));
assertThat(persons, hasItems(siblingNames));
assertThat(persons).hasSize(siblingNames.length);
assertThat(persons).contains(siblingNames);
}
private void assertPersonWithNameAndSiblingLink(String name) throws Exception {
@@ -694,8 +696,8 @@ public class JpaWebTests extends CommonWebTests {
// Assert content inlined
Object john = JsonPath.<JSONArray> read(response.getContentAsString(), jsonPath).get(0);
assertThat(john, is(notNullValue()));
assertThat(JsonPath.read(john, "$.firstName"), is(notNullValue()));
assertThat(john).isNotNull();
assertThat(JsonPath.<String> read(john, "$.firstName")).isNotNull();
// Assert sibling link exposed in resource pointed to
Link selfLink = new Link(JsonPath.<String> read(john, "$._links.self.href"));

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.data.rest.webmvc.jpa;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.Before;
@@ -81,19 +81,19 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
.andExpect(jsonPath("$._links.profile.href", endsWith(ProfileController.PROFILE_ROOT_MAPPING)));
}
@Test // DATAREST-230, DATAREST-638
@Test // DATAREST-230, DATAREST-638
public void profileRootLinkContainsMetadataForEachRepo() throws Exception {
Link profileLink = client.discoverUnique(new Link(ROOT_URI), ProfileResourceProcessor.PROFILE_REL);
assertThat(client.discoverUnique(profileLink, "self", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "people", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "items", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "authors", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "books", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "orders", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "receipts", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "addresses", MediaType.ALL), is(notNullValue()));
assertThat(client.discoverUnique(profileLink, "self", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "people", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "items", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "authors", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "books", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "orders", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "receipts", MediaType.ALL)).isNotNull();
assertThat(client.discoverUnique(profileLink, "addresses", MediaType.ALL)).isNotNull();
}
@Test // DATAREST-638

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.json;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import javax.persistence.EntityManager;
@@ -70,12 +69,12 @@ public class Jackson2DatatypeHelperIntegrationTests {
}
@Test // DATAREST-500
public void configuresHIbernate4ModuleToLoadLazyLoadingProxies() throws Exception {
public void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception {
PersistentEntity<?, ?> entity = entities.getPersistentEntity(Order.class);
PersistentProperty<?> property = entity.getPersistentProperty("creator");
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(orders.findOne(this.order.getId()));
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(Order.class);
PersistentProperty<?> property = entity.getRequiredPersistentProperty("creator");
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(orders.findOne(this.order.getId()).orElse(null));
assertThat(objectMapper.writeValueAsString(accessor.getProperty(property)), is(not("null")));
assertThat(objectMapper.writeValueAsString(accessor.getProperty(property))).isNotEqualTo("null");
}
}

View File

@@ -15,7 +15,8 @@
*/
package org.springframework.data.rest.webmvc.json;
import static org.hamcrest.MatcherAssert.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.io.IOException;
@@ -121,9 +122,9 @@ public class PersistentEntitySerializationTests {
Person p = mapper.readValue(PERSON_JSON_IN, Person.class);
assertThat(p.getFirstName(), is("John"));
assertThat(p.getLastName(), is("Doe"));
assertThat(p.getSiblings(), is(Collections.EMPTY_LIST));
assertThat(p.getFirstName()).isEqualTo("John");
assertThat(p.getLastName()).isEqualTo("Doe");
assertThat(p.getSiblings()).isEqualTo(Collections.EMPTY_LIST);
}
@Test // DATAREST-238
@@ -170,7 +171,7 @@ public class PersistentEntitySerializationTests {
String child = String.format("{ \"firstName\" : \"Bilbo\", \"father\" : \"/persons/%s\"}", father.getId());
Person result = mapper.readValue(child, Person.class);
assertThat(result.getFather(), is(father));
assertThat(result.getFather()).isEqualTo(father);
}
@Test // DATAREST-248
@@ -183,7 +184,7 @@ public class PersistentEntitySerializationTests {
firstSibling.getId(), secondSibling.getId());
Person result = mapper.readValue(child, Person.class);
assertThat(result.getSiblings(), hasItems(firstSibling, secondSibling));
assertThat(result.getSiblings()).contains(firstSibling, secondSibling);
}
@Test // DATAREST-248
@@ -192,7 +193,7 @@ public class PersistentEntitySerializationTests {
String content = TestUtils.readFileFromClasspath("order.json");
Order order = mapper.readValue(content, Order.class);
assertThat(order.getLineItems(), hasSize(2));
assertThat(order.getLineItems()).hasSize(2);
}
@Test // DATAREST-250
@@ -214,7 +215,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(persistentEntityResource);
assertThat(JsonPath.read(result, "$._embedded.orders[*].lineItems"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$._embedded.orders[*].lineItems")).isNotNull();
}
@Test // DATAREST-521
@@ -237,7 +238,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$._embedded.father[*]._links.self"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$._embedded.father[*]._links.self")).isNotNull();
}
@Test // DATAREST-521
@@ -253,7 +254,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$._links.processed"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$._links.processed")).isNotNull();
}
@Test // DATAREST-697
@@ -267,7 +268,7 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(new Resource<PersonSummary>(projection));
assertThat(JsonPath.read(result, "$._links.self"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$._links.self")).isNotNull();
}
@Test // DATAREST-880
@@ -275,7 +276,7 @@ public class PersistentEntitySerializationTests {
CreditCard creditCard = new CreditCard(new CreditCard.CCN("1234123412341234"));
assertThat(JsonPath.read(mapper.writeValueAsString(creditCard), "$.ccn"), is("1234123412341234"));
assertThat(JsonPath.<Object> read(mapper.writeValueAsString(creditCard), "$.ccn")).isEqualTo("1234123412341234");
}
@Test // DATAREST-872
@@ -292,12 +293,12 @@ public class PersistentEntitySerializationTests {
guest.addMeal(dinner);
PersistentEntityResource resource = PersistentEntityResource//
.build(guest, context.getPersistentEntity(Guest.class))//
.build(guest, context.getRequiredPersistentEntity(Guest.class))//
.withLink(new Link("/guests/1")).build();
String result = mapper.writeValueAsString(resource);
assertThat(JsonPath.read(result, "$.room.type"), equalTo("suite"));
assertThat(JsonPath.read(result, "$.meals[0].type"), equalTo("dinner"));
assertThat(JsonPath.<Object> read(result, "$.room.type")).isEqualTo("suite");
assertThat(JsonPath.<Object> read(result, "$.meals[0].type")).isEqualTo("dinner");
}
}

View File

@@ -39,13 +39,13 @@ import org.springframework.data.rest.core.mapping.RepositoryResourceMappings;
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
import org.springframework.data.rest.core.support.EntityLookup;
import org.springframework.data.rest.core.support.SelfLinkProvider;
import org.springframework.data.rest.core.util.Java8PluginRegistry;
import org.springframework.data.rest.webmvc.EmbeddedResourcesAssembler;
import org.springframework.data.rest.webmvc.jpa.Person;
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.LookupObjectSerializer;
import org.springframework.data.rest.webmvc.mapping.Associations;
import org.springframework.data.rest.webmvc.mapping.LinkCollector;
import org.springframework.data.rest.webmvc.spi.BackendIdConverter;
import org.springframework.data.rest.webmvc.spi.BackendIdConverter.DefaultIdConverter;
import org.springframework.data.rest.webmvc.support.ExcerptProjector;
import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVariables;
@@ -58,7 +58,6 @@ import org.springframework.hateoas.ResourceProcessor;
import org.springframework.hateoas.core.EvoInflectorRelProvider;
import org.springframework.hateoas.hal.Jackson2HalModule;
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
import org.springframework.plugin.core.OrderAwarePluginRegistry;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -119,7 +118,7 @@ public class RepositoryTestsConfig {
config().getRepositoryDetectionStrategy());
EntityLinks entityLinks = new RepositoryEntityLinks(repositories(), mappings, config(),
mock(PagingAndSortingTemplateVariables.class),
OrderAwarePluginRegistry.<Class<?>, BackendIdConverter> create(Arrays.asList(DefaultIdConverter.INSTANCE)));
Java8PluginRegistry.of(Arrays.asList(DefaultIdConverter.INSTANCE)));
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(persistentEntities(), entityLinks,
Collections.<EntityLookup<?>> emptyList());

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.support;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.Serializable;
import java.lang.reflect.Method;
@@ -53,7 +52,7 @@ public class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests
Object resolvedId = resolver.resolveArgument(parameter, null, request, null);
assertThat(resolvedId, is((Object) 5L));
assertThat(resolvedId).isEqualTo(5L);
}
static class SampleController {

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.rest.webmvc.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.allOf;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,7 +53,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Link link = entityLinks.linkToSingleResource(Person.class, 1);
assertThat(link.getHref(), endsWith("/people/1{?projection}"));
assertThat(link.getRel(), is("person"));
assertThat(link.getRel()).isEqualTo("person");
}
@Test
@@ -59,9 +61,9 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Link link = entityLinks.linkToCollectionResource(Person.class);
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItems("page", "size", "sort"));
assertThat(link.getRel(), is("people"));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("page", "size", "sort");
assertThat(link.getRel()).isEqualTo("people");
}
@Test // DATAREST-221
@@ -69,8 +71,8 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Link link = entityLinks.linkToSingleResource(Order.class, 1);
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItem(configuration.getProjectionConfiguration().getParameterName()));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains(configuration.getProjectionConfiguration().getParameterName());
}
@Test // DATAREST-155
@@ -83,11 +85,11 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
@Test // DATAREST-317
public void adaptsToExistingPageable() {
Link link = entityLinks.linkToPagedResource(Person.class, new PageRequest(0, 10));
Link link = entityLinks.linkToPagedResource(Person.class, PageRequest.of(0, 10));
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasSize(2));
assertThat(link.getVariableNames(), hasItems("sort", "projection"));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).hasSize(2);
assertThat(link.getVariableNames()).contains("sort", "projection");
}
@Test // DATAREST-467
@@ -95,11 +97,11 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Links links = entityLinks.linksToSearchResources(Person.class);
assertThat(links.hasLink("firstname"), is(true));
assertThat(links.hasLink("firstname")).isTrue();
Link firstnameLink = links.getLink("firstname");
assertThat(firstnameLink.isTemplated(), is(true));
assertThat(firstnameLink.getVariableNames(), hasItems("page", "size"));
assertThat(firstnameLink.isTemplated()).isTrue();
assertThat(firstnameLink.getVariableNames()).contains("page", "size");
}
@Test // DATAREST-467
@@ -107,20 +109,20 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Link link = entityLinks.linkToSearchResource(Person.class, "firstname");
assertThat(link, is(notNullValue()));
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItems("firstname", "page", "size"));
assertThat(link).isNotNull();
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("firstname", "page", "size");
}
@Test // DATAREST-467, DATAREST-519
public void prepopulatesPaginationInformationForSearchResourceLink() {
Link link = entityLinks.linkToSearchResource(Person.class, "firstname", new PageRequest(0, 10));
Link link = entityLinks.linkToSearchResource(Person.class, "firstname", PageRequest.of(0, 10));
assertThat(link, is(notNullValue()));
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItem("firstname"));
assertThat(link.getVariableNames(), not(hasItems("page", "size")));
assertThat(link).isNotNull();
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("firstname");
assertThat(link.getVariableNames()).doesNotContain("page", "size");
UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build();
assertThat(components.getQueryParams(), allOf(hasKey("page"), hasKey("size")));
@@ -131,19 +133,19 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
Link link = entityLinks.linkToSearchResource(Person.class, "lastname");
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItems("lastname", "sort"));
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("lastname", "sort");
}
@Test // DATAREST-467, DATAREST-519
public void prepopulatesSortInformationForSearchResourceLink() {
Link link = entityLinks.linkToSearchResource(Person.class, "lastname", new Sort("firstname"));
Link link = entityLinks.linkToSearchResource(Person.class, "lastname", Sort.by("firstname"));
assertThat(link, is(notNullValue()));
assertThat(link.isTemplated(), is(true));
assertThat(link.getVariableNames(), hasItem("lastname"));
assertThat(link.getVariableNames(), not(hasItems("sort")));
assertThat(link).isNotNull();
assertThat(link.isTemplated()).isTrue();
assertThat(link.getVariableNames()).contains("lastname");
assertThat(link.getVariableNames()).doesNotContain("sort");
UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build();
assertThat(components.getQueryParams(), hasKey("sort"));
@@ -153,7 +155,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
public void addsProjectVariableToSearchResourceIfAvailable() {
for (Link link : entityLinks.linksToSearchResources(Book.class)) {
assertThat(link.getVariableNames(), hasItem("projection"));
assertThat(link.getVariableNames()).contains("projection");
}
}
}