DATAREST-1008 - Adapt to API changes in Spring Data Commons, Java 8 upgrades and Mockito 2.7.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
22
spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java
Normal file → Executable file
22
spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/tests/mongodb/MongoWebTests.java
Normal file → Executable 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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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> {}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user