DATAREST-1008 - Adapt to API changes in Spring Data Commons, Java 8 upgrades and Mockito 2.7.
This commit is contained in:
48
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java
Normal file → Executable file
48
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AssociationLinksUnitTests.java
Normal file → Executable 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.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,11 +25,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
@@ -53,8 +51,8 @@ public class AssociationLinksUnitTests {
|
||||
Associations links;
|
||||
|
||||
ResourceMappings mappings;
|
||||
KeyValueMappingContext mappingContext;
|
||||
KeyValuePersistentEntity<?> entity;
|
||||
KeyValueMappingContext<?, ?> mappingContext;
|
||||
PersistentEntity<?, ?> entity;
|
||||
ResourceMetadata sampleResourceMetadata;
|
||||
|
||||
@Mock RepositoryRestConfiguration config;
|
||||
@@ -62,8 +60,8 @@ public class AssociationLinksUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.mappingContext = new KeyValueMappingContext();
|
||||
this.entity = mappingContext.getPersistentEntity(Sample.class);
|
||||
this.mappingContext = new KeyValueMappingContext<>();
|
||||
this.entity = mappingContext.getRequiredPersistentEntity(Sample.class);
|
||||
this.mappings = new PersistentEntitiesResourceMappings(new PersistentEntities(Arrays.asList(mappingContext)));
|
||||
this.links = new Associations(mappings, config);
|
||||
}
|
||||
@@ -79,37 +77,33 @@ public class AssociationLinksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void considersNullPropertyUnlinkable() {
|
||||
assertThat(links.isLinkableAssociation((PersistentProperty<?>) null), is(false));
|
||||
public void rejectsNullPropertyForIsLinkable() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
links.isLinkableAssociation((PersistentProperty<?>) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void consideredHiddenPropertyUnlinkable() {
|
||||
assertThat(links.isLinkableAssociation(entity.getPersistentProperty("hiddenProperty")), is(false));
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void considersUnexportedPropertyUnlinkable() {
|
||||
|
||||
KeyValuePersistentProperty property = entity.getPersistentProperty("unexportedProperty");
|
||||
assertThat(links.isLinkableAssociation(property), is(false));
|
||||
assertThat(links.isLinkableAssociation(entity.getRequiredPersistentProperty("hiddenProperty"))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void createsLinkToAssociationProperty() {
|
||||
|
||||
PersistentProperty<?> property = entity.getPersistentProperty("property");
|
||||
List<Link> associationLinks = links.getLinksFor(property.getAssociation(), new Path("/base"));
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("property");
|
||||
List<Link> associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base"));
|
||||
|
||||
assertThat(associationLinks, hasSize(1));
|
||||
assertThat(associationLinks, hasItem(new Link("/base/property", "property")));
|
||||
assertThat(associationLinks).hasSize(1);
|
||||
assertThat(associationLinks).contains(new Link("/base/property", "property"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void doesNotCreateLinksForHiddenProperty() {
|
||||
|
||||
PersistentProperty<?> property = entity.getPersistentProperty("hiddenProperty");
|
||||
assertThat(links.getLinksFor(property.getAssociation(), new Path("/sample")), hasSize(0));
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("hiddenProperty");
|
||||
assertThat(links.getLinksFor(property.getRequiredAssociation(), new Path("/sample"))).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,12 +111,12 @@ public class AssociationLinksUnitTests {
|
||||
|
||||
doReturn(true).when(config).isLookupType(Property.class);
|
||||
|
||||
assertThat(links.isLookupType(entity.getPersistentProperty("hiddenProperty")), is(true));
|
||||
assertThat(links.isLookupType(entity.getRequiredPersistentProperty("hiddenProperty"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegatesResourceMetadataLookupToMappings() {
|
||||
assertThat(links.getMetadataFor(Property.class), is(mappings.getMetadataFor(Property.class)));
|
||||
assertThat(links.getMetadataFor(Property.class)).isEqualTo(mappings.getMetadataFor(Property.class));
|
||||
}
|
||||
|
||||
public static class Sample {
|
||||
|
||||
8
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java
Normal file → Executable file
8
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/AugmentingHandlerMappingUnitTests.java
Normal file → Executable file
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -15,13 +15,11 @@
|
||||
*/
|
||||
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.mockito.Mockito.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -66,7 +64,7 @@ public class AugmentingHandlerMappingUnitTests {
|
||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();
|
||||
|
||||
for (RequestMappingInfo info : handlerMethods.keySet()) {
|
||||
assertThat(info.getPatternsCondition().getPatterns(), hasItem(Matchers.startsWith("/api")));
|
||||
assertThat(info.getPatternsCondition().getPatterns()).allMatch(it -> it.startsWith("/api"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java
Normal file → Executable file
13
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java
Normal file → Executable file
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
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.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -32,8 +33,8 @@ public class BaseUriUnitTests {
|
||||
@Test // DATAREST-276
|
||||
public void doesNotMatchNonOverlap() {
|
||||
|
||||
assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar"), is(nullValue()));
|
||||
assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar"), is(nullValue()));
|
||||
assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar")).isNull();
|
||||
assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -69,12 +70,12 @@ public class BaseUriUnitTests {
|
||||
|
||||
assertThat(uri.getRepositoryLookupPath("/foo"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/"), isEmptyString());
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people"), is("/people"));
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people/"), is("/people"));
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people")).isEqualTo("/people");
|
||||
assertThat(uri.getRepositoryLookupPath("/foo/people/")).isEqualTo("/people");
|
||||
}
|
||||
|
||||
@Test // DATAREST-674, SPR-13455
|
||||
public void repositoryLookupPathHandlesDoubleSlashes() {
|
||||
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1"), is("/books/1"));
|
||||
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1")).isEqualTo("/books/1");
|
||||
}
|
||||
}
|
||||
|
||||
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java
Normal file → Executable file
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/CustomAcceptHeaderHttpServletRequestUnitTests.java
Normal file → Executable file
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
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.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -52,7 +53,7 @@ public class CustomAcceptHeaderHttpServletRequestUnitTests {
|
||||
|
||||
List<String> expected = Collections.list(servletRequest.getHeaders(HttpHeaders.ACCEPT));
|
||||
|
||||
assertThat(expected, hasSize(2));
|
||||
assertThat(expected, hasItems(MediaType.APPLICATION_OCTET_STREAM_VALUE, MediaType.APPLICATION_ATOM_XML_VALUE));
|
||||
assertThat(expected).hasSize(2);
|
||||
assertThat(expected).contains(MediaType.APPLICATION_OCTET_STREAM_VALUE, MediaType.APPLICATION_ATOM_XML_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java
Normal file → Executable file
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/IncomingRequestUnitTests.java
Normal file → Executable 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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -44,8 +43,8 @@ public class IncomingRequestUnitTests {
|
||||
|
||||
IncomingRequest incomingRequest = new IncomingRequest(new ServletServerHttpRequest(request));
|
||||
|
||||
assertThat(incomingRequest.isJsonPatchRequest(), is(true));
|
||||
assertThat(incomingRequest.isJsonMergePatchRequest(), is(false));
|
||||
assertThat(incomingRequest.isJsonPatchRequest()).isTrue();
|
||||
assertThat(incomingRequest.isJsonMergePatchRequest()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-498
|
||||
@@ -55,7 +54,7 @@ public class IncomingRequestUnitTests {
|
||||
|
||||
IncomingRequest incomingRequest = new IncomingRequest(new ServletServerHttpRequest(request));
|
||||
|
||||
assertThat(incomingRequest.isJsonPatchRequest(), is(false));
|
||||
assertThat(incomingRequest.isJsonMergePatchRequest(), is(true));
|
||||
assertThat(incomingRequest.isJsonPatchRequest()).isFalse();
|
||||
assertThat(incomingRequest.isJsonMergePatchRequest()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java
Normal file → Executable file
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java
Normal file → Executable 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 java.util.Collections;
|
||||
|
||||
@@ -24,7 +23,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Resources;
|
||||
@@ -68,7 +67,7 @@ public class PersistentEntityResourceUnitTests {
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource.build(payload, entity).build();
|
||||
|
||||
assertThat(resource.getEmbeddeds(), is(notNullValue()));
|
||||
assertThat(resource.getEmbeddeds(), is(emptyIterable()));
|
||||
assertThat(resource.getEmbeddeds()).isNotNull();
|
||||
assertThat(resource.getEmbeddeds()).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
52
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java
Normal file → Executable file
52
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryCorsConfigurationAccessorUnitTests.java
Normal file → Executable file
@@ -15,20 +15,20 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
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 static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.RepositoryCorsConfigurationAccessor;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
@@ -53,7 +53,8 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, repositories);
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE,
|
||||
Optional.of(repositories));
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
@@ -61,13 +62,13 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
|
||||
CorsConfiguration configuration = accessor.createConfiguration(AnnotatedRepository.class);
|
||||
|
||||
assertThat(configuration, is(notNullValue()));
|
||||
assertThat(configuration.getAllowCredentials(), is(true));
|
||||
assertThat(configuration.getAllowedHeaders(), hasItem("*"));
|
||||
assertThat(configuration.getAllowedOrigins(), hasItem("*"));
|
||||
assertThat(configuration).isNotNull();
|
||||
assertThat(configuration.getAllowCredentials()).isTrue();
|
||||
assertThat(configuration.getAllowedHeaders()).contains("*");
|
||||
assertThat(configuration.getAllowedOrigins()).contains("*");
|
||||
assertThat(configuration.getAllowedMethods(),
|
||||
hasItems("OPTIONS", "HEAD", "GET", "PATCH", "POST", "PUT", "DELETE", "TRACE"));
|
||||
assertThat(configuration.getMaxAge(), is(1800L));
|
||||
assertThat(configuration.getMaxAge()).isEqualTo(1800L);
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
@@ -75,30 +76,25 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
|
||||
CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class);
|
||||
|
||||
assertThat(configuration, is(notNullValue()));
|
||||
assertThat(configuration.getAllowCredentials(), is(true));
|
||||
assertThat(configuration.getAllowedHeaders(), hasItem("Content-type"));
|
||||
assertThat(configuration.getExposedHeaders(), hasItem("Accept"));
|
||||
assertThat(configuration.getAllowedOrigins(), hasItem("http://far.far.away"));
|
||||
assertThat(configuration.getAllowedMethods(), hasItem("PATCH"));
|
||||
assertThat(configuration.getAllowedMethods(), not(hasItem("DELETE")));
|
||||
assertThat(configuration.getAllowCredentials(), is(true));
|
||||
assertThat(configuration.getMaxAge(), is(1234L));
|
||||
assertThat(configuration).isNotNull();
|
||||
assertThat(configuration.getAllowCredentials()).isTrue();
|
||||
assertThat(configuration.getAllowedHeaders()).contains("Content-type");
|
||||
assertThat(configuration.getExposedHeaders()).contains("Accept");
|
||||
assertThat(configuration.getAllowedOrigins()).contains("http://far.far.away");
|
||||
assertThat(configuration.getAllowedMethods()).contains("PATCH");
|
||||
assertThat(configuration.getAllowedMethods()).doesNotContain("DELETE");
|
||||
assertThat(configuration.getAllowCredentials()).isTrue();
|
||||
assertThat(configuration.getMaxAge()).isEqualTo(1234L);
|
||||
}
|
||||
|
||||
@Test // DATAREST-994
|
||||
public void returnsNullCorsConfigurationWithNullRepositories() {
|
||||
public void returnsNoCorsConfigurationWithNoRepositories() {
|
||||
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, null);
|
||||
|
||||
ResourceMetadata resourceMetadata = mock(ResourceMetadata.class);
|
||||
when(resourceMetadata.getPath()).thenReturn(new Path("/people"));
|
||||
when(resourceMetadata.isExported()).thenReturn(true);
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.empty());
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
when(mappings.iterator()).thenReturn(singletonList(resourceMetadata).iterator());
|
||||
|
||||
assertThat(accessor.findCorsConfiguration("/people"), is(nullValue()));
|
||||
assertThat(accessor.findCorsConfiguration("/people")).isEmpty();
|
||||
}
|
||||
|
||||
interface PlainRepository {}
|
||||
|
||||
13
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java
Normal file → Executable file
13
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -23,12 +23,13 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
@@ -62,12 +63,12 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
@Mock RepositoryInvoker invoker;
|
||||
@Mock ApplicationEventPublisher publisher;
|
||||
|
||||
KeyValueMappingContext mappingContext = new KeyValueMappingContext();
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
|
||||
@Test // DATAREST-791
|
||||
public void usesRepositoryInvokerToLookupRelatedInstance() throws Exception {
|
||||
|
||||
KeyValuePersistentEntity<?> entity = mappingContext.getPersistentEntity(Sample.class);
|
||||
KeyValuePersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Sample.class);
|
||||
|
||||
ResourceMappings mappings = new PersistentEntitiesResourceMappings(
|
||||
new PersistentEntities(Collections.singleton(mappingContext)));
|
||||
@@ -79,8 +80,8 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
controller.setApplicationEventPublisher(publisher);
|
||||
|
||||
doReturn(invoker).when(invokerFactory).getInvokerFor(Reference.class);
|
||||
doReturn(new Sample()).when(invoker).invokeFindOne(4711);
|
||||
doReturn(new Reference()).when(invoker).invokeFindOne("some-id");
|
||||
doReturn(Optional.of(new Sample())).when(invoker).invokeFindOne(4711);
|
||||
doReturn(Optional.of(new Reference())).when(invoker).invokeFindOne("some-id");
|
||||
doReturn(new Sample()).when(invoker).invokeSave(any(Object.class));
|
||||
|
||||
RootResourceInformation information = new RootResourceInformation(metadata, entity, invoker);
|
||||
|
||||
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java
Normal file → Executable file
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandlerUnitTests.java
Normal file → Executable 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 ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
@@ -63,7 +62,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
ResponseEntity<ExceptionMessage> result = HANDLER
|
||||
.handleNotReadable(new HttpMessageNotReadableException("Message!"));
|
||||
|
||||
assertThat(result.getStatusCode(), is(HttpStatus.BAD_REQUEST));
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Test // DATAREST-507
|
||||
@@ -71,7 +70,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
|
||||
ResponseEntity<ExceptionMessage> result = HANDLER.handleConflict(new DataIntegrityViolationException("Message!"));
|
||||
|
||||
assertThat(result.getStatusCode(), is(HttpStatus.CONFLICT));
|
||||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
@Test // DATAREST-706
|
||||
@@ -81,7 +80,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
|
||||
ResponseEntity<ExceptionMessage> result = HANDLER.handleMiscFailures(new Exception(message));
|
||||
|
||||
assertThat(result.getBody(), is(notNullValue()));
|
||||
assertThat(result.getBody().getMessage(), is(message));
|
||||
assertThat(result.getBody()).isNotNull();
|
||||
assertThat(result.getBody().getMessage()).isEqualTo(message);
|
||||
}
|
||||
}
|
||||
|
||||
37
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java
Normal file → Executable file
37
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMappingUnitTests.java
Normal file → Executable 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.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -25,7 +24,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
|
||||
@@ -46,7 +45,7 @@ import org.springframework.web.method.HandlerMethod;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
static final AnnotationConfigWebApplicationContext CONTEXT = new AnnotationConfigWebApplicationContext();
|
||||
@@ -95,7 +94,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
public void returnsNullForUriNotMapped() throws Exception {
|
||||
|
||||
handlerMapping.afterPropertiesSet();
|
||||
assertThat(handlerMapping.lookupHandlerMethod("/foo", mockRequest), is(nullValue()));
|
||||
assertThat(handlerMapping.lookupHandlerMethod("/foo", mockRequest)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-111
|
||||
@@ -107,8 +106,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
handlerMapping.afterPropertiesSet();
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/people", mockRequest);
|
||||
|
||||
assertThat(method, is(notNullValue()));
|
||||
assertThat(method.getMethod(), is(listEntitiesMethod));
|
||||
assertThat(method).isNotNull();
|
||||
assertThat(method.getMethod()).isEqualTo(listEntitiesMethod);
|
||||
}
|
||||
|
||||
@Test // DATAREST-292
|
||||
@@ -122,14 +121,13 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base/people", mockRequest);
|
||||
|
||||
assertThat(method, is(notNullValue()));
|
||||
assertThat(method.getMethod(), is(listEntitiesMethod));
|
||||
assertThat(method).isNotNull();
|
||||
assertThat(method.getMethod()).isEqualTo(listEntitiesMethod);
|
||||
}
|
||||
|
||||
@Test // DATAREST-292
|
||||
public void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base");
|
||||
|
||||
configuration.setBasePath("/base");
|
||||
@@ -137,8 +135,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base", mockRequest);
|
||||
|
||||
assertThat(method, is(notNullValue()));
|
||||
assertThat(method.getMethod(), is(rootHandlerMethod));
|
||||
assertThat(method).isNotNull();
|
||||
assertThat(method.getMethod()).isEqualTo(rootHandlerMethod);
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -152,8 +150,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base/people/", mockRequest);
|
||||
|
||||
assertThat(method, is(notNullValue()));
|
||||
assertThat(method.getMethod(), is(listEntitiesMethod));
|
||||
assertThat(method).isNotNull();
|
||||
assertThat(method.getMethod()).isEqualTo(listEntitiesMethod);
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -168,14 +166,13 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/base/people", mockRequest);
|
||||
|
||||
assertThat(method, is(notNullValue()));
|
||||
assertThat(method.getMethod(), is(listEntitiesMethod));
|
||||
assertThat(method).isNotNull();
|
||||
assertThat(method.getMethod()).isEqualTo(listEntitiesMethod);
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/servlet-path");
|
||||
mockRequest.setServletPath("/servlet-path");
|
||||
|
||||
@@ -183,7 +180,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/servlet-path", mockRequest);
|
||||
|
||||
assertThat(method, is(nullValue()));
|
||||
assertThat(method).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
@@ -200,7 +197,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
HandlerMethod method = handlerMapping.lookupHandlerMethod("/people", mockRequest);
|
||||
|
||||
assertThat(method, is(nullValue()));
|
||||
assertThat(method).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-609
|
||||
@@ -210,7 +207,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
mockRequest = new MockHttpServletRequest("GET", "/people{?projection}");
|
||||
|
||||
assertThat(handlerMapping.getHandler(mockRequest), is(nullValue()));
|
||||
assertThat(handlerMapping.getHandler(mockRequest)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-994
|
||||
|
||||
5
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java
Normal file → Executable file
5
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositorySearchesResourceUnitTests.java
Normal file → Executable 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;
|
||||
|
||||
@@ -35,6 +34,6 @@ public class RepositorySearchesResourceUnitTests {
|
||||
|
||||
@Test // DATAREST-515
|
||||
public void returnsConfiguredDomainType() {
|
||||
assertThat(new RepositorySearchesResource(String.class).getDomainType(), is(typeCompatibleWith(String.class)));
|
||||
assertThat(new RepositorySearchesResource(String.class).getDomainType()).isAssignableFrom(String.class);
|
||||
}
|
||||
}
|
||||
|
||||
29
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java
Normal file → Executable file
29
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/ResourceStatusUnitTests.java
Normal file → Executable file
@@ -15,23 +15,22 @@
|
||||
*/
|
||||
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 lombok.Value;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.rest.core.util.Supplier;
|
||||
import org.springframework.data.rest.webmvc.ResourceStatus.StatusAndHeaders;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -45,7 +44,7 @@ import org.springframework.http.HttpStatus;
|
||||
public class ResourceStatusUnitTests {
|
||||
|
||||
ResourceStatus status;
|
||||
KeyValuePersistentEntity<?> entity;
|
||||
KeyValuePersistentEntity<?, ?> entity;
|
||||
|
||||
@Mock HttpHeadersPreparer preparer;
|
||||
@Mock Supplier<PersistentEntityResource> supplier;
|
||||
@@ -55,10 +54,10 @@ public class ResourceStatusUnitTests {
|
||||
|
||||
this.status = ResourceStatus.of(preparer);
|
||||
|
||||
KeyValueMappingContext context = new KeyValueMappingContext();
|
||||
this.entity = context.getPersistentEntity(Sample.class);
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
this.entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
|
||||
doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), Matchers.any());
|
||||
doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), any());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-835
|
||||
@@ -83,22 +82,22 @@ public class ResourceStatusUnitTests {
|
||||
@Test // DATAREST-835
|
||||
public void returnsNotModifiedIfEntityIsStillConsideredValid() {
|
||||
|
||||
doReturn(true).when(preparer).isObjectStillValid(Matchers.any(), Matchers.any(HttpHeaders.class));
|
||||
doReturn(true).when(preparer).isObjectStillValid(any(), any(HttpHeaders.class));
|
||||
|
||||
assertNotModified(status.getStatusAndHeaders(new HttpHeaders(), new Sample(0), entity));
|
||||
}
|
||||
|
||||
private void assertModified(StatusAndHeaders statusAndHeaders) {
|
||||
|
||||
assertThat(statusAndHeaders.isModified(), is(true));
|
||||
assertThat(statusAndHeaders.toResponseEntity(supplier).getStatusCode(), is(HttpStatus.OK));
|
||||
assertThat(statusAndHeaders.isModified()).isTrue();
|
||||
assertThat(statusAndHeaders.toResponseEntity(supplier).getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
verify(supplier).get();
|
||||
}
|
||||
|
||||
private void assertNotModified(StatusAndHeaders statusAndHeaders) {
|
||||
|
||||
assertThat(statusAndHeaders.isModified(), is(false));
|
||||
assertThat(statusAndHeaders.toResponseEntity(supplier).getStatusCode(), is(HttpStatus.NOT_MODIFIED));
|
||||
assertThat(statusAndHeaders.isModified()).isFalse();
|
||||
assertThat(statusAndHeaders.toResponseEntity(supplier).getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
|
||||
@Value
|
||||
|
||||
2
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java
Normal file → Executable file
2
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RootResourceInformationUnitTests.java
Normal file → Executable file
@@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.config;
|
||||
|
||||
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 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.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -63,19 +62,19 @@ public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||
PagingAndSortingTemplateVariables variables = new ArgumentResolverPagingAndSortingTemplateVariables(
|
||||
pageableResolver, sortResolver);
|
||||
|
||||
assertThat(variables.supportsParameter(getParameterMock(Pageable.class)), is(true));
|
||||
assertThat(variables.supportsParameter(getParameterMock(Sort.class)), is(true));
|
||||
assertThat(variables.supportsParameter(getParameterMock(Object.class)), is(false));
|
||||
assertThat(variables.supportsParameter(getParameterMock(Pageable.class))).isTrue();
|
||||
assertThat(variables.supportsParameter(getParameterMock(Sort.class))).isTrue();
|
||||
assertThat(variables.supportsParameter(getParameterMock(Object.class))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void forwardsEnhanceRequestForPageable() {
|
||||
assertForwardsEnhanceFor(new PageRequest(0, 10), pageableResolver, sortResolver);
|
||||
assertForwardsEnhanceFor(PageRequest.of(0, 10), pageableResolver, sortResolver);
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void forwardsEnhanceRequestForSort() {
|
||||
assertForwardsEnhanceFor(new Sort("property"), sortResolver, pageableResolver);
|
||||
assertForwardsEnhanceFor(Sort.by("property"), sortResolver, pageableResolver);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@@ -97,6 +96,6 @@ public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||
|
||||
verify(expected, times(1)).enhance(builder, null, value);
|
||||
verify(unexpected, times(0)).enhance(Mockito.any(UriComponentsBuilder.class), Mockito.any(MethodParameter.class),
|
||||
anyObject());
|
||||
any());
|
||||
}
|
||||
}
|
||||
|
||||
47
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java
Normal file → Executable file
47
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java
Normal file → Executable 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 java.util.Collection;
|
||||
import java.util.Date;
|
||||
@@ -85,8 +84,8 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
@Test // DATAREST-210
|
||||
public void assertEnableHypermediaSupportWorkingCorrectly() {
|
||||
|
||||
assertThat(context.getBean("entityLinksPluginRegistry"), is(notNullValue()));
|
||||
assertThat(context.getBean(LinkDiscoverers.class), is(notNullValue()));
|
||||
assertThat(context.getBean("entityLinksPluginRegistry")).isNotNull();
|
||||
assertThat(context.getBean(LinkDiscoverers.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,15 +106,15 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
.getBean(HateoasPageableHandlerMethodArgumentResolver.class);
|
||||
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
|
||||
resolver.enhance(builder, null, new PageRequest(0, 9000, Direction.ASC, "firstname"));
|
||||
resolver.enhance(builder, null, PageRequest.of(0, 9000, Direction.ASC, "firstname"));
|
||||
|
||||
MultiValueMap<String, String> params = builder.build().getQueryParams();
|
||||
|
||||
assertThat(params.containsKey("myPage"), is(true));
|
||||
assertThat(params.containsKey("mySort"), is(true));
|
||||
assertThat(params.containsKey("myPage")).isTrue();
|
||||
assertThat(params.containsKey("mySort")).isTrue();
|
||||
|
||||
assertThat(params.get("mySize"), hasSize(1));
|
||||
assertThat(params.get("mySize").get(0), is("7000"));
|
||||
assertThat(params.get("mySize")).hasSize(1);
|
||||
assertThat(params.get("mySize").get(0)).isEqualTo("7000");
|
||||
}
|
||||
|
||||
@Test // DATAREST-336
|
||||
@@ -131,8 +130,8 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
Object result = JsonPath.read(mapper.writeValueAsString(sample), "$.date");
|
||||
assertThat(result, is(instanceOf(String.class)));
|
||||
assertThat(result, is((Object) formatter.print(sample.date, Locale.US)));
|
||||
assertThat(result).isInstanceOf(String.class);
|
||||
assertThat(result).isEqualTo(formatter.print(sample.date, Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class) // DATAREST-362
|
||||
@@ -146,10 +145,10 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
Collection<MappingJackson2HttpMessageConverter> converters = context
|
||||
.getBeansOfType(MappingJackson2HttpMessageConverter.class).values();
|
||||
|
||||
for (HttpMessageConverter<?> converter : converters) {
|
||||
assertThat(converter, is(anyOf(instanceOf(TypeConstrainedMappingJackson2HttpMessageConverter.class),
|
||||
instanceOf(AlpsJsonHttpMessageConverter.class))));
|
||||
}
|
||||
converters.forEach(converter -> {
|
||||
assertThat(converter).isInstanceOfAny(TypeConstrainedMappingJackson2HttpMessageConverter.class,
|
||||
AlpsJsonHttpMessageConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-424
|
||||
@@ -158,8 +157,8 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
CollectingComponent component = context.getBean(CollectingComponent.class);
|
||||
List<HttpMessageConverter<?>> converters = component.converters;
|
||||
|
||||
assertThat(converters.get(0).getSupportedMediaTypes(), hasItem(MediaTypes.HAL_JSON));
|
||||
assertThat(converters.get(1).getSupportedMediaTypes(), hasItem(RestMediaTypes.SCHEMA_JSON));
|
||||
assertThat(converters.get(0).getSupportedMediaTypes()).contains(MediaTypes.HAL_JSON);
|
||||
assertThat(converters.get(1).getSupportedMediaTypes()).contains(RestMediaTypes.SCHEMA_JSON);
|
||||
}
|
||||
|
||||
@Test // DATAREST-424
|
||||
@@ -171,8 +170,8 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
|
||||
List<HttpMessageConverter<?>> converters = component.converters;
|
||||
|
||||
assertThat(converters.get(0).getSupportedMediaTypes(), hasItem(RestMediaTypes.SCHEMA_JSON));
|
||||
assertThat(converters.get(1).getSupportedMediaTypes(), hasItem(MediaTypes.HAL_JSON));
|
||||
assertThat(converters.get(0).getSupportedMediaTypes()).contains(RestMediaTypes.SCHEMA_JSON);
|
||||
assertThat(converters.get(1).getSupportedMediaTypes()).contains(MediaTypes.HAL_JSON);
|
||||
}
|
||||
|
||||
@Test // DATAREST-431, DATACMNS-626
|
||||
@@ -180,10 +179,10 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
|
||||
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
||||
|
||||
assertThat(service.canConvert(String.class, Point.class), is(true));
|
||||
assertThat(service.canConvert(Point.class, String.class), is(true));
|
||||
assertThat(service.canConvert(String.class, Distance.class), is(true));
|
||||
assertThat(service.canConvert(Distance.class, String.class), is(true));
|
||||
assertThat(service.canConvert(String.class, Point.class)).isTrue();
|
||||
assertThat(service.canConvert(Point.class, String.class)).isTrue();
|
||||
assertThat(service.canConvert(String.class, Distance.class)).isTrue();
|
||||
assertThat(service.canConvert(Distance.class, String.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-686
|
||||
@@ -193,7 +192,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
MessageSourceAccessor.class);
|
||||
Object messageSource = ReflectionTestUtils.getField(accessor, "messageSource");
|
||||
|
||||
assertThat((String) ReflectionTestUtils.getField(messageSource, "defaultEncoding"), is("UTF-8"));
|
||||
assertThat((String) ReflectionTestUtils.getField(messageSource, "defaultEncoding")).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
113
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java
Normal file → Executable file
113
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/DomainObjectReaderUnitTests.java
Normal file → Executable 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 lombok.AllArgsConstructor;
|
||||
@@ -42,7 +43,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
@@ -82,7 +83,7 @@ public class DomainObjectReaderUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
KeyValueMappingContext mappingContext = new KeyValueMappingContext();
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
mappingContext.getPersistentEntity(SampleUser.class);
|
||||
mappingContext.getPersistentEntity(Person.class);
|
||||
mappingContext.getPersistentEntity(TypeWithGenericMap.class);
|
||||
@@ -112,8 +113,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
SampleUser result = reader.readPut((ObjectNode) node, user, new ObjectMapper());
|
||||
|
||||
assertThat(result.name, is(nullValue()));
|
||||
assertThat(result.password, is("password"));
|
||||
assertThat(result.name).isNull();
|
||||
assertThat(result.password).isEqualTo("password");
|
||||
}
|
||||
|
||||
@Test // DATAREST-556
|
||||
@@ -126,8 +127,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Person result = reader.readPut((ObjectNode) node, new Person("Dave", "Matthews"), mapper);
|
||||
|
||||
assertThat(result.firstName, is("Carter"));
|
||||
assertThat(result.lastName, is("Beauford"));
|
||||
assertThat(result.firstName).isEqualTo("Carter");
|
||||
assertThat(result.lastName).isEqualTo("Beauford");
|
||||
}
|
||||
|
||||
@Test // DATAREST-605
|
||||
@@ -142,8 +143,8 @@ public class DomainObjectReaderUnitTests {
|
||||
SampleUser result = reader.readPut((ObjectNode) node, user, new ObjectMapper());
|
||||
|
||||
// Assert that the nested Map values also consider ignored properties
|
||||
assertThat(result.relatedUsers.get("parent").password, is("password"));
|
||||
assertThat(result.relatedUsers.get("parent").name, is("Oliver"));
|
||||
assertThat(result.relatedUsers.get("parent").password).isEqualTo("password");
|
||||
assertThat(result.relatedUsers.get("parent").name).isEqualTo("Oliver");
|
||||
}
|
||||
|
||||
@Test // DATAREST-701
|
||||
@@ -159,11 +160,11 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
TypeWithGenericMap result = reader.readPut((ObjectNode) node, target, mapper);
|
||||
|
||||
assertThat(result.map.get("a"), is((Object) "1"));
|
||||
assertThat(result.map.get("a")).isEqualTo((Object) "1");
|
||||
|
||||
Object object = result.map.get("b");
|
||||
assertThat(object, is(instanceOf(Map.class)));
|
||||
assertThat(((Map<Object, Object>) object).get("c"), is((Object) "2"));
|
||||
assertThat(object).isInstanceOf(Map.class);
|
||||
assertThat(((Map<Object, Object>) object).get("c")).isEqualTo((Object) "2");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-701
|
||||
@@ -188,10 +189,10 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
VersionedType result = reader.readPut(node, type, mapper);
|
||||
|
||||
assertThat(result.lastname, is("Matthews"));
|
||||
assertThat(result.firstname, is(nullValue()));
|
||||
assertThat(result.id, is(1L));
|
||||
assertThat(result.version, is(1L));
|
||||
assertThat(result.lastname).isEqualTo("Matthews");
|
||||
assertThat(result.firstname).isNull();
|
||||
assertThat(result.id).isEqualTo(1L);
|
||||
assertThat(result.version).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test // DATAREST-873
|
||||
@@ -205,7 +206,7 @@ public class DomainObjectReaderUnitTests {
|
||||
SampleWithCreatedDate sample = new SampleWithCreatedDate();
|
||||
sample.createdDate = reference;
|
||||
|
||||
assertThat(reader.readPut(node, sample, mapper).createdDate, is(reference));
|
||||
assertThat(reader.readPut(node, sample, mapper).createdDate).isEqualTo(reference);
|
||||
}
|
||||
|
||||
@Test // DATAREST-931
|
||||
@@ -222,7 +223,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
User result = reader.read(source, user, new ObjectMapper());
|
||||
|
||||
assertThat(result.phones.get(0).creationDate, is(notNullValue()));
|
||||
assertThat(result.phones.get(0).creationDate).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-919
|
||||
@@ -249,18 +250,18 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
TypeWithGenericMap result = reader.readPut(payload, map, mapper);
|
||||
|
||||
assertThat(result.map.get("sub1"), is((Object) "ok"));
|
||||
assertThat(result.map.get("sub1")).isEqualTo((Object) "ok");
|
||||
|
||||
List<String> sub2 = as(result.map.get("sub2"), List.class);
|
||||
assertThat(sub2.get(0), is("ok1"));
|
||||
assertThat(sub2.get(1), is("ok2"));
|
||||
assertThat(sub2.get(0)).isEqualTo("ok1");
|
||||
assertThat(sub2.get(1)).isEqualTo("ok2");
|
||||
|
||||
List<Map<String, String>> sub3 = as(result.map.get("sub3"), List.class);
|
||||
assertThat(sub3.get(0).get("childOk1"), is("ok"));
|
||||
assertThat(sub3.get(0).get("childOk1")).isEqualTo("ok");
|
||||
|
||||
Map<Object, String> sub4 = as(result.map.get("sub4"), Map.class);
|
||||
assertThat(sub4.get("c1"), is("v1"));
|
||||
assertThat(sub4.get("c2"), is("new"));
|
||||
assertThat(sub4.get("c1")).isEqualTo("v1");
|
||||
assertThat(sub4.get("c2")).isEqualTo("new");
|
||||
}
|
||||
|
||||
@Test // DATAREST-938
|
||||
@@ -279,11 +280,11 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Outer result = reader.doMerge((ObjectNode) node, outer, new ObjectMapper());
|
||||
|
||||
assertThat(result, is(sameInstance(outer)));
|
||||
assertThat(result.prop, is("else"));
|
||||
assertThat(result.inner.prop, is("something"));
|
||||
assertThat(result.inner.name, is("new inner name"));
|
||||
assertThat(result.inner, is(sameInstance(inner)));
|
||||
assertThat(result).isSameAs(outer);
|
||||
assertThat(result.prop).isEqualTo("else");
|
||||
assertThat(result.inner.prop).isEqualTo("something");
|
||||
assertThat(result.inner.name).isEqualTo("new inner name");
|
||||
assertThat(result.inner).isSameAs(inner);
|
||||
}
|
||||
|
||||
@Test // DATAREST-937
|
||||
@@ -297,8 +298,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
SampleWithTransient result = reader.readPut((ObjectNode) node, sample, new ObjectMapper());
|
||||
|
||||
assertThat(result.name, is("new name"));
|
||||
assertThat(result.temporary, is("new temp"));
|
||||
assertThat(result.name).isEqualTo("new name");
|
||||
assertThat(result.temporary).isEqualTo("new temp");
|
||||
}
|
||||
|
||||
@Test // DATAREST-953
|
||||
@@ -315,7 +316,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items.get(0).some, is("value"));
|
||||
assertThat(result.inner.items.get(0).some).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-956
|
||||
@@ -333,10 +334,10 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items.size(), is(3));
|
||||
assertThat(result.inner.items.get(0).some, is("value1"));
|
||||
assertThat(result.inner.items.get(1).some, is("value2"));
|
||||
assertThat(result.inner.items.get(2).some, is("value3"));
|
||||
assertThat(result.inner.items).hasSize(3);
|
||||
assertThat(result.inner.items.get(0).some).isEqualTo("value1");
|
||||
assertThat(result.inner.items.get(1).some).isEqualTo("value2");
|
||||
assertThat(result.inner.items.get(2).some).isEqualTo("value3");
|
||||
}
|
||||
|
||||
@Test // DATAREST-956
|
||||
@@ -355,8 +356,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items.size(), is(1));
|
||||
assertThat(result.inner.items.get(0).some, is("value"));
|
||||
assertThat(result.inner.items).hasSize(1);
|
||||
assertThat(result.inner.items.get(0).some).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-959
|
||||
@@ -370,8 +371,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items.size(), is(1));
|
||||
assertThat(result.inner.items.get(0).some, is("value"));
|
||||
assertThat(result.inner.items).hasSize(1);
|
||||
assertThat(result.inner.items.get(0).some).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-959
|
||||
@@ -386,14 +387,14 @@ public class DomainObjectReaderUnitTests {
|
||||
.readTree("{ \"inner\" : { \"object\" : [ { \"some\" : \"value\" }, { \"some\" : \"otherValue\" } ] } }");
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
assertThat(result.inner.object, is(instanceOf(Collection.class)));
|
||||
assertThat(result.inner.object).isInstanceOf(Collection.class);
|
||||
|
||||
Collection<?> collection = (Collection<?>) result.inner.object;
|
||||
assertThat(collection.size(), is(2));
|
||||
assertThat(collection).hasSize(2);
|
||||
|
||||
Iterator<Map<String, Object>> iterator = (Iterator<Map<String, Object>>) collection.iterator();
|
||||
assertThat(iterator.next().get("some"), is((Object) "value"));
|
||||
assertThat(iterator.next().get("some"), is((Object) "otherValue"));
|
||||
assertThat(iterator.next().get("some")).isEqualTo((Object) "value");
|
||||
assertThat(iterator.next().get("some")).isEqualTo((Object) "otherValue");
|
||||
}
|
||||
|
||||
@Test // DATAREST-965
|
||||
@@ -411,8 +412,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items, is(nullValue()));
|
||||
assertThat((String) result.inner.object, is("value"));
|
||||
assertThat(result.inner.items).isNull();
|
||||
assertThat((String) result.inner.object).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-965
|
||||
@@ -428,9 +429,9 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Parent result = reader.readPut((ObjectNode) node, source, new ObjectMapper());
|
||||
|
||||
assertThat(result.inner.items.size(), is(1));
|
||||
assertThat(result.inner.items.get(0).some, is("value"));
|
||||
assertThat(result.inner.object, is(nullValue()));
|
||||
assertThat(result.inner.items).hasSize(1);
|
||||
assertThat(result.inner.items.get(0).some).isEqualTo("value");
|
||||
assertThat(result.inner.object).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-986
|
||||
@@ -442,8 +443,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
Product result = reader.readPut((ObjectNode) node, new Product(), mapper);
|
||||
|
||||
assertThat(result.map.get(Locale.ENGLISH), is(new LocalizedValue("eventual")));
|
||||
assertThat(result.map.get(Locale.GERMAN), is(new LocalizedValue("schlussendlich")));
|
||||
assertThat(result.map.get(Locale.ENGLISH)).isEqualTo(new LocalizedValue("eventual"));
|
||||
assertThat(result.map.get(Locale.GERMAN)).isEqualTo(new LocalizedValue("schlussendlich"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-987
|
||||
@@ -478,8 +479,8 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
SampleWithReference result = reader.mergeForPut(source, target, new ObjectMapper());
|
||||
|
||||
assertThat(result.nested, is(source.nested));
|
||||
assertThat(result.nested == originalCollection, is(false));
|
||||
assertThat(result.nested).isEqualTo(source.nested);
|
||||
assertThat(result.nested == originalCollection).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-944
|
||||
@@ -492,14 +493,14 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
SampleWithReference result = reader.mergeForPut(source, target, new ObjectMapper());
|
||||
|
||||
assertThat(result.nested, is(source.nested));
|
||||
assertThat(result.nested == originalCollection, is(true));
|
||||
assertThat(result.nested).isEqualTo(source.nested);
|
||||
assertThat(result.nested).isSameAs(originalCollection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T as(Object source, Class<T> type) {
|
||||
|
||||
assertThat(source, is(instanceOf(type)));
|
||||
assertThat(source).isInstanceOf(type);
|
||||
return (T) source;
|
||||
}
|
||||
|
||||
|
||||
43
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java
Normal file → Executable file
43
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/EnumTranslatorUnitTests.java
Normal file → Executable 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 java.util.Locale;
|
||||
|
||||
@@ -54,17 +53,17 @@ public class EnumTranslatorUnitTests {
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForNullSource() {
|
||||
assertThat(configuration.fromText(MyEnum.class, null), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForEmptySource() {
|
||||
assertThat(configuration.fromText(MyEnum.class, null), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForUnknownValue() {
|
||||
assertThat(configuration.fromText(MyEnum.class, "Foobar"), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Foobar")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
@@ -72,13 +71,13 @@ public class EnumTranslatorUnitTests {
|
||||
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE), is(MyEnum.SECOND_VALUE.name()));
|
||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo(MyEnum.SECOND_VALUE.name());
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void returnsDefaultTranslationByDefault() {
|
||||
|
||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE), is("Second value"));
|
||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo("Second value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
@@ -86,14 +85,14 @@ public class EnumTranslatorUnitTests {
|
||||
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE"), is(MyEnum.FIRST_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesStandardTranslationAndEnumNameByDefault() {
|
||||
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE"), is(MyEnum.FIRST_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value"), is(MyEnum.SECOND_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
@@ -104,22 +103,22 @@ public class EnumTranslatorUnitTests {
|
||||
messageSource.addMessage(MyEnum.class.getName().concat(".").concat(MyEnum.FIRST_VALUE.name()), Locale.US,
|
||||
"Translated");
|
||||
|
||||
assertThat(configuration.asText(MyEnum.FIRST_VALUE), is("Translated"));
|
||||
assertThat(configuration.asText(MyEnum.FIRST_VALUE)).isEqualTo("Translated");
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesEnumNameByDefaultEvenIfMessageDefined() {
|
||||
|
||||
// Parses resolved message and enum name
|
||||
assertThat(configuration.fromText(MyEnum.class, "Translated"), is(MyEnum.FIRST_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE"), is(MyEnum.FIRST_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
|
||||
// Does not parse default translation as explicit translation is available
|
||||
assertThat(configuration.fromText(MyEnum.class, "First value"), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, "First value")).isNull();
|
||||
|
||||
// Parses default translation as no explicit translation is available
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value"), is(MyEnum.SECOND_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE"), is(MyEnum.SECOND_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
@@ -128,8 +127,8 @@ public class EnumTranslatorUnitTests {
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
// Parses default translation as no explicit translation is available
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value"), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE"), is(MyEnum.SECOND_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value")).isNull();
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,12 +137,12 @@ public class EnumTranslatorUnitTests {
|
||||
configuration.setParseEnumNameAsFallback(false);
|
||||
|
||||
// Parses resolved message and enum name
|
||||
assertThat(configuration.fromText(MyEnum.class, "Translated"), is(MyEnum.FIRST_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE"), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isNull();
|
||||
|
||||
// Parses default translation as no explicit translation is available
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value"), is(MyEnum.SECOND_VALUE));
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE"), is(nullValue()));
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "SECOND_VALUE")).isNull();
|
||||
}
|
||||
|
||||
static enum MyEnum {
|
||||
|
||||
21
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java
Normal file → Executable file
21
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonMetadataUnitTests.java
Normal file → Executable 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 java.io.IOException;
|
||||
|
||||
@@ -51,7 +50,7 @@ public class JacksonMetadataUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.context = new KeyValueMappingContext();
|
||||
this.context = new KeyValueMappingContext<>();
|
||||
|
||||
this.mapper = new ObjectMapper();
|
||||
this.mapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
|
||||
@@ -62,11 +61,11 @@ public class JacksonMetadataUnitTests {
|
||||
|
||||
JacksonMetadata metadata = new JacksonMetadata(mapper, User.class);
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getPersistentEntity(User.class);
|
||||
PersistentProperty<?> property = entity.getPersistentProperty("username");
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(User.class);
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("username");
|
||||
|
||||
assertThat(metadata.isExported(property), is(true));
|
||||
assertThat(metadata.isReadOnly(property), is(true));
|
||||
assertThat(metadata.isExported(property)).isTrue();
|
||||
assertThat(metadata.isReadOnly(property)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-644
|
||||
@@ -74,10 +73,10 @@ public class JacksonMetadataUnitTests {
|
||||
|
||||
JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class);
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getPersistentEntity(Value.class);
|
||||
PersistentProperty<?> property = entity.getPersistentProperty("value");
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Value.class);
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("value");
|
||||
|
||||
assertThat(metadata.isReadOnly(property), is(false));
|
||||
assertThat(metadata.isReadOnly(property)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-644
|
||||
@@ -86,7 +85,7 @@ public class JacksonMetadataUnitTests {
|
||||
JsonSerializer<?> serializer = new JacksonMetadata(new ObjectMapper(), SomeBean.class)
|
||||
.getTypeSerializer(SomeBean.class);
|
||||
|
||||
assertThat(serializer, is(instanceOf(SomeBeanSerializer.class)));
|
||||
assertThat(serializer).isInstanceOf(SomeBeanSerializer.class);
|
||||
}
|
||||
|
||||
static class User {
|
||||
|
||||
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java
Normal file → Executable file
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JacksonSerializersUnitTests.java
Normal file → Executable 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.Collection;
|
||||
@@ -53,7 +54,7 @@ public class JacksonSerializersUnitTests {
|
||||
|
||||
Sample result = mapper.readValue("{ \"property\" : \"value\"}", Sample.class);
|
||||
|
||||
assertThat(result.property, is(SampleEnum.VALUE));
|
||||
assertThat(result.property).isEqualTo(SampleEnum.VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
@@ -61,7 +62,7 @@ public class JacksonSerializersUnitTests {
|
||||
|
||||
Sample result = mapper.readValue("{ \"collection\" : [ \"value\" ] }", Sample.class);
|
||||
|
||||
assertThat(result.collection, hasItem(SampleEnum.VALUE));
|
||||
assertThat(result.collection).contains(SampleEnum.VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
@@ -77,7 +78,7 @@ public class JacksonSerializersUnitTests {
|
||||
|
||||
Sample result = mapper.readValue("{ \"mapToEnum\" : { \"foo\" : \"value\" } }", Sample.class);
|
||||
|
||||
assertThat(result.mapToEnum.get("foo"), is(SampleEnum.VALUE));
|
||||
assertThat(result.mapToEnum.get("foo")).isEqualTo(SampleEnum.VALUE);
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
5
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java
Normal file → Executable file
5
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/JsonSchemaUnitTests.java
Normal file → Executable 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 org.junit.Test;
|
||||
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
|
||||
@@ -37,7 +36,7 @@ public class JsonSchemaUnitTests {
|
||||
|
||||
JsonSchemaProperty property = new JsonSchemaProperty("foo", null, "bar", false);
|
||||
|
||||
assertThat(property.with(type.getProperty("foo")).type, is("number"));
|
||||
assertThat(property.with(type.getRequiredProperty("foo")).type).isEqualTo("number");
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
27
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java
Normal file → Executable file
27
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappedPropertiesUnitTests.java
Normal file → Executable file
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
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 org.junit.Test;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@@ -35,37 +34,37 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class MappedPropertiesUnitTests {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
KeyValueMappingContext context = new KeyValueMappingContext();
|
||||
KeyValuePersistentEntity<?> entity = context.getPersistentEntity(Sample.class);
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
MappedProperties properties = MappedProperties.fromJacksonProperties(entity, mapper);
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData"), is(false));
|
||||
assertThat(properties.getPersistentProperty("notExposedBySpringData"), is(nullValue()));
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData")).isFalse();
|
||||
assertThat(properties.getPersistentProperty("notExposedBySpringData")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void doesNotExposeMappedPropertyForNonJacksonProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedByJackson"), is(false));
|
||||
assertThat(properties.getPersistentProperty("notExposedByJackson"), is(nullValue()));
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedByJackson")).isFalse();
|
||||
assertThat(properties.getPersistentProperty("notExposedByJackson")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void exposesProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("exposedProperty"), is(true));
|
||||
assertThat(properties.getPersistentProperty("exposedProperty"), is(notNullValue()));
|
||||
assertThat(properties.hasPersistentPropertyForField("exposedProperty")).isTrue();
|
||||
assertThat(properties.getPersistentProperty("exposedProperty")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void exposesRenamedPropertyByExternalName() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("email"), is(true));
|
||||
assertThat(properties.getPersistentProperty("email"), is(notNullValue()));
|
||||
assertThat(properties.getMappedName(entity.getPersistentProperty("emailAddress")), is("email"));
|
||||
assertThat(properties.hasPersistentPropertyForField("email")).isTrue();
|
||||
assertThat(properties.getPersistentProperty("email")).isNotNull();
|
||||
assertThat(properties.getMappedName(entity.getRequiredPersistentProperty("emailAddress"))).isEqualTo("email");
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
25
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java
Normal file → Executable file
25
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/MappingAwarePageableArgumentResolverUnitTests.java
Normal file → Executable file
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -59,31 +58,31 @@ public class MappingAwarePageableArgumentResolverUnitTests {
|
||||
@Test // DATAREST-906
|
||||
public void resolveArgumentShouldReturnTranslatedPageable() throws Exception {
|
||||
|
||||
Sort translated = new Sort("world");
|
||||
Pageable pageable = new PageRequest(0, 1, Direction.ASC, "hello");
|
||||
Sort translated = Sort.by("world");
|
||||
Pageable pageable = PageRequest.of(0, 1, Direction.ASC, "hello");
|
||||
|
||||
when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory)).thenReturn(pageable);
|
||||
when(translator.translateSort(pageable.getSort(), parameter, webRequest)).thenReturn(translated);
|
||||
|
||||
Pageable result = resolver.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory);
|
||||
|
||||
assertThat(result.getPageSize(), is(1));
|
||||
assertThat(result.getPageNumber(), is(0));
|
||||
assertThat(result.getSort(), is(equalTo(translated)));
|
||||
assertThat(result.getPageSize()).isEqualTo(1);
|
||||
assertThat(result.getPageNumber()).isEqualTo(0);
|
||||
assertThat(result.getSort()).isEqualTo(translated);
|
||||
}
|
||||
|
||||
@Test // DATAREST-906
|
||||
public void resolveArgumentShouldReturnPageableWithoutSort() throws Exception {
|
||||
|
||||
Pageable pageable = new PageRequest(0, 1);
|
||||
Pageable pageable = PageRequest.of(0, 1);
|
||||
|
||||
when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory)).thenReturn(pageable);
|
||||
|
||||
Pageable result = resolver.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory);
|
||||
|
||||
assertThat(result.getPageSize(), is(1));
|
||||
assertThat(result.getPageNumber(), is(0));
|
||||
assertThat(result.getSort(), is(nullValue()));
|
||||
assertThat(result.getPageSize()).isEqualTo(1);
|
||||
assertThat(result.getPageNumber()).isEqualTo(0);
|
||||
assertThat(result.getSort()).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-906
|
||||
@@ -91,6 +90,6 @@ public class MappingAwarePageableArgumentResolverUnitTests {
|
||||
|
||||
Pageable result = resolver.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory);
|
||||
|
||||
assertThat(result, is(nullValue()));
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
27
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java
Normal file → Executable file
27
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityJackson2ModuleUnitTests.java
Normal file → Executable 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 static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -28,7 +27,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -36,8 +35,8 @@ import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.UriToEntityConverter;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
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.AssociationOmittingSerializerModifier;
|
||||
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.AssociationUriResolvingDeserializerModifier;
|
||||
@@ -49,7 +48,6 @@ import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.plugin.core.OrderAwarePluginRegistry;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
@@ -78,7 +76,7 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
KeyValueMappingContext mappingContext = new KeyValueMappingContext();
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
mappingContext.getPersistentEntity(Sample.class);
|
||||
mappingContext.getPersistentEntity(SampleWithAdditionalGetters.class);
|
||||
mappingContext.getPersistentEntity(PersistentEntityJackson2ModuleUnitTests.PetOwner.class);
|
||||
@@ -89,12 +87,10 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
|
||||
NestedEntitySerializer nestedEntitySerializer = new NestedEntitySerializer(persistentEntities,
|
||||
new EmbeddedResourcesAssembler(persistentEntities, associations, mock(ExcerptProjector.class)), invoker);
|
||||
OrderAwarePluginRegistry<EntityLookup<?>, Class<?>> lookups = OrderAwarePluginRegistry.create();
|
||||
|
||||
SimpleModule module = new SimpleModule();
|
||||
|
||||
module.setSerializerModifier(new AssociationOmittingSerializerModifier(persistentEntities, associations,
|
||||
nestedEntitySerializer, new LookupObjectSerializer(lookups)));
|
||||
nestedEntitySerializer, new LookupObjectSerializer(Java8PluginRegistry.empty())));
|
||||
module.setDeserializerModifier(new AssociationUriResolvingDeserializerModifier(persistentEntities, associations,
|
||||
converter, mock(RepositoryInvokerFactory.class)));
|
||||
|
||||
@@ -110,7 +106,7 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
|
||||
String result = mapper.writeValueAsString(sample);
|
||||
|
||||
assertThat(JsonPath.read(result, "$.foo"), is((Object) "bar"));
|
||||
assertThat(JsonPath.<String> read(result, "$.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test // DATAREST-340
|
||||
@@ -119,14 +115,15 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
SampleWithAdditionalGetters sample = new SampleWithAdditionalGetters();
|
||||
|
||||
String result = mapper.writeValueAsString(sample);
|
||||
assertThat(JsonPath.read(result, "$.number"), is((Object) 5));
|
||||
|
||||
assertThat(JsonPath.<Integer> read(result, "$.number")).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test // DATAREST-662
|
||||
public void resolvesReferenceToSubtypeCorrectly() throws IOException {
|
||||
|
||||
PersistentProperty<?> property = persistentEntities.getPersistentEntity(PetOwner.class)
|
||||
.getPersistentProperty("pet");
|
||||
PersistentProperty<?> property = persistentEntities.getRequiredPersistentEntity(PetOwner.class)
|
||||
.getRequiredPersistentProperty("pet");
|
||||
|
||||
when(associations.isLinkableAssociation(property)).thenReturn(true);
|
||||
when(converter.convert(new UriTemplate("/pets/1").expand(), TypeDescriptor.valueOf(URI.class),
|
||||
@@ -134,8 +131,8 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
|
||||
PetOwner petOwner = mapper.readValue("{\"pet\":\"/pets/1\"}", PetOwner.class);
|
||||
|
||||
assertThat(petOwner, is(notNullValue()));
|
||||
assertThat(petOwner.getPet(), is(notNullValue()));
|
||||
assertThat(petOwner).isNotNull();
|
||||
assertThat(petOwner.getPet()).isNotNull();
|
||||
}
|
||||
|
||||
static class PetOwner {
|
||||
|
||||
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java
Normal file → Executable file
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/ProjectionJacksonIntegrationTests.java
Normal file → Executable 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 java.util.Arrays;
|
||||
|
||||
@@ -62,7 +61,7 @@ public class ProjectionJacksonIntegrationTests {
|
||||
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
|
||||
|
||||
String result = mapper.writeValueAsString(projection);
|
||||
assertThat(JsonPath.read(result, "$.firstname"), is((Object) "Dave"));
|
||||
assertThat(JsonPath.<String> read(result, "$.firstname")).isEqualTo((Object) "Dave");
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
@@ -83,7 +82,7 @@ public class ProjectionJacksonIntegrationTests {
|
||||
|
||||
String result = mapper.writeValueAsString(resources);
|
||||
|
||||
assertThat(JsonPath.read(result, "$._embedded.customers[0].firstname"), is((Object) "Dave"));
|
||||
assertThat(JsonPath.<String> read(result, "$._embedded.customers[0].firstname")).isEqualTo((Object) "Dave");
|
||||
}
|
||||
|
||||
static class Customer {
|
||||
|
||||
83
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java
Normal file → Executable file
83
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/SortTranslatorUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
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;
|
||||
@@ -48,14 +47,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class SortTranslatorUnitTests {
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
KeyValueMappingContext mappingContext;
|
||||
KeyValueMappingContext<?, ?> mappingContext;
|
||||
PersistentEntities persistentEntities;
|
||||
SortTranslator sortTranslator;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
mappingContext = new KeyValueMappingContext();
|
||||
mappingContext = new KeyValueMappingContext<>();
|
||||
mappingContext.getPersistentEntity(Plain.class);
|
||||
mappingContext.getPersistentEntity(WithJsonProperty.class);
|
||||
mappingContext.getPersistentEntity(UnwrapEmbedded.class);
|
||||
@@ -70,106 +69,106 @@ public class SortTranslatorUnitTests {
|
||||
@Test // DATAREST-883
|
||||
public void shouldMapKnownProperties() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("hello", "name"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "name"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("hello"), is(nullValue()));
|
||||
assertThat(translatedSort.getOrderFor("name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("hello")).isNull();
|
||||
assertThat(translatedSort.getOrderFor("name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
public void returnsNullSortIfNoPropertiesMatch() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("hello", "world"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "world"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort, is(nullValue()));
|
||||
assertThat(translatedSort).isEqualTo(Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
public void shouldMapKnownPropertiesWithJsonProperty() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("hello", "foo"),
|
||||
mappingContext.getPersistentEntity(WithJsonProperty.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("hello", "foo"),
|
||||
mappingContext.getRequiredPersistentEntity(WithJsonProperty.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("hello"), is(nullValue()));
|
||||
assertThat(translatedSort.getOrderFor("name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("hello")).isNull();
|
||||
assertThat(translatedSort.getOrderFor("name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
public void shouldJacksonFieldNameForMapping() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("name"),
|
||||
mappingContext.getPersistentEntity(WithJsonProperty.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("name"),
|
||||
mappingContext.getRequiredPersistentEntity(WithJsonProperty.class));
|
||||
|
||||
assertThat(translatedSort, is(nullValue()));
|
||||
assertThat(translatedSort).isEqualTo(Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void shouldMapKnownNestedProperties() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(
|
||||
new Sort("embedded.name", "embedded.collection", "embedded.someInterface"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort.by("embedded.name", "embedded.collection", "embedded.someInterface"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("embedded.name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("embedded.collection"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("embedded.someInterface"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("embedded.name")).isNotNull();
|
||||
assertThat(translatedSort.getOrderFor("embedded.collection")).isNotNull();
|
||||
assertThat(translatedSort.getOrderFor("embedded.someInterface")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void shouldSkipWrongNestedProperties() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("embedded.unknown"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("embedded.unknown"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort, is(nullValue()));
|
||||
assertThat(translatedSort).isEqualTo(Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test // DATAREST-910, DATAREST-976
|
||||
public void shouldSkipKnownAssociationProperties() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("association.name"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("association.name"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort, is(nullValue()));
|
||||
assertThat(translatedSort).isEqualTo(Sort.unsorted());
|
||||
}
|
||||
|
||||
@Test // DATAREST-976
|
||||
public void shouldMapEmbeddableAssociationProperties() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("refEmbedded.name"),
|
||||
mappingContext.getPersistentEntity(Plain.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("refEmbedded.name"),
|
||||
mappingContext.getRequiredPersistentEntity(Plain.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("refEmbedded.name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("refEmbedded.name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void shouldJacksonFieldNameForNestedFieldMapping() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("em.foo"),
|
||||
mappingContext.getPersistentEntity(WithJsonProperty.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("em.foo"),
|
||||
mappingContext.getRequiredPersistentEntity(WithJsonProperty.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("embeddedWithJsonProperty.bar"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("embeddedWithJsonProperty.bar")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void shouldTranslatePathForSingleLevelJsonUnwrappedObject() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("un-name"),
|
||||
mappingContext.getPersistentEntity(UnwrapEmbedded.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("un-name"),
|
||||
mappingContext.getRequiredPersistentEntity(UnwrapEmbedded.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("embedded.name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("embedded.name")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void shouldTranslatePathForMultiLevelLevelJsonUnwrappedObject() {
|
||||
|
||||
Sort translatedSort = sortTranslator.translateSort(new Sort("un-name", "burrito.un-name"),
|
||||
mappingContext.getPersistentEntity(MultiUnwrapped.class));
|
||||
Sort translatedSort = sortTranslator.translateSort(Sort.by("un-name", "burrito.un-name"),
|
||||
mappingContext.getRequiredPersistentEntity(MultiUnwrapped.class));
|
||||
|
||||
assertThat(translatedSort.getOrderFor("anotherWrap.embedded.name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("burrito.embedded.name"), is(notNullValue()));
|
||||
assertThat(translatedSort.getOrderFor("anotherWrap.embedded.name")).isNotNull();
|
||||
assertThat(translatedSort.getOrderFor("burrito.embedded.name")).isNotNull();
|
||||
}
|
||||
|
||||
static class Plain {
|
||||
|
||||
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java
Normal file → Executable file
11
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/UriStringDeserializerUnitTests.java
Normal file → Executable file
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
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.net.URI;
|
||||
@@ -29,7 +28,7 @@ import org.junit.rules.ExpectedException;
|
||||
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.convert.TypeDescriptor;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.rest.core.UriToEntityConverter;
|
||||
@@ -82,8 +81,8 @@ public class UriStringDeserializerUnitTests {
|
||||
@Test // DATAREST-377
|
||||
public void returnsNullUriIfSourceIsEmptyOrNull() throws Exception {
|
||||
|
||||
assertThat(invokeConverterWith(""), is(nullValue()));
|
||||
assertThat(invokeConverterWith(null), is(nullValue()));
|
||||
assertThat(invokeConverterWith("")).isNull();
|
||||
assertThat(invokeConverterWith(null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-377
|
||||
|
||||
53
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java
Normal file → Executable file
53
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/WrappedPropertiesUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -46,13 +45,13 @@ public class WrappedPropertiesUnitTests {
|
||||
|
||||
static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
KeyValueMappingContext mappingContext;
|
||||
KeyValueMappingContext<?, ?> mappingContext;
|
||||
PersistentEntities persistentEntities;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
mappingContext = new KeyValueMappingContext();
|
||||
mappingContext = new KeyValueMappingContext<>();
|
||||
mappingContext.getPersistentEntity(MultiLevelNesting.class);
|
||||
mappingContext.getPersistentEntity(SyntheticProperties.class);
|
||||
|
||||
@@ -62,72 +61,72 @@ public class WrappedPropertiesUnitTests {
|
||||
@Test // DATAREST-910
|
||||
public void wrappedPropertiesShouldConsiderSingleLevelUnwrapping() {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(OneLevelNesting.class);
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getRequiredPersistentEntity(OneLevelNesting.class);
|
||||
WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity,
|
||||
MAPPER);
|
||||
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("street"), is(true));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("one"), is(false));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("street")).isTrue();
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("one")).isFalse();
|
||||
|
||||
List<PersistentProperty<?>> street = wrappedProperties.getPersistentProperties("street");
|
||||
|
||||
PersistentProperty<?> addressProperty = persistentEntity.getPersistentProperty("address");
|
||||
PersistentProperty<?> streetProperty = persistentEntities.getPersistentEntity(Address.class)
|
||||
.getPersistentProperty("street");
|
||||
PersistentProperty<?> addressProperty = persistentEntity.getRequiredPersistentProperty("address");
|
||||
PersistentProperty<?> streetProperty = persistentEntities.getRequiredPersistentEntity(Address.class)
|
||||
.getRequiredPersistentProperty("street");
|
||||
|
||||
assertThat(street, contains(addressProperty, streetProperty));
|
||||
assertThat(street).contains(addressProperty, streetProperty);
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void wrappedPropertiesShouldConsiderMultiLevelUnwrapping() {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(MultiLevelNesting.class);
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class);
|
||||
WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity,
|
||||
new ObjectMapper());
|
||||
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-one-post"), is(true));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-street-post"), is(true));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("nested"), is(false));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-one-post")).isTrue();
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-street-post")).isTrue();
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("nested")).isFalse();
|
||||
|
||||
List<PersistentProperty<?>> street = wrappedProperties.getPersistentProperties("pre-street-post");
|
||||
|
||||
PersistentProperty<?> oneLevelNestingProperty = persistentEntity.getPersistentProperty("unwrapped");
|
||||
PersistentProperty<?> addressProperty = persistentEntities.getPersistentEntity(OneLevelNesting.class)
|
||||
.getPersistentProperty("address");
|
||||
PersistentProperty<?> streetProperty = persistentEntities.getPersistentEntity(Address.class)
|
||||
.getPersistentProperty("street");
|
||||
PersistentProperty<?> oneLevelNestingProperty = persistentEntity.getRequiredPersistentProperty("unwrapped");
|
||||
PersistentProperty<?> addressProperty = persistentEntities.getRequiredPersistentEntity(OneLevelNesting.class)
|
||||
.getRequiredPersistentProperty("address");
|
||||
PersistentProperty<?> streetProperty = persistentEntities.getRequiredPersistentEntity(Address.class)
|
||||
.getRequiredPersistentProperty("street");
|
||||
|
||||
assertThat(street, contains(oneLevelNestingProperty, addressProperty, streetProperty));
|
||||
assertThat(street).contains(oneLevelNestingProperty, addressProperty, streetProperty);
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void wrappedPropertiesShouldConsiderJacksonFieldNames() {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(MultiLevelNesting.class);
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class);
|
||||
WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity,
|
||||
new ObjectMapper());
|
||||
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-zip-post"), is(true));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-zip-post")).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void wrappedPropertiesShouldIgnoreIgnoredJacksonFields() {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(MultiLevelNesting.class);
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getRequiredPersistentEntity(MultiLevelNesting.class);
|
||||
WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity,
|
||||
new ObjectMapper());
|
||||
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-street-ignored"), is(false));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("pre-street-ignored")).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
public void wrappedPropertiesShouldIgnoreSyntheticProperties() {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getPersistentEntity(SyntheticProperties.class);
|
||||
PersistentEntity<?, ?> persistentEntity = persistentEntities.getRequiredPersistentEntity(SyntheticProperties.class);
|
||||
WrappedProperties wrappedProperties = WrappedProperties.fromJacksonProperties(persistentEntities, persistentEntity,
|
||||
new ObjectMapper());
|
||||
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("street"), is(false));
|
||||
assertThat(wrappedProperties.hasPersistentPropertiesForField("street")).isFalse();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
4
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationTests.java
Normal file → Executable file
4
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/AddOperationTests.java
Normal file → Executable file
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json.patch;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -82,6 +82,6 @@ public class AddOperationTests {
|
||||
|
||||
new AddOperation("/items/-", "Some text.").perform(todo, Todo.class);
|
||||
|
||||
assertThat(todo.getItems().get(0), is("Some text."));
|
||||
assertThat(todo.getItems().get(0)).isEqualTo("Some text.");
|
||||
}
|
||||
}
|
||||
|
||||
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/CopyOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/MoveOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PathToSpelTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/PathToSpelTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/RemoveOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/patch/TestOperationTests.java
Normal file → Executable file
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.data.rest.webmvc.json.patch;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Roy Clarkson
|
||||
* @author Craig Walls
|
||||
|
||||
36
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java
Normal file → Executable file
36
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.mapping;
|
||||
|
||||
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.Arrays;
|
||||
@@ -26,7 +25,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||
@@ -55,13 +54,13 @@ public class AssociationsUnitTests {
|
||||
|
||||
Associations associations;
|
||||
|
||||
KeyValueMappingContext mappingContext;
|
||||
KeyValueMappingContext<?, ?> mappingContext;
|
||||
ResourceMappings mappings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.mappingContext = new KeyValueMappingContext();
|
||||
this.mappingContext = new KeyValueMappingContext<>();
|
||||
this.mappingContext.getPersistentEntity(Root.class);
|
||||
|
||||
this.mappings = new PersistentEntitiesResourceMappings(new PersistentEntities(Arrays.asList(mappingContext)));
|
||||
@@ -81,37 +80,37 @@ public class AssociationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void handlesNullPropertyForLookupTypeCheck() {
|
||||
assertThat(associations.isLookupType(null), is(false));
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> associations.isLookupType(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forwardsLookupTypeCheckToConfiguration() {
|
||||
|
||||
doReturn(Root.class).when(property).getActualType();
|
||||
assertThat(associations.isLookupType(property), is(false));
|
||||
assertThat(associations.isLookupType(property)).isFalse();
|
||||
|
||||
doReturn(true).when(configuration).isLookupType(Root.class);
|
||||
assertThat(associations.isLookupType(property), is(true));
|
||||
assertThat(associations.isLookupType(property)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forwardsIdExposureCheckToConfiguration() {
|
||||
|
||||
doReturn(Root.class).when(entity).getType();
|
||||
assertThat(associations.isIdExposed(entity), is(false));
|
||||
assertThat(associations.isIdExposed(entity)).isFalse();
|
||||
|
||||
doReturn(true).when(configuration).isIdExposedFor(Root.class);
|
||||
assertThat(associations.isIdExposed(entity), is(true));
|
||||
assertThat(associations.isIdExposed(entity)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exposesConfiguredMapping() {
|
||||
assertThat(associations.getMappings(), is(mappings));
|
||||
assertThat(associations.getMappings()).isEqualTo(mappings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forwardsMetadataLookupToMappings() {
|
||||
assertThat(associations.getMetadataFor(Root.class), is(notNullValue()));
|
||||
assertThat(associations.getMetadataFor(Root.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,8 +118,8 @@ public class AssociationsUnitTests {
|
||||
|
||||
List<Link> links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path(""));
|
||||
|
||||
assertThat(links, hasSize(1));
|
||||
assertThat(links, hasItem(new Link("/relatedAndExported", "relatedAndExported")));
|
||||
assertThat(links).hasSize(1);
|
||||
assertThat(links).contains(new Link("/relatedAndExported", "relatedAndExported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,13 +127,16 @@ public class AssociationsUnitTests {
|
||||
|
||||
List<Link> links = associations.getLinksFor(getAssociation(Root.class, "relatedButNotExported"), new Path(""));
|
||||
|
||||
assertThat(links, hasSize(0));
|
||||
assertThat(links).hasSize(0);
|
||||
}
|
||||
|
||||
private Association<? extends PersistentProperty<?>> getAssociation(Class<?> type, String name) {
|
||||
|
||||
KeyValuePersistentEntity<?> rootEntity = mappingContext.getPersistentEntity(type);
|
||||
return new Association<KeyValuePersistentProperty>(rootEntity.getPersistentProperty(name), null);
|
||||
KeyValuePersistentEntity<?, ? extends KeyValuePersistentProperty<?>> rootEntity = mappingContext
|
||||
.getRequiredPersistentEntity(type);
|
||||
KeyValuePersistentProperty<?> property = rootEntity.getRequiredPersistentProperty(name);
|
||||
|
||||
return new Association(property, null);
|
||||
}
|
||||
|
||||
static class Root {
|
||||
|
||||
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DelegatingHandlerMappingUnitTests.java
Normal file → Executable file
9
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/DelegatingHandlerMappingUnitTests.java
Normal file → Executable file
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.UnsatisfiedServletRequestParameterException;
|
||||
@@ -54,7 +54,6 @@ public class DelegatingHandlerMappingUnitTests {
|
||||
assertHandlerTriedButExceptionThrown(mapping, UnsatisfiedServletRequestParameterException.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final void assertHandlerTriedButExceptionThrown(HandlerMapping mapping, Class<? extends Exception> type)
|
||||
throws Exception {
|
||||
|
||||
@@ -66,7 +65,7 @@ public class DelegatingHandlerMappingUnitTests {
|
||||
fail(String.format("Expected %s!", type.getSimpleName()));
|
||||
|
||||
} catch (Exception o_O) {
|
||||
assertThat(o_O, is(instanceOf(type)));
|
||||
assertThat(o_O).isInstanceOf(type);
|
||||
verify(second, times(1)).getHandler(request);
|
||||
} finally {
|
||||
reset(first, second);
|
||||
|
||||
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java
Normal file → Executable file
0
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagDoesntMatchExceptionUnitTests.java
Normal file → Executable file
55
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java
Normal file → Executable file
55
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/ETagUnitTests.java
Normal file → Executable file
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -36,42 +35,45 @@ import org.springframework.http.HttpHeaders;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ETagUnitTests {
|
||||
|
||||
KeyValueMappingContext context = new KeyValueMappingContext();
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
|
||||
@Test(expected = ETagDoesntMatchException.class) // DATAREST-160
|
||||
public void expectWrongEtag() throws Exception {
|
||||
|
||||
ETag eTag = ETag.from("1");
|
||||
eTag.verify(context.getPersistentEntity(Sample.class), new Sample(0L));
|
||||
eTag.verify(context.getRequiredPersistentEntity(Sample.class), new Sample(0L));
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void expectCorrectEtag() throws Exception {
|
||||
ETag.from("0").verify(context.getPersistentEntity(Sample.class), new Sample(0L));
|
||||
ETag.from("0").verify(context.getRequiredPersistentEntity(Sample.class), new Sample(0L));
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void createsETagFromVersionValue() throws Exception {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getPersistentEntity(Sample.class);
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
ETag from = ETag.from(PersistentEntityResource.build(new Sample(0L), entity).build());
|
||||
|
||||
assertThat(from.toString(), is((Object) "\"0\""));
|
||||
assertThat(from.toString()).isEqualTo((Object) "\"0\"");
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void surroundsValueWithQuotationMarksOnToString() {
|
||||
assertThat(ETag.from("1").toString(), is("\"1\""));
|
||||
assertThat(ETag.from("1").toString()).isEqualTo("\"1\"");
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void returnsNoEtagForNullStringSource() {
|
||||
assertThat(ETag.from((String) null), is(ETag.NO_ETAG));
|
||||
assertThat(ETag.from((String) null)).isEqualTo(ETag.NO_ETAG);
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void returnsNoEtagForNullPersistentEntityResourceSource() {
|
||||
assertThat(ETag.from((PersistentEntityResource) null), is(ETag.NO_ETAG));
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
ETag.from((PersistentEntityResource) null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
@@ -81,48 +83,49 @@ public class ETagUnitTests {
|
||||
ETag two = ETag.from("2");
|
||||
ETag nullETag = ETag.from((String) null);
|
||||
|
||||
assertThat(one.equals(one), is(true));
|
||||
assertThat(one.equals(two), is(false));
|
||||
assertThat(two.equals(one), is(false));
|
||||
assertThat(nullETag.equals(one), is(false));
|
||||
assertThat(one.equals(two), is(false));
|
||||
assertThat(one.equals(""), is(false));
|
||||
assertThat(one.equals(one)).isTrue();
|
||||
assertThat(one.equals(two)).isFalse();
|
||||
assertThat(two.equals(one)).isFalse();
|
||||
assertThat(nullETag.equals(one)).isFalse();
|
||||
assertThat(one.equals(two)).isFalse();
|
||||
assertThat(one.equals("")).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void returnsNoEtagForEntityWithoutVersionProperty() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getPersistentEntity(SampleWithoutVersion.class);
|
||||
assertThat(ETag.from(PersistentEntityResource.build(new SampleWithoutVersion(), entity).build()), is(ETag.NO_ETAG));
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(SampleWithoutVersion.class);
|
||||
assertThat(ETag.from(PersistentEntityResource.build(new SampleWithoutVersion(), entity).build()))
|
||||
.isEqualTo(ETag.NO_ETAG);
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void noETagReturnsNullForToString() {
|
||||
assertThat(ETag.NO_ETAG.toString(), is(nullValue()));
|
||||
assertThat(ETag.NO_ETAG.toString()).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void noETagDoesNotRejectVerification() {
|
||||
ETag.NO_ETAG.verify(context.getPersistentEntity(Sample.class), new Sample(5L));
|
||||
ETag.NO_ETAG.verify(context.getRequiredPersistentEntity(Sample.class), new Sample(5L));
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void verificationDoesNotRejectNullEntity() {
|
||||
ETag.from("5").verify(context.getPersistentEntity(Sample.class), null);
|
||||
ETag.from("5").verify(context.getRequiredPersistentEntity(Sample.class), null);
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void stripsTrailingAndLeadingQuotesOnCreation() {
|
||||
|
||||
assertThat(ETag.from("\"1\""), is(ETag.from("1")));
|
||||
assertThat(ETag.from("\"\"1\"\""), is(ETag.from("1")));
|
||||
assertThat(ETag.from("\"1\"")).isEqualTo(ETag.from("1"));
|
||||
assertThat(ETag.from("\"\"1\"\"")).isEqualTo(ETag.from("1"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void addsETagToHeadersIfNotNoETag() {
|
||||
|
||||
HttpHeaders headers = ETag.from("1").addTo(new HttpHeaders());
|
||||
assertThat(headers.getETag(), is(notNullValue()));
|
||||
assertThat(headers.getETag()).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
@@ -130,7 +133,7 @@ public class ETagUnitTests {
|
||||
|
||||
HttpHeaders headers = ETag.NO_ETAG.addTo(new HttpHeaders());
|
||||
|
||||
assertThat(headers.containsKey("ETag"), is(false));
|
||||
assertThat(headers.containsKey("ETag")).isFalse();
|
||||
}
|
||||
|
||||
// tag::versioned-sample[]
|
||||
|
||||
15
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java
Normal file → Executable file
15
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/PersistentEntityProjectorUnitTests.java
Normal file → Executable file
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
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 static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
||||
@@ -61,7 +60,7 @@ public class PersistentEntityProjectorUnitTests {
|
||||
|
||||
Object object = new Object();
|
||||
|
||||
assertThat(projector.project(object), is(object));
|
||||
assertThat(projector.project(object)).isEqualTo(object);
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
@@ -69,7 +68,7 @@ public class PersistentEntityProjectorUnitTests {
|
||||
|
||||
configuration.addProjection(Sample.class, Object.class);
|
||||
|
||||
assertThat(projector.project(new Object()), is(instanceOf(Sample.class)));
|
||||
assertThat(projector.project(new Object())).isInstanceOf(Sample.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-806
|
||||
@@ -77,12 +76,12 @@ public class PersistentEntityProjectorUnitTests {
|
||||
|
||||
configuration.addProjection(Sample.class, Object.class);
|
||||
|
||||
assertThat(projector.projectExcerpt(new Object()), is(instanceOf(Sample.class)));
|
||||
assertThat(projector.projectExcerpt(new Object())).isInstanceOf(Sample.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-806
|
||||
public void excerptProjectionIsUsedForExcerpt() {
|
||||
assertThat(projector.projectExcerpt(new Object()), is(instanceOf(Excerpt.class)));
|
||||
assertThat(projector.projectExcerpt(new Object())).isInstanceOf(Excerpt.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-806
|
||||
@@ -92,7 +91,7 @@ public class PersistentEntityProjectorUnitTests {
|
||||
|
||||
PersistentEntityProjector projector = new PersistentEntityProjector(configuration, factory, null, mappings);
|
||||
|
||||
assertThat(projector.projectExcerpt(new Object()), is(instanceOf(Excerpt.class)));
|
||||
assertThat(projector.projectExcerpt(new Object())).isInstanceOf(Excerpt.class);
|
||||
}
|
||||
|
||||
interface Sample {}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.support;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -84,7 +83,7 @@ public class RepositoryConstraintViolationExceptionMessageUnitTests {
|
||||
|
||||
List<ValidationError> result = message.getErrors();
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result.get(0).getInvalidValue(), is(value));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.get(0).getInvalidValue()).isEqualTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java
Normal file → Executable file
7
spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/UriUtilsUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.util;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
@@ -38,7 +37,7 @@ public class UriUtilsUnitTests {
|
||||
Method method = ClassUtils.getMethod(MappedMethod.class, "method");
|
||||
List<String> pathSegments = UriUtils.getPathSegments(method);
|
||||
|
||||
assertThat(pathSegments, hasItems("hello", "world"));
|
||||
assertThat(pathSegments).contains("hello", "world");
|
||||
}
|
||||
|
||||
@Test // DATAREST-910
|
||||
@@ -47,7 +46,7 @@ public class UriUtilsUnitTests {
|
||||
Method method = ClassUtils.getMethod(MappedClassAndMethod.class, "method");
|
||||
List<String> pathSegments = UriUtils.getPathSegments(method);
|
||||
|
||||
assertThat(pathSegments, hasItems("hello", "world"));
|
||||
assertThat(pathSegments).contains("hello", "world");
|
||||
}
|
||||
|
||||
static class MappedMethod {
|
||||
|
||||
Reference in New Issue
Block a user