DATAREST-1064 - Adapt to API changes in repository interfaces.

Additional cleanups in QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver to make sure a QuerydslRepositoryInvokerAdapter is only applied if the QuerydslPredicateBuilder actually exposes a predicate. Extracted a couple of methods to make sure the mapping pipeline reads nicely.
This commit is contained in:
Oliver Gierke
2017-05-03 17:22:54 +02:00
parent 632ca25998
commit f906695e7a
26 changed files with 104 additions and 89 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import com.jayway.jsonpath.JsonPath;
@@ -62,7 +63,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
ResultActions actions = mvc.perform(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).andExpect(status().isOk());
for (String rel : expectedRootLinkRels()) {
actions.andExpect(client.hasLinkWithRel(rel));
actions.andDo(MockMvcResultHandlers.print()).andExpect(client.hasLinkWithRel(rel));
}
}

View File

@@ -237,18 +237,18 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
public void deletesEntityWithCustomLookupCorrectly() throws Exception {
Address address = repository.save(new Address());
assertThat(repository.findOne(address.id)).isNotNull();
assertThat(repository.findById(address.id)).isNotNull();
RootResourceInformation resourceInformation = getResourceInformation(Address.class);
RepositoryInvoker invoker = spy(resourceInformation.getInvoker());
doReturn(Optional.of(address)).when(invoker).invokeFindOne("foo");
doReturn(Optional.of(address)).when(invoker).invokeFindById("foo");
RootResourceInformation informationSpy = Mockito.spy(resourceInformation);
doReturn(invoker).when(informationSpy).getInvoker();
controller.deleteItemResource(informationSpy, "foo", ETag.from("0"));
assertThat(repository.findOne(address.id)).isEmpty();
assertThat(repository.findById(address.id)).isEmpty();
}
interface AddressProjection {}

View File

@@ -53,7 +53,7 @@ public class TestDataPopulator {
Author john = new Author("John");
Author thomas = new Author("Thomas");
Iterable<Author> authors = this.authors.save(Arrays.asList(ollie, mark, michael, david, john, thomas));
Iterable<Author> authors = this.authors.saveAll(Arrays.asList(ollie, mark, michael, david, john, thomas));
books.save(new Book("1449323952", "Spring Data", 1000, authors, new Offer(21.21, "EUR")));
books.save(new Book("1449323953", "Spring Data (Second Edition)", 2000, authors, new Offer(30.99, "EUR")));
@@ -79,6 +79,6 @@ public class TestDataPopulator {
jane.addSibling(john);
jane.setFather(billyBob);
people.save(Arrays.asList(john, jane));
people.saveAll(Arrays.asList(john, jane));
}
}

View File

@@ -73,7 +73,7 @@ public class Jackson2DatatypeHelperIntegrationTests {
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(Order.class);
PersistentProperty<?> property = entity.getRequiredPersistentProperty("creator");
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(orders.findOne(this.order.getId()).orElse(null));
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(orders.findById(this.order.getId()).orElse(null));
assertThat(objectMapper.writeValueAsString(accessor.getProperty(property))).isNotEqualTo("null");
}

View File

@@ -33,5 +33,5 @@ public interface ProfileRepository extends PagingAndSortingRepository<Profile, S
long countByType(@Param("type") String type);
// DATAREST-511
Optional<Profile> findById(@Param("id") String id);
Optional<Profile> findProfileById(@Param("id") String id);
}

View File

@@ -71,7 +71,7 @@ public class MongoWebTests extends CommonWebTests {
linkedIn.setPerson(1L);
linkedIn.setType("LinkedIn");
repository.save(Arrays.asList(twitter, linkedIn));
repository.saveAll(Arrays.asList(twitter, linkedIn));
Address address = new Address();
address.street = "ETagDoesntMatchExceptionUnitTests";
@@ -288,7 +288,7 @@ public class MongoWebTests extends CommonWebTests {
Profile profile = repository.findAll().iterator().next();
Link link = client.discoverUnique("profiles", "search", "findById");
Link link = client.discoverUnique("profiles", "search", "findProfileById");
mvc.perform(get(link.expand(profile.getId()).getHref())).//
andExpect(status().isOk());
@@ -297,7 +297,7 @@ public class MongoWebTests extends CommonWebTests {
@Test // DATAREST-517
public void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception {
Link link = client.discoverUnique("profiles", "search", "findById");
Link link = client.discoverUnique("profiles", "search", "findProfileById");
mvc.perform(get(link.expand("").getHref())).//
andExpect(status().isNotFound());
@@ -319,7 +319,7 @@ public class MongoWebTests extends CommonWebTests {
@Test // DATAREST-835
public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
Link link = client.discoverUnique("profiles", "search", "findById");
Link link = client.discoverUnique("profiles", "search", "findProfileById");
Profile profile = repository.findAll().iterator().next();

View File

@@ -16,6 +16,7 @@
package org.springframework.data.rest.webmvc.config;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
@@ -29,7 +30,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
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.QuerydslRepositoryInvokerAdapter;
import org.springframework.data.querydsl.SimpleEntityPathResolver;
@@ -47,6 +47,8 @@ import org.springframework.data.rest.tests.mongodb.ReceiptRepository;
import org.springframework.data.rest.tests.mongodb.User;
import org.springframework.test.util.ReflectionTestUtils;
import com.querydsl.core.types.Predicate;
/**
* Unit tests for {@link QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver}.
*
@@ -60,6 +62,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
@Mock Repositories repositories;
@Mock RepositoryInvokerFactory invokerFactory;
@Mock ResourceMetadataHandlerMethodArgumentResolver resourceMetadataResolver;
@Mock QuerydslPredicateBuilder builder;
@Mock RepositoryInvoker invoker;
@Mock MethodParameter parameter;
@@ -71,12 +74,11 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
QuerydslPredicateBuilder builder = new QuerydslPredicateBuilder(new DefaultConversionService(),
factory.getEntityPathResolver());
this.resolver = new QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver(repositories, invokerFactory,
resourceMetadataResolver, builder, factory);
when(builder.getPredicate(any(), any(), any())).thenReturn(mock(Predicate.class));
when(parameter.hasParameterAnnotation(QuerydslPredicate.class)).thenReturn(true);
}

View File

@@ -30,7 +30,7 @@ public interface PreAuthorizedOrderRepository extends CrudRepository<Order, UUID
@PreAuthorize("hasRole('ROLE_ADMIN')") // <2>
@Override
void delete(UUID aLong);
void deleteById(UUID aLong);
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Override
@@ -38,7 +38,7 @@ public interface PreAuthorizedOrderRepository extends CrudRepository<Order, UUID
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Override
void delete(Iterable<? extends Order> orders);
void deleteAll(Iterable<? extends Order> orders);
@PreAuthorize("hasRole('ROLE_ADMIN')")
@Override

View File

@@ -28,7 +28,7 @@ public interface SecuredPersonRepository extends CrudRepository<Person, UUID> {
@Secured("ROLE_ADMIN") // <2>
@Override
void delete(UUID aLong);
void deleteById(UUID aLong);
@Secured("ROLE_ADMIN")
@Override
@@ -36,7 +36,7 @@ public interface SecuredPersonRepository extends CrudRepository<Person, UUID> {
@Secured("ROLE_ADMIN")
@Override
void delete(Iterable<? extends Person> persons);
void deleteAll(Iterable<? extends Person> persons);
@Secured("ROLE_ADMIN")
@Override

View File

@@ -69,7 +69,7 @@ public class SolrWebTests extends CommonWebTests {
public void setUp() {
super.setUp();
repo.save(Arrays.asList(PLAYSTATION, GAMEBOY, AMIGA500));
repo.saveAll(Arrays.asList(PLAYSTATION, GAMEBOY, AMIGA500));
}
@After