DATAREST-1499, DATAREST-1500 - Cleanups.

Moved off Spring Framework deprecations for HttpMessageNotReadableException. This required some rearrangements of method signatures for types (hopefully) exclusively used by internal abstractions (some public, but not very friendly for user extension in the first place).

Switched to consistent use of Pageable.unpaged() instead of null. Switched to the use of new factory methods in Spring HATEOAS. Some Java 8 based improvements in request handling to simplify the implementation code. Deprecation of code that got obsolete due to the use of the factory methods.

Moved off some deprecations in Jackson APIs.

Removed a couple of unused imports. General avoidance of common warnings. Suppression where needed. Removed dead code in configuration.
This commit is contained in:
Oliver Drotbohm
2020-03-27 14:10:41 +01:00
parent 774fed5524
commit 4c17d54e9a
28 changed files with 163 additions and 139 deletions

View File

@@ -20,8 +20,8 @@ import static org.mockito.Mockito.*;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.util.ClassUtils;
/**
* Unit tests for {@link BasePathAwareHandlerMapping}.
@@ -54,7 +54,7 @@ public class BasePathAwareHandlerMappingUnitTests {
ProxyFactory factory = new ProxyFactory(source);
Object proxy = factory.getProxy();
assertThat(ClassUtils.isCglibProxy(proxy)).isTrue();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
return proxy.getClass();
}

View File

@@ -25,9 +25,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.server.core.EmbeddedWrapper;
import org.springframework.hateoas.server.core.EmbeddedWrappers;
@@ -50,7 +50,7 @@ public class PersistentEntityResourceUnitTests {
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo"));
this.resources = new CollectionModel<EmbeddedWrapper>(Collections.singleton(wrapper));
this.resources = CollectionModel.of(Collections.singleton(wrapper));
}
@Test(expected = IllegalArgumentException.class) // DATAREST-317

View File

@@ -44,8 +44,8 @@ import org.springframework.data.rest.core.mapping.ResourceMetadata;
import org.springframework.data.rest.core.mapping.ResourceType;
import org.springframework.data.rest.core.mapping.SupportedHttpMethods;
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpMethod;
/**
@@ -84,7 +84,7 @@ public class RepositoryPropertyReferenceControllerUnitTests {
doReturn(new Sample()).when(invoker).invokeSave(any(Object.class));
RootResourceInformation information = new RootResourceInformation(metadata, entity, invoker);
CollectionModel<Object> request = new CollectionModel<Object>(Collections.emptySet(), Link.of("/reference/some-id"));
CollectionModel<Object> request = CollectionModel.empty(Link.of("/reference/some-id"));
controller.createPropertyReference(information, HttpMethod.POST, request, 4711, "references");

View File

@@ -30,6 +30,7 @@ import org.springframework.data.rest.webmvc.support.ExceptionMessage;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.mock.http.MockHttpInputMessage;
/**
* Unit tests for {@link RepositoryRestExceptionHandler}.
@@ -60,7 +61,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
public void handlesHttpMessageNotReadableException() {
ResponseEntity<ExceptionMessage> result = HANDLER
.handleNotReadable(new HttpMessageNotReadableException("Message!"));
.handleNotReadable(new HttpMessageNotReadableException("Message!", new MockHttpInputMessage(new byte[0])));
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}

View File

@@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.Path;
@@ -41,7 +42,6 @@ import org.springframework.data.rest.webmvc.support.DefaultedPageable;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockServletContext;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.util.pattern.PathPattern;
@@ -308,7 +308,7 @@ public class RepositoryRestHandlerMappingUnitTests {
ProxyFactory factory = new ProxyFactory(source);
Object proxy = factory.getProxy();
assertThat(ClassUtils.isCglibProxy(proxy)).isTrue();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
return proxy.getClass();
}

View File

@@ -36,7 +36,6 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Immutable;
@@ -59,6 +58,7 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
@@ -172,7 +172,7 @@ public class DomainObjectReaderUnitTests {
assertThat(((Map<Object, Object>) object).get("c")).isEqualTo("2");
}
@Test(expected = IllegalArgumentException.class) // DATAREST-701
@Test(expected = JsonMappingException.class) // DATAREST-701
public void rejectsMergingUnknownDomainObject() throws Exception {
ObjectMapper mapper = new ObjectMapper();
@@ -486,6 +486,7 @@ public class DomainObjectReaderUnitTests {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree("{ \"enums\" : [ \"SECOND\", \"FIRST\" ] }");
@SuppressWarnings("deprecation")
CollectionOfEnumWithMethods result = reader.merge((ObjectNode) node, sample, mapper);
assertThat(result.enums).containsExactly(SampleEnum.SECOND, SampleEnum.FIRST);
@@ -568,18 +569,19 @@ public class DomainObjectReaderUnitTests {
ObjectMapper mapper = new ObjectMapper();
ObjectNode source = (ObjectNode) mapper.readTree("{ \"lastLogin\" : null, \"email\" : \"bar@foo.com\"}");
@SuppressWarnings("deprecation")
SampleUser result = reader.merge(source, user, mapper);
assertThat(result.lastLogin).isNotNull();
assertThat(result.email).isEqualTo("foo@bar.com");
}
@Test // DATAREST-1068
public void arraysCanBeResizedDuringMerge() throws Exception {
ObjectMapper mapper = new ObjectMapper();
ArrayHolder target = new ArrayHolder(new String[] { });
ArrayHolder target = new ArrayHolder(new String[] {});
JsonNode node = mapper.readTree("{ \"array\" : [ \"new\" ] }");
ArrayHolder updated = reader.doMerge((ObjectNode) node, target, mapper);
assertThat(updated.array).containsExactly("new");
}
@@ -807,7 +809,7 @@ public class DomainObjectReaderUnitTests {
static class WithNullCollection {
List<String> strings;
}
// DATAREST-1068
@Value
static class ArrayHolder {

View File

@@ -77,7 +77,7 @@ public class ProjectionJacksonIntegrationTests {
customer.address = new Address();
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
CollectionModel<CustomerProjection> resources = new CollectionModel<CustomerProjection>(Arrays.asList(projection));
CollectionModel<CustomerProjection> resources = CollectionModel.of(Arrays.asList(projection));
String result = mapper.writeValueAsString(resources);

View File

@@ -147,6 +147,7 @@ public class AssociationsUnitTests {
assertThat(links).contains(Link.of("/relatedAndExported{?" + projectionParameterName + "}", "relatedAndExported"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private Association<? extends PersistentProperty<?>> getAssociation(Class<?> type, String name) {
KeyValuePersistentEntity<?, ? extends KeyValuePersistentProperty<?>> rootEntity = mappingContext