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

@@ -19,9 +19,12 @@ import java.util.Collections;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
@@ -58,6 +61,10 @@ public abstract class AbstractControllerIntegrationTests {
@Configuration
public static class TestConfiguration extends RepositoryRestMvcConfiguration {
public TestConfiguration(ApplicationContext context, ObjectFactory<ConversionService> conversionService) {
super(context, conversionService);
}
@Bean
public PersistentEntityResourceAssembler persistentEntityResourceAssembler() {

View File

@@ -1,6 +1,5 @@
package org.springframework.data.rest.tests;
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,9 +13,11 @@ package org.springframework.data.rest.tests;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.tests;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.fail;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -80,18 +81,18 @@ public abstract class AbstractWebIntegrationTests {
}
protected void setupMockMvc() {
this.mvc = MockMvcBuilders.webAppContextSetup(context).//
defaultRequest(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).build();
this.mvc = MockMvcBuilders.webAppContextSetup(context)//
.defaultRequest(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).build();
}
protected MockHttpServletResponse postAndGet(Link link, Object payload, MediaType mediaType) throws Exception {
String href = link.isTemplated() ? link.expand().getHref() : link.getHref();
MockHttpServletResponse response = mvc.perform(post(href).content(payload.toString()).contentType(mediaType)).//
andExpect(status().isCreated()).//
andExpect(header().string("Location", is(notNullValue()))).//
andReturn().getResponse();
MockHttpServletResponse response = mvc.perform(post(href).content(payload.toString()).contentType(mediaType))//
.andExpect(status().isCreated())//
.andExpect(header().string("Location", is(notNullValue())))//
.andReturn().getResponse();
String content = response.getContentAsString();
@@ -106,9 +107,9 @@ public abstract class AbstractWebIntegrationTests {
String href = link.isTemplated() ? link.expand().getHref() : link.getHref();
MockHttpServletResponse response = mvc.perform(put(href).content(payload.toString()).contentType(mediaType)).//
andExpect(status().is2xxSuccessful()).//
andReturn().getResponse();
MockHttpServletResponse response = mvc.perform(put(href).content(payload.toString()).contentType(mediaType))//
.andExpect(status().is2xxSuccessful())//
.andReturn().getResponse();
return StringUtils.hasText(response.getContentAsString()) ? response : client.request(link);
}
@@ -120,9 +121,8 @@ public abstract class AbstractWebIntegrationTests {
MockHttpServletResponse response = mvc
.perform(MockMvcRequestBuilders.request(HttpMethod.PATCH, href).//
content(payload.toString()).contentType(mediaType))
.//
andExpect(status().is2xxSuccessful()).//
andReturn().getResponse();
.andExpect(status().is2xxSuccessful())//
.andReturn().getResponse();
return StringUtils.hasText(response.getContentAsString()) ? response : client.request(href);
}
@@ -131,13 +131,13 @@ public abstract class AbstractWebIntegrationTests {
String href = link.isTemplated() ? link.expand().getHref() : link.getHref();
mvc.perform(delete(href)).//
andExpect(status().isNoContent()).//
andReturn().getResponse();
mvc.perform(delete(href))//
.andExpect(status().isNoContent())//
.andReturn().getResponse();
// Check that the resource is unavailable after a DELETE
mvc.perform(get(href)).//
andExpect(status().isNotFound());
mvc.perform(get(href))//
.andExpect(status().isNotFound());
}
protected Link assertHasContentLinkWithRel(String rel, MockHttpServletResponse response) throws Exception {
@@ -157,8 +157,13 @@ public abstract class AbstractWebIntegrationTests {
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()));
String message = "Expected to%s find a link with rel %s in the content section of the response!";
if (expected) {
assertThat(href).as(message, "", rel).isNotNull();
} else {
assertThat(href).as(message, " not", rel).isNull();
}
return new Link(href, rel);
@@ -177,7 +182,7 @@ public abstract class AbstractWebIntegrationTests {
String content = response.getContentAsString();
Link link = client.getDiscoverer(response).findLinkWithRel(rel, content);
assertThat("Expected not to find link with rel " + rel + " but found " + link + "!", link, is(nullValue()));
assertThat(link).as("Expected not to find link with rel %s but found %s!", rel, link).isNull();
}
@SuppressWarnings("unchecked")
@@ -186,12 +191,11 @@ public abstract class AbstractWebIntegrationTests {
String content = response.getContentAsString();
Object jsonPathResult = JsonPath.read(content, path);
assertThat(String.format("JSONPath lookup for %s did return null in %s.", path, content), jsonPathResult,
is(notNullValue()));
assertThat(jsonPathResult).as("JSONPath lookup for %s did return null in %s.", path, content).isNotNull();
if (jsonPathResult instanceof JSONArray) {
JSONArray array = (JSONArray) jsonPathResult;
assertThat(array, hasSize(greaterThan(0)));
assertThat(array.size()).isGreaterThan(0);
}
return (T) jsonPathResult;
@@ -223,7 +227,7 @@ public abstract class AbstractWebIntegrationTests {
jsonString = jsonQueryResults != null ? jsonQueryResults.toString() : null;
}
assertThat(jsonString, is(expected));
assertThat(jsonString).isEqualTo(expected);
return jsonString;
}
@@ -237,8 +241,9 @@ public abstract class AbstractWebIntegrationTests {
MockHttpServletResponse response = result.getResponse();
String s = response.getContentAsString();
assertThat("Expected not to find link with rel " + rel + " but found one in " + s, //
client.getDiscoverer(response).findLinkWithRel(rel, s), nullValue());
assertThat(client.getDiscoverer(response).findLinkWithRel(rel, s))//
.as("Expected not to find link with rel %s but found one in %s!", rel, s)//
.isNull();
}
};
}

View File

@@ -1,4 +1,3 @@
package org.springframework.data.rest.tests;
/*
* Copyright 2013-2017 the original author or authors.
*
@@ -14,9 +13,10 @@ package org.springframework.data.rest.tests;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.tests;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -215,8 +215,8 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
Links links = Links.valueOf(response.getHeader("Link"));
assertThat(links.hasLink(Link.REL_SELF), is(true));
assertThat(links.hasLink("profile"), is(true));
assertThat(links.hasLink(Link.REL_SELF)).isTrue();
assertThat(links.hasLink("profile")).isTrue();
}
}

View File

@@ -39,12 +39,12 @@ 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.json.PersistentEntityJackson2Module;
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;
@@ -57,7 +57,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;
@@ -111,7 +110,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;
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");
}
}
}

View File

@@ -18,14 +18,14 @@ package org.springframework.data.rest.tests.mongodb;
import java.math.BigInteger;
import java.util.List;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
/**
* @author Oliver Gierke
*/
public interface UserRepository extends CrudRepository<User, BigInteger>, QueryDslPredicateExecutor<User> {
public interface UserRepository extends CrudRepository<User, BigInteger>, QuerydslPredicateExecutor<User> {
List<User> findByFirstname(String firstname);

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.data.rest.tests.mongodb;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.http.HttpHeaders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@ -25,6 +25,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import org.assertj.core.api.Condition;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -133,11 +134,11 @@ public class MongoWebTests extends CommonWebTests {
Link profileSearches = client.discoverUnique(profiles, "search");
Link countByTypeLink = client.discoverUnique(profileSearches, "countByType");
assertThat(countByTypeLink.isTemplated(), is(true));
assertThat(countByTypeLink.getVariableNames(), hasItem("type"));
assertThat(countByTypeLink.isTemplated()).isTrue();
assertThat(countByTypeLink.getVariableNames()).contains("type");
MockHttpServletResponse response = client.request(countByTypeLink.expand("Twitter"));
assertThat(response.getContentAsString(), is("1"));
assertThat(response.getContentAsString()).isEqualTo("1");
}
@Test
@@ -147,10 +148,11 @@ public class MongoWebTests extends CommonWebTests {
Link userLink = assertHasContentLinkWithRel("self", client.request(usersLink));
MockHttpServletResponse response = patchAndGet(userLink,
"{\"lastname\" : null, \"address\" : { \"zipCode\" : \"ZIP\"}}", MediaType.APPLICATION_JSON);
"{\"lastname\" : null, \"address\" : { \"zipCode\" : \"ZIP\"}}",
org.springframework.http.MediaType.APPLICATION_JSON);
assertThat(JsonPath.read(response.getContentAsString(), "$.lastname"), is(nullValue()));
assertThat(JsonPath.read(response.getContentAsString(), "$.address.zipCode"), is((Object) "ZIP"));
assertThat(JsonPath.<String> read(response.getContentAsString(), "$.lastname")).isNull();
assertThat(JsonPath.<String> read(response.getContentAsString(), "$.address.zipCode")).isEqualTo("ZIP");
}
@Test
@@ -165,8 +167,8 @@ public class MongoWebTests extends CommonWebTests {
+ "{ \"op\": \"remove\", \"path\": \"/lastname\" }]", //
RestMediaTypes.JSON_PATCH_JSON);
assertThat(JsonPath.read(response.getContentAsString(), "$.lastname"), is(nullValue()));
assertThat(JsonPath.read(response.getContentAsString(), "$.address.zipCode"), is((Object) "ZIP"));
assertThat(JsonPath.<String> read(response.getContentAsString(), "$.lastname")).isNull();
assertThat(JsonPath.<String> read(response.getContentAsString(), "$.address.zipCode")).isEqualTo("ZIP");
}
@Test // DATAREST-160
@@ -204,7 +206,7 @@ public class MongoWebTests extends CommonWebTests {
String header = mvc.perform(get("/profiles/{id}", profile.getId())).//
andReturn().getResponse().getHeader("Last-Modified");
assertThat(header, not(isEmptyOrNullString()));
assertThat(header).isNot(new Condition<String>(it -> it == null || it.isEmpty(), "Foo"));
}
@Test // DATAREST-482

View File

@@ -15,15 +15,13 @@
*/
package org.springframework.data.rest.webmvc;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.math.BigInteger;
import java.util.Collections;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,7 +36,6 @@ import org.springframework.data.rest.tests.mongodb.User;
import org.springframework.data.rest.webmvc.mapping.Associations;
import org.springframework.data.rest.webmvc.support.Projector;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.Links;
import org.springframework.test.context.ContextConfiguration;
@@ -62,7 +59,7 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
Projector projector = mock(Projector.class);
when(projector.projectExcerpt(anyObject())).thenAnswer(new ReturnsArgumentAt(0));
when(projector.projectExcerpt(any())).thenAnswer(new ReturnsArgumentAt(0));
PersistentEntityResourceAssembler assembler = new PersistentEntityResourceAssembler(entities, projector,
associations, new DefaultSelfLinkProvider(entities, entityLinks, Collections.<EntityLookup<?>> emptyList()));
@@ -74,8 +71,8 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
Links links = new Links(resource.getLinks());
assertThat(links, is(Matchers.<Link> iterableWithSize(2)));
assertThat(links.getLink("self").getVariables(), is(Matchers.empty()));
assertThat(links.getLink("user").getVariableNames(), is(hasItem("projection")));
assertThat(links).hasSize(2);
assertThat(links.getLink("self").getVariables()).isEmpty();
assertThat(links.getLink("user").getVariableNames()).contains("projection");
}
}

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 org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,13 +46,13 @@ public class RepositoryRestHandlerMappingIntegrationTests extends AbstractContro
HandlerExecutionChain chain = mapping.getHandler(mockRequest);
assertThat(chain, is(notNullValue()));
assertThat(chain).isNotNull();
Object handler = chain.getHandler();
assertThat(handler, is(instanceOf(HandlerMethod.class)));
assertThat(handler).isInstanceOf(HandlerMethod.class);
HandlerMethod method = (HandlerMethod) handler;
assertThat(method.getMethod().getDeclaringClass(), is(typeCompatibleWith(RepositoryEntityController.class)));
assertThat(method.getMethod().getName(), is("getCollectionResource"));
assertThat(method.getMethod().getDeclaringClass()).isAssignableFrom(RepositoryEntityController.class);
assertThat(method.getMethod().getName()).isEqualTo("getCollectionResource");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.rest.tests.mongodb.TestUtils.*;
@@ -29,7 +28,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
@@ -87,8 +86,8 @@ public class JsonPatchHandlerUnitTests {
User result = handler.applyPatch(asStream(input), user);
assertThat(result.lastname, is(nullValue()));
assertThat(result.address.zipCode, is("ZIP"));
assertThat(result.lastname).isNull();
assertThat(result.address.zipCode).isEqualTo("ZIP");
}
@Test // DATAREST-348
@@ -98,8 +97,8 @@ public class JsonPatchHandlerUnitTests {
User result = handler.applyMergePatch(asStream(input), user);
assertThat(result.lastname, is(nullValue()));
assertThat(result.address.zipCode, is("ZIP"));
assertThat(result.lastname).isNull();
assertThat(result.address.zipCode).isEqualTo("ZIP");
}
/**
@@ -120,8 +119,8 @@ public class JsonPatchHandlerUnitTests {
handler.applyPatch(asStream(input), user);
assertThat(user.colleagues, hasSize(1));
assertThat(user.colleagues.get(0).firstname, is(christoph.firstname));
assertThat(user.colleagues).hasSize(1);
assertThat(user.colleagues.get(0).firstname).isEqualTo(christoph.firstname);
}
@Test // DATAREST-609

View File

@@ -15,22 +15,22 @@
*/
package org.springframework.data.rest.webmvc.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslRepositoryInvokerAdapter;
import org.springframework.data.querydsl.SimpleEntityPathResolver;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
@@ -70,7 +70,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
public void setUp() {
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
ReflectionTestUtils.setField(factory, "repositories", repositories);
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
QuerydslPredicateBuilder builder = new QuerydslPredicateBuilder(new DefaultConversionService(),
factory.getEntityPathResolver());
@@ -84,39 +84,38 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
public void returnsInvokerIfRepositoryIsNotQuerydslAware() {
ReceiptRepository repository = mock(ReceiptRepository.class);
when(repositories.getRepositoryFor(Receipt.class)).thenReturn(repository);
when(repositories.getRepositoryFor(Receipt.class)).thenReturn(Optional.of(repository));
RepositoryInvoker result = resolver.postProcess(parameter, invoker, Receipt.class, NO_PARAMETERS);
assertThat(result, is(invoker));
assertThat(result).isEqualTo(invoker);
}
@Test // DATAREST-616
public void wrapsInvokerInQuerydslAdapter() {
Object repository = mock(QuerydslUserRepository.class);
when(repositories.getRepositoryFor(User.class)).thenReturn(repository);
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
RepositoryInvoker result = resolver.postProcess(parameter, invoker, User.class, NO_PARAMETERS);
assertThat(result, is(instanceOf(QuerydslRepositoryInvokerAdapter.class)));
assertThat(result).isInstanceOf(QuerydslRepositoryInvokerAdapter.class);
}
@Test // DATAREST-616
public void invokesCustomizationOnRepositoryIfItImplementsCustomizer() {
QuerydslCustomizingUserRepository repository = mock(QuerydslCustomizingUserRepository.class);
when(repositories.hasRepositoryFor(User.class)).thenReturn(true);
when(repositories.getRepositoryFor(User.class)).thenReturn(repository);
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
RepositoryInvoker result = resolver.postProcess(parameter, invoker, User.class, NO_PARAMETERS);
assertThat(result, is(instanceOf(QuerydslRepositoryInvokerAdapter.class)));
assertThat(result).isInstanceOf(QuerydslRepositoryInvokerAdapter.class);
verify(repository, times(1)).customize(Mockito.any(QuerydslBindings.class), Mockito.any(QUser.class));
}
interface QuerydslUserRepository extends QueryDslPredicateExecutor<User> {}
interface QuerydslUserRepository extends QuerydslPredicateExecutor<User> {}
interface QuerydslCustomizingUserRepository
extends QueryDslPredicateExecutor<User>, QuerydslBinderCustomizer<QUser> {}
extends QuerydslPredicateExecutor<User>, QuerydslBinderCustomizer<QUser> {}
}

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.util.Arrays;
@@ -113,12 +114,12 @@ public class PersistentEntitySerializationTests {
String result = mapper.writeValueAsString(persistentEntityResource);
assertThat(JsonPath.read(result, "$._embedded.users[*].address"), is(notNullValue()));
assertThat(JsonPath.<Object> read(result, "$._embedded.users[*].address")).isNotNull();
}
@Test // DATAREST-654
public void deserializesTranslatedEnumProperty() throws Exception {
assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender, is(Gender.MALE));
assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender).isEqualTo(Gender.MALE);
}
@Test // DATAREST-864

View File

@@ -15,8 +15,9 @@
*/
package org.springframework.data.rest.webmvc.json;
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.mockito.Mockito.*;
import java.util.ArrayList;
@@ -179,7 +180,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
try {
assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector), constraint.matcher);
} catch (PathNotFoundException e) {
assertThat(constraint.matcher.matches(null), is(true));
assertThat(constraint.matcher.matches(null)).isTrue();
} catch (RuntimeException e) {
assertThat(e, constraint.matcher);
}

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.util.Arrays;
@@ -61,6 +60,6 @@ public class RepositoryLinkBuildUnitTests {
new BaseUri(baseUri));
Link link = builder.withSelfRel();
assertThat(link.getHref(), is(expectedUri));
assertThat(link.getHref()).isEqualTo(expectedUri);
}
}

View File

@@ -4,8 +4,7 @@
<fieldType name="string" class="solr.StrField" />
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true"
required="true" />
<field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="name" type="string" indexed="true" stored="true" />
<field name="cat" type="string" indexed="true" stored="true" multiValued="true" />
</fields>