@@ -15,13 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.core;
|
package org.springframework.data.rest.core;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.core.domain.Person;
|
import org.springframework.data.rest.core.domain.Person;
|
||||||
import org.springframework.data.rest.core.domain.PersonRepository;
|
import org.springframework.data.rest.core.domain.PersonRepository;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
|
* Base class for integration tests loading {@link RepositoryTestsConfig} and populating the {@link PersonRepository}
|
||||||
@@ -29,14 +29,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = RepositoryTestsConfig.class)
|
@ContextConfiguration(classes = RepositoryTestsConfig.class)
|
||||||
public abstract class AbstractIntegrationTests {
|
public abstract class AbstractIntegrationTests {
|
||||||
|
|
||||||
@Autowired PersonRepository repository;
|
@Autowired PersonRepository repository;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void populateDatabase() {
|
void populateDatabase() {
|
||||||
repository.save(new Person("John", "Doe"));
|
repository.save(new Person("John", "Doe"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,63 +17,63 @@ package org.springframework.data.rest.core;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link Path}.
|
* Unit tests for {@link Path}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class PathUnitTests {
|
class PathUnitTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combinesSimplePaths() {
|
void combinesSimplePaths() {
|
||||||
|
|
||||||
Path builder = new Path("foo").slash("bar");
|
Path builder = new Path("foo").slash("bar");
|
||||||
assertThat(builder.toString()).isEqualTo("/foo/bar");
|
assertThat(builder.toString()).isEqualTo("/foo/bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removesLeadingAndTrailingSlashes() {
|
void removesLeadingAndTrailingSlashes() {
|
||||||
|
|
||||||
Path builder = new Path("foo/").slash("/bar").slash("//foobar///");
|
Path builder = new Path("foo/").slash("/bar").slash("//foobar///");
|
||||||
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removesWhitespace() {
|
void removesWhitespace() {
|
||||||
|
|
||||||
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
|
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
|
||||||
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchesWithLeadingSlash() {
|
void matchesWithLeadingSlash() {
|
||||||
assertThat(new Path("/foobar").matches("/foobar")).isTrue();
|
assertThat(new Path("/foobar").matches("/foobar")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void matchesWithoutLeadingSlash() {
|
void matchesWithoutLeadingSlash() {
|
||||||
assertThat(new Path("/foobar").matches("foobar")).isTrue();
|
assertThat(new Path("/foobar").matches("foobar")).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotMatchIfDifferent() {
|
void doesNotMatchIfDifferent() {
|
||||||
assertThat(new Path("/foobar").matches("barfoo")).isFalse();
|
assertThat(new Path("/foobar").matches("barfoo")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotPrefixAbsoluteUris() {
|
void doesNotPrefixAbsoluteUris() {
|
||||||
assertThat(new Path("http://localhost").toString()).isEqualTo("http://localhost");
|
assertThat(new Path("http://localhost").toString()).isEqualTo("http://localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-222
|
@Test // DATAREST-222
|
||||||
public void doesNotMatchIfReferenceContainsReservedCharacters() {
|
void doesNotMatchIfReferenceContainsReservedCharacters() {
|
||||||
assertThat(new Path("/foobar").matches("barfoo{?foo}")).isFalse();
|
assertThat(new Path("/foobar").matches("barfoo{?foo}")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-222
|
@Test // DATAREST-222
|
||||||
public void doesNotMatchNullReference() {
|
void doesNotMatchNullReference() {
|
||||||
assertThat(new Path("/foobar").matches(null)).isFalse();
|
assertThat(new Path("/foobar").matches(null)).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.repository.support.Repositories;
|
import org.springframework.data.repository.support.Repositories;
|
||||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
@@ -36,13 +36,13 @@ import org.springframework.test.annotation.DirtiesContext;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
|
class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
|
||||||
|
|
||||||
@Autowired RepositoryRestConfiguration config;
|
@Autowired RepositoryRestConfiguration config;
|
||||||
@Autowired Repositories repositories;
|
@Autowired Repositories repositories;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
|
void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
|
||||||
|
|
||||||
ResourceMapping mapping = config.getResourceMappingForRepository(ConfiguredPersonRepository.class);
|
ResourceMapping mapping = config.getResourceMappingForRepository(ConfiguredPersonRepository.class);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegra
|
|||||||
|
|
||||||
@Test // DATAREST-1304
|
@Test // DATAREST-1304
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void exposesLookupPropertyFromLambda() {
|
void exposesLookupPropertyFromLambda() {
|
||||||
|
|
||||||
config.withEntityLookup() //
|
config.withEntityLookup() //
|
||||||
.forRepository(ProfileRepository.class) //
|
.forRepository(ProfileRepository.class) //
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ package org.springframework.data.rest.core;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
|
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
|
||||||
import org.springframework.data.rest.core.config.MetadataConfiguration;
|
import org.springframework.data.rest.core.config.MetadataConfiguration;
|
||||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
||||||
@@ -37,40 +37,40 @@ import org.springframework.http.MediaType;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @soundtrack Adam F - Circles (Colors)
|
* @soundtrack Adam F - Circles (Colors)
|
||||||
*/
|
*/
|
||||||
public class RepositoryRestConfigurationUnitTests {
|
class RepositoryRestConfigurationUnitTests {
|
||||||
|
|
||||||
RepositoryRestConfiguration configuration;
|
RepositoryRestConfiguration configuration;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
this.configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodiesIfAcceptHeaderPresentByDefault() {
|
void returnsBodiesIfAcceptHeaderPresentByDefault() {
|
||||||
|
|
||||||
assertThat(configuration.returnBodyOnCreate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
assertThat(configuration.returnBodyOnCreate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
||||||
assertThat(configuration.returnBodyOnUpdate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
assertThat(configuration.returnBodyOnUpdate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
|
void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
|
||||||
|
|
||||||
assertThat(configuration.returnBodyOnCreate(null)).isFalse();
|
assertThat(configuration.returnBodyOnCreate(null)).isFalse();
|
||||||
assertThat(configuration.returnBodyOnUpdate(null)).isFalse();
|
assertThat(configuration.returnBodyOnUpdate(null)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
|
void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
|
||||||
|
|
||||||
assertThat(configuration.returnBodyOnCreate("")).isFalse();
|
assertThat(configuration.returnBodyOnCreate("")).isFalse();
|
||||||
assertThat(configuration.returnBodyOnUpdate("")).isFalse();
|
assertThat(configuration.returnBodyOnUpdate("")).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
|
void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
|
||||||
|
|
||||||
configuration.setReturnBodyOnUpdate(false);
|
configuration.setReturnBodyOnUpdate(false);
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class RepositoryRestConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
|
void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
|
||||||
|
|
||||||
configuration.setReturnBodyOnCreate(false);
|
configuration.setReturnBodyOnCreate(false);
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class RepositoryRestConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodyForUpdateIfExplicitlyActivated() {
|
void returnsBodyForUpdateIfExplicitlyActivated() {
|
||||||
|
|
||||||
configuration.setReturnBodyOnUpdate(true);
|
configuration.setReturnBodyOnUpdate(true);
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ public class RepositoryRestConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodyForCreateIfExplicitlyActivated() {
|
void returnsBodyForCreateIfExplicitlyActivated() {
|
||||||
|
|
||||||
configuration.setReturnBodyOnCreate(true);
|
configuration.setReturnBodyOnCreate(true);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public class RepositoryRestConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-776
|
@Test // DATAREST-776
|
||||||
public void considersDomainTypeOfValueRepositoryLookupTypes() {
|
void considersDomainTypeOfValueRepositoryLookupTypes() {
|
||||||
|
|
||||||
configuration.withEntityLookup().forLookupRepository(ProfileRepository.class);
|
configuration.withEntityLookup().forLookupRepository(ProfileRepository.class);
|
||||||
|
|
||||||
@@ -118,13 +118,13 @@ public class RepositoryRestConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1076
|
@Test // DATAREST-1076
|
||||||
public void rejectsNullRelProvider() {
|
void rejectsNullRelProvider() {
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
.isThrownBy(() -> configuration.setLinkRelationProvider(null));
|
.isThrownBy(() -> configuration.setLinkRelationProvider(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1974
|
@Test // #1974
|
||||||
public void considersAtRelationOnTypesByDefault() {
|
void considersAtRelationOnTypesByDefault() {
|
||||||
assertThat(configuration.getLinkRelationProvider().getItemResourceRelFor(Sample.class))
|
assertThat(configuration.getLinkRelationProvider().getItemResourceRelFor(Sample.class))
|
||||||
.isEqualTo(LinkRelation.of("something"));
|
.isEqualTo(LinkRelation.of("something"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import javax.naming.InvalidNameException;
|
|||||||
import javax.naming.Name;
|
import javax.naming.Name;
|
||||||
import javax.naming.ldap.LdapName;
|
import javax.naming.ldap.LdapName;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.core.convert.support.DefaultConversionService;
|
import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,10 +29,10 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
|||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class StringToLdapNameConverterUnitTests {
|
class StringToLdapNameConverterUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-1198
|
@Test // DATAREST-1198
|
||||||
public void shouldCreateLdapName() throws InvalidNameException {
|
void shouldCreateLdapName() throws InvalidNameException {
|
||||||
|
|
||||||
LdapName converted = StringToLdapNameConverter.INSTANCE.convert("dc=foo");
|
LdapName converted = StringToLdapNameConverter.INSTANCE.convert("dc=foo");
|
||||||
|
|
||||||
@@ -40,14 +40,14 @@ public class StringToLdapNameConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1198
|
@Test // DATAREST-1198
|
||||||
public void failedConversionShouldThrowIAE() {
|
void failedConversionShouldThrowIAE() {
|
||||||
|
|
||||||
assertThatThrownBy(() -> StringToLdapNameConverter.INSTANCE.convert("foo"))
|
assertThatThrownBy(() -> StringToLdapNameConverter.INSTANCE.convert("foo"))
|
||||||
.isInstanceOf(IllegalArgumentException.class);
|
.isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1198
|
@Test // DATAREST-1198
|
||||||
public void shouldConvertStringInNameViaConversionService() {
|
void shouldConvertStringInNameViaConversionService() {
|
||||||
|
|
||||||
DefaultConversionService conversionService = new DefaultConversionService();
|
DefaultConversionService conversionService = new DefaultConversionService();
|
||||||
conversionService.addConverter(StringToLdapNameConverter.INSTANCE);
|
conversionService.addConverter(StringToLdapNameConverter.INSTANCE);
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ import java.util.HashSet;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.core.convert.ConversionFailedException;
|
import org.springframework.core.convert.ConversionFailedException;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
|
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
|
||||||
@@ -47,8 +47,8 @@ import org.springframework.data.util.Streamable;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class UriToEntityConverterUnitTests {
|
class UriToEntityConverterUnitTests {
|
||||||
|
|
||||||
static final TypeDescriptor URI_TYPE = TypeDescriptor.valueOf(URI.class);
|
static final TypeDescriptor URI_TYPE = TypeDescriptor.valueOf(URI.class);
|
||||||
static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
|
static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
|
||||||
@@ -60,8 +60,8 @@ public class UriToEntityConverterUnitTests {
|
|||||||
KeyValueMappingContext<?, ?> context;
|
KeyValueMappingContext<?, ?> context;
|
||||||
UriToEntityConverter converter;
|
UriToEntityConverter converter;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.context = new KeyValueMappingContext<>();
|
this.context = new KeyValueMappingContext<>();
|
||||||
this.context.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(Entity.class, NonEntity.class)));
|
this.context.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(Entity.class, NonEntity.class)));
|
||||||
@@ -72,7 +72,7 @@ public class UriToEntityConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void supportsOnlyEntitiesWithIdProperty() {
|
void supportsOnlyEntitiesWithIdProperty() {
|
||||||
|
|
||||||
Set<ConvertiblePair> result = converter.getConvertibleTypes();
|
Set<ConvertiblePair> result = converter.getConvertibleTypes();
|
||||||
|
|
||||||
@@ -81,12 +81,12 @@ public class UriToEntityConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
|
void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
|
||||||
assertThat(converter.matches(URI_TYPE, ENTITY_TYPE)).isFalse();
|
assertThat(converter.matches(URI_TYPE, ENTITY_TYPE)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
|
void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
|
||||||
|
|
||||||
doReturn(Optional.of(mock(RepositoryInformation.class))).when(repositories)
|
doReturn(Optional.of(mock(RepositoryInformation.class))).when(repositories)
|
||||||
.getRepositoryInformationFor(ENTITY_TYPE.getType());
|
.getRepositoryInformationFor(ENTITY_TYPE.getType());
|
||||||
@@ -95,12 +95,12 @@ public class UriToEntityConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void cannotConvertEntityWithoutIdentifier() {
|
void cannotConvertEntityWithoutIdentifier() {
|
||||||
assertThat(converter.matches(URI_TYPE, TypeDescriptor.valueOf(NonEntity.class))).isFalse();
|
assertThat(converter.matches(URI_TYPE, TypeDescriptor.valueOf(NonEntity.class))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void invokesConverterWithLastUriPathSegment() {
|
void invokesConverterWithLastUriPathSegment() {
|
||||||
|
|
||||||
Entity reference = new Entity();
|
Entity reference = new Entity();
|
||||||
|
|
||||||
@@ -108,39 +108,49 @@ public class UriToEntityConverterUnitTests {
|
|||||||
doReturn(Optional.of(reference)).when(invoker).invokeFindById("1");
|
doReturn(Optional.of(reference)).when(invoker).invokeFindById("1");
|
||||||
doReturn(invoker).when(invokerFactory).getInvokerFor(ENTITY_TYPE.getType());
|
doReturn(invoker).when(invokerFactory).getInvokerFor(ENTITY_TYPE.getType());
|
||||||
|
|
||||||
assertThat(converter.convert(URI.create("/foo/bar/1"), URI_TYPE, ENTITY_TYPE)).isEqualTo((Object) reference);
|
assertThat(converter.convert(URI.create("/foo/bar/1"), URI_TYPE, ENTITY_TYPE)).isEqualTo(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ConversionFailedException.class) // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void rejectsUnknownType() {
|
void rejectsUnknownType() {
|
||||||
converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE);
|
|
||||||
|
assertThatExceptionOfType(ConversionFailedException.class) //
|
||||||
|
.isThrownBy(() -> converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ConversionFailedException.class) // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void rejectsUriWithLessThanTwoSegments() {
|
void rejectsUriWithLessThanTwoSegments() {
|
||||||
converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE);
|
|
||||||
|
assertThatExceptionOfType(ConversionFailedException.class) //
|
||||||
|
.isThrownBy(() -> converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
@Test // DATAREST-741
|
||||||
public void rejectsNullPersistentEntities() {
|
void rejectsNullPersistentEntities() {
|
||||||
new UriToEntityConverter(null, invokerFactory, repositories);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new UriToEntityConverter(null, invokerFactory, repositories));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
@Test // DATAREST-741
|
||||||
public void rejectsNullRepositoryInvokerFactory() {
|
void rejectsNullRepositoryInvokerFactory() {
|
||||||
new UriToEntityConverter(mock(PersistentEntities.class), null, repositories);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), null, repositories));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
@Test // DATAREST-741
|
||||||
public void rejectsNullRepositories() {
|
void rejectsNullRepositories() {
|
||||||
new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAREST-1018
|
* @see DATAREST-1018
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void doesNotRegisterTypeWithUnmanagedRawType() {
|
void doesNotRegisterTypeWithUnmanagedRawType() {
|
||||||
|
|
||||||
PersistentEntities entities = mock(PersistentEntities.class);
|
PersistentEntities entities = mock(PersistentEntities.class);
|
||||||
doReturn(Streamable.of(ClassTypeInformation.OBJECT)).when(entities).getManagedTypes();
|
doReturn(Streamable.of(ClassTypeInformation.OBJECT)).when(entities).getManagedTypes();
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.NotReadablePropertyException;
|
import org.springframework.beans.NotReadablePropertyException;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
import org.springframework.data.mapping.context.PersistentEntities;
|
import org.springframework.data.mapping.context.PersistentEntities;
|
||||||
@@ -33,12 +33,12 @@ import org.springframework.validation.Errors;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class ValidationErrorsUnitTests {
|
class ValidationErrorsUnitTests {
|
||||||
|
|
||||||
PersistentEntities entities;
|
PersistentEntities entities;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
context.getPersistentEntity(Foo.class);
|
context.getPersistentEntity(Foo.class);
|
||||||
@@ -47,7 +47,7 @@ public class ValidationErrorsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-798
|
@Test // DATAREST-798
|
||||||
public void exposesNestedViolationsCorrectly() {
|
void exposesNestedViolationsCorrectly() {
|
||||||
|
|
||||||
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
||||||
|
|
||||||
@@ -59,12 +59,12 @@ public class ValidationErrorsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-801
|
@Test // DATAREST-801
|
||||||
public void getsTheNestedFieldsValue() {
|
void getsTheNestedFieldsValue() {
|
||||||
expectedErrorBehavior(new ValidationErrors(new Foo(), entities));
|
expectedErrorBehavior(new ValidationErrors(new Foo(), entities));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1163
|
@Test // DATAREST-1163
|
||||||
public void returnsNullForPropertyValue() {
|
void returnsNullForPropertyValue() {
|
||||||
|
|
||||||
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration.ProjectionDefinition;
|
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration.ProjectionDefinition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,40 +27,53 @@ import org.springframework.data.rest.core.config.ProjectionDefinitionConfigurati
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class ProjectionDefinitionConfigurationUnitTests {
|
class ProjectionDefinitionConfigurationUnitTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void rejectsNullProjectionTypeForAutoConfiguration() {
|
void rejectsNullProjectionTypeForAutoConfiguration() {
|
||||||
new ProjectionDefinitionConfiguration().addProjection(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
assertThatIllegalArgumentException() //
|
||||||
public void rejectsUnannotatedClassForConfigurationShortcut() {
|
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(null));
|
||||||
new ProjectionDefinitionConfiguration().addProjection(String.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
|
||||||
public void rejectsNullProjectionTypeForManualConfiguration() {
|
|
||||||
new ProjectionDefinitionConfiguration().addProjection(null, "name", Object.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
|
||||||
public void rejectsNullNameForManualConfiguration() {
|
|
||||||
new ProjectionDefinitionConfiguration().addProjection(String.class, (String) null, Object.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
|
||||||
public void rejectsEmptyNameForManualConfiguration() {
|
|
||||||
new ProjectionDefinitionConfiguration().addProjection(String.class, "", Object.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
|
||||||
public void rejectsEmptySourceTypes() {
|
|
||||||
new ProjectionDefinitionConfiguration().addProjection(String.class, "name", new Class<?>[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void findsRegisteredProjection() {
|
void rejectsUnannotatedClassForConfigurationShortcut() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-221
|
||||||
|
void rejectsNullProjectionTypeForManualConfiguration() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(null, "name", Object.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-221
|
||||||
|
void rejectsNullNameForManualConfiguration() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(
|
||||||
|
() -> new ProjectionDefinitionConfiguration().addProjection(String.class, (String) null, Object.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-221
|
||||||
|
void rejectsEmptyNameForManualConfiguration() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class, "", Object.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-221
|
||||||
|
void rejectsEmptySourceTypes() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(String.class, "name", new Class<?>[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-221
|
||||||
|
void findsRegisteredProjection() {
|
||||||
|
|
||||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||||
configuration.addProjection(Integer.class, "name", String.class);
|
configuration.addProjection(Integer.class, "name", String.class);
|
||||||
@@ -69,7 +82,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void registersAnnotatedProjection() {
|
void registersAnnotatedProjection() {
|
||||||
|
|
||||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||||
configuration.addProjection(SampleProjection.class);
|
configuration.addProjection(SampleProjection.class);
|
||||||
@@ -78,7 +91,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void defaultsNameToSimpleClassNameIfNotAnnotated() {
|
void defaultsNameToSimpleClassNameIfNotAnnotated() {
|
||||||
|
|
||||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||||
configuration.addProjection(Default.class);
|
configuration.addProjection(Default.class);
|
||||||
@@ -87,7 +100,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void definitionEquals() {
|
void definitionEquals() {
|
||||||
|
|
||||||
ProjectionDefinition objectName = ProjectionDefinition.of(Object.class, Object.class, "name");
|
ProjectionDefinition objectName = ProjectionDefinition.of(Object.class, Object.class, "name");
|
||||||
ProjectionDefinition sameObjectName = ProjectionDefinition.of(Object.class, Object.class, "name");
|
ProjectionDefinition sameObjectName = ProjectionDefinition.of(Object.class, Object.class, "name");
|
||||||
@@ -108,7 +121,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-385
|
@Test // DATAREST-385
|
||||||
public void returnsProjectionForParentClass() {
|
void returnsProjectionForParentClass() {
|
||||||
|
|
||||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||||
configuration.addProjection(ParentProjection.class);
|
configuration.addProjection(ParentProjection.class);
|
||||||
@@ -119,12 +132,12 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void defaultsParamternameToProjection() {
|
void defaultsParamternameToProjection() {
|
||||||
assertThat(new ProjectionDefinitionConfiguration().getParameterName()).isEqualTo("projection");
|
assertThat(new ProjectionDefinitionConfiguration().getParameterName()).isEqualTo("projection");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-747
|
@Test // DATAREST-747
|
||||||
public void returnsMostConcreteProjectionForSourceType() {
|
void returnsMostConcreteProjectionForSourceType() {
|
||||||
|
|
||||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||||
configuration.addProjection(ParentProjection.class);
|
configuration.addProjection(ParentProjection.class);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static org.springframework.data.rest.core.support.ResourceMappingUtils.*;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@@ -36,12 +36,12 @@ import org.springframework.hateoas.server.core.EvoInflectorLinkRelationProvider;
|
|||||||
* @author Jon Brisbin
|
* @author Jon Brisbin
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ResourceMappingUnitTests {
|
class ResourceMappingUnitTests {
|
||||||
|
|
||||||
LinkRelationProvider relProvider = new EvoInflectorLinkRelationProvider();
|
LinkRelationProvider relProvider = new EvoInflectorLinkRelationProvider();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDetectPathAndRemoveLeadingSlashIfAny() {
|
void shouldDetectPathAndRemoveLeadingSlashIfAny() {
|
||||||
|
|
||||||
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
||||||
findRel(AnnotatedWithLeadingSlashPersonRepository.class),
|
findRel(AnnotatedWithLeadingSlashPersonRepository.class),
|
||||||
@@ -56,7 +56,7 @@ public class ResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
|
void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
|
||||||
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByFirstName", String.class,
|
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByFirstName", String.class,
|
||||||
Pageable.class);
|
Pageable.class);
|
||||||
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
||||||
@@ -70,7 +70,7 @@ public class ResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
|
void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
|
||||||
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByLastName", String.class,
|
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByLastName", String.class,
|
||||||
Pageable.class);
|
Pageable.class);
|
||||||
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
||||||
|
|||||||
@@ -15,10 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.core.context;
|
package org.springframework.data.rest.core.context;
|
||||||
|
|
||||||
import org.junit.Before;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -32,7 +33,7 @@ import org.springframework.data.rest.core.domain.PersonBeforeSaveHandler;
|
|||||||
import org.springframework.data.rest.core.domain.PersonRepository;
|
import org.springframework.data.rest.core.domain.PersonRepository;
|
||||||
import org.springframework.data.rest.core.event.*;
|
import org.springframework.data.rest.core.event.*;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
|
* Tests around the {@link org.springframework.context.ApplicationEvent} handling abstractions.
|
||||||
@@ -40,9 +41,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Jon Brisbin
|
* @author Jon Brisbin
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class RepositoryEventIntegrationTests {
|
class RepositoryEventIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ RepositoryTestsConfig.class })
|
@Import({ RepositoryTestsConfig.class })
|
||||||
@@ -68,58 +69,78 @@ public class RepositoryEventIntegrationTests {
|
|||||||
@Autowired PersonRepository people;
|
@Autowired PersonRepository people;
|
||||||
Person person;
|
Person person;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
person = people.save(new Person("Jane", "Doe"));
|
person = people.save(new Person("Jane", "Doe"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchBeforeCreate() throws Exception {
|
void shouldDispatchBeforeCreate() throws Exception {
|
||||||
appCtx.publishEvent(new BeforeCreateEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new BeforeCreateEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchAfterCreate() throws Exception {
|
void shouldDispatchAfterCreate() throws Exception {
|
||||||
appCtx.publishEvent(new AfterCreateEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new AfterCreateEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchBeforeSave() throws Exception {
|
void shouldDispatchBeforeSave() throws Exception {
|
||||||
appCtx.publishEvent(new BeforeSaveEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new BeforeSaveEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchAfterSave() throws Exception {
|
void shouldDispatchAfterSave() throws Exception {
|
||||||
appCtx.publishEvent(new AfterSaveEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new AfterSaveEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchBeforeDelete() throws Exception {
|
void shouldDispatchBeforeDelete() throws Exception {
|
||||||
appCtx.publishEvent(new BeforeDeleteEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new BeforeDeleteEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchAfterDelete() throws Exception {
|
void shouldDispatchAfterDelete() throws Exception {
|
||||||
appCtx.publishEvent(new AfterDeleteEvent(person));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new AfterDeleteEvent(person)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchBeforeLinkSave() throws Exception {
|
void shouldDispatchBeforeLinkSave() throws Exception {
|
||||||
appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object()));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchAfterLinkSave() throws Exception {
|
void shouldDispatchAfterLinkSave() throws Exception {
|
||||||
appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object()));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchBeforeLinkDelete() throws Exception {
|
void shouldDispatchBeforeLinkDelete() throws Exception {
|
||||||
appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object()));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
@Test // DATAREST-388
|
||||||
public void shouldDispatchAfterLinkDelete() throws Exception {
|
void shouldDispatchAfterLinkDelete() throws Exception {
|
||||||
appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object()));
|
|
||||||
|
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||||
|
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.core.context;
|
package org.springframework.data.rest.core.context;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
@@ -33,7 +35,7 @@ import org.springframework.data.rest.core.domain.PersonNameValidator;
|
|||||||
import org.springframework.data.rest.core.event.BeforeSaveEvent;
|
import org.springframework.data.rest.core.event.BeforeSaveEvent;
|
||||||
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
|
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests to check the {@link org.springframework.validation.Validator} integration.
|
* Tests to check the {@link org.springframework.validation.Validator} integration.
|
||||||
@@ -41,9 +43,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Jon Brisbin
|
* @author Jon Brisbin
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class ValidatorIntegrationTests {
|
class ValidatorIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ RepositoryTestsConfig.class, JpaRepositoryConfig.class })
|
@Import({ RepositoryTestsConfig.class, JpaRepositoryConfig.class })
|
||||||
@@ -62,12 +64,14 @@ public class ValidatorIntegrationTests {
|
|||||||
@Autowired ConfigurableApplicationContext context;
|
@Autowired ConfigurableApplicationContext context;
|
||||||
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
||||||
|
|
||||||
@Test(expected = RepositoryConstraintViolationException.class)
|
@Test
|
||||||
public void shouldValidateLastName() throws Exception {
|
void shouldValidateLastName() throws Exception {
|
||||||
|
|
||||||
mappingContext.getPersistentEntity(Person.class);
|
mappingContext.getPersistentEntity(Person.class);
|
||||||
|
|
||||||
// Empty name should be rejected by PersonNameValidator
|
// Empty name should be rejected by PersonNameValidator
|
||||||
context.publishEvent(new BeforeSaveEvent(new Person("Dave", "")));
|
|
||||||
|
assertThatExceptionOfType(RepositoryConstraintViolationException.class)
|
||||||
|
.isThrownBy(() -> context.publishEvent(new BeforeSaveEvent(new Person("Dave", ""))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.core.domain;
|
package org.springframework.data.rest.core.domain;
|
||||||
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
|
import org.springframework.data.rest.core.annotation.*;
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterDelete;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterLinkDelete;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterLinkSave;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterSave;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleBeforeDelete;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleBeforeLinkDelete;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleBeforeLinkSave;
|
|
||||||
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
|
|
||||||
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sample annotation-based event handler.
|
* Sample annotation-based event handler.
|
||||||
@@ -39,26 +29,26 @@ public class AnnotatedPersonEventHandler {
|
|||||||
@HandleAfterCreate
|
@HandleAfterCreate
|
||||||
@HandleAfterDelete
|
@HandleAfterDelete
|
||||||
@HandleAfterSave
|
@HandleAfterSave
|
||||||
public void handleAfter(Person p) {
|
void handleAfter(Person p) {
|
||||||
throw new EventHandlerInvokedException();
|
throw new EventHandlerInvokedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@HandleAfterLinkDelete
|
@HandleAfterLinkDelete
|
||||||
@HandleAfterLinkSave
|
@HandleAfterLinkSave
|
||||||
public void handleAfterLink(Person p, Object o) {
|
void handleAfterLink(Person p, Object o) {
|
||||||
throw new EventHandlerInvokedException();
|
throw new EventHandlerInvokedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@HandleBeforeCreate
|
@HandleBeforeCreate
|
||||||
@HandleBeforeDelete
|
@HandleBeforeDelete
|
||||||
@HandleBeforeSave
|
@HandleBeforeSave
|
||||||
public void handleBefore(Person p) {
|
void handleBefore(Person p) {
|
||||||
throw new EventHandlerInvokedException();
|
throw new EventHandlerInvokedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@HandleBeforeLinkDelete
|
@HandleBeforeLinkDelete
|
||||||
@HandleBeforeLinkSave
|
@HandleBeforeLinkSave
|
||||||
public void handleBeforeLink(Person p, Object o) {
|
void handleBeforeLink(Person p, Object o) {
|
||||||
throw new EventHandlerInvokedException();
|
throw new EventHandlerInvokedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.springframework.data.annotation.Reference;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Value
|
@Value
|
||||||
public class Order {
|
class Order {
|
||||||
|
|
||||||
@Id UUID id = UUID.randomUUID();
|
@Id UUID id = UUID.randomUUID();
|
||||||
@Reference Person creator;
|
@Reference Person creator;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class ProfileLoader implements InitializingBean {
|
class ProfileLoader implements InitializingBean {
|
||||||
|
|
||||||
@Autowired ProfileRepository profiles;
|
@Autowired ProfileRepository profiles;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
|
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
|
||||||
@@ -43,11 +43,11 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
* @author Fabian Trampusch
|
* @author Fabian Trampusch
|
||||||
* @author Joseph Valerio
|
* @author Joseph Valerio
|
||||||
*/
|
*/
|
||||||
public class AnnotatedEventHandlerInvokerUnitTests {
|
class AnnotatedEventHandlerInvokerUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-582
|
@Test // DATAREST-582
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void doesNotDiscoverMethodsOnProxyClasses() {
|
void doesNotDiscoverMethodsOnProxyClasses() {
|
||||||
|
|
||||||
ProxyFactory factory = new ProxyFactory();
|
ProxyFactory factory = new ProxyFactory();
|
||||||
factory.setTarget(new Sample());
|
factory.setTarget(new Sample());
|
||||||
@@ -63,7 +63,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-606
|
@Test // DATAREST-606
|
||||||
public void invokesPrivateEventHandlerMethods() {
|
void invokesPrivateEventHandlerMethods() {
|
||||||
|
|
||||||
SampleWithPrivateHandler sampleHandler = new SampleWithPrivateHandler();
|
SampleWithPrivateHandler sampleHandler = new SampleWithPrivateHandler();
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-970
|
@Test // DATAREST-970
|
||||||
public void invokesEventHandlerInOrderMethods() {
|
void invokesEventHandlerInOrderMethods() {
|
||||||
|
|
||||||
SampleOrderEventHandler1 orderHandler1 = new SampleOrderEventHandler1();
|
SampleOrderEventHandler1 orderHandler1 = new SampleOrderEventHandler1();
|
||||||
SampleOrderEventHandler2 orderHandler2 = new SampleOrderEventHandler2();
|
SampleOrderEventHandler2 orderHandler2 = new SampleOrderEventHandler2();
|
||||||
@@ -94,7 +94,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-983
|
@Test // DATAREST-983
|
||||||
public void invokesEventHandlerOnParentClass() {
|
void invokesEventHandlerOnParentClass() {
|
||||||
|
|
||||||
FirstEventHandler firstHandler = new FirstEventHandler();
|
FirstEventHandler firstHandler = new FirstEventHandler();
|
||||||
SecondEventHandler secondHandler = new SecondEventHandler();
|
SecondEventHandler secondHandler = new SecondEventHandler();
|
||||||
@@ -111,7 +111,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1075
|
@Test // DATAREST-1075
|
||||||
public void doesInvokeMethodOnlyOnceForMockitoSpy() {
|
void doesInvokeMethodOnlyOnceForMockitoSpy() {
|
||||||
|
|
||||||
EventHandler handler = spy(new EventHandler());
|
EventHandler handler = spy(new EventHandler());
|
||||||
AnnotatedEventHandlerInvoker invoker = new AnnotatedEventHandlerInvoker();
|
AnnotatedEventHandlerInvoker invoker = new AnnotatedEventHandlerInvoker();
|
||||||
@@ -124,7 +124,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-582
|
@Test // DATAREST-582
|
||||||
public void invocesInterceptorForProxiedListener() {
|
void invocesInterceptorForProxiedListener() {
|
||||||
|
|
||||||
SampleInterceptor interceptor = new SampleInterceptor();
|
SampleInterceptor interceptor = new SampleInterceptor();
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
static class Sample {
|
static class Sample {
|
||||||
|
|
||||||
@HandleBeforeCreate
|
@HandleBeforeCreate
|
||||||
public void method(Sample sample) {}
|
void method(Sample sample) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RepositoryEventHandler
|
@RepositoryEventHandler
|
||||||
@@ -216,7 +216,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
|||||||
static class EventHandler {
|
static class EventHandler {
|
||||||
|
|
||||||
@HandleAfterCreate
|
@HandleAfterCreate
|
||||||
public void doAfterCreate(Payload bar) {}
|
void doAfterCreate(Payload bar) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Payload {}
|
static class Payload {}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ import static org.springframework.http.HttpMethod.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||||
import org.springframework.data.annotation.Reference;
|
import org.springframework.data.annotation.Reference;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
@@ -46,18 +46,18 @@ import org.springframework.http.HttpMethod;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class CrudMethodsSupportedHttpMethodsUnitTests {
|
class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||||
|
|
||||||
@Mock RepositoryResourceMappings mappings;
|
@Mock RepositoryResourceMappings mappings;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
when(mappings.exposeMethodsByDefault()).thenReturn(true);
|
when(mappings.exposeMethodsByDefault()).thenReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATACMNS-589, DATAREST-409
|
@Test // DATACMNS-589, DATAREST-409
|
||||||
public void doesNotSupportAnyHttpMethodForEmptyRepository() {
|
void doesNotSupportAnyHttpMethodForEmptyRepository() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedMethods = getSupportedHttpMethodsFor(RawRepository.class);
|
SupportedHttpMethods supportedMethods = getSupportedHttpMethodsFor(RawRepository.class);
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
||||||
public void defaultsSupportedHttpMethodsForItemResource() {
|
void defaultsSupportedHttpMethodsForItemResource() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
||||||
public void defaultsSupportedHttpMethodsForCollectionResource() {
|
void defaultsSupportedHttpMethodsForCollectionResource() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATACMNS-589, DATAREST-409
|
@Test // DATACMNS-589, DATAREST-409
|
||||||
public void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
|
void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(HidesDelete.class);
|
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(HidesDelete.class);
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-523
|
@Test // DATAREST-523
|
||||||
public void exposesMethodsForProperties() {
|
void exposesMethodsForProperties() {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
KeyValuePersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Entity.class);
|
KeyValuePersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||||
@@ -118,17 +118,17 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-825
|
@Test // DATAREST-825
|
||||||
public void supportsDeleteIfFindOneIsHidden() {
|
void supportsDeleteIfFindOneIsHidden() {
|
||||||
assertMethodsSupported(getSupportedHttpMethodsFor(HidesFindOne.class), ITEM, true, DELETE, PATCH, PUT, OPTIONS);
|
assertMethodsSupported(getSupportedHttpMethodsFor(HidesFindOne.class), ITEM, true, DELETE, PATCH, PUT, OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-825
|
@Test // DATAREST-825
|
||||||
public void doesNotSupportDeleteIfNoFindOneAvailable() {
|
void doesNotSupportDeleteIfNoFindOneAvailable() {
|
||||||
assertMethodsSupported(getSupportedHttpMethodsFor(NoFindOne.class), ITEM, false, DELETE);
|
assertMethodsSupported(getSupportedHttpMethodsFor(NoFindOne.class), ITEM, false, DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1176
|
@Test // DATAREST-1176
|
||||||
public void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
|
void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
|
||||||
|
|
||||||
reset(mappings);
|
reset(mappings);
|
||||||
when(mappings.exposeMethodsByDefault()).thenReturn(false);
|
when(mappings.exposeMethodsByDefault()).thenReturn(false);
|
||||||
|
|||||||
@@ -19,17 +19,17 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.springframework.http.HttpMethod.*;
|
import static org.springframework.http.HttpMethod.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link ExposureConfiguration}.
|
* Unit tests for {@link ExposureConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class ExposureConfigurationUnitTests {
|
class ExposureConfigurationUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-948
|
@Test // DATAREST-948
|
||||||
public void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
|
void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
|
||||||
|
|
||||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class ExposureConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-948
|
@Test // DATAREST-948
|
||||||
public void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
|
void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
|
||||||
|
|
||||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class ExposureConfigurationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-948
|
@Test // DATAREST-948
|
||||||
public void appliesTypeSpecificFilterForAggregateSubTypes() {
|
void appliesTypeSpecificFilterForAggregateSubTypes() {
|
||||||
|
|
||||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||||
configuration.forDomainType(Sample.class).withItemExposure((metadata, methods) -> methods.disable(POST));
|
configuration.forDomainType(Sample.class).withItemExposure((metadata, methods) -> methods.disable(POST));
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.annotation.Reference;
|
import org.springframework.data.annotation.Reference;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||||
@@ -34,8 +34,8 @@ import org.springframework.data.rest.core.annotation.RestResource;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class MappingResourceMetadataUnitTests {
|
class MappingResourceMetadataUnitTests {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class MappingResourceMetadataUnitTests {
|
|||||||
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
|
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
|
||||||
|
|
||||||
@Test // DATAREST-514
|
@Test // DATAREST-514
|
||||||
public void allowsLookupOfPropertyByMappedName() {
|
void allowsLookupOfPropertyByMappedName() {
|
||||||
|
|
||||||
KeyValuePersistentProperty<?> property = entity.getRequiredPersistentProperty("related");
|
KeyValuePersistentProperty<?> property = entity.getRequiredPersistentProperty("related");
|
||||||
|
|
||||||
@@ -57,13 +57,13 @@ public class MappingResourceMetadataUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-518
|
@Test // DATAREST-518
|
||||||
public void isNotExportedByDefault() {
|
void isNotExportedByDefault() {
|
||||||
|
|
||||||
assertThat(metadata.isExported()).isFalse();
|
assertThat(metadata.isExported()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-518
|
@Test // DATAREST-518
|
||||||
public void isExportedIfExplicitlyAnnotated() {
|
void isExportedIfExplicitlyAnnotated() {
|
||||||
|
|
||||||
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getRequiredPersistentEntity(Related.class),
|
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getRequiredPersistentEntity(Related.class),
|
||||||
resourceMappings);
|
resourceMappings);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
import org.springframework.data.mapping.context.PersistentEntities;
|
import org.springframework.data.mapping.context.PersistentEntities;
|
||||||
|
|
||||||
@@ -26,10 +26,10 @@ import org.springframework.data.mapping.context.PersistentEntities;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class PersistentEntitiesResourceMappingsUnitTests {
|
class PersistentEntitiesResourceMappingsUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-1320
|
@Test // DATAREST-1320
|
||||||
public void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
|
void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class PersistentEntitiesResourceMappingsUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // GH-2033
|
@Test // GH-2033
|
||||||
public void transparentlyAddsValueToCacheOnHasMappingRequests() {
|
void transparentlyAddsValueToCacheOnHasMappingRequests() {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
context.getPersistentEntity(Sample.class);
|
context.getPersistentEntity(Sample.class);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.annotation.Reference;
|
import org.springframework.data.annotation.Reference;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||||
@@ -42,13 +42,13 @@ import org.springframework.hateoas.LinkRelation;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class PersistentPropertyResourceMappingUnitTests {
|
class PersistentPropertyResourceMappingUnitTests {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@Test // DATAREST-175
|
@Test // DATAREST-175
|
||||||
public void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
|
void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
|
||||||
|
|
||||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "first");
|
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "first");
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-175
|
@Test // DATAREST-175
|
||||||
public void considersMappingAnnotationOnDomainClassProperty() {
|
void considersMappingAnnotationOnDomainClassProperty() {
|
||||||
|
|
||||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-175
|
@Test // DATAREST-175
|
||||||
public void considersMappingAnnotationOnDomainClassPropertyMethod() {
|
void considersMappingAnnotationOnDomainClassPropertyMethod() {
|
||||||
|
|
||||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "third");
|
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "third");
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-233
|
@Test // DATAREST-233
|
||||||
public void returnsDefaultDescriptionKey() {
|
void returnsDefaultDescriptionKey() {
|
||||||
|
|
||||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-233
|
@Test // DATAREST-233
|
||||||
public void considersAtDescription() {
|
void considersAtDescription() {
|
||||||
|
|
||||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "fourth");
|
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "fourth");
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1994
|
@Test // #1994
|
||||||
public void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
|
void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
|
||||||
|
|
||||||
PersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
PersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("third");
|
PersistentProperty<?> property = entity.getRequiredPersistentProperty("third");
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
@@ -34,10 +34,10 @@ import org.springframework.hateoas.LinkRelation;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class RepositoryCollectionResourceMappingUnitTests {
|
class RepositoryCollectionResourceMappingUnitTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildsDefaultMappingForRepository() {
|
void buildsDefaultMappingForRepository() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = getResourceMappingFor(PersonRepository.class);
|
CollectionResourceMapping mapping = getResourceMappingFor(PersonRepository.class);
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void honorsAnnotatedsMapping() {
|
void honorsAnnotatedsMapping() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedPersonRepository.class);
|
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedPersonRepository.class);
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void repositoryAnnotationTrumpsDomainTypeMapping() {
|
void repositoryAnnotationTrumpsDomainTypeMapping() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedAnnotatedPersonRepository.class);
|
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedAnnotatedPersonRepository.class);
|
||||||
|
|
||||||
@@ -70,19 +70,19 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
|
void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
|
||||||
|
|
||||||
ResourceMapping mapping = getResourceMappingFor(PackageProtectedRepository.class);
|
ResourceMapping mapping = getResourceMappingFor(PackageProtectedRepository.class);
|
||||||
assertThat(mapping.isExported()).isFalse();
|
assertThat(mapping.isExported()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-229
|
@Test // DATAREST-229
|
||||||
public void detectsPagingRepository() {
|
void detectsPagingRepository() {
|
||||||
assertThat(getResourceMappingFor(PersonRepository.class).isPagingResource()).isTrue();
|
assertThat(getResourceMappingFor(PersonRepository.class).isPagingResource()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void discoversCustomizationsUsingRestRepositoryResource() {
|
void discoversCustomizationsUsingRestRepositoryResource() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = getResourceMappingFor(RepositoryAnnotatedRepository.class);
|
CollectionResourceMapping mapping = getResourceMappingFor(RepositoryAnnotatedRepository.class);
|
||||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
||||||
@@ -90,7 +90,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-445
|
@Test // DATAREST-445
|
||||||
public void usesDomainTypeFromRepositoryMetadata() {
|
void usesDomainTypeFromRepositoryMetadata() {
|
||||||
|
|
||||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class) {
|
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class) {
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1401
|
@Test // DATAREST-1401
|
||||||
public void rejectsPathsWithMultipleSegments() {
|
void rejectsPathsWithMultipleSegments() {
|
||||||
|
|
||||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(InvalidPath.class);
|
RepositoryMetadata metadata = new DefaultRepositoryMetadata(InvalidPath.class);
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1401
|
@Test // DATAREST-1401
|
||||||
public void exposesProjectionTypeIfConfigured() {
|
void exposesProjectionTypeIfConfigured() {
|
||||||
|
|
||||||
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).hasValue(Object.class);
|
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).hasValue(Object.class);
|
||||||
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isEmpty();
|
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isEmpty();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||||
@@ -35,10 +35,10 @@ import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.Re
|
|||||||
* @soundtrack Katinka - Ausverkauf
|
* @soundtrack Katinka - Ausverkauf
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class RepositoryDetectionStrategiesUnitTests {
|
class RepositoryDetectionStrategiesUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-473
|
@Test // DATAREST-473
|
||||||
public void allExposesAllRepositories() {
|
void allExposesAllRepositories() {
|
||||||
|
|
||||||
assertExposures(ALL, new HashMap<Class<?>, Boolean>() {
|
assertExposures(ALL, new HashMap<Class<?>, Boolean>() {
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-473
|
@Test // DATAREST-473
|
||||||
public void defaultHonorsVisibilityAndAnnotations() {
|
void defaultHonorsVisibilityAndAnnotations() {
|
||||||
|
|
||||||
assertExposures(DEFAULT, new HashMap<Class<?>, Boolean>() {
|
assertExposures(DEFAULT, new HashMap<Class<?>, Boolean>() {
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-473
|
@Test // DATAREST-473
|
||||||
public void visibilityHonorsTypeVisibilityOnly() {
|
void visibilityHonorsTypeVisibilityOnly() {
|
||||||
|
|
||||||
assertExposures(VISIBILITY, new HashMap<Class<?>, Boolean>() {
|
assertExposures(VISIBILITY, new HashMap<Class<?>, Boolean>() {
|
||||||
{
|
{
|
||||||
@@ -77,7 +77,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-473
|
@Test // DATAREST-473
|
||||||
public void annotatedHonorsAnnotationsOnly() {
|
void annotatedHonorsAnnotationsOnly() {
|
||||||
|
|
||||||
assertExposures(ANNOTATED, new HashMap<Class<?>, Boolean>() {
|
assertExposures(ANNOTATED, new HashMap<Class<?>, Boolean>() {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -37,14 +37,14 @@ import org.springframework.hateoas.LinkRelation;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class RepositoryMethodResourceMappingUnitTests {
|
class RepositoryMethodResourceMappingUnitTests {
|
||||||
|
|
||||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class);
|
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class);
|
||||||
RepositoryCollectionResourceMapping resourceMapping = new RepositoryCollectionResourceMapping(metadata,
|
RepositoryCollectionResourceMapping resourceMapping = new RepositoryCollectionResourceMapping(metadata,
|
||||||
RepositoryDetectionStrategies.DEFAULT);
|
RepositoryDetectionStrategies.DEFAULT);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultsMappingToMethodName() throws Exception {
|
void defaultsMappingToMethodName() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||||
ResourceMapping mapping = getMappingFor(method);
|
ResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -53,7 +53,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void usesConfiguredNameWithLeadingSlash() throws Exception {
|
void usesConfiguredNameWithLeadingSlash() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
||||||
ResourceMapping mapping = getMappingFor(method);
|
ResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -62,7 +62,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-31
|
@Test // DATAREST-31
|
||||||
public void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
|
void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||||
MethodResourceMapping mapping = getMappingFor(method);
|
MethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -71,7 +71,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-31
|
@Test // DATAREST-31
|
||||||
public void resolvesParameterNamesIfNotAnnotated() throws Exception {
|
void resolvesParameterNamesIfNotAnnotated() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
||||||
MethodResourceMapping mapping = getMappingFor(method);
|
MethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -81,7 +81,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-229
|
@Test // DATAREST-229
|
||||||
public void considersPagingFinderAPagingResource() throws Exception {
|
void considersPagingFinderAPagingResource() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||||
MethodResourceMapping mapping = getMappingFor(method);
|
MethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -90,7 +90,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
|
void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||||
MethodResourceMapping mapping = getMappingFor(method);
|
MethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -99,7 +99,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-384
|
@Test // DATAREST-384
|
||||||
public void considersResourceSortableIfSortParameterIsPresent() throws Exception {
|
void considersResourceSortableIfSortParameterIsPresent() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Sort.class);
|
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Sort.class);
|
||||||
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -113,7 +113,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void returnsDomainTypeAsProjectionSourceType() throws Exception {
|
void returnsDomainTypeAsProjectionSourceType() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||||
MethodResourceMapping mapping = getMappingFor(method);
|
MethodResourceMapping mapping = getMappingFor(method);
|
||||||
@@ -122,7 +122,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-699
|
@Test // DATAREST-699
|
||||||
public void doesNotIncludePageableAsParameter() throws Exception {
|
void doesNotIncludePageableAsParameter() throws Exception {
|
||||||
|
|
||||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class, Pageable.class);
|
Method method = PersonRepository.class.getMethod("findByLastname", String.class, Pageable.class);
|
||||||
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.ListableBeanFactory;
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
@@ -44,7 +44,7 @@ import org.springframework.data.rest.core.domain.Person;
|
|||||||
import org.springframework.data.rest.core.domain.Profile;
|
import org.springframework.data.rest.core.domain.Profile;
|
||||||
import org.springframework.hateoas.LinkRelation;
|
import org.springframework.hateoas.LinkRelation;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link RepositoryResourceMappings}.
|
* Integration tests for {@link RepositoryResourceMappings}.
|
||||||
@@ -52,17 +52,17 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
public class RepositoryResourceMappingsIntegrationTests {
|
class RepositoryResourceMappingsIntegrationTests {
|
||||||
|
|
||||||
@Autowired ListableBeanFactory factory;
|
@Autowired ListableBeanFactory factory;
|
||||||
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
||||||
|
|
||||||
ResourceMappings mappings;
|
ResourceMappings mappings;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
mappingContext.getPersistentEntity(Profile.class);
|
mappingContext.getPersistentEntity(Profile.class);
|
||||||
|
|
||||||
@@ -75,12 +75,12 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void detectsAllMappings() {
|
void detectsAllMappings() {
|
||||||
assertThat(mappings).hasSize(5);
|
assertThat(mappings).hasSize(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exportsResourceAndSearchesForPersons() {
|
void exportsResourceAndSearchesForPersons() {
|
||||||
|
|
||||||
ResourceMetadata personMappings = mappings.getMetadataFor(Person.class);
|
ResourceMetadata personMappings = mappings.getMetadataFor(Person.class);
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotExportAnyMappingsForHiddenRepository() {
|
void doesNotExportAnyMappingsForHiddenRepository() {
|
||||||
|
|
||||||
ResourceMetadata creditCardMapping = mappings.getMetadataFor(CreditCard.class);
|
ResourceMetadata creditCardMapping = mappings.getMetadataFor(CreditCard.class);
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-112
|
@Test // DATAREST-112
|
||||||
public void usesPropertyNameAsRelForPropertyResourceMapping() {
|
void usesPropertyNameAsRelForPropertyResourceMapping() {
|
||||||
|
|
||||||
Repositories repositories = new Repositories(factory);
|
Repositories repositories = new Repositories(factory);
|
||||||
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(Person.class);
|
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(Person.class);
|
||||||
@@ -113,7 +113,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-111
|
@Test // DATAREST-111
|
||||||
public void exposesResourceByPath() {
|
void exposesResourceByPath() {
|
||||||
|
|
||||||
assertThat(mappings.exportsTopLevelResourceFor("people")).isTrue();
|
assertThat(mappings.exportsTopLevelResourceFor("people")).isTrue();
|
||||||
assertThat(mappings.exportsTopLevelResourceFor("orders")).isTrue();
|
assertThat(mappings.exportsTopLevelResourceFor("orders")).isTrue();
|
||||||
@@ -126,7 +126,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-107
|
@Test // DATAREST-107
|
||||||
public void skipsSearchMethodsNotExported() {
|
void skipsSearchMethodsNotExported() {
|
||||||
|
|
||||||
ResourceMetadata creditCardMetadata = mappings.getMetadataFor(CreditCard.class);
|
ResourceMetadata creditCardMetadata = mappings.getMetadataFor(CreditCard.class);
|
||||||
SearchResourceMappings searchResourceMappings = creditCardMetadata.getSearchResourceMappings();
|
SearchResourceMappings searchResourceMappings = creditCardMetadata.getSearchResourceMappings();
|
||||||
@@ -145,7 +145,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-325
|
@Test // DATAREST-325
|
||||||
public void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
|
void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
|
||||||
|
|
||||||
ResourceMetadata metadata = mappings.getMetadataFor(Author.class);
|
ResourceMetadata metadata = mappings.getMetadataFor(Author.class);
|
||||||
assertThat(metadata.isExported()).isTrue();
|
assertThat(metadata.isExported()).isTrue();
|
||||||
@@ -163,7 +163,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testname() {
|
void testname() {
|
||||||
|
|
||||||
ResourceMetadata metadata = mappings.getMetadataFor(Person.class);
|
ResourceMetadata metadata = mappings.getMetadataFor(Person.class);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.rest.core.Path;
|
import org.springframework.data.rest.core.Path;
|
||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
import org.springframework.data.rest.core.annotation.RestResource;
|
||||||
import org.springframework.hateoas.LinkRelation;
|
import org.springframework.hateoas.LinkRelation;
|
||||||
@@ -27,10 +27,10 @@ import org.springframework.hateoas.LinkRelation;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class TypeBasedCollectionResourceMappingUnitTests {
|
class TypeBasedCollectionResourceMappingUnitTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultsMappingsByType() {
|
void defaultsMappingsByType() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void usesCustomizedRel() {
|
void usesCustomizedRel() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(CustomizedSample.class);
|
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(CustomizedSample.class);
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-99
|
@Test // DATAREST-99
|
||||||
public void doesNotExportNonPublicTypesByDefault() {
|
void doesNotExportNonPublicTypesByDefault() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(HiddenSample.class);
|
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(HiddenSample.class);
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
|||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void usesDefaultDescriptionIfNoAnnotationPresent() {
|
void usesDefaultDescriptionIfNoAnnotationPresent() {
|
||||||
|
|
||||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
||||||
ResourceDescription description = mapping.getDescription();
|
ResourceDescription description = mapping.getDescription();
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.support.DefaultConversionService;
|
import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
@@ -44,18 +44,18 @@ import org.springframework.hateoas.server.EntityLinks;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @soundtrack Trio Rotation - Triopane
|
* @soundtrack Trio Rotation - Triopane
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DefaultSelfLinkProviderUnitTests {
|
class DefaultSelfLinkProviderUnitTests {
|
||||||
|
|
||||||
SelfLinkProvider provider;
|
SelfLinkProvider provider;
|
||||||
|
|
||||||
@Mock EntityLinks entityLinks;
|
@Mock(lenient = true) EntityLinks entityLinks;
|
||||||
PersistentEntities entities;
|
PersistentEntities entities;
|
||||||
List<EntityLookup<?>> lookups;
|
List<EntityLookup<?>> lookups;
|
||||||
ConversionService conversionService;
|
ConversionService conversionService;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
when(entityLinks.linkToItemResource(any(Class.class), any(Object.class))).then(invocation -> {
|
when(entityLinks.linkToItemResource(any(Class.class), any(Object.class))).then(invocation -> {
|
||||||
|
|
||||||
@@ -75,23 +75,29 @@ public class DefaultSelfLinkProviderUnitTests {
|
|||||||
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, lookups, conversionService);
|
this.provider = new DefaultSelfLinkProvider(entities, entityLinks, lookups, conversionService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
@Test // DATAREST-724
|
||||||
public void rejectsNullEntities() {
|
void rejectsNullEntities() {
|
||||||
new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
assertThatIllegalArgumentException() //
|
||||||
public void rejectsNullEntityLinks() {
|
.isThrownBy(() -> new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService));
|
||||||
new DefaultSelfLinkProvider(entities, null, lookups, conversionService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
|
||||||
public void rejectsNullEntityLookups() {
|
|
||||||
new DefaultSelfLinkProvider(entities, entityLinks, null, conversionService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-724
|
@Test // DATAREST-724
|
||||||
public void usesEntityIdIfNoLookupDefined() {
|
void rejectsNullEntityLinks() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new DefaultSelfLinkProvider(entities, null, lookups, conversionService));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-724
|
||||||
|
void rejectsNullEntityLookups() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new DefaultSelfLinkProvider(entities, entityLinks, null, conversionService));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-724
|
||||||
|
void usesEntityIdIfNoLookupDefined() {
|
||||||
|
|
||||||
Profile profile = new Profile("Name", "Type");
|
Profile profile = new Profile("Name", "Type");
|
||||||
Link link = provider.createSelfLinkFor(profile);
|
Link link = provider.createSelfLinkFor(profile);
|
||||||
@@ -101,7 +107,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-724
|
@Test // DATAREST-724
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void usesEntityLookupIfDefined() {
|
void usesEntityLookupIfDefined() {
|
||||||
|
|
||||||
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
||||||
when(lookup.supports(Profile.class)).thenReturn(true);
|
when(lookup.supports(Profile.class)).thenReturn(true);
|
||||||
@@ -116,7 +122,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-724, DATAREST-1549
|
@Test // DATAREST-724, DATAREST-1549
|
||||||
public void rejectsLinkCreationForUnknownEntity() {
|
void rejectsLinkCreationForUnknownEntity() {
|
||||||
|
|
||||||
assertThatExceptionOfType(MappingException.class) //
|
assertThatExceptionOfType(MappingException.class) //
|
||||||
.isThrownBy(() -> provider.createSelfLinkFor(new Object())) //
|
.isThrownBy(() -> provider.createSelfLinkFor(new Object())) //
|
||||||
|
|||||||
@@ -17,54 +17,53 @@ package org.springframework.data.rest.core.support;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import lombok.Value;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import java.util.stream.Stream;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.jupiter.api.DynamicTest;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.jupiter.api.TestFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures proper detection and removal of leading slash in strings.
|
* Ensures proper detection and removal of leading slash in strings.
|
||||||
*
|
*
|
||||||
* @author Florent Biville
|
* @author Florent Biville
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
class ResourceStringUtilsTests {
|
||||||
public class ResourceStringUtilsTests {
|
|
||||||
|
|
||||||
final String actual;
|
@TestFactory
|
||||||
final String expected;
|
Stream<DynamicTest> shouldDetectTextPresence() {
|
||||||
final boolean hasText;
|
|
||||||
|
|
||||||
public ResourceStringUtilsTests(String testDescription, String actual, String expected, boolean hasText) {
|
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
|
||||||
|
assertThat(ResourceStringUtils.hasTextExceptSlash(it.getActual())).isEqualTo(it.hasText);
|
||||||
this.actual = actual;
|
});
|
||||||
this.expected = expected;
|
|
||||||
this.hasText = hasText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters(name = "{0}")
|
@TestFactory
|
||||||
public static Collection<?> parameters() {
|
Stream<DynamicTest> shouldRemoveLeadingSlashIfAny() {
|
||||||
return Arrays
|
|
||||||
.asList(
|
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
|
||||||
new Object[][] { { "empty string has no text and should remain empty", "", "", false },
|
assertThat(ResourceStringUtils.removeLeadingSlash(it.getActual())).isEqualTo(it.getExpected());
|
||||||
{ "blank string has no text and should remain as is", " ", " ", false },
|
});
|
||||||
{ "string made of only a leading slash has no text and should be returned empty", "/", "", false },
|
|
||||||
{ "blank string with only slashes has no text and should be returned as is", " / ", " / ",
|
|
||||||
false },
|
|
||||||
{ "normal string has text and should be returned as such", "hello", "hello", true },
|
|
||||||
{ "normal string with leading slash has text and should be returned without leading slash", "/hello",
|
|
||||||
"hello", true }, });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
static Stream<Fixture> fixtures() {
|
||||||
public void shouldDetectTextPresence() {
|
|
||||||
assertThat(ResourceStringUtils.hasTextExceptSlash(actual)).isEqualTo(hasText);
|
return Stream.of(
|
||||||
|
Fixture.of("empty string has no text and should remain empty", "", "", false),
|
||||||
|
Fixture.of("blank string has no text and should remain as is", " ", " ", false),
|
||||||
|
Fixture.of("string made of only a leading slash has no text and should be returned empty", "/", "", false),
|
||||||
|
Fixture.of("blank string with only slashes has no text and should be returned as is", " / ", " / ",
|
||||||
|
false),
|
||||||
|
Fixture.of("normal string has text and should be returned as such", "hello", "hello", true),
|
||||||
|
Fixture.of("normal string with leading slash has text and should be returned without leading slash", "/hello",
|
||||||
|
"hello", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Value(staticConstructor = "of")
|
||||||
public void shouldRemoveLeadingSlashIfAny() {
|
static class Fixture {
|
||||||
assertThat(ResourceStringUtils.removeLeadingSlash(actual)).isEqualTo(expected);
|
|
||||||
|
String name, actual, expected;
|
||||||
|
boolean hasText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,10 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.assertj.core.api.AbstractOptionalAssert;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.Parameterized;
|
|
||||||
import org.junit.runners.Parameterized.Parameter;
|
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
|
||||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||||
import org.springframework.data.rest.core.domain.Profile;
|
import org.springframework.data.rest.core.domain.Profile;
|
||||||
@@ -41,8 +33,7 @@ import org.springframework.data.rest.core.domain.Profile;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||||
public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
|
||||||
|
|
||||||
static final Object REFERENCE = new Object();
|
static final Object REFERENCE = new Object();
|
||||||
|
|
||||||
@@ -52,11 +43,8 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
|||||||
RepositoryInvokerFactory factory;
|
RepositoryInvokerFactory factory;
|
||||||
Method method;
|
Method method;
|
||||||
|
|
||||||
public @Parameter(0) Object source;
|
@BeforeEach
|
||||||
public @Parameter(1) Consumer<AbstractOptionalAssert<?, Object>> value;
|
void setUp() throws Exception {
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
|
|
||||||
when(delegate.getInvokerFor(Object.class)).thenReturn(invoker);
|
when(delegate.getInvokerFor(Object.class)).thenReturn(invoker);
|
||||||
|
|
||||||
@@ -64,21 +52,9 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
|||||||
this.method = Object.class.getMethod("toString");
|
this.method = Object.class.getMethod("toString");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
|
||||||
public static Collection<Object[]> data() {
|
|
||||||
|
|
||||||
return Arrays.asList(new Object[][] { //
|
|
||||||
{ null, $(it -> it.isEmpty()) }, //
|
|
||||||
{ Optional.empty(), $(it -> it.isEmpty()) }, //
|
|
||||||
{ Optional.of(REFERENCE), $(it -> it.hasValue(REFERENCE)) }, //
|
|
||||||
{ com.google.common.base.Optional.absent(), $(it -> it.isEmpty()) }, //
|
|
||||||
{ com.google.common.base.Optional.of(REFERENCE), $(it -> it.hasValue(REFERENCE)) } //
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test // DATAREST-724, DATAREST-1261
|
@Test // DATAREST-724, DATAREST-1261
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void usesRegisteredEntityLookup() {
|
void usesRegisteredEntityLookup() {
|
||||||
|
|
||||||
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
||||||
|
|
||||||
@@ -91,8 +67,4 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
|||||||
verify(lookup, times(1)).lookupEntity(eq(1L));
|
verify(lookup, times(1)).lookupEntity(eq(1L));
|
||||||
verify(invoker, never()).invokeFindById(eq(1L)); // DATAREST-1261
|
verify(invoker, never()).invokeFindById(eq(1L)); // DATAREST-1261
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Consumer<AbstractOptionalAssert<?, Object>> $(Consumer<AbstractOptionalAssert<?, Object>> consumer) {
|
|
||||||
return consumer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import static org.hamcrest.CoreMatchers.*;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -32,7 +32,7 @@ import org.springframework.hateoas.MediaTypes;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
@@ -45,10 +45,10 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack Miles Davis - Blue in green (Kind of blue)
|
* @soundtrack Miles Davis - Blue in green (Kind of blue)
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class HalExplorerIntegrationTests {
|
class HalExplorerIntegrationTests {
|
||||||
|
|
||||||
static final String BASE_PATH = "/api";
|
static final String BASE_PATH = "/api";
|
||||||
static final String EXPLORER_INDEX = "/explorer/index.html";
|
static final String EXPLORER_INDEX = "/explorer/index.html";
|
||||||
@@ -69,14 +69,14 @@ public class HalExplorerIntegrationTests {
|
|||||||
|
|
||||||
MockMvc mvc;
|
MockMvc mvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.mvc = MockMvcBuilders.webAppContextSetup(context).//
|
this.mvc = MockMvcBuilders.webAppContextSetup(context).//
|
||||||
defaultRequest(get(BASE_PATH).accept(MediaType.TEXT_HTML)).build();
|
defaultRequest(get(BASE_PATH).accept(MediaType.TEXT_HTML)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-293
|
@Test // DATAREST-293
|
||||||
public void exposesJsonUnderApiRootByDefault() throws Exception {
|
void exposesJsonUnderApiRootByDefault() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get(BASE_PATH).accept(MediaType.ALL)).//
|
mvc.perform(get(BASE_PATH).accept(MediaType.ALL)).//
|
||||||
andExpect(status().isOk()).//
|
andExpect(status().isOk()).//
|
||||||
@@ -84,7 +84,7 @@ public class HalExplorerIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-293
|
@Test // DATAREST-293
|
||||||
public void redirectsToBrowserForApiRootAndHtml() throws Exception {
|
void redirectsToBrowserForApiRootAndHtml() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get(BASE_PATH).accept(MediaType.TEXT_HTML)).//
|
mvc.perform(get(BASE_PATH).accept(MediaType.TEXT_HTML)).//
|
||||||
andExpect(status().isFound()).//
|
andExpect(status().isFound()).//
|
||||||
@@ -92,7 +92,7 @@ public class HalExplorerIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-293
|
@Test // DATAREST-293
|
||||||
public void forwardsBrowserToIndexHtml() throws Exception {
|
void forwardsBrowserToIndexHtml() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get(BASE_PATH.concat("/explorer"))).//
|
mvc.perform(get(BASE_PATH.concat("/explorer"))).//
|
||||||
andExpect(status().isFound()).//
|
andExpect(status().isFound()).//
|
||||||
@@ -100,7 +100,7 @@ public class HalExplorerIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-293
|
@Test // DATAREST-293
|
||||||
public void exposesHalBrowser() throws Exception {
|
void exposesHalBrowser() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get(BASE_PATH.concat("/explorer/index.html"))).//
|
mvc.perform(get(BASE_PATH.concat("/explorer/index.html"))).//
|
||||||
andExpect(status().isOk()).//
|
andExpect(status().isOk()).//
|
||||||
@@ -108,7 +108,7 @@ public class HalExplorerIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-293
|
@Test // DATAREST-293
|
||||||
public void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception {
|
void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get(BASE_PATH).accept(MediaType.APPLICATION_JSON, MediaType.ALL)).//
|
mvc.perform(get(BASE_PATH).accept(MediaType.APPLICATION_JSON, MediaType.ALL)).//
|
||||||
andExpect(status().isOk()).//
|
andExpect(status().isOk()).//
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import java.util.Collections;
|
|||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
@@ -41,10 +40,10 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @soundtrack Nils Wülker - Homeless Diamond (feat. Lauren Flynn)
|
* @soundtrack Nils Wülker - Homeless Diamond (feat. Lauren Flynn)
|
||||||
*/
|
*/
|
||||||
public class HalExplorerUnitTests {
|
class HalExplorerUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-565, DATAREST-720
|
@Test // DATAREST-565, DATAREST-720
|
||||||
public void createsContextRelativeRedirectForBrowser() throws Exception {
|
void createsContextRelativeRedirectForBrowser() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
@@ -64,7 +63,7 @@ public class HalExplorerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1264
|
@Test // DATAREST-1264
|
||||||
public void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException {
|
void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException {
|
||||||
|
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/explorer");
|
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/explorer");
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
package org.springframework.data.rest.tests;
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
@@ -14,11 +13,12 @@ package org.springframework.data.rest.tests;
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.springframework.data.rest.tests;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -41,7 +41,7 @@ import org.springframework.data.rest.webmvc.support.Projector;
|
|||||||
import org.springframework.hateoas.server.EntityLinks;
|
import org.springframework.hateoas.server.EntityLinks;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
@@ -53,7 +53,7 @@ import org.springframework.web.context.request.WebRequest;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public abstract class AbstractControllerIntegrationTests {
|
public abstract class AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public abstract class AbstractControllerIntegrationTests {
|
|||||||
@Autowired RepositoryInvokerFactory invokerFactory;
|
@Autowired RepositoryInvokerFactory invokerFactory;
|
||||||
@Autowired ResourceMappings mappings;
|
@Autowired ResourceMappings mappings;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void initWebInfrastructure() {
|
public void initWebInfrastructure() {
|
||||||
TestMvcClient.initWebTest();
|
TestMvcClient.initWebTest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ import static org.hamcrest.CoreMatchers.*;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
|
import net.minidev.json.JSONArray;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.minidev.json.JSONArray;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
@@ -36,7 +37,7 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.ResultMatcher;
|
import org.springframework.test.web.servlet.ResultMatcher;
|
||||||
@@ -61,7 +62,7 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Ľubomír Varga
|
* @author Ľubomír Varga
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class })
|
@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class })
|
||||||
public abstract class AbstractWebIntegrationTests {
|
public abstract class AbstractWebIntegrationTests {
|
||||||
@@ -74,7 +75,7 @@ public abstract class AbstractWebIntegrationTests {
|
|||||||
protected TestMvcClient client;
|
protected TestMvcClient client;
|
||||||
protected MockMvc mvc;
|
protected MockMvc mvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setupMockMvc();
|
setupMockMvc();
|
||||||
this.client = new TestMvcClient(mvc, discoverers);
|
this.client = new TestMvcClient(mvc, discoverers);
|
||||||
|
|||||||
@@ -17,16 +17,17 @@ package org.springframework.data.rest.tests;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assume.*;
|
import static org.junit.jupiter.api.Assumptions.*;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
|
import net.minidev.json.JSONArray;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.minidev.json.JSONArray;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||||
import org.springframework.hateoas.IanaLinkRelations;
|
import org.springframework.hateoas.IanaLinkRelations;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
@@ -57,7 +58,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
// Root test cases
|
// Root test cases
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exposesRootResource() throws Exception {
|
void exposesRootResource() throws Exception {
|
||||||
|
|
||||||
ResultActions actions = mvc.perform(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).andExpect(status().isOk());
|
ResultActions actions = mvc.perform(get("/").accept(TestMvcClient.DEFAULT_MEDIA_TYPE)).andExpect(status().isOk());
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-113, DATAREST-638
|
@Test // DATAREST-113, DATAREST-638
|
||||||
public void exposesSchemasForResourcesExposed() throws Exception {
|
void exposesSchemasForResourcesExposed() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request("/");
|
MockHttpServletResponse response = client.request("/");
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-203
|
@Test // DATAREST-203
|
||||||
public void servesHalWhenRequested() throws Exception {
|
void servesHalWhenRequested() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/")). //
|
mvc.perform(get("/")). //
|
||||||
andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)). //
|
andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)). //
|
||||||
@@ -100,7 +101,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-203
|
@Test // DATAREST-203
|
||||||
public void servesHalWhenJsonIsRequested() throws Exception {
|
void servesHalWhenJsonIsRequested() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/").accept(MediaType.APPLICATION_JSON)). //
|
mvc.perform(get("/").accept(MediaType.APPLICATION_JSON)). //
|
||||||
andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)). //
|
andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)). //
|
||||||
@@ -108,7 +109,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-203
|
@Test // DATAREST-203
|
||||||
public void exposesSearchesForRootResources() throws Exception {
|
void exposesSearchesForRootResources() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request("/");
|
MockHttpServletResponse response = client.request("/");
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nic() throws Exception {
|
void nic() throws Exception {
|
||||||
|
|
||||||
Map<LinkRelation, String> payloads = getPayloadToPost();
|
Map<LinkRelation, String> payloads = getPayloadToPost();
|
||||||
assumeFalse(payloads.isEmpty());
|
assumeFalse(payloads.isEmpty());
|
||||||
@@ -162,7 +163,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-198
|
@Test // DATAREST-198
|
||||||
public void accessLinkedResources() throws Exception {
|
void accessLinkedResources() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse rootResource = client.request("/");
|
MockHttpServletResponse rootResource = client.request("/");
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-230
|
@Test // DATAREST-230
|
||||||
public void exposesDescriptionAsAlpsDocuments() throws Exception {
|
void exposesDescriptionAsAlpsDocuments() throws Exception {
|
||||||
|
|
||||||
MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");
|
MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");
|
||||||
|
|
||||||
@@ -204,14 +205,14 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-448
|
@Test // DATAREST-448
|
||||||
public void returnsNotFoundForUriNotBackedByARepository() throws Exception {
|
void returnsNotFoundForUriNotBackedByARepository() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/index.html")).//
|
mvc.perform(get("/index.html")).//
|
||||||
andExpect(status().isNotFound());
|
andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-658
|
@Test // DATAREST-658
|
||||||
public void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception {
|
void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception {
|
||||||
|
|
||||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-661
|
@Test // DATAREST-661
|
||||||
public void patchToNonExistingResourceReturnsNotFound() throws Exception {
|
void patchToNonExistingResourceReturnsNotFound() throws Exception {
|
||||||
|
|
||||||
LinkRelation rel = expectedRootLinkRels().iterator().next();
|
LinkRelation rel = expectedRootLinkRels().iterator().next();
|
||||||
String uri = client.discoverUnique(rel).expand().getHref().concat("/");
|
String uri = client.discoverUnique(rel).expand().getHref().concat("/");
|
||||||
@@ -249,7 +250,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1003
|
@Test // DATAREST-1003
|
||||||
public void rejectsUnsupportedAcceptTypeForResources() throws Exception {
|
void rejectsUnsupportedAcceptTypeForResources() throws Exception {
|
||||||
|
|
||||||
for (LinkRelation string : expectedRootLinkRels()) {
|
for (LinkRelation string : expectedRootLinkRels()) {
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.tests;
|
package org.springframework.data.rest.tests;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
@@ -26,10 +24,10 @@ import java.util.Iterator;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
|
||||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
|
||||||
import org.springframework.hateoas.LinkRelation;
|
import org.springframework.hateoas.LinkRelation;
|
||||||
import org.springframework.hateoas.Links;
|
import org.springframework.hateoas.Links;
|
||||||
|
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||||
|
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
@@ -85,8 +83,8 @@ public class TestMvcClient {
|
|||||||
|
|
||||||
HttpHeaders headers = response.getHeaders();
|
HttpHeaders headers = response.getHeaders();
|
||||||
|
|
||||||
assertThat(headers.getAllow(), hasSize(methods.length));
|
assertThat(headers.getAllow()).hasSize(methods.length);
|
||||||
assertThat(headers.getAllow(), hasItems(methods));
|
assertThat(headers.getAllow()).contains(methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -356,8 +354,10 @@ public class TestMvcClient {
|
|||||||
MockHttpServletResponse response = result.getResponse();
|
MockHttpServletResponse response = result.getResponse();
|
||||||
String s = response.getContentAsString();
|
String s = response.getContentAsString();
|
||||||
|
|
||||||
assertThat("Expected to find link with rel " + rel + " but found none in " + s, //
|
assertThat(getDiscoverer(response).findLinkWithRel(rel, s)) //
|
||||||
getDiscoverer(response).findLinkWithRel(rel, s), notNullValue());
|
.as(() -> "Expected to find link with rel " + rel + " but found none in " + s) //
|
||||||
|
.isNotNull();
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import org.springframework.data.util.AnnotatedTypeScanner;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@ImportResource("classpath:META-INF/spring/cache-config.xml")
|
@ImportResource("classpath:META-INF/spring/cache-config.xml")
|
||||||
@EnableGemfireRepositories
|
@EnableGemfireRepositories
|
||||||
public class GeodeRepositoryConfig {
|
class GeodeRepositoryConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Remove, once Spring Data Gemfire exposes a mapping context.
|
* TODO: Remove, once Spring Data Gemfire exposes a mapping context.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = GeodeRepositoryConfig.class)
|
@ContextConfiguration(classes = GeodeRepositoryConfig.class)
|
||||||
public class GeodeWebTests extends CommonWebTests {
|
class GeodeWebTests extends CommonWebTests {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.springframework.data.rest.tests.TestMvcClient.*;
|
import static org.springframework.data.rest.tests.TestMvcClient.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||||
@@ -36,24 +36,24 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired RepositoryController controller;
|
@Autowired RepositoryController controller;
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void rootResourceExposesGetOnly() {
|
void rootResourceExposesGetOnly() {
|
||||||
|
|
||||||
HttpEntity<?> response = controller.optionsForRepositories();
|
HttpEntity<?> response = controller.optionsForRepositories();
|
||||||
assertAllowHeaders(response, HttpMethod.GET);
|
assertAllowHeaders(response, HttpMethod.GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333, DATAREST-330
|
@Test // DATAREST-333, DATAREST-330
|
||||||
public void headRequestReturnsNoContent() {
|
void headRequestReturnsNoContent() {
|
||||||
assertThat(controller.headForRepositories().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
assertThat(controller.headForRepositories().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-160, DATAREST-333, DATAREST-463
|
@Test // DATAREST-160, DATAREST-333, DATAREST-463
|
||||||
public void exposesLinksToRepositories() {
|
void exposesLinksToRepositories() {
|
||||||
|
|
||||||
RepositoryLinksResource resource = controller.listRepositories().getBody();
|
RepositoryLinksResource resource = controller.listRepositories().getBody();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import static org.springframework.http.HttpMethod.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -62,7 +62,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = { ConfigurationCustomizer.class, JpaRepositoryConfig.class })
|
@ContextConfiguration(classes = { ConfigurationCustomizer.class, JpaRepositoryConfig.class })
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired RepositoryEntityController controller;
|
@Autowired RepositoryEntityController controller;
|
||||||
@Autowired AddressRepository repository;
|
@Autowired AddressRepository repository;
|
||||||
@@ -82,25 +82,28 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpRequestMethodNotSupportedException.class) // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception {
|
void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception {
|
||||||
|
|
||||||
repository.save(new Address());
|
repository.save(new Address());
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Address.class);
|
RootResourceInformation request = getResourceInformation(Address.class);
|
||||||
controller.getCollectionResource(request, null, null, null);
|
|
||||||
|
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class) //
|
||||||
|
.isThrownBy(() -> controller.getCollectionResource(request, null, null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpRequestMethodNotSupportedException.class) // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void rejectsEntityCreationIfSaveIsNotExported() throws Exception {
|
void rejectsEntityCreationIfSaveIsNotExported() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Address.class);
|
RootResourceInformation request = getResourceInformation(Address.class);
|
||||||
|
|
||||||
controller.postCollectionResource(request, null, null, MediaType.APPLICATION_JSON_VALUE);
|
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class) //
|
||||||
|
.isThrownBy(() -> controller.postCollectionResource(request, null, null, MediaType.APPLICATION_JSON_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-301
|
@Test // DATAREST-301
|
||||||
public void setsExpandedSelfUriInLocationHeader() throws Exception {
|
void setsExpandedSelfUriInLocationHeader() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation information = getResourceInformation(Order.class);
|
RootResourceInformation information = getResourceInformation(Order.class);
|
||||||
|
|
||||||
@@ -114,20 +117,25 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void exposesHeadForCollectionResourceIfExported() throws Exception {
|
void exposesHeadForCollectionResourceIfExported() throws Exception {
|
||||||
ResponseEntity<?> entity = controller.headCollectionResource(getResourceInformation(Person.class),
|
ResponseEntity<?> entity = controller.headCollectionResource(getResourceInformation(Person.class),
|
||||||
new DefaultedPageable(Pageable.unpaged(), false));
|
new DefaultedPageable(Pageable.unpaged(), false));
|
||||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception {
|
void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception {
|
||||||
controller.headCollectionResource(getResourceInformation(CreditCard.class),
|
|
||||||
new DefaultedPageable(Pageable.unpaged(), false));
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> {
|
||||||
|
|
||||||
|
controller.headCollectionResource(getResourceInformation(CreditCard.class),
|
||||||
|
new DefaultedPageable(Pageable.unpaged(), false));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void exposesHeadForItemResourceIfExported() throws Exception {
|
void exposesHeadForItemResourceIfExported() throws Exception {
|
||||||
|
|
||||||
Address address = repository.save(new Address());
|
Address address = repository.save(new Address());
|
||||||
|
|
||||||
@@ -137,34 +145,36 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception {
|
void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception {
|
||||||
controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler);
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() {
|
void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() {
|
||||||
|
|
||||||
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Address.class));
|
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Address.class));
|
||||||
assertAllowHeaders(response, OPTIONS);
|
assertAllowHeaders(response, OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() {
|
void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() {
|
||||||
|
|
||||||
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Person.class));
|
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Person.class));
|
||||||
assertAllowHeaders(response, GET, POST, HEAD, OPTIONS);
|
assertAllowHeaders(response, GET, POST, HEAD, OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() {
|
void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() {
|
||||||
|
|
||||||
HttpEntity<?> response = controller.optionsForItemResource(getResourceInformation(Person.class));
|
HttpEntity<?> response = controller.optionsForItemResource(getResourceInformation(Person.class));
|
||||||
assertAllowHeaders(response, GET, PUT, PATCH, DELETE, HEAD, OPTIONS);
|
assertAllowHeaders(response, GET, PUT, PATCH, DELETE, HEAD, OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333, DATAREST-348
|
@Test // DATAREST-333, DATAREST-348
|
||||||
public void optionsForItermResourceSetsAllowPatchHeader() {
|
void optionsForItermResourceSetsAllowPatchHeader() {
|
||||||
|
|
||||||
ResponseEntity<?> entity = controller.optionsForItemResource(getResourceInformation(Person.class));
|
ResponseEntity<?> entity = controller.optionsForItemResource(getResourceInformation(Person.class));
|
||||||
|
|
||||||
@@ -176,7 +186,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception {
|
void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Order.class);
|
RootResourceInformation request = getResourceInformation(Order.class);
|
||||||
Order order = request.getInvoker().invokeSave(new Order(new Person()));
|
Order order = request.getInvoker().invokeSave(new Order(new Person()));
|
||||||
@@ -189,7 +199,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException {
|
void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Order.class);
|
RootResourceInformation request = getResourceInformation(Order.class);
|
||||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||||
@@ -200,7 +210,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception {
|
void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Order.class);
|
RootResourceInformation request = getResourceInformation(Order.class);
|
||||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||||
@@ -212,7 +222,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-34
|
@Test // DATAREST-34
|
||||||
public void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception {
|
void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Order.class);
|
RootResourceInformation request = getResourceInformation(Order.class);
|
||||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||||
@@ -224,7 +234,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-581
|
@Test // DATAREST-581
|
||||||
public void createsEtagForProjectedEntityCorrectly() throws Exception {
|
void createsEtagForProjectedEntityCorrectly() throws Exception {
|
||||||
|
|
||||||
Address address = repository.save(new Address());
|
Address address = repository.save(new Address());
|
||||||
|
|
||||||
@@ -244,7 +254,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-724
|
@Test // DATAREST-724
|
||||||
public void deletesEntityWithCustomLookupCorrectly() throws Exception {
|
void deletesEntityWithCustomLookupCorrectly() throws Exception {
|
||||||
|
|
||||||
Address address = repository.save(new Address());
|
Address address = repository.save(new Address());
|
||||||
assertThat(repository.findById(address.id)).isNotNull();
|
assertThat(repository.findById(address.id)).isNotNull();
|
||||||
@@ -262,7 +272,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-948
|
@Test // DATAREST-948
|
||||||
public void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException {
|
void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Address.class);
|
RootResourceInformation request = getResourceInformation(Address.class);
|
||||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||||
|
|||||||
@@ -18,9 +18,8 @@ package org.springframework.data.rest.webmvc;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||||
import org.springframework.data.rest.webmvc.jpa.Book;
|
import org.springframework.data.rest.webmvc.jpa.Book;
|
||||||
@@ -36,7 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired RepositoryPropertyReferenceController controller;
|
@Autowired RepositoryPropertyReferenceController controller;
|
||||||
@Autowired TestDataPopulator populator;
|
@Autowired TestDataPopulator populator;
|
||||||
@@ -45,8 +44,8 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
|||||||
PersistentEntityResourceAssembler assembler;
|
PersistentEntityResourceAssembler assembler;
|
||||||
RootResourceInformation information;
|
RootResourceInformation information;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.assembler = mock(PersistentEntityResourceAssembler.class);
|
this.assembler = mock(PersistentEntityResourceAssembler.class);
|
||||||
this.information = getResourceInformation(Book.class);
|
this.information = getResourceInformation(Book.class);
|
||||||
@@ -54,7 +53,7 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exposesResourceForCustomizedPropertyResourcePath() throws Exception {
|
void exposesResourceForCustomizedPropertyResourcePath() throws Exception {
|
||||||
|
|
||||||
Book book = books.findAll().iterator().next();
|
Book book = books.findAll().iterator().next();
|
||||||
|
|
||||||
@@ -62,11 +61,12 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
|||||||
.isEqualTo(HttpStatus.OK);
|
.isEqualTo(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class)
|
@Test
|
||||||
public void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() throws Exception {
|
void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() {
|
||||||
|
|
||||||
Book book = books.findAll().iterator().next();
|
Book book = books.findAll().iterator().next();
|
||||||
|
|
||||||
controller.followPropertyReference(information, book.id, "authors", assembler);
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.followPropertyReference(information, book.id, "authors", assembler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ package org.springframework.data.rest.webmvc;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.springframework.data.rest.tests.TestMvcClient.*;
|
import static org.springframework.data.rest.tests.TestMvcClient.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -35,9 +35,9 @@ import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
|||||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||||
import org.springframework.data.rest.webmvc.jpa.TestDataPopulator;
|
import org.springframework.data.rest.webmvc.jpa.TestDataPopulator;
|
||||||
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
import org.springframework.hateoas.PagedModel;
|
import org.springframework.hateoas.PagedModel;
|
||||||
import org.springframework.hateoas.RepresentationModel;
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
import org.springframework.hateoas.CollectionModel;
|
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
@@ -55,7 +55,7 @@ import org.springframework.util.MultiValueMap;
|
|||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
static final DefaultedPageable PAGEABLE = new DefaultedPageable(PageRequest.of(0, 10), true);
|
static final DefaultedPageable PAGEABLE = new DefaultedPageable(PageRequest.of(0, 10), true);
|
||||||
|
|
||||||
@@ -63,16 +63,16 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
@Autowired RepositorySearchController controller;
|
@Autowired RepositorySearchController controller;
|
||||||
@Autowired PersistentEntityResourceAssembler assembler;
|
@Autowired PersistentEntityResourceAssembler assembler;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
loader.populateRepositories();
|
loader.populateRepositories();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rendersCorrectSearchLinksForPersons() throws Exception {
|
void rendersCorrectSearchLinksForPersons() throws Exception {
|
||||||
|
|
||||||
RootResourceInformation request = getResourceInformation(Person.class);
|
RootResourceInformation request = getResourceInformation(Person.class);
|
||||||
RepresentationModel resource = controller.listSearches(request);
|
RepresentationModel<?> resource = controller.listSearches(request);
|
||||||
|
|
||||||
ResourceTester tester = ResourceTester.of(resource);
|
ResourceTester tester = ResourceTester.of(resource);
|
||||||
tester.assertNumberOfLinks(7); // Self link included
|
tester.assertNumberOfLinks(7); // Self link included
|
||||||
@@ -86,18 +86,22 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
tester.assertHasLinkEndingWith("findCreatedDateByLastName", "findCreatedDateByLastName{?lastname}");
|
tester.assertHasLinkEndingWith("findCreatedDateByLastName", "findCreatedDateByLastName{?lastname}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class)
|
@Test
|
||||||
public void returns404ForUnexportedRepository() {
|
void returns404ForUnexportedRepository() {
|
||||||
controller.listSearches(getResourceInformation(CreditCard.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class)
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
public void returns404ForRepositoryWithoutSearches() {
|
.isThrownBy(() -> controller.listSearches(getResourceInformation(CreditCard.class)));
|
||||||
controller.listSearches(getResourceInformation(Author.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executesSearchAgainstRepository() {
|
void returns404ForRepositoryWithoutSearches() {
|
||||||
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.listSearches(getResourceInformation(Author.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void executesSearchAgainstRepository() {
|
||||||
|
|
||||||
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
||||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
|
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
|
||||||
@@ -114,43 +118,51 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
tester.withContentResource(new HasSelfLink(BASE.slash(metadata.getPath()).slash("{id}")));
|
tester.withContentResource(new HasSelfLink(BASE.slash(metadata.getPath()).slash("{id}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() {
|
void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() {
|
||||||
controller.headForSearches(getResourceInformation(Author.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
public void exposesHeadForSearchResourceIfResourceIsNotExposed() {
|
.isThrownBy(() -> controller.headForSearches(getResourceInformation(Author.class)));
|
||||||
controller.headForSearches(getResourceInformation(CreditCard.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void exposesHeadForSearchResourceIfResourceIsExposed() {
|
void exposesHeadForSearchResourceIfResourceIsNotExposed() {
|
||||||
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.headForSearches(getResourceInformation(CreditCard.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-330
|
||||||
|
void exposesHeadForSearchResourceIfResourceIsExposed() {
|
||||||
controller.headForSearches(getResourceInformation(Person.class));
|
controller.headForSearches(getResourceInformation(Person.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void exposesHeadForExistingQueryMethodResource() {
|
void exposesHeadForExistingQueryMethodResource() {
|
||||||
controller.headForSearch(getResourceInformation(Person.class), "findByCreatedUsingISO8601Date");
|
controller.headForSearch(getResourceInformation(Person.class), "findByCreatedUsingISO8601Date");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void doesNotExposeHeadForInvalidQueryMethodResource() {
|
void doesNotExposeHeadForInvalidQueryMethodResource() {
|
||||||
controller.headForSearch(getResourceInformation(Person.class), "foobar");
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.headForSearch(getResourceInformation(Person.class), "foobar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void searchResourceSupportsGetOnly() {
|
void searchResourceSupportsGetOnly() {
|
||||||
assertAllowHeaders(controller.optionsForSearches(getResourceInformation(Person.class)), HttpMethod.GET);
|
assertAllowHeaders(controller.optionsForSearches(getResourceInformation(Person.class)), HttpMethod.GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void returns404ForOptionsForRepositoryWithoutSearches() {
|
void returns404ForOptionsForRepositoryWithoutSearches() {
|
||||||
controller.optionsForSearches(getResourceInformation(Address.class));
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> controller.optionsForSearches(getResourceInformation(Address.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-333
|
@Test // DATAREST-333
|
||||||
public void queryMethodResourceSupportsGetOnly() {
|
void queryMethodResourceSupportsGetOnly() {
|
||||||
|
|
||||||
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
||||||
HttpEntity<Object> response = controller.optionsForSearch(resourceInformation, "firstname");
|
HttpEntity<Object> response = controller.optionsForSearch(resourceInformation, "firstname");
|
||||||
@@ -159,7 +171,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-502
|
@Test // DATAREST-502
|
||||||
public void interpretsUriAsReferenceToRelatedEntity() {
|
void interpretsUriAsReferenceToRelatedEntity() {
|
||||||
|
|
||||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
|
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
|
||||||
parameters.add("author", "/author/1");
|
parameters.add("author", "/author/1");
|
||||||
@@ -173,7 +185,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-515
|
@Test // DATAREST-515
|
||||||
public void repositorySearchResourceExposesDomainType() {
|
void repositorySearchResourceExposesDomainType() {
|
||||||
|
|
||||||
RepositorySearchesResource searches = controller.listSearches(getResourceInformation(Person.class));
|
RepositorySearchesResource searches = controller.listSearches(getResourceInformation(Person.class));
|
||||||
|
|
||||||
@@ -181,7 +193,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1121
|
@Test // DATAREST-1121
|
||||||
public void returnsSimpleResponseEntityForQueryMethod() {
|
void returnsSimpleResponseEntityForQueryMethod() {
|
||||||
|
|
||||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
|
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
|
||||||
parameters.add("lastname", "Thornton");
|
parameters.add("lastname", "Thornton");
|
||||||
|
|||||||
@@ -19,14 +19,15 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import static org.springframework.data.rest.core.mapping.ResourceType.*;
|
import static org.springframework.data.rest.core.mapping.ResourceType.*;
|
||||||
import static org.springframework.http.HttpMethod.*;
|
import static org.springframework.http.HttpMethod.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.data.rest.core.mapping.ResourceType;
|
||||||
import org.springframework.data.rest.core.mapping.SupportedHttpMethods;
|
import org.springframework.data.rest.core.mapping.SupportedHttpMethods;
|
||||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||||
import org.springframework.data.rest.webmvc.jpa.Address;
|
import org.springframework.data.rest.webmvc.jpa.Address;
|
||||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,20 +35,20 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests {
|
class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Test // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void getIsNotSupportedIfFindAllIsNotExported() {
|
void getIsNotSupportedIfFindAllIsNotExported() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
||||||
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(GET);
|
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void postIsNotSupportedIfSaveIsNotExported() {
|
void postIsNotSupportedIfSaveIsNotExported() {
|
||||||
|
|
||||||
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
||||||
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(POST);
|
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(POST);
|
||||||
|
|||||||
@@ -15,15 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc.alps;
|
package org.springframework.data.rest.webmvc.alps;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.After;
|
import net.minidev.json.JSONArray;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -48,8 +49,6 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
|
|
||||||
import com.jayway.jsonpath.JsonPath;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
|
||||||
import net.minidev.json.JSONArray;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link AlpsController}.
|
* Integration tests for {@link AlpsController}.
|
||||||
*
|
*
|
||||||
@@ -58,7 +57,7 @@ import net.minidev.json.JSONArray;
|
|||||||
*/
|
*/
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, AlpsControllerIntegrationTests.Config.class })
|
@ContextConfiguration(classes = { JpaRepositoryConfig.class, AlpsControllerIntegrationTests.Config.class })
|
||||||
public class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired WebApplicationContext context;
|
@Autowired WebApplicationContext context;
|
||||||
@Autowired LinkDiscoverers discoverers;
|
@Autowired LinkDiscoverers discoverers;
|
||||||
@@ -81,20 +80,20 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
|
|
||||||
TestMvcClient client;
|
TestMvcClient client;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
this.client = new TestMvcClient(mvc, this.discoverers);
|
this.client = new TestMvcClient(mvc, this.discoverers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
configuration.setEnableEnumTranslation(false);
|
configuration.setEnableEnumTranslation(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-230
|
@Test // DATAREST-230
|
||||||
public void exposesAlpsCollectionResources() throws Exception {
|
void exposesAlpsCollectionResources() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||||
@@ -105,7 +104,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-638
|
@Test // DATAREST-638
|
||||||
public void verifyThatAlpsIsDefaultProfileFormat() throws Exception {
|
void verifyThatAlpsIsDefaultProfileFormat() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||||
@@ -117,7 +116,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-463
|
@Test // DATAREST-463
|
||||||
public void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception {
|
void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
||||||
@@ -132,7 +131,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-494
|
@Test // DATAREST-494
|
||||||
public void linksToJsonSchemaFromRepresentationDescriptor() throws Exception {
|
void linksToJsonSchemaFromRepresentationDescriptor() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
||||||
@@ -143,11 +142,11 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
String href = JsonPath.<JSONArray> read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0)
|
String href = JsonPath.<JSONArray> read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0)
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
assertThat(href, endsWith("/profile/items"));
|
assertThat(href).endsWith("/profile/items");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-516
|
@Test // DATAREST-516
|
||||||
public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
|
void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||||
@@ -164,7 +163,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-630
|
@Test // DATAREST-630
|
||||||
public void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception {
|
void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
||||||
@@ -175,7 +174,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-683
|
@Test // DATAREST-683
|
||||||
public void enumValueListingsAreTranslatedIfEnabled() throws Exception {
|
void enumValueListingsAreTranslatedIfEnabled() throws Exception {
|
||||||
|
|
||||||
configuration.setEnableEnumTranslation(true);
|
configuration.setEnableEnumTranslation(true);
|
||||||
|
|
||||||
@@ -193,7 +192,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-753
|
@Test // DATAREST-753
|
||||||
public void alpsCanHandleGroovyDomainObjects() throws Exception {
|
void alpsCanHandleGroovyDomainObjects() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profile");
|
Link profileLink = client.discoverUnique("profile");
|
||||||
Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses");
|
Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses");
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.*;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||||
@@ -48,7 +48,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
* @soundtrack 2 Unlimited - No Limit
|
* @soundtrack 2 Unlimited - No Limit
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class CorsConfig extends JpaRepositoryConfig {
|
static class CorsConfig extends JpaRepositoryConfig {
|
||||||
@@ -81,7 +81,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesSelectiveDefaultCorsConfiguration() throws Exception {
|
void appliesSelectiveDefaultCorsConfiguration() throws Exception {
|
||||||
|
|
||||||
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesGlobalCorsConfiguration() throws Exception {
|
void appliesGlobalCorsConfiguration() throws Exception {
|
||||||
|
|
||||||
Link findBooks = client.discoverUnique(LinkRelation.of("books"));
|
Link findBooks = client.discoverUnique(LinkRelation.of("books"));
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
* @see BooksXmlController
|
* @see BooksXmlController
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesCorsConfigurationOnCustomControllers() throws Exception {
|
void appliesCorsConfigurationOnCustomControllers() throws Exception {
|
||||||
|
|
||||||
// Preflight request
|
// Preflight request
|
||||||
mvc.perform(options("/books/xml/1234") //
|
mvc.perform(options("/books/xml/1234") //
|
||||||
@@ -143,7 +143,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
* @see BooksPdfController
|
* @see BooksPdfController
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesCorsConfigurationOnCustomControllerMethod() throws Exception {
|
void appliesCorsConfigurationOnCustomControllerMethod() throws Exception {
|
||||||
|
|
||||||
// Preflight request
|
// Preflight request
|
||||||
mvc.perform(options("/books/pdf/1234").header(HttpHeaders.ORIGIN, "http://far.far.example")
|
mvc.perform(options("/books/pdf/1234").header(HttpHeaders.ORIGIN, "http://far.far.example")
|
||||||
@@ -156,7 +156,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesCorsConfigurationOnRepository() throws Exception {
|
void appliesCorsConfigurationOnRepository() throws Exception {
|
||||||
|
|
||||||
Link authorsLink = client.discoverUnique(LinkRelation.of("authors"));
|
Link authorsLink = client.discoverUnique(LinkRelation.of("authors"));
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception {
|
void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception {
|
||||||
|
|
||||||
// Preflight request
|
// Preflight request
|
||||||
mvc.perform(options("/authors/pdf/1234").header(HttpHeaders.ORIGIN, "http://not.so.far.example")
|
mvc.perform(options("/authors/pdf/1234").header(HttpHeaders.ORIGIN, "http://not.so.far.example")
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -46,7 +45,7 @@ import org.springframework.http.HttpHeaders;
|
|||||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
@@ -61,9 +60,9 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class DataRest262Tests {
|
class DataRest262Tests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ RepositoryRestMvcConfiguration.class, JpaInfrastructureConfig.class })
|
@Import({ RepositoryRestMvcConfiguration.class, JpaInfrastructureConfig.class })
|
||||||
@@ -78,8 +77,8 @@ public class DataRest262Tests {
|
|||||||
|
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.mapper = beanFactory //
|
this.mapper = beanFactory //
|
||||||
.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) //
|
.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) //
|
||||||
@@ -90,7 +89,7 @@ public class DataRest262Tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void deserializesNestedAssociation() throws Exception {
|
void deserializesNestedAssociation() throws Exception {
|
||||||
|
|
||||||
Airport airport = repository.save(new Airport());
|
Airport airport = repository.save(new Airport());
|
||||||
String payload = "{\"orgOrDstFlightPart\":{\"airport\":\"/api/airports/" + airport.id + "\"}}";
|
String payload = "{\"orgOrDstFlightPart\":{\"airport\":\"/api/airports/" + airport.id + "\"}}";
|
||||||
@@ -100,7 +99,7 @@ public class DataRest262Tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void serializesLinksToNestedAssociations() throws Exception {
|
void serializesLinksToNestedAssociations() throws Exception {
|
||||||
|
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
request.addHeader(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE);
|
request.addHeader(HttpHeaders.ACCEPT, MediaTypes.HAL_JSON_VALUE);
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ import static org.hamcrest.Matchers.*;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -34,7 +33,7 @@ import org.springframework.hateoas.client.LinkDiscoverer;
|
|||||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
@@ -47,11 +46,11 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration(
|
@ContextConfiguration(
|
||||||
classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class, DataRest363Tests.Config.class })
|
classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class, DataRest363Tests.Config.class })
|
||||||
public class DataRest363Tests {
|
class DataRest363Tests {
|
||||||
|
|
||||||
private static MediaType MEDIA_TYPE = MediaType.APPLICATION_JSON;
|
private static MediaType MEDIA_TYPE = MediaType.APPLICATION_JSON;
|
||||||
|
|
||||||
@@ -78,8 +77,8 @@ public class DataRest363Tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).//
|
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).//
|
||||||
defaultRequest(get("/")).build();
|
defaultRequest(get("/")).build();
|
||||||
@@ -89,7 +88,7 @@ public class DataRest363Tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-363
|
@Test // DATAREST-363
|
||||||
public void testBasics() throws Exception {
|
void testBasics() throws Exception {
|
||||||
|
|
||||||
ResultActions frodoActions = testMvcClient.follow("/people/".concat(frodo.getId().toString()));
|
ResultActions frodoActions = testMvcClient.follow("/people/".concat(frodo.getId().toString()));
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -50,7 +50,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ RepositoryRestMvcConfiguration.class, JpaRepositoryConfig.class })
|
@Import({ RepositoryRestMvcConfiguration.class, JpaRepositoryConfig.class })
|
||||||
@@ -87,14 +87,14 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
|||||||
@Autowired ApplicationContext context;
|
@Autowired ApplicationContext context;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
loader.populateRepositories();
|
loader.populateRepositories();
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void executesSearchThatTakesAMappedSortProperty() throws Exception {
|
void executesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||||
|
|
||||||
Link findBySortedLink = client.discoverUnique(LinkRelation.of("books"), IanaLinkRelations.SEARCH,
|
Link findBySortedLink = client.discoverUnique(LinkRelation.of("books"), IanaLinkRelations.SEARCH,
|
||||||
LinkRelation.of("find-spring-books-sorted"));
|
LinkRelation.of("find-spring-books-sorted"));
|
||||||
@@ -114,7 +114,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void shouldApplyDefaultPageable() throws Exception {
|
void shouldApplyDefaultPageable() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/books/default-pageable"))//
|
mvc.perform(get("/books/default-pageable"))//
|
||||||
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
||||||
@@ -122,7 +122,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void shouldOverrideDefaultPageable() throws Exception {
|
void shouldOverrideDefaultPageable() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/books/default-pageable?size=10"))//
|
mvc.perform(get("/books/default-pageable?size=10"))//
|
||||||
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class JpaInfrastructureConfig {
|
class JpaInfrastructureConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource dataSource() {
|
public DataSource dataSource() {
|
||||||
|
|||||||
@@ -15,10 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc.jpa;
|
package org.springframework.data.rest.webmvc.jpa;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.springframework.data.rest.webmvc.util.TestUtils.*;
|
import static org.springframework.data.rest.webmvc.util.TestUtils.*;
|
||||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
|
||||||
import static org.springframework.http.HttpHeaders.*;
|
import static org.springframework.http.HttpHeaders.*;
|
||||||
@@ -33,8 +32,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
@@ -123,7 +122,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#setUp()
|
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#setUp()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
loader.populateRepositories();
|
loader.populateRepositories();
|
||||||
super.setUp();
|
super.setUp();
|
||||||
@@ -162,7 +161,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-99
|
@Test // DATAREST-99
|
||||||
public void doesNotExposeCreditCardRepository() throws Exception {
|
void doesNotExposeCreditCardRepository() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/")). //
|
mvc.perform(get("/")). //
|
||||||
andExpect(status().isOk()). //
|
andExpect(status().isOk()). //
|
||||||
@@ -170,7 +169,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void accessPersons() throws Exception {
|
void accessPersons() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request("/people?page=0&size=1");
|
MockHttpServletResponse response = client.request("/people?page=0&size=1");
|
||||||
|
|
||||||
@@ -187,7 +186,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-169
|
@Test // DATAREST-169
|
||||||
public void exposesLinkForRelatedResource() throws Exception {
|
void exposesLinkForRelatedResource() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request("/");
|
MockHttpServletResponse response = client.request("/");
|
||||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||||
@@ -199,7 +198,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-200
|
@Test // DATAREST-200
|
||||||
public void exposesInlinedEntities() throws Exception {
|
void exposesInlinedEntities() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request("/");
|
MockHttpServletResponse response = client.request("/");
|
||||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||||
@@ -209,7 +208,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-199
|
@Test // DATAREST-199
|
||||||
public void createsOrderUsingPut() throws Exception {
|
void createsOrderUsingPut() throws Exception {
|
||||||
|
|
||||||
mvc.perform(//
|
mvc.perform(//
|
||||||
put("/orders/{id}", 4711).//
|
put("/orders/{id}", 4711).//
|
||||||
@@ -218,7 +217,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-117
|
@Test // DATAREST-117
|
||||||
public void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception {
|
void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
@@ -238,7 +237,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-95
|
@Test // DATAREST-95
|
||||||
public void createThenPatch() throws Exception {
|
void createThenPatch() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
|
|
||||||
@@ -262,7 +261,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-150
|
@Test // DATAREST-150
|
||||||
public void createThenPut() throws Exception {
|
void createThenPut() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
|
|
||||||
@@ -272,29 +271,29 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
|
|
||||||
Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo);
|
Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo);
|
||||||
|
|
||||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), equalTo("Bilbo"));
|
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName")).isEqualTo("Bilbo");
|
||||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), equalTo("Baggins"));
|
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
|
||||||
|
|
||||||
MockHttpServletResponse frodo = putAndGet(bilboLink, //
|
MockHttpServletResponse frodo = putAndGet(bilboLink, //
|
||||||
"{ \"firstName\" : \"Frodo\" }", //
|
"{ \"firstName\" : \"Frodo\" }", //
|
||||||
MediaType.APPLICATION_JSON);
|
MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), equalTo("Frodo"));
|
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName")).isEqualTo("Frodo");
|
||||||
assertNull(JsonPath.read(frodo.getContentAsString(), "$.lastName"));
|
assertThat(JsonPath.<Object> read(frodo.getContentAsString(), "$.lastName")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listsSiblingsWithContentCorrectly() throws Exception {
|
void listsSiblingsWithContentCorrectly() throws Exception {
|
||||||
assertPersonWithNameAndSiblingLink("John");
|
assertPersonWithNameAndSiblingLink("John");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listsEmptySiblingsCorrectly() throws Exception {
|
void listsEmptySiblingsCorrectly() throws Exception {
|
||||||
assertPersonWithNameAndSiblingLink("Billy Bob");
|
assertPersonWithNameAndSiblingLink("Billy Bob");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-219
|
@Test // DATAREST-219
|
||||||
public void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception {
|
void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"), //
|
new Person("Bilbo", "Baggins"), //
|
||||||
@@ -311,7 +310,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-219
|
@Test // DATAREST-219
|
||||||
public void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception {
|
void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"), //
|
new Person("Bilbo", "Baggins"), //
|
||||||
@@ -326,7 +325,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-219
|
@Test // DATAREST-219
|
||||||
public void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception {
|
void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"), //
|
new Person("Bilbo", "Baggins"), //
|
||||||
@@ -345,7 +344,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-219
|
@Test // DATAREST-219
|
||||||
public void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception {
|
void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"), //
|
new Person("Bilbo", "Baggins"), //
|
||||||
@@ -369,7 +368,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
* checks for its first name. Than it sets Pippin Baggins as creator of the Order. Check for first name is done again.
|
* checks for its first name. Than it sets Pippin Baggins as creator of the Order. Check for first name is done again.
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-1356
|
@Test // DATAREST-1356
|
||||||
public void associateCreatorToOrderWithSinglePut() throws Exception {
|
void associateCreatorToOrderWithSinglePut() throws Exception {
|
||||||
|
|
||||||
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
||||||
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
||||||
@@ -387,7 +386,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
* will contain "send only 1 link" substring.
|
* will contain "send only 1 link" substring.
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-1356
|
@Test // DATAREST-1356
|
||||||
public void associateTwoCreatorsToOrderWithSinglePut() throws Exception {
|
void associateTwoCreatorsToOrderWithSinglePut() throws Exception {
|
||||||
|
|
||||||
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
||||||
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
||||||
@@ -399,7 +398,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-219
|
@Test // DATAREST-219
|
||||||
public void manipulatePropertyCollectionRestfullyWithDelete() throws Exception {
|
void manipulatePropertyCollectionRestfullyWithDelete() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"), //
|
new Person("Bilbo", "Baggins"), //
|
||||||
@@ -419,7 +418,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-50
|
@Test // DATAREST-50
|
||||||
public void propertiesCanHaveNulls() throws Exception {
|
void propertiesCanHaveNulls() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
|
|
||||||
@@ -436,7 +435,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-238
|
@Test // DATAREST-238
|
||||||
public void putShouldWorkDespiteExistingLinks() throws Exception {
|
void putShouldWorkDespiteExistingLinks() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
|
|
||||||
@@ -458,7 +457,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception {
|
void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||||
|
|
||||||
@@ -467,7 +466,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-217
|
@Test // DATAREST-217
|
||||||
public void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception {
|
void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||||
|
|
||||||
@@ -481,7 +480,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
* @see OrderSummary
|
* @see OrderSummary
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void returnsProjectionIfRequested() throws Exception {
|
void returnsProjectionIfRequested() throws Exception {
|
||||||
|
|
||||||
Link orders = client.discoverUnique(LinkRelation.of("orders"));
|
Link orders = client.discoverUnique(LinkRelation.of("orders"));
|
||||||
|
|
||||||
@@ -500,12 +499,12 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-261
|
@Test // DATAREST-261
|
||||||
public void relProviderDetectsCustomizedMapping() {
|
void relProviderDetectsCustomizedMapping() {
|
||||||
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo(LinkRelation.of("people"));
|
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo(LinkRelation.of("people"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-311
|
@Test // DATAREST-311
|
||||||
public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
|
void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||||
Person daenerys = new Person("Daenerys", "Targaryen");
|
Person daenerys = new Person("Daenerys", "Targaryen");
|
||||||
@@ -531,7 +530,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-317
|
@Test // DATAREST-317
|
||||||
public void rendersExcerptProjectionsCorrectly() throws Exception {
|
void rendersExcerptProjectionsCorrectly() throws Exception {
|
||||||
|
|
||||||
Link authorsLink = client.discoverUnique("authors");
|
Link authorsLink = client.discoverUnique("authors");
|
||||||
|
|
||||||
@@ -554,7 +553,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-353
|
@Test // DATAREST-353
|
||||||
public void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
|
void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
|
||||||
|
|
||||||
Link receiptsLink = client.discoverUnique("receipts");
|
Link receiptsLink = client.discoverUnique("receipts");
|
||||||
|
|
||||||
@@ -563,7 +562,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-384
|
@Test // DATAREST-384
|
||||||
public void exectuesSearchThatTakesASort() throws Exception {
|
void exectuesSearchThatTakesASort() throws Exception {
|
||||||
|
|
||||||
Link booksLink = client.discoverUnique("books");
|
Link booksLink = client.discoverUnique("books");
|
||||||
Link searchLink = client.discoverUnique(booksLink, "search");
|
Link searchLink = client.discoverUnique(booksLink, "search");
|
||||||
@@ -586,7 +585,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-160
|
@Test // DATAREST-160
|
||||||
public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||||
|
|
||||||
Link receiptLink = client.discoverUnique("receipts");
|
Link receiptLink = client.discoverUnique("receipts");
|
||||||
|
|
||||||
@@ -613,7 +612,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-423
|
@Test // DATAREST-423
|
||||||
public void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception {
|
void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse authorsResponse = client.request(client.discoverUnique("authors"));
|
MockHttpServletResponse authorsResponse = client.request(client.discoverUnique("authors"));
|
||||||
|
|
||||||
@@ -624,7 +623,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-523
|
@Test // DATAREST-523
|
||||||
public void augmentsCollectionAssociationUsingPost() throws Exception {
|
void augmentsCollectionAssociationUsingPost() throws Exception {
|
||||||
|
|
||||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||||
new Person("Bilbo", "Baggins"));
|
new Person("Bilbo", "Baggins"));
|
||||||
@@ -645,7 +644,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-658
|
@Test // DATAREST-658
|
||||||
public void returnsLinkHeadersForHeadRequestToItemResource() throws Exception {
|
void returnsLinkHeadersForHeadRequestToItemResource() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people")));
|
MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people")));
|
||||||
String personHref = JsonPath.read(response.getContentAsString(), "$._embedded.people[0]._links.self.href");
|
String personHref = JsonPath.read(response.getContentAsString(), "$._embedded.people[0]._links.self.href");
|
||||||
@@ -660,7 +659,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-883
|
@Test // DATAREST-883
|
||||||
public void exectuesSearchThatTakesAMappedSortProperty() throws Exception {
|
void exectuesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||||
|
|
||||||
Link findBySortedLink = client.discoverUnique("books", "search", "find-by-sorted");
|
Link findBySortedLink = client.discoverUnique("books", "search", "find-by-sorted");
|
||||||
|
|
||||||
@@ -681,7 +680,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-883
|
@Test // DATAREST-883
|
||||||
public void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception {
|
void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception {
|
||||||
|
|
||||||
Link findByLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
|
Link findByLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
|
||||||
|
|
||||||
@@ -701,14 +700,14 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-910
|
@Test // DATAREST-910
|
||||||
public void callUnmappedCustomRepositoryController() throws Exception {
|
void callUnmappedCustomRepositoryController() throws Exception {
|
||||||
|
|
||||||
mvc.perform(post("/orders/search/sort")).andExpect(status().isOk());
|
mvc.perform(post("/orders/search/sort")).andExpect(status().isOk());
|
||||||
mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk());
|
mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-976
|
@Test // DATAREST-976
|
||||||
public void appliesSortByEmbeddedAssociation() throws Exception {
|
void appliesSortByEmbeddedAssociation() throws Exception {
|
||||||
|
|
||||||
Link booksLink = client.discoverUnique("books");
|
Link booksLink = client.discoverUnique("books");
|
||||||
Link searchLink = client.discoverUnique(booksLink, "search");
|
Link searchLink = client.discoverUnique(booksLink, "search");
|
||||||
@@ -731,7 +730,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1213
|
@Test // DATAREST-1213
|
||||||
public void createThenPatchWithProjection() throws Exception {
|
void createThenPatchWithProjection() throws Exception {
|
||||||
|
|
||||||
Link link = createCategory();
|
Link link = createCategory();
|
||||||
String payload = "{ \"name\" : \"patched\" }";
|
String payload = "{ \"name\" : \"patched\" }";
|
||||||
@@ -744,7 +743,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1213
|
@Test // DATAREST-1213
|
||||||
public void createThenPutWithProjection() throws Exception {
|
void createThenPutWithProjection() throws Exception {
|
||||||
|
|
||||||
Link link = createCategory();
|
Link link = createCategory();
|
||||||
String payload = "{ \"name\" : \"put\" }";
|
String payload = "{ \"name\" : \"put\" }";
|
||||||
@@ -757,7 +756,7 @@ public class JpaWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1991
|
@Test // #1991
|
||||||
public void answersToHalFormsRequests() throws Exception {
|
void answersToHalFormsRequests() throws Exception {
|
||||||
|
|
||||||
mvc.perform(get("/")
|
mvc.perform(get("/")
|
||||||
.accept(MediaTypes.HAL_FORMS_JSON))
|
.accept(MediaTypes.HAL_FORMS_JSON))
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
|
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
|
||||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @soundtrack RFLKTD - Liquid Crystals
|
* @soundtrack RFLKTD - Liquid Crystals
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests {
|
class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
static class CorsConfig extends JpaRepositoryConfig {
|
static class CorsConfig extends JpaRepositoryConfig {
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests
|
|||||||
* @see ItemRepository
|
* @see ItemRepository
|
||||||
*/
|
*/
|
||||||
@Test // DATAREST-1397
|
@Test // DATAREST-1397
|
||||||
public void appliesRepositoryCorsConfiguration() throws Exception {
|
void appliesRepositoryCorsConfiguration() throws Exception {
|
||||||
|
|
||||||
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -49,7 +49,7 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
*/
|
*/
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, ProfileIntegrationTests.Config.class })
|
@ContextConfiguration(classes = { JpaRepositoryConfig.class, ProfileIntegrationTests.Config.class })
|
||||||
public class ProfileIntegrationTests extends AbstractControllerIntegrationTests {
|
class ProfileIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired WebApplicationContext context;
|
@Autowired WebApplicationContext context;
|
||||||
@Autowired LinkDiscoverers discoverers;
|
@Autowired LinkDiscoverers discoverers;
|
||||||
@@ -67,15 +67,15 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
|||||||
|
|
||||||
TestMvcClient client;
|
TestMvcClient client;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
this.client = new TestMvcClient(mvc, this.discoverers);
|
this.client = new TestMvcClient(mvc, this.discoverers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-230, DATAREST-638
|
@Test // DATAREST-230, DATAREST-638
|
||||||
public void exposesProfileLink() throws Exception {
|
void exposesProfileLink() throws Exception {
|
||||||
|
|
||||||
client.follow(ROOT_URI)//
|
client.follow(ROOT_URI)//
|
||||||
.andExpect(status().is2xxSuccessful())//
|
.andExpect(status().is2xxSuccessful())//
|
||||||
@@ -83,7 +83,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-230, DATAREST-638
|
@Test // DATAREST-230, DATAREST-638
|
||||||
public void profileRootLinkContainsMetadataForEachRepo() throws Exception {
|
void profileRootLinkContainsMetadataForEachRepo() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique(Link.of(ROOT_URI), ProfileResourceProcessor.PROFILE_REL);
|
Link profileLink = client.discoverUnique(Link.of(ROOT_URI), ProfileResourceProcessor.PROFILE_REL);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-638
|
@Test // DATAREST-638
|
||||||
public void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception {
|
void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception {
|
||||||
|
|
||||||
Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people");
|
Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people");
|
||||||
Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL);
|
Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import javax.persistence.Id;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class SimulatedGroovyDomainClass implements GroovyObject {
|
class SimulatedGroovyDomainClass implements GroovyObject {
|
||||||
|
|
||||||
private @Id @GeneratedValue Long id;
|
private @Id @GeneratedValue Long id;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -38,7 +38,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
package org.springframework.data.rest.webmvc.jpa.groovy;
|
package org.springframework.data.rest.webmvc.jpa.groovy;
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.rest.webmvc.jpa.groovy.SimulatedGroovyDomainClass;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulates a repository built on a Groovy domain object.
|
* Simulates a repository built on a Groovy domain object.
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
@@ -36,7 +36,7 @@ import org.springframework.data.rest.webmvc.jpa.Person;
|
|||||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -46,10 +46,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class })
|
@ContextConfiguration(classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class })
|
||||||
@Transactional
|
@Transactional
|
||||||
public class Jackson2DatatypeHelperIntegrationTests {
|
class Jackson2DatatypeHelperIntegrationTests {
|
||||||
|
|
||||||
@Autowired PersistentEntities entities;
|
@Autowired PersistentEntities entities;
|
||||||
@Autowired ApplicationContext context;
|
@Autowired ApplicationContext context;
|
||||||
@@ -62,8 +62,8 @@ public class Jackson2DatatypeHelperIntegrationTests {
|
|||||||
|
|
||||||
Order order;
|
Order order;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews"))));
|
this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews"))));
|
||||||
this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class)
|
this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class)
|
||||||
@@ -75,7 +75,7 @@ public class Jackson2DatatypeHelperIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-500
|
@Test // DATAREST-500
|
||||||
public void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception {
|
void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception {
|
||||||
|
|
||||||
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(Order.class);
|
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(Order.class);
|
||||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("creator");
|
PersistentProperty<?> property = entity.getRequiredPersistentProperty("creator");
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import java.io.StringWriter;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -48,7 +48,7 @@ import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
|||||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletWebRequest;
|
import org.springframework.web.context.request.ServletWebRequest;
|
||||||
@@ -65,10 +65,10 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Alex Leigh
|
* @author Alex Leigh
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, PersistentEntitySerializationTests.TestConfig.class })
|
@ContextConfiguration(classes = { JpaRepositoryConfig.class, PersistentEntitySerializationTests.TestConfig.class })
|
||||||
@Transactional
|
@Transactional
|
||||||
public class PersistentEntitySerializationTests {
|
class PersistentEntitySerializationTests {
|
||||||
|
|
||||||
private static final String PERSON_JSON_IN = "{\"firstName\": \"John\",\"lastName\": \"Doe\"}";
|
private static final String PERSON_JSON_IN = "{\"firstName\": \"John\",\"lastName\": \"Doe\"}";
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ public class PersistentEntitySerializationTests {
|
|||||||
LinkDiscoverer discoverer;
|
LinkDiscoverer discoverer;
|
||||||
ProjectionFactory projectionFactory;
|
ProjectionFactory projectionFactory;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deserializesPersonEntity() throws IOException {
|
void deserializesPersonEntity() throws IOException {
|
||||||
|
|
||||||
Person p = mapper.readValue(PERSON_JSON_IN, Person.class);
|
Person p = mapper.readValue(PERSON_JSON_IN, Person.class);
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-238
|
@Test // DATAREST-238
|
||||||
public void deserializePersonWithLinks() throws IOException {
|
void deserializePersonWithLinks() throws IOException {
|
||||||
|
|
||||||
String bilbo = "{\n" + " \"_links\" : {\n" + " \"self\" : {\n"
|
String bilbo = "{\n" + " \"_links\" : {\n" + " \"self\" : {\n"
|
||||||
+ " \"href\" : \"http://localhost/people/4\"\n" + " },\n" + " \"siblings\" : {\n"
|
+ " \"href\" : \"http://localhost/people/4\"\n" + " },\n" + " \"siblings\" : {\n"
|
||||||
@@ -129,7 +129,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-238
|
@Test // DATAREST-238
|
||||||
public void serializesPersonEntity() throws IOException, InterruptedException {
|
void serializesPersonEntity() throws IOException, InterruptedException {
|
||||||
|
|
||||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(Person.class);
|
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(Person.class);
|
||||||
Person person = people.save(new Person("John", "Doe"));
|
Person person = people.save(new Person("John", "Doe"));
|
||||||
@@ -154,7 +154,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-248
|
@Test // DATAREST-248
|
||||||
public void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception {
|
void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception {
|
||||||
|
|
||||||
Person father = people.save(new Person("John", "Doe"));
|
Person father = people.save(new Person("John", "Doe"));
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-248
|
@Test // DATAREST-248
|
||||||
public void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception {
|
void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception {
|
||||||
|
|
||||||
Person firstSibling = people.save(new Person("John", "Doe"));
|
Person firstSibling = people.save(new Person("John", "Doe"));
|
||||||
Person secondSibling = people.save(new Person("Dave", "Doe"));
|
Person secondSibling = people.save(new Person("Dave", "Doe"));
|
||||||
@@ -178,7 +178,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-248
|
@Test // DATAREST-248
|
||||||
public void deserializesEmbeddedAssociationsCorrectly() throws Exception {
|
void deserializesEmbeddedAssociationsCorrectly() throws Exception {
|
||||||
|
|
||||||
String content = TestUtils.readFileFromClasspath("order.json");
|
String content = TestUtils.readFileFromClasspath("order.json");
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-250
|
@Test // DATAREST-250
|
||||||
public void serializesReferencesWithinPagedResourceCorrectly() throws Exception {
|
void serializesReferencesWithinPagedResourceCorrectly() throws Exception {
|
||||||
|
|
||||||
Person creator = new Person("Dave", "Matthews");
|
Person creator = new Person("Dave", "Matthews");
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-521
|
@Test // DATAREST-521
|
||||||
public void serializesLinksForExcerpts() throws Exception {
|
void serializesLinksForExcerpts() throws Exception {
|
||||||
|
|
||||||
Person dave = new Person("Dave", "Matthews");
|
Person dave = new Person("Dave", "Matthews");
|
||||||
dave.setId(1L);
|
dave.setId(1L);
|
||||||
@@ -232,7 +232,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-521
|
@Test // DATAREST-521
|
||||||
public void rendersAdditionalLinksRegisteredWithResource() throws Exception {
|
void rendersAdditionalLinksRegisteredWithResource() throws Exception {
|
||||||
|
|
||||||
Person dave = new Person("Dave", "Matthews");
|
Person dave = new Person("Dave", "Matthews");
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-697
|
@Test // DATAREST-697
|
||||||
public void rendersProjectionWithinSimpleResourceCorrectly() throws Exception {
|
void rendersProjectionWithinSimpleResourceCorrectly() throws Exception {
|
||||||
|
|
||||||
Person person = new Person("Dave", "Matthews");
|
Person person = new Person("Dave", "Matthews");
|
||||||
person.setId(1L);
|
person.setId(1L);
|
||||||
@@ -262,7 +262,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-880
|
@Test // DATAREST-880
|
||||||
public void unwrapsNestedTypeCorrectly() throws Exception {
|
void unwrapsNestedTypeCorrectly() throws Exception {
|
||||||
|
|
||||||
CreditCard creditCard = new CreditCard(new CreditCard.CCN("1234123412341234"));
|
CreditCard creditCard = new CreditCard(new CreditCard.CCN("1234123412341234"));
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-872
|
@Test // DATAREST-872
|
||||||
public void serializesInheritance() throws Exception {
|
void serializesInheritance() throws Exception {
|
||||||
|
|
||||||
Suite suite = new Suite();
|
Suite suite = new Suite();
|
||||||
suite.setSuiteCode("Suite 42");
|
suite.setSuiteCode("Suite 42");
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class RepositoryTestsConfig {
|
class RepositoryTestsConfig {
|
||||||
|
|
||||||
@Autowired ApplicationContext appCtx;
|
@Autowired ApplicationContext appCtx;
|
||||||
@Autowired(required = false) List<MappingContext<?, ?>> mappingContexts = Collections.emptyList();
|
@Autowired(required = false) List<MappingContext<?, ?>> mappingContexts = Collections.emptyList();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||||
@@ -38,13 +38,13 @@ import org.springframework.web.context.request.ServletWebRequest;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
public class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests
|
class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests
|
||||||
extends AbstractControllerIntegrationTests {
|
extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired BackendIdHandlerMethodArgumentResolver resolver;
|
@Autowired BackendIdHandlerMethodArgumentResolver resolver;
|
||||||
|
|
||||||
@Test // DATAREST-155
|
@Test // DATAREST-155
|
||||||
public void translatesUriToBackendId() throws Exception {
|
void translatesUriToBackendId() throws Exception {
|
||||||
|
|
||||||
Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class);
|
Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class);
|
||||||
MethodParameter parameter = new MethodParameter(method, 0);
|
MethodParameter parameter = new MethodParameter(method, 0);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc.support;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
@@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests {
|
class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import(JpaRepositoryConfig.class)
|
@Import(JpaRepositoryConfig.class)
|
||||||
@@ -63,7 +63,7 @@ public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception {
|
void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique("addresses");
|
Link link = client.discoverUnique("addresses");
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.support;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -40,13 +40,13 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||||
public class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired RepositoryRestConfiguration configuration;
|
@Autowired RepositoryRestConfiguration configuration;
|
||||||
@Autowired RepositoryEntityLinks entityLinks;
|
@Autowired RepositoryEntityLinks entityLinks;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnsLinkToSingleResource() {
|
void returnsLinkToSingleResource() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToItemResource(Person.class, 1);
|
Link link = entityLinks.linkToItemResource(Person.class, 1);
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnsTemplatedLinkForPagingResource() {
|
void returnsTemplatedLinkForPagingResource() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToCollectionResource(Person.class);
|
Link link = entityLinks.linkToCollectionResource(Person.class);
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
|
void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToItemResource(Order.class, 1);
|
Link link = entityLinks.linkToItemResource(Order.class, 1);
|
||||||
|
|
||||||
@@ -74,14 +74,14 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-155
|
@Test // DATAREST-155
|
||||||
public void usesCustomGeneratedBackendId() {
|
void usesCustomGeneratedBackendId() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToItemResource(Book.class, 7L);
|
Link link = entityLinks.linkToItemResource(Book.class, 7L);
|
||||||
assertThat(link.expand().getHref()).endsWith("/7-7-7-7-7-7-7");
|
assertThat(link.expand().getHref()).endsWith("/7-7-7-7-7-7-7");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-317
|
@Test // DATAREST-317
|
||||||
public void adaptsToExistingPageable() {
|
void adaptsToExistingPageable() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToPagedResource(Person.class, PageRequest.of(0, 10));
|
Link link = entityLinks.linkToPagedResource(Person.class, PageRequest.of(0, 10));
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void returnsLinksToSearchResources() {
|
void returnsLinksToSearchResources() {
|
||||||
|
|
||||||
Links links = entityLinks.linksToSearchResources(Person.class);
|
Links links = entityLinks.linksToSearchResources(Person.class);
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void returnsLinkToSearchResource() {
|
void returnsLinkToSearchResource() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"));
|
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"));
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467, DATAREST-519
|
@Test // DATAREST-467, DATAREST-519
|
||||||
public void prepopulatesPaginationInformationForSearchResourceLink() {
|
void prepopulatesPaginationInformationForSearchResourceLink() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"), PageRequest.of(0, 10));
|
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"), PageRequest.of(0, 10));
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void returnsTemplatedLinkForSortedSearchResource() {
|
void returnsTemplatedLinkForSortedSearchResource() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"));
|
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"));
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467, DATAREST-519
|
@Test // DATAREST-467, DATAREST-519
|
||||||
public void prepopulatesSortInformationForSearchResourceLink() {
|
void prepopulatesSortInformationForSearchResourceLink() {
|
||||||
|
|
||||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"), Sort.by("firstname"));
|
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"), Sort.by("firstname"));
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-668, DATAREST-519, DATAREST-467
|
@Test // DATAREST-668, DATAREST-519, DATAREST-467
|
||||||
public void addsProjectVariableToSearchResourceIfAvailable() {
|
void addsProjectVariableToSearchResourceIfAvailable() {
|
||||||
|
|
||||||
for (Link link : entityLinks.linksToSearchResources(Book.class)) {
|
for (Link link : entityLinks.linksToSearchResources(Book.class)) {
|
||||||
assertThat(link.getVariableNames()).contains("projection");
|
assertThat(link.getVariableNames()).contains("projection");
|
||||||
@@ -158,7 +158,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1980
|
@Test // #1980
|
||||||
public void considersIdConverterInLinkForItemResource() {
|
void considersIdConverterInLinkForItemResource() {
|
||||||
|
|
||||||
Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel();
|
Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel();
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ import java.util.Map;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.assertj.core.api.Condition;
|
import org.assertj.core.api.Condition;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.tests.CommonWebTests;
|
import org.springframework.data.rest.tests.CommonWebTests;
|
||||||
import org.springframework.data.rest.tests.TestMatchers;
|
import org.springframework.data.rest.tests.TestMatchers;
|
||||||
@@ -62,7 +62,7 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = MongoDbRepositoryConfig.class)
|
@ContextConfiguration(classes = MongoDbRepositoryConfig.class)
|
||||||
public class MongoWebTests extends CommonWebTests {
|
class MongoWebTests extends CommonWebTests {
|
||||||
|
|
||||||
private static final MediaType TEXT_URI_LIST = MediaType.parseMediaType("text/uri-list");
|
private static final MediaType TEXT_URI_LIST = MediaType.parseMediaType("text/uri-list");
|
||||||
|
|
||||||
@@ -72,8 +72,8 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void populateProfiles() {
|
void populateProfiles() {
|
||||||
|
|
||||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||||
|
|
||||||
@@ -122,8 +122,8 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void cleanUp() {
|
void cleanUp() {
|
||||||
repository.deleteAll();
|
repository.deleteAll();
|
||||||
userRepository.deleteAll();
|
userRepository.deleteAll();
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void foo() throws Exception {
|
void foo() throws Exception {
|
||||||
|
|
||||||
Link profileLink = client.discoverUnique("profiles");
|
Link profileLink = client.discoverUnique("profiles");
|
||||||
client.follow(profileLink).//
|
client.follow(profileLink).//
|
||||||
@@ -146,7 +146,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rendersEmbeddedDocuments() throws Exception {
|
void rendersEmbeddedDocuments() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -155,7 +155,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-247
|
@Test // DATAREST-247
|
||||||
public void executeQueryMethodWithPrimitiveReturnType() throws Exception {
|
void executeQueryMethodWithPrimitiveReturnType() throws Exception {
|
||||||
|
|
||||||
Link profiles = client.discoverUnique("profiles");
|
Link profiles = client.discoverUnique("profiles");
|
||||||
Link profileSearches = client.discoverUnique(profiles, "search");
|
Link profileSearches = client.discoverUnique(profiles, "search");
|
||||||
@@ -169,7 +169,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testname() throws Exception {
|
void testname() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -183,7 +183,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testname2() throws Exception {
|
void testname2() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -199,7 +199,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-160
|
@Test // DATAREST-160
|
||||||
public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||||
|
|
||||||
Link receiptLink = client.discoverUnique("receipts");
|
Link receiptLink = client.discoverUnique("receipts");
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-471
|
@Test // DATAREST-471
|
||||||
public void auditableResourceHasLastModifiedHeaderSet() throws Exception {
|
void auditableResourceHasLastModifiedHeaderSet() throws Exception {
|
||||||
|
|
||||||
Profile profile = repository.findAll().iterator().next();
|
Profile profile = repository.findAll().iterator().next();
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-482
|
@Test // DATAREST-482
|
||||||
public void putDoesNotRemoveAssociations() throws Exception {
|
void putDoesNotRemoveAssociations() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -260,7 +260,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-482
|
@Test // DATAREST-482
|
||||||
public void emptiesAssociationForEmptyUriList() throws Exception {
|
void emptiesAssociationForEmptyUriList() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -274,7 +274,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-491
|
@Test // DATAREST-491
|
||||||
public void updatesMapPropertyCorrectly() throws Exception {
|
void updatesMapPropertyCorrectly() throws Exception {
|
||||||
|
|
||||||
Link profilesLink = client.discoverUnique("profiles");
|
Link profilesLink = client.discoverUnique("profiles");
|
||||||
Link profileLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(profilesLink));
|
Link profileLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(profilesLink));
|
||||||
@@ -288,7 +288,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-506
|
@Test // DATAREST-506
|
||||||
public void supportsConditionalGetsOnItemResource() throws Exception {
|
void supportsConditionalGetsOnItemResource() throws Exception {
|
||||||
|
|
||||||
Receipt receipt = new Receipt();
|
Receipt receipt = new Receipt();
|
||||||
receipt.amount = new BigDecimal(50);
|
receipt.amount = new BigDecimal(50);
|
||||||
@@ -313,7 +313,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-511
|
@Test // DATAREST-511
|
||||||
public void invokesQueryResourceReturningAnOptional() throws Exception {
|
void invokesQueryResourceReturningAnOptional() throws Exception {
|
||||||
|
|
||||||
Profile profile = repository.findAll().iterator().next();
|
Profile profile = repository.findAll().iterator().next();
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-517
|
@Test // DATAREST-517
|
||||||
public void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception {
|
void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-712
|
@Test // DATAREST-712
|
||||||
public void invokesQueryMethodTakingAReferenceCorrectly() throws Exception {
|
void invokesQueryMethodTakingAReferenceCorrectly() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique("users", "search", "findByColleaguesContains");
|
Link link = client.discoverUnique("users", "search", "findByColleaguesContains");
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
|
void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
|
void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
|
||||||
|
|
||||||
Link link = client.discoverUnique("profiles", "search", "findByType");
|
Link link = client.discoverUnique("profiles", "search", "findByType");
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1458
|
@Test // DATAREST-1458
|
||||||
public void accessCollectionAssociationResourceAsUriList() throws Exception {
|
void accessCollectionAssociationResourceAsUriList() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -383,7 +383,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1458
|
@Test // DATAREST-1458
|
||||||
public void accessAssociationResourceAsUriList() throws Exception {
|
void accessAssociationResourceAsUriList() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -395,7 +395,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1458
|
@Test // DATAREST-1458
|
||||||
public void accessMapCollectionAssociationResourceAsUriList() throws Exception {
|
void accessMapCollectionAssociationResourceAsUriList() throws Exception {
|
||||||
|
|
||||||
Link usersLink = client.discoverUnique("users");
|
Link usersLink = client.discoverUnique("users");
|
||||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||||
@@ -409,7 +409,7 @@ public class MongoWebTests extends CommonWebTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-762
|
@Test // DATAREST-762
|
||||||
public void paginatedLinksContainQuerydslPropertyReferences() throws Exception {
|
void paginatedLinksContainQuerydslPropertyReferences() throws Exception {
|
||||||
|
|
||||||
Map<String, Object> parameters = new HashMap<>();
|
Map<String, Object> parameters = new HashMap<>();
|
||||||
parameters.put("page", "0");
|
parameters.put("page", "0");
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
@@ -46,14 +46,14 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = { TestConfiguration.class, MongoDbRepositoryConfig.class })
|
@ContextConfiguration(classes = { TestConfiguration.class, MongoDbRepositoryConfig.class })
|
||||||
public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests {
|
class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired PersistentEntities entities;
|
@Autowired PersistentEntities entities;
|
||||||
@Autowired EntityLinks entityLinks;
|
@Autowired EntityLinks entityLinks;
|
||||||
@Autowired Associations associations;
|
@Autowired Associations associations;
|
||||||
|
|
||||||
@Test // DATAREST-609
|
@Test // DATAREST-609
|
||||||
public void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception {
|
void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception {
|
||||||
|
|
||||||
Projector projector = mock(Projector.class);
|
Projector projector = mock(Projector.class);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||||
import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
|
import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
|
||||||
@@ -34,12 +34,12 @@ import org.springframework.web.servlet.HandlerMapping;
|
|||||||
* @soundtrack Elephants Crossing - Echo (Irrelephant)
|
* @soundtrack Elephants Crossing - Echo (Irrelephant)
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = MongoDbRepositoryConfig.class)
|
@ContextConfiguration(classes = MongoDbRepositoryConfig.class)
|
||||||
public class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests {
|
class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests {
|
||||||
|
|
||||||
@Autowired HandlerMapping mapping;
|
@Autowired HandlerMapping mapping;
|
||||||
|
|
||||||
@Test // DATAREST-617
|
@Test // DATAREST-617
|
||||||
public void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception {
|
void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception {
|
||||||
|
|
||||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/users");
|
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/users");
|
||||||
mockRequest.addHeader("Accept", "application/*+json");
|
mockRequest.addHeader("Accept", "application/*+json");
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc.config;
|
package org.springframework.data.rest.webmvc.config;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
@@ -29,15 +29,15 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
public abstract class AbstractRepositoryRestMvcConfigurationIntegrationTests {
|
public abstract class AbstractRepositoryRestMvcConfigurationIntegrationTests {
|
||||||
|
|
||||||
@Autowired WebApplicationContext context;
|
@Autowired WebApplicationContext context;
|
||||||
protected MockMvc mvc;
|
protected MockMvc mvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,11 @@ import static org.springframework.data.rest.tests.mongodb.TestUtils.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.mapping.context.PersistentEntities;
|
import org.springframework.data.mapping.context.PersistentEntities;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
@@ -47,17 +45,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class JsonPatchHandlerUnitTests {
|
class JsonPatchHandlerUnitTests {
|
||||||
|
|
||||||
JsonPatchHandler handler;
|
JsonPatchHandler handler;
|
||||||
User user;
|
User user;
|
||||||
|
|
||||||
@Mock ResourceMappings mappings;
|
@Mock ResourceMappings mappings;
|
||||||
public @Rule ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
MongoMappingContext context = new MongoMappingContext();
|
MongoMappingContext context = new MongoMappingContext();
|
||||||
context.getPersistentEntity(User.class);
|
context.getPersistentEntity(User.class);
|
||||||
@@ -79,7 +76,7 @@ public class JsonPatchHandlerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-348
|
@Test // DATAREST-348
|
||||||
public void appliesRemoveOperationCorrectly() throws Exception {
|
void appliesRemoveOperationCorrectly() throws Exception {
|
||||||
|
|
||||||
String input = "[{ \"op\": \"replace\", \"path\": \"/address/zipCode\", \"value\": \"ZIP\" },"
|
String input = "[{ \"op\": \"replace\", \"path\": \"/address/zipCode\", \"value\": \"ZIP\" },"
|
||||||
+ "{ \"op\": \"remove\", \"path\": \"/lastname\" }]";
|
+ "{ \"op\": \"remove\", \"path\": \"/lastname\" }]";
|
||||||
@@ -91,7 +88,7 @@ public class JsonPatchHandlerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-348
|
@Test // DATAREST-348
|
||||||
public void appliesMergePatchCorrectly() throws Exception {
|
void appliesMergePatchCorrectly() throws Exception {
|
||||||
|
|
||||||
String input = "{ \"address\" : { \"zipCode\" : \"ZIP\"}, \"lastname\" : null }";
|
String input = "{ \"address\" : { \"zipCode\" : \"ZIP\"}, \"lastname\" : null }";
|
||||||
|
|
||||||
@@ -105,7 +102,7 @@ public class JsonPatchHandlerUnitTests {
|
|||||||
* DATAREST-537
|
* DATAREST-537
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void removesArrayItemCorrectly() throws Exception {
|
void removesArrayItemCorrectly() throws Exception {
|
||||||
|
|
||||||
User thomas = new User();
|
User thomas = new User();
|
||||||
thomas.firstname = "Thomas";
|
thomas.firstname = "Thomas";
|
||||||
@@ -124,11 +121,10 @@ public class JsonPatchHandlerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-609
|
@Test // DATAREST-609
|
||||||
public void hintsToMediaTypeIfBodyCantBeRead() throws Exception {
|
void hintsToMediaTypeIfBodyCantBeRead() throws Exception {
|
||||||
|
|
||||||
exception.expect(HttpMessageNotReadableException.class);
|
assertThatExceptionOfType(HttpMessageNotReadableException.class)
|
||||||
exception.expectMessage(RestMediaTypes.JSON_PATCH_JSON.toString());
|
.isThrownBy(() -> handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User()))
|
||||||
|
.withMessageContaining(RestMediaTypes.JSON_PATCH_JSON.toString());
|
||||||
handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
import org.springframework.data.querydsl.QuerydslRepositoryInvokerAdapter;
|
import org.springframework.data.querydsl.QuerydslRepositoryInvokerAdapter;
|
||||||
@@ -54,23 +54,23 @@ import com.querydsl.core.types.Predicate;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests {
|
class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests {
|
||||||
|
|
||||||
static final Map<String, String[]> NO_PARAMETERS = Collections.emptyMap();
|
static final Map<String, String[]> NO_PARAMETERS = Collections.emptyMap();
|
||||||
|
|
||||||
@Mock Repositories repositories;
|
@Mock Repositories repositories;
|
||||||
@Mock RepositoryInvokerFactory invokerFactory;
|
@Mock RepositoryInvokerFactory invokerFactory;
|
||||||
@Mock ResourceMetadataHandlerMethodArgumentResolver resourceMetadataResolver;
|
@Mock ResourceMetadataHandlerMethodArgumentResolver resourceMetadataResolver;
|
||||||
@Mock QuerydslPredicateBuilder builder;
|
@Mock(lenient = true) QuerydslPredicateBuilder builder;
|
||||||
|
|
||||||
@Mock RepositoryInvoker invoker;
|
@Mock RepositoryInvoker invoker;
|
||||||
@Mock MethodParameter parameter;
|
@Mock MethodParameter parameter;
|
||||||
|
|
||||||
QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver resolver;
|
QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver resolver;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
||||||
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
|
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
|
||||||
@@ -83,7 +83,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-616
|
@Test // DATAREST-616
|
||||||
public void returnsInvokerIfRepositoryIsNotQuerydslAware() {
|
void returnsInvokerIfRepositoryIsNotQuerydslAware() {
|
||||||
|
|
||||||
ReceiptRepository repository = mock(ReceiptRepository.class);
|
ReceiptRepository repository = mock(ReceiptRepository.class);
|
||||||
when(repositories.getRepositoryFor(Receipt.class)).thenReturn(Optional.of(repository));
|
when(repositories.getRepositoryFor(Receipt.class)).thenReturn(Optional.of(repository));
|
||||||
@@ -94,7 +94,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-616
|
@Test // DATAREST-616
|
||||||
public void wrapsInvokerInQuerydslAdapter() {
|
void wrapsInvokerInQuerydslAdapter() {
|
||||||
|
|
||||||
Object repository = mock(QuerydslUserRepository.class);
|
Object repository = mock(QuerydslUserRepository.class);
|
||||||
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
|
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
|
||||||
@@ -105,7 +105,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-616
|
@Test // DATAREST-616
|
||||||
public void invokesCustomizationOnRepositoryIfItImplementsCustomizer() {
|
void invokesCustomizationOnRepositoryIfItImplementsCustomizer() {
|
||||||
|
|
||||||
QuerydslCustomizingUserRepository repository = mock(QuerydslCustomizingUserRepository.class);
|
QuerydslCustomizingUserRepository repository = mock(QuerydslCustomizingUserRepository.class);
|
||||||
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
|
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -45,7 +45,7 @@ import org.springframework.hateoas.mediatype.MessageResolver;
|
|||||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletWebRequest;
|
import org.springframework.web.context.request.ServletWebRequest;
|
||||||
|
|
||||||
@@ -60,10 +60,10 @@ import com.jayway.jsonpath.ReadContext;
|
|||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class,
|
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class,
|
||||||
PersistentEntitySerializationTests.TestConfig.class })
|
PersistentEntitySerializationTests.TestConfig.class })
|
||||||
public class PersistentEntitySerializationTests {
|
class PersistentEntitySerializationTests {
|
||||||
|
|
||||||
@Autowired ObjectMapper mapper;
|
@Autowired ObjectMapper mapper;
|
||||||
@Autowired Repositories repositories;
|
@Autowired Repositories repositories;
|
||||||
@@ -86,8 +86,8 @@ public class PersistentEntitySerializationTests {
|
|||||||
LinkDiscoverer linkDiscoverer;
|
LinkDiscoverer linkDiscoverer;
|
||||||
ProjectionFactory projectionFactory;
|
ProjectionFactory projectionFactory;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-250
|
@Test // DATAREST-250
|
||||||
public void serializesEmbeddedReferencesCorrectly() throws Exception {
|
void serializesEmbeddedReferencesCorrectly() throws Exception {
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.address = new Address();
|
user.address = new Address();
|
||||||
@@ -116,12 +116,12 @@ public class PersistentEntitySerializationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void deserializesTranslatedEnumProperty() throws Exception {
|
void deserializesTranslatedEnumProperty() throws Exception {
|
||||||
assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender).isEqualTo(Gender.MALE);
|
assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender).isEqualTo(Gender.MALE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-864
|
@Test // DATAREST-864
|
||||||
public void createsNestedResourceForMap() throws Exception {
|
void createsNestedResourceForMap() throws Exception {
|
||||||
|
|
||||||
User dave = users.save(new User());
|
User dave = users.save(new User());
|
||||||
dave.colleaguesMap = new HashMap<String, Nested>();
|
dave.colleaguesMap = new HashMap<String, Nested>();
|
||||||
|
|||||||
@@ -15,18 +15,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc.json;
|
package org.springframework.data.rest.webmvc.json;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.junit.Before;
|
import org.hamcrest.MatcherAssert;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -48,7 +48,7 @@ import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaCon
|
|||||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||||
import org.springframework.hateoas.mediatype.MessageResolver;
|
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -59,9 +59,9 @@ import com.jayway.jsonpath.PathNotFoundException;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, TestConfiguration.class })
|
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, TestConfiguration.class })
|
||||||
public class PersistentEntityToJsonSchemaConverterUnitTests {
|
class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||||
|
|
||||||
@Autowired MessageResolver resolver;
|
@Autowired MessageResolver resolver;
|
||||||
@Autowired RepositoryRestConfiguration configuration;
|
@Autowired RepositoryRestConfiguration configuration;
|
||||||
@@ -89,8 +89,8 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
|||||||
|
|
||||||
PersistentEntityToJsonSchemaConverter converter;
|
PersistentEntityToJsonSchemaConverter converter;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
TestMvcClient.initWebTest();
|
TestMvcClient.initWebTest();
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-631, DATAREST-632
|
@Test // DATAREST-631, DATAREST-632
|
||||||
public void fulfillsConstraintsForProfile() {
|
void fulfillsConstraintsForProfile() {
|
||||||
|
|
||||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||||
constraints.add(new Constraint("$.properties.id", is(notNullValue()), "Has descriptor for id property"));
|
constraints.add(new Constraint("$.properties.id", is(notNullValue()), "Has descriptor for id property"));
|
||||||
@@ -114,7 +114,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-632
|
@Test // DATAREST-632
|
||||||
public void fulfillsConstraintsForUser() throws Exception {
|
void fulfillsConstraintsForUser() throws Exception {
|
||||||
|
|
||||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||||
constraints.add(new Constraint("$.properties.id", is(nullValue()), "Does NOT have descriptor for id property"));
|
constraints.add(new Constraint("$.properties.id", is(nullValue()), "Does NOT have descriptor for id property"));
|
||||||
@@ -166,7 +166,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-754
|
@Test // DATAREST-754
|
||||||
public void handlesGroovyDomainObjects() {
|
void handlesGroovyDomainObjects() {
|
||||||
|
|
||||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||||
constraints.add(new Constraint("$.properties.name", is(notNullValue()), "Has descriptor for name property"));
|
constraints.add(new Constraint("$.properties.name", is(notNullValue()), "Has descriptor for name property"));
|
||||||
@@ -182,11 +182,12 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
|||||||
for (Constraint constraint : constraints) {
|
for (Constraint constraint : constraints) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector), constraint.matcher);
|
MatcherAssert.assertThat(constraint.description, JsonPath.read(writeSchemaFor, constraint.selector),
|
||||||
|
constraint.matcher);
|
||||||
} catch (PathNotFoundException e) {
|
} catch (PathNotFoundException e) {
|
||||||
assertThat(constraint.matcher.matches(null)).isTrue();
|
assertThat(constraint.matcher.matches(null)).isTrue();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
assertThat(e, constraint.matcher);
|
MatcherAssert.assertThat(e, constraint.matcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.mapping.context.PersistentEntities;
|
import org.springframework.data.mapping.context.PersistentEntities;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
import org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings;
|
import org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings;
|
||||||
@@ -34,12 +34,12 @@ import org.springframework.hateoas.Link;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class RepositoryLinkBuildUnitTests {
|
class RepositoryLinkBuildUnitTests {
|
||||||
|
|
||||||
MongoMappingContext context = new MongoMappingContext();
|
MongoMappingContext context = new MongoMappingContext();
|
||||||
|
|
||||||
@Test // DATAREST-292
|
@Test // DATAREST-292
|
||||||
public void usesCurrentRequestsUriBaseForRelativeBaseUri() {
|
void usesCurrentRequestsUriBaseForRelativeBaseUri() {
|
||||||
|
|
||||||
TestMvcClient.initWebTest();
|
TestMvcClient.initWebTest();
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public class RepositoryLinkBuildUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-292, DATAREST-296
|
@Test // DATAREST-292, DATAREST-296
|
||||||
public void usesBaseUriOnlyIfItIsAbsolute() {
|
void usesBaseUriOnlyIfItIsAbsolute() {
|
||||||
assertRootUriFor("http://foobar/api", "http://foobar/api/profile");
|
assertRootUriFor("http://foobar/api", "http://foobar/api/profile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
|||||||
@Configuration // <1>
|
@Configuration // <1>
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) // <2>
|
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) // <2>
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3>
|
class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3>
|
||||||
// end::code[]
|
// end::code[]
|
||||||
@Autowired
|
@Autowired
|
||||||
public void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
|
void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser("user").password("user").roles("USER").and()
|
.withUser("user").password("user").roles("USER").and()
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import static org.springframework.security.test.web.servlet.setup.SecurityMockMv
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
import org.springframework.data.map.repository.config.EnableMapRepositories;
|
||||||
@@ -36,7 +36,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|||||||
import org.springframework.security.core.authority.AuthorityUtils;
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
@@ -48,10 +48,10 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class,
|
@ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class,
|
||||||
RepositoryRestMvcConfiguration.class })
|
RepositoryRestMvcConfiguration.class })
|
||||||
public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
@Autowired WebApplicationContext context;
|
@Autowired WebApplicationContext context;
|
||||||
@Autowired MethodSecurityInterceptor methodSecurityInterceptor;
|
@Autowired MethodSecurityInterceptor methodSecurityInterceptor;
|
||||||
@@ -63,7 +63,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
@EnableMapRepositories
|
@EnableMapRepositories
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
@Override
|
@Override
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deletePersonAccessDeniedForNoCredentials() throws Exception {
|
void deletePersonAccessDeniedForNoCredentials() throws Exception {
|
||||||
|
|
||||||
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
||||||
final String people = client.discoverUnique("people").expand().getHref();
|
final String people = client.discoverUnique("people").expand().getHref();
|
||||||
@@ -113,7 +113,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deletePersonAccessDeniedForUsers() throws Exception {
|
void deletePersonAccessDeniedForUsers() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||||
with(user("user").roles("USER"))).//
|
with(user("user").roles("USER"))).//
|
||||||
@@ -128,7 +128,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deletePersonAccessGrantedForAdmins() throws Exception {
|
void deletePersonAccessGrantedForAdmins() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||||
with(user("user").roles("USER", "ADMIN"))).//
|
with(user("user").roles("USER", "ADMIN"))).//
|
||||||
@@ -143,14 +143,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllPeopleAccessDeniedForNoCredentials() throws Throwable {
|
void findAllPeopleAccessDeniedForNoCredentials() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("people").expand().getHref())).//
|
mvc.perform(get(client.discoverUnique("people").expand().getHref())).//
|
||||||
andExpect(status().isUnauthorized());
|
andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllPeopleAccessGrantedForUsers() throws Throwable {
|
void findAllPeopleAccessGrantedForUsers() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||||
with(user("user").roles("USER"))).//
|
with(user("user").roles("USER"))).//
|
||||||
@@ -158,7 +158,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllPeopleAccessGrantedForAdmins() throws Throwable {
|
void findAllPeopleAccessGrantedForAdmins() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||||
with(user("user").roles("USER", "ADMIN"))).//
|
with(user("user").roles("USER", "ADMIN"))).//
|
||||||
@@ -166,7 +166,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deleteOrderAccessDeniedForNoCredentials() throws Exception {
|
void deleteOrderAccessDeniedForNoCredentials() throws Exception {
|
||||||
|
|
||||||
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
// Getting the collection is not tested here. This is to get the URI that will later be tested for DELETE
|
||||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||||
@@ -181,7 +181,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deleteOrderAccessDeniedForUsers() throws Exception {
|
void deleteOrderAccessDeniedForUsers() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||||
with(user("user").roles("USER"))).//
|
with(user("user").roles("USER"))).//
|
||||||
@@ -193,7 +193,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void deleteOrderAccessGrantedForAdmins() throws Exception {
|
void deleteOrderAccessGrantedForAdmins() throws Exception {
|
||||||
|
|
||||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||||
with(user("user").roles("USER"))).//
|
with(user("user").roles("USER"))).//
|
||||||
@@ -208,14 +208,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllOrdersAccessDeniedForNoCredentials() throws Throwable {
|
void findAllOrdersAccessDeniedForNoCredentials() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref())).//
|
mvc.perform(get(client.discoverUnique("orders").expand().getHref())).//
|
||||||
andExpect(status().isUnauthorized());
|
andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllOrdersAccessGrantedForUsers() throws Throwable {
|
void findAllOrdersAccessGrantedForUsers() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||||
with(user("user").roles("USER"))).//
|
with(user("user").roles("USER"))).//
|
||||||
@@ -223,7 +223,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-327
|
@Test // DATAREST-327
|
||||||
public void findAllOrdersAccessGrantedForAdmins() throws Throwable {
|
void findAllOrdersAccessGrantedForAdmins() throws Throwable {
|
||||||
|
|
||||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||||
with(user("user").roles("USER", "ADMIN"))).//
|
with(user("user").roles("USER", "ADMIN"))).//
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import org.springframework.hateoas.server.RepresentationModelProcessor;
|
|||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableMapRepositories
|
@EnableMapRepositories
|
||||||
public class ShopConfiguration {
|
class ShopConfiguration {
|
||||||
|
|
||||||
@Autowired CustomerRepository customers;
|
@Autowired CustomerRepository customers;
|
||||||
@Autowired OrderRepository orders;
|
@Autowired OrderRepository orders;
|
||||||
@@ -77,7 +77,7 @@ public class ShopConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
void init() {
|
||||||
|
|
||||||
LineItemType lineItemType = lineItemTypes.save(new LineItemType("good"));
|
LineItemType lineItemType = lineItemTypes.save(new LineItemType("good"));
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
|
||||||
import com.jayway.jsonpath.JsonPath;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
@@ -37,12 +37,12 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Craig Andrews
|
* @author Craig Andrews
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = ShopConfiguration.class)
|
@ContextConfiguration(classes = ShopConfiguration.class)
|
||||||
public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rendersRepresentationCorrectly() throws Exception {
|
void rendersRepresentationCorrectly() throws Exception {
|
||||||
|
|
||||||
Link ordersLink = client.discoverUnique("orders");
|
Link ordersLink = client.discoverUnique("orders");
|
||||||
String selfLink = JsonPath.parse(client.request(ordersLink).getContentAsString())
|
String selfLink = JsonPath.parse(client.request(ordersLink).getContentAsString())
|
||||||
@@ -63,7 +63,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void renderProductNameOnlyProjection() throws Exception {
|
void renderProductNameOnlyProjection() throws Exception {
|
||||||
|
|
||||||
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void renderProductNameOnlyProjectionResourceProcessor() throws Exception {
|
void renderProductNameOnlyProjectionResourceProcessor() throws Exception {
|
||||||
|
|
||||||
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-221
|
@Test // DATAREST-221
|
||||||
public void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception {
|
void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception {
|
||||||
|
|
||||||
Map<String, Object> arguments = Collections.singletonMap("projection", "itemsOnly");
|
Map<String, Object> arguments = Collections.singletonMap("projection", "itemsOnly");
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,13 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.springframework.data.annotation.Reference;
|
import org.springframework.data.annotation.Reference;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
@@ -47,8 +49,9 @@ import org.springframework.hateoas.Link;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Haroun Pacquee
|
* @author Haroun Pacquee
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class AssociationLinksUnitTests {
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
class AssociationLinksUnitTests {
|
||||||
|
|
||||||
Associations links;
|
Associations links;
|
||||||
|
|
||||||
@@ -60,8 +63,8 @@ public class AssociationLinksUnitTests {
|
|||||||
@Mock RepositoryRestConfiguration config;
|
@Mock RepositoryRestConfiguration config;
|
||||||
@Mock ProjectionDefinitionConfiguration projectionDefinitionConfig;
|
@Mock ProjectionDefinitionConfiguration projectionDefinitionConfig;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
doReturn(projectionDefinitionConfig).when(config).getProjectionConfiguration();
|
doReturn(projectionDefinitionConfig).when(config).getProjectionConfiguration();
|
||||||
|
|
||||||
@@ -71,18 +74,22 @@ public class AssociationLinksUnitTests {
|
|||||||
this.links = new Associations(mappings, config);
|
this.links = new Associations(mappings, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void rejectsNullMappings() {
|
void rejectsNullMappings() {
|
||||||
new Associations(null, mock(RepositoryRestConfiguration.class));
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new Associations(null, mock(RepositoryRestConfiguration.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void rejectsNullConfiguration() {
|
void rejectsNullConfiguration() {
|
||||||
new Associations(mappings, null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new Associations(mappings, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void rejectsNullPropertyForIsLinkable() {
|
void rejectsNullPropertyForIsLinkable() {
|
||||||
|
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||||
links.isLinkableAssociation((PersistentProperty<?>) null);
|
links.isLinkableAssociation((PersistentProperty<?>) null);
|
||||||
@@ -90,12 +97,12 @@ public class AssociationLinksUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void consideredHiddenPropertyUnlinkable() {
|
void consideredHiddenPropertyUnlinkable() {
|
||||||
assertThat(links.isLinkableAssociation(entity.getRequiredPersistentProperty("hiddenProperty"))).isFalse();
|
assertThat(links.isLinkableAssociation(entity.getRequiredPersistentProperty("hiddenProperty"))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void createsLinkToAssociationProperty() {
|
void createsLinkToAssociationProperty() {
|
||||||
|
|
||||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("property");
|
PersistentProperty<?> property = entity.getRequiredPersistentProperty("property");
|
||||||
List<Link> associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base"));
|
List<Link> associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base"));
|
||||||
@@ -105,14 +112,14 @@ public class AssociationLinksUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-262
|
@Test // DATAREST-262
|
||||||
public void doesNotCreateLinksForHiddenProperty() {
|
void doesNotCreateLinksForHiddenProperty() {
|
||||||
|
|
||||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("hiddenProperty");
|
PersistentProperty<?> property = entity.getRequiredPersistentProperty("hiddenProperty");
|
||||||
assertThat(links.getLinksFor(property.getRequiredAssociation(), new Path("/sample"))).hasSize(0);
|
assertThat(links.getLinksFor(property.getRequiredAssociation(), new Path("/sample"))).hasSize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void detectsLookupTypes() {
|
void detectsLookupTypes() {
|
||||||
|
|
||||||
doReturn(true).when(config).isLookupType(Property.class);
|
doReturn(true).when(config).isLookupType(Property.class);
|
||||||
|
|
||||||
@@ -120,7 +127,7 @@ public class AssociationLinksUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void delegatesResourceMetadataLookupToMappings() {
|
void delegatesResourceMetadataLookupToMappings() {
|
||||||
assertThat(links.getMetadataFor(Property.class)).isEqualTo(mappings.getMetadataFor(Property.class));
|
assertThat(links.getMetadataFor(Property.class)).isEqualTo(mappings.getMetadataFor(Property.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -39,7 +39,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
public class AugmentingHandlerMappingUnitTests {
|
class AugmentingHandlerMappingUnitTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class Config {
|
static class Config {
|
||||||
@@ -51,7 +51,7 @@ public class AugmentingHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void augmentsRequestMappingsWithBaseUriFromConfiguration() {
|
void augmentsRequestMappingsWithBaseUriFromConfiguration() {
|
||||||
|
|
||||||
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
@@ -33,12 +33,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class BasePathAwareHandlerMappingUnitTests {
|
class BasePathAwareHandlerMappingUnitTests {
|
||||||
|
|
||||||
HandlerMappingStub mapping;
|
HandlerMappingStub mapping;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class);
|
RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class);
|
||||||
doReturn(URI.create("")).when(configuration).getBasePath();
|
doReturn(URI.create("")).when(configuration).getBasePath();
|
||||||
@@ -47,7 +47,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1132
|
@Test // DATAREST-1132
|
||||||
public void detectsAnnotationsOnProxies() {
|
void detectsAnnotationsOnProxies() {
|
||||||
|
|
||||||
Class<?> type = createProxy(new SomeController());
|
Class<?> type = createProxy(new SomeController());
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1132
|
@Test // DATAREST-1132
|
||||||
public void doesNotConsiderMetaAnnotation() {
|
void doesNotConsiderMetaAnnotation() {
|
||||||
|
|
||||||
Class<?> type = createProxy(new RepositoryController());
|
Class<?> type = createProxy(new RepositoryController());
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1342, #1628, #1686, #1946
|
@Test // #1342, #1628, #1686, #1946
|
||||||
public void rejectsAtRequestMappingOnCustomController() {
|
void rejectsAtRequestMappingOnCustomController() {
|
||||||
|
|
||||||
assertThatIllegalStateException()
|
assertThatIllegalStateException()
|
||||||
.isThrownBy(() -> {
|
.isThrownBy(() -> {
|
||||||
@@ -73,7 +73,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // #1342, #1628, #1686, #1946
|
@Test // #1342, #1628, #1686, #1946
|
||||||
public void doesNotRejectAtRequestMappingOnStandardMvcController() {
|
void doesNotRejectAtRequestMappingOnStandardMvcController() {
|
||||||
|
|
||||||
assertThatNoException()
|
assertThatNoException()
|
||||||
.isThrownBy(() -> mapping.isHandler(ValidController.class));
|
.isThrownBy(() -> mapping.isHandler(ValidController.class));
|
||||||
|
|||||||
@@ -19,24 +19,24 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link BaseUri}.
|
* Unit tests for {@link BaseUri}.
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class BaseUriUnitTests {
|
class BaseUriUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void doesNotMatchNonOverlap() {
|
void doesNotMatchNonOverlap() {
|
||||||
|
|
||||||
assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar")).isNull();
|
assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar")).isNull();
|
||||||
assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar")).isNull();
|
assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void matchesSimpleBaseUri() {
|
void matchesSimpleBaseUri() {
|
||||||
|
|
||||||
BaseUri uri = new BaseUri(URI.create("foo"));
|
BaseUri uri = new BaseUri(URI.create("foo"));
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class BaseUriUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void ignoresTrailingSlash() {
|
void ignoresTrailingSlash() {
|
||||||
|
|
||||||
BaseUri uri = new BaseUri(URI.create("foo/"));
|
BaseUri uri = new BaseUri(URI.create("foo/"));
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class BaseUriUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void ignoresLeadingSlash() {
|
void ignoresLeadingSlash() {
|
||||||
|
|
||||||
BaseUri uri = new BaseUri(URI.create("/foo"));
|
BaseUri uri = new BaseUri(URI.create("/foo"));
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ public class BaseUriUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void matchesAbsoluteBaseUriOnOverlap() {
|
void matchesAbsoluteBaseUriOnOverlap() {
|
||||||
|
|
||||||
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
|
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class BaseUriUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-674, SPR-13455
|
@Test // DATAREST-674, SPR-13455
|
||||||
public void repositoryLookupPathHandlesDoubleSlashes() {
|
void repositoryLookupPathHandlesDoubleSlashes() {
|
||||||
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1")).isEqualTo("/books/1");
|
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1")).isEqualTo("/books/1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.CustomAcceptHeaderHttpServletRequest;
|
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.CustomAcceptHeaderHttpServletRequest;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -37,12 +36,12 @@ import org.springframework.util.StringUtils;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack Spring engineering team meeting @ SpringOne Platform 2016
|
* @soundtrack Spring engineering team meeting @ SpringOne Platform 2016
|
||||||
*/
|
*/
|
||||||
public class CustomAcceptHeaderHttpServletRequestUnitTests {
|
class CustomAcceptHeaderHttpServletRequestUnitTests {
|
||||||
|
|
||||||
HttpServletRequest request = new MockHttpServletRequest();
|
HttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
||||||
@Test // DATAREST-863
|
@Test // DATAREST-863
|
||||||
public void returnsRegisterdHeadersOnAccessForMultipleOnes() {
|
void returnsRegisterdHeadersOnAccessForMultipleOnes() {
|
||||||
|
|
||||||
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
|
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
|
||||||
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);
|
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ package org.springframework.data.rest.webmvc;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.http.server.ServletServerHttpRequest;
|
import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
@@ -27,17 +27,17 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class IncomingRequestUnitTests {
|
class IncomingRequestUnitTests {
|
||||||
|
|
||||||
MockHttpServletRequest request;
|
MockHttpServletRequest request;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.request = new MockHttpServletRequest("PATCH", "/");
|
this.request = new MockHttpServletRequest("PATCH", "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-498
|
@Test // DATAREST-498
|
||||||
public void identifiesJsonPatchRequestForRequestWithContentTypeParameters() {
|
void identifiesJsonPatchRequestForRequestWithContentTypeParameters() {
|
||||||
|
|
||||||
request.addHeader("Content-Type", "application/json-patch+json;charset=UTF-8");
|
request.addHeader("Content-Type", "application/json-patch+json;charset=UTF-8");
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class IncomingRequestUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-498
|
@Test // DATAREST-498
|
||||||
public void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() {
|
void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() {
|
||||||
|
|
||||||
request.addHeader("Content-Type", "application/merge-patch+json;charset=UTF-8");
|
request.addHeader("Content-Type", "application/merge-patch+json;charset=UTF-8");
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
import org.springframework.hateoas.CollectionModel;
|
import org.springframework.hateoas.CollectionModel;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
@@ -36,8 +36,8 @@ import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class PersistentEntityResourceUnitTests {
|
class PersistentEntityResourceUnitTests {
|
||||||
|
|
||||||
@Mock Object payload;
|
@Mock Object payload;
|
||||||
@Mock PersistentEntity<?, ?> entity;
|
@Mock PersistentEntity<?, ?> entity;
|
||||||
@@ -45,26 +45,30 @@ public class PersistentEntityResourceUnitTests {
|
|||||||
CollectionModel<EmbeddedWrapper> resources;
|
CollectionModel<EmbeddedWrapper> resources;
|
||||||
Link link = Link.of("http://localhost", "foo");
|
Link link = Link.of("http://localhost", "foo");
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
|
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
|
||||||
EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo"));
|
EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo"));
|
||||||
this.resources = CollectionModel.of(Collections.singleton(wrapper));
|
this.resources = CollectionModel.of(Collections.singleton(wrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-317
|
@Test // DATAREST-317
|
||||||
public void rejectsNullPayload() {
|
void rejectsNullPayload() {
|
||||||
PersistentEntityResource.build(null, entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-317
|
assertThatIllegalArgumentException() //
|
||||||
public void rejectsNullPersistentEntity() {
|
.isThrownBy(() -> PersistentEntityResource.build(null, entity));
|
||||||
PersistentEntityResource.build(payload, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-317
|
@Test // DATAREST-317
|
||||||
public void defaultsEmbeddedsToEmptyResources() {
|
void rejectsNullPersistentEntity() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> PersistentEntityResource.build(payload, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-317
|
||||||
|
void defaultsEmbeddedsToEmptyResources() {
|
||||||
|
|
||||||
PersistentEntityResource resource = PersistentEntityResource.build(payload, entity).build();
|
PersistentEntityResource resource = PersistentEntityResource.build(payload, entity).build();
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.repository.support.Repositories;
|
import org.springframework.data.repository.support.Repositories;
|
||||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver;
|
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.NoOpStringValueResolver;
|
||||||
@@ -41,22 +41,22 @@ import org.springframework.web.cors.CorsConfiguration;
|
|||||||
* @soundtrack Aso Mamiko - Drive Me Crazy (Club Mix)
|
* @soundtrack Aso Mamiko - Drive Me Crazy (Club Mix)
|
||||||
* @since 2.6
|
* @since 2.6
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RepositoryCorsConfigurationAccessorUnitTests {
|
class RepositoryCorsConfigurationAccessorUnitTests {
|
||||||
|
|
||||||
RepositoryCorsConfigurationAccessor accessor;
|
RepositoryCorsConfigurationAccessor accessor;
|
||||||
|
|
||||||
@Mock ResourceMappings mappings;
|
@Mock ResourceMappings mappings;
|
||||||
@Mock Repositories repositories;
|
@Mock Repositories repositories;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void before() throws Exception {
|
||||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE,
|
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE,
|
||||||
Optional.of(repositories));
|
Optional.of(repositories));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void createConfigurationShouldConstructCorsConfiguration() {
|
void createConfigurationShouldConstructCorsConfiguration() {
|
||||||
|
|
||||||
CorsConfiguration configuration = accessor.createConfiguration(AnnotatedRepository.class);
|
CorsConfiguration configuration = accessor.createConfiguration(AnnotatedRepository.class);
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-573
|
@Test // DATAREST-573
|
||||||
public void createConfigurationShouldConstructFullCorsConfiguration() {
|
void createConfigurationShouldConstructFullCorsConfiguration() {
|
||||||
|
|
||||||
CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class);
|
CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-994
|
@Test // DATAREST-994
|
||||||
public void returnsNoCorsConfigurationWithNoRepositories() {
|
void returnsNoCorsConfigurationWithNoRepositories() {
|
||||||
|
|
||||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.empty());
|
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.empty());
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
import org.springframework.data.mapping.context.PersistentEntities;
|
import org.springframework.data.mapping.context.PersistentEntities;
|
||||||
@@ -41,8 +41,8 @@ import org.springframework.data.web.PagedResourcesAssembler;
|
|||||||
*
|
*
|
||||||
* @author Jeroen Reijn
|
* @author Jeroen Reijn
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RepositoryEntityControllerTest {
|
class RepositoryEntityControllerTest {
|
||||||
|
|
||||||
@Mock Repositories repositories;
|
@Mock Repositories repositories;
|
||||||
@Mock RepositoryRestConfiguration restConfiguration;
|
@Mock RepositoryRestConfiguration restConfiguration;
|
||||||
@@ -54,7 +54,7 @@ public class RepositoryEntityControllerTest {
|
|||||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@Test // DATAREST-1143
|
@Test // DATAREST-1143
|
||||||
public void testUnknownItemThrowsResourceNotFound() throws Exception {
|
void testUnknownItemThrowsResourceNotFound() throws Exception {
|
||||||
|
|
||||||
KeyValuePersistentEntity<?, ?> entity = mappingContext
|
KeyValuePersistentEntity<?, ?> entity = mappingContext
|
||||||
.getRequiredPersistentEntity(RepositoryPropertyReferenceControllerUnitTests.Sample.class);
|
.getRequiredPersistentEntity(RepositoryPropertyReferenceControllerUnitTests.Sample.class);
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
@@ -53,8 +53,8 @@ import org.springframework.http.HttpMethod;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RepositoryPropertyReferenceControllerUnitTests {
|
class RepositoryPropertyReferenceControllerUnitTests {
|
||||||
|
|
||||||
@Mock Repositories repositories;
|
@Mock Repositories repositories;
|
||||||
@Mock PagedResourcesAssembler<Object> assembler;
|
@Mock PagedResourcesAssembler<Object> assembler;
|
||||||
@@ -65,7 +65,7 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
|||||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@Test // DATAREST-791
|
@Test // DATAREST-791
|
||||||
public void usesRepositoryInvokerToLookupRelatedInstance() throws Exception {
|
void usesRepositoryInvokerToLookupRelatedInstance() throws Exception {
|
||||||
|
|
||||||
KeyValuePersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Sample.class);
|
KeyValuePersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Sample.class);
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import ch.qos.logback.classic.Level;
|
import ch.qos.logback.classic.Level;
|
||||||
import ch.qos.logback.classic.Logger;
|
import ch.qos.logback.classic.Logger;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.support.StaticMessageSource;
|
import org.springframework.context.support.StaticMessageSource;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
@@ -37,14 +37,14 @@ import org.springframework.mock.http.MockHttpInputMessage;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class RepositoryRestExceptionHandlerUnitTests {
|
class RepositoryRestExceptionHandlerUnitTests {
|
||||||
|
|
||||||
static final RepositoryRestExceptionHandler HANDLER = new RepositoryRestExceptionHandler(new StaticMessageSource());
|
static final RepositoryRestExceptionHandler HANDLER = new RepositoryRestExceptionHandler(new StaticMessageSource());
|
||||||
|
|
||||||
static Logger logger;
|
static Logger logger;
|
||||||
static Level logLevel;
|
static Level logLevel;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void silenceLog() {
|
public static void silenceLog() {
|
||||||
|
|
||||||
logger = (Logger) LoggerFactory.getLogger(RepositoryRestExceptionHandler.class);
|
logger = (Logger) LoggerFactory.getLogger(RepositoryRestExceptionHandler.class);
|
||||||
@@ -52,13 +52,13 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
|||||||
logger.setLevel(Level.OFF);
|
logger.setLevel(Level.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterAll
|
||||||
public static void enableLogging() {
|
public static void enableLogging() {
|
||||||
logger.setLevel(logLevel);
|
logger.setLevel(logLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-427
|
@Test // DATAREST-427
|
||||||
public void handlesHttpMessageNotReadableException() {
|
void handlesHttpMessageNotReadableException() {
|
||||||
|
|
||||||
ResponseEntity<ExceptionMessage> result = HANDLER
|
ResponseEntity<ExceptionMessage> result = HANDLER
|
||||||
.handleNotReadable(new HttpMessageNotReadableException("Message!", new MockHttpInputMessage(new byte[0])));
|
.handleNotReadable(new HttpMessageNotReadableException("Message!", new MockHttpInputMessage(new byte[0])));
|
||||||
@@ -67,7 +67,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-507
|
@Test // DATAREST-507
|
||||||
public void handlesConflictCorrectly() {
|
void handlesConflictCorrectly() {
|
||||||
|
|
||||||
ResponseEntity<ExceptionMessage> result = HANDLER.handleConflict(new DataIntegrityViolationException("Message!"));
|
ResponseEntity<ExceptionMessage> result = HANDLER.handleConflict(new DataIntegrityViolationException("Message!"));
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-706
|
@Test // DATAREST-706
|
||||||
public void forwardsExceptionForMiscellaneousFailure() {
|
void forwardsExceptionForMiscellaneousFailure() {
|
||||||
|
|
||||||
String message = "My Message!";
|
String message = "My Message!";
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
@@ -57,8 +57,8 @@ import org.springframework.web.util.pattern.PathPattern;
|
|||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RepositoryRestHandlerMappingUnitTests {
|
class RepositoryRestHandlerMappingUnitTests {
|
||||||
|
|
||||||
static final AnnotationConfigWebApplicationContext CONTEXT = new AnnotationConfigWebApplicationContext();
|
static final AnnotationConfigWebApplicationContext CONTEXT = new AnnotationConfigWebApplicationContext();
|
||||||
|
|
||||||
@@ -68,8 +68,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
CONTEXT.refresh();
|
CONTEXT.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mock ResourceMappings mappings;
|
@Mock(lenient = true) ResourceMappings mappings;
|
||||||
@Mock ResourceMetadata resourceMetadata;
|
@Mock(lenient = true) ResourceMetadata resourceMetadata;
|
||||||
@Mock Repositories repositories;
|
@Mock Repositories repositories;
|
||||||
|
|
||||||
RepositoryRestConfiguration configuration;
|
RepositoryRestConfiguration configuration;
|
||||||
@@ -77,8 +77,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
MockHttpServletRequest mockRequest;
|
MockHttpServletRequest mockRequest;
|
||||||
Method listEntitiesMethod, rootHandlerMethod;
|
Method listEntitiesMethod, rootHandlerMethod;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
|
|
||||||
configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||||
@@ -99,23 +99,27 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
rootHandlerMethod = RepositoryController.class.getMethod("listRepositories");
|
rootHandlerMethod = RepositoryController.class.getMethod("listRepositories");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void rejectsNullMappings() {
|
void rejectsNullMappings() {
|
||||||
new RepositoryRestHandlerMapping(null, configuration);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new RepositoryRestHandlerMapping(null, configuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void rejectsNullConfiguration() {
|
void rejectsNullConfiguration() {
|
||||||
new RepositoryRestHandlerMapping(mappings, null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new RepositoryRestHandlerMapping(mappings, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-111
|
@Test // DATAREST-111
|
||||||
public void returnsNullForUriNotMapped() throws Exception {
|
void returnsNullForUriNotMapped() throws Exception {
|
||||||
assertThat(handlerMapping.get().getHandler(mockRequest)).isNull();
|
assertThat(handlerMapping.get().getHandler(mockRequest)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-111
|
@Test // DATAREST-111
|
||||||
public void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception {
|
void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/people");
|
mockRequest = new MockHttpServletRequest("GET", "/people");
|
||||||
@@ -127,7 +131,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-292
|
@Test // DATAREST-292
|
||||||
public void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception {
|
void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
||||||
@@ -141,7 +145,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-292
|
@Test // DATAREST-292
|
||||||
public void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception {
|
void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||||
|
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/base");
|
mockRequest = new MockHttpServletRequest("GET", "/base");
|
||||||
|
|
||||||
@@ -154,7 +158,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception {
|
void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/base/people/");
|
mockRequest = new MockHttpServletRequest("GET", "/base/people/");
|
||||||
@@ -168,7 +172,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception {
|
void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
||||||
@@ -183,7 +187,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
||||||
|
|
||||||
mockRequest = new MockHttpServletRequest("GET", "/servlet-path");
|
mockRequest = new MockHttpServletRequest("GET", "/servlet-path");
|
||||||
mockRequest.setServletPath("/servlet-path");
|
mockRequest.setServletPath("/servlet-path");
|
||||||
@@ -196,7 +200,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-276
|
@Test // DATAREST-276
|
||||||
public void refrainsFromMappingWhenUrisDontMatch() throws Exception {
|
void refrainsFromMappingWhenUrisDontMatch() throws Exception {
|
||||||
|
|
||||||
String baseUri = "foo";
|
String baseUri = "foo";
|
||||||
String uri = baseUri.concat("/people");
|
String uri = baseUri.concat("/people");
|
||||||
@@ -213,7 +217,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-609
|
@Test // DATAREST-609
|
||||||
public void rejectsUnexpandedUriTemplateWithNotFound() throws Exception {
|
void rejectsUnexpandedUriTemplateWithNotFound() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
|
|
||||||
@@ -223,7 +227,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1019
|
@Test // DATAREST-1019
|
||||||
public void resolvesCorsConfigurationFromRequestUri() {
|
void resolvesCorsConfigurationFromRequestUri() {
|
||||||
|
|
||||||
String uri = "/people";
|
String uri = "/people";
|
||||||
|
|
||||||
@@ -240,7 +244,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1019
|
@Test // DATAREST-1019
|
||||||
public void stripsBaseUriForCorsConfigurationResolution() {
|
void stripsBaseUriForCorsConfigurationResolution() {
|
||||||
|
|
||||||
String baseUri = "/foo";
|
String baseUri = "/foo";
|
||||||
String uri = baseUri.concat("/people");
|
String uri = baseUri.concat("/people");
|
||||||
@@ -260,12 +264,12 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-994
|
@Test // DATAREST-994
|
||||||
public void twoArgumentConstructorDoesNotThrowException() {
|
void twoArgumentConstructorDoesNotThrowException() {
|
||||||
new RepositoryRestHandlerMapping(mappings, configuration);
|
new RepositoryRestHandlerMapping(mappings, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1132
|
@Test // DATAREST-1132
|
||||||
public void detectsAnnotationsOnProxies() {
|
void detectsAnnotationsOnProxies() {
|
||||||
|
|
||||||
Class<?> type = createProxy(new SomeController());
|
Class<?> type = createProxy(new SomeController());
|
||||||
|
|
||||||
@@ -278,7 +282,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1294
|
@Test // DATAREST-1294
|
||||||
public void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception {
|
void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
|
|
||||||
@@ -293,7 +297,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1332
|
@Test // DATAREST-1332
|
||||||
public void handlesCorsPreflightRequestsProperly() throws Exception {
|
void handlesCorsPreflightRequestsProperly() throws Exception {
|
||||||
|
|
||||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link RepositorySearchesResource}
|
* Unit tests for {@link RepositorySearchesResource}
|
||||||
@@ -25,15 +25,17 @@ import org.junit.Test;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack Bakkushan - Gefahr (Bakkushan)
|
* @soundtrack Bakkushan - Gefahr (Bakkushan)
|
||||||
*/
|
*/
|
||||||
public class RepositorySearchesResourceUnitTests {
|
class RepositorySearchesResourceUnitTests {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-515
|
@Test // DATAREST-515
|
||||||
public void rejectsNullDomainType() {
|
void rejectsNullDomainType() {
|
||||||
new RepositorySearchesResource(null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new RepositorySearchesResource(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-515
|
@Test // DATAREST-515
|
||||||
public void returnsConfiguredDomainType() {
|
void returnsConfiguredDomainType() {
|
||||||
assertThat(new RepositorySearchesResource(String.class).getDomainType()).isAssignableFrom(String.class);
|
assertThat(new RepositorySearchesResource(String.class).getDomainType()).isAssignableFrom(String.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ import lombok.Value;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
@@ -43,8 +43,9 @@ import org.springframework.http.HttpStatus;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ResourceStatusUnitTests {
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
|
class ResourceStatusUnitTests {
|
||||||
|
|
||||||
ResourceStatus status;
|
ResourceStatus status;
|
||||||
KeyValuePersistentEntity<?, ?> entity;
|
KeyValuePersistentEntity<?, ?> entity;
|
||||||
@@ -52,10 +53,8 @@ public class ResourceStatusUnitTests {
|
|||||||
@Mock HttpHeadersPreparer preparer;
|
@Mock HttpHeadersPreparer preparer;
|
||||||
@Mock Supplier<PersistentEntityResource> supplier;
|
@Mock Supplier<PersistentEntityResource> supplier;
|
||||||
|
|
||||||
public @Rule ExpectedException exception = ExpectedException.none();
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
|
|
||||||
this.status = ResourceStatus.of(preparer);
|
this.status = ResourceStatus.of(preparer);
|
||||||
|
|
||||||
@@ -65,18 +64,20 @@ public class ResourceStatusUnitTests {
|
|||||||
doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), any());
|
doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void rejectsNullPreparer() {
|
void rejectsNullPreparer() {
|
||||||
ResourceStatus.of(null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> ResourceStatus.of(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void returnsModifiedIfNoHeadersGiven() {
|
void returnsModifiedIfNoHeadersGiven() {
|
||||||
assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Sample(0), entity));
|
assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Sample(0), entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void returnsNotModifiedForEntityWithRequestedETag() {
|
void returnsNotModifiedForEntityWithRequestedETag() {
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setIfNoneMatch("\"1\"");
|
headers.setIfNoneMatch("\"1\"");
|
||||||
@@ -85,7 +86,7 @@ public class ResourceStatusUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-835
|
@Test // DATAREST-835
|
||||||
public void returnsNotModifiedIfEntityIsStillConsideredValid() {
|
void returnsNotModifiedIfEntityIsStillConsideredValid() {
|
||||||
|
|
||||||
doReturn(true).when(preparer).isObjectStillValid(any(), any(HttpHeaders.class));
|
doReturn(true).when(preparer).isObjectStillValid(any(), any(HttpHeaders.class));
|
||||||
|
|
||||||
@@ -93,12 +94,11 @@ public class ResourceStatusUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1121
|
@Test // DATAREST-1121
|
||||||
public void rejectsInvalidPersistentEntityDomainObjectCombination() {
|
void rejectsInvalidPersistentEntityDomainObjectCombination() {
|
||||||
|
|
||||||
exception.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException() //
|
||||||
exception.expectMessage(entity.getType().getName());
|
.isThrownBy(() -> assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity)))
|
||||||
|
.withMessageContaining(entity.getType().getName());
|
||||||
assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertModified(StatusAndHeaders statusAndHeaders) {
|
private void assertModified(StatusAndHeaders statusAndHeaders) {
|
||||||
|
|||||||
@@ -15,21 +15,22 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc;
|
package org.springframework.data.rest.webmvc;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.springframework.data.rest.core.mapping.ResourceType.*;
|
|
||||||
import static org.springframework.http.HttpMethod.*;
|
import static org.springframework.http.HttpMethod.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||||
|
import org.springframework.data.rest.core.mapping.ResourceType;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,8 +38,8 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class RootResourceInformationUnitTests {
|
class RootResourceInformationUnitTests {
|
||||||
|
|
||||||
@Mock ResourceMetadata metadata;
|
@Mock ResourceMetadata metadata;
|
||||||
@Mock PersistentEntity<?, ?> entity;
|
@Mock PersistentEntity<?, ?> entity;
|
||||||
@@ -46,18 +47,21 @@ public class RootResourceInformationUnitTests {
|
|||||||
|
|
||||||
RootResourceInformation information;
|
RootResourceInformation information;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.invoker = mock(RepositoryInvoker.class, new DefaultBooleanToTrue());
|
this.invoker = mock(RepositoryInvoker.class, new DefaultBooleanToTrue());
|
||||||
this.information = new RootResourceInformation(metadata, entity, invoker);
|
this.information = new RootResourceInformation(metadata, entity, invoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
@Test // DATAREST-330
|
||||||
public void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException {
|
void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException {
|
||||||
|
|
||||||
when(metadata.isExported()).thenReturn(false);
|
when(metadata.isExported()).thenReturn(false);
|
||||||
information.verifySupportedMethod(HEAD, COLLECTION);
|
|
||||||
|
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||||
|
.isThrownBy(() -> information.verifySupportedMethod(HEAD, ResourceType.COLLECTION));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@@ -39,25 +39,29 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||||
|
|
||||||
@Mock HateoasPageableHandlerMethodArgumentResolver pageableResolver;
|
@Mock HateoasPageableHandlerMethodArgumentResolver pageableResolver;
|
||||||
@Mock HateoasSortHandlerMethodArgumentResolver sortResolver;
|
@Mock HateoasSortHandlerMethodArgumentResolver sortResolver;
|
||||||
@Mock UriComponentsBuilder builder;
|
@Mock UriComponentsBuilder builder;
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void rejectsNullArgumentResolverForPageable() {
|
void rejectsNullArgumentResolverForPageable() {
|
||||||
new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-467
|
assertThatIllegalArgumentException() //
|
||||||
public void rejectsNullArgumentResolverForSort() {
|
.isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver));
|
||||||
new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void supportsPageableAndSortMethodParameters() {
|
void rejectsNullArgumentResolverForSort() {
|
||||||
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // DATAREST-467
|
||||||
|
void supportsPageableAndSortMethodParameters() {
|
||||||
|
|
||||||
PagingAndSortingTemplateVariables variables = new ArgumentResolverPagingAndSortingTemplateVariables(
|
PagingAndSortingTemplateVariables variables = new ArgumentResolverPagingAndSortingTemplateVariables(
|
||||||
pageableResolver, sortResolver);
|
pageableResolver, sortResolver);
|
||||||
@@ -68,12 +72,12 @@ public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void forwardsEnhanceRequestForPageable() {
|
void forwardsEnhanceRequestForPageable() {
|
||||||
assertForwardsEnhanceFor(PageRequest.of(0, 10), pageableResolver, sortResolver);
|
assertForwardsEnhanceFor(PageRequest.of(0, 10), pageableResolver, sortResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-467
|
@Test // DATAREST-467
|
||||||
public void forwardsEnhanceRequestForSort() {
|
void forwardsEnhanceRequestForSort() {
|
||||||
assertForwardsEnhanceFor(Sort.by("property"), sortResolver, pageableResolver);
|
assertForwardsEnhanceFor(Sort.by("property"), sortResolver, pageableResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.rest.webmvc.config;
|
package org.springframework.data.rest.webmvc.config;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@@ -24,11 +23,11 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||||
@@ -43,14 +42,14 @@ import org.springframework.web.servlet.handler.RequestMatchResult;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack Benny Greb - Stabila (Moving Parts)
|
* @soundtrack Benny Greb - Stabila (Moving Parts)
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DelegatingHandlerMappingUnitTests {
|
class DelegatingHandlerMappingUnitTests {
|
||||||
|
|
||||||
@Mock HandlerMapping first, second;
|
@Mock HandlerMapping first, second;
|
||||||
@Mock HttpServletRequest request;
|
@Mock HttpServletRequest request;
|
||||||
|
|
||||||
@Test // DATAREST-490, DATAREST-522, DATAREST-1387
|
@Test // DATAREST-490, DATAREST-522, DATAREST-1387
|
||||||
public void consultsAllHandlerMappingsAndThrowsExceptionEventually() throws Exception {
|
void consultsAllHandlerMappingsAndThrowsExceptionEventually() throws Exception {
|
||||||
|
|
||||||
DelegatingHandlerMapping mapping = new DelegatingHandlerMapping(Arrays.asList(first, second), null);
|
DelegatingHandlerMapping mapping = new DelegatingHandlerMapping(Arrays.asList(first, second), null);
|
||||||
|
|
||||||
@@ -61,11 +60,11 @@ public class DelegatingHandlerMappingUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1193
|
@Test // DATAREST-1193
|
||||||
public void exposesMatchabilityOfSelectedMapping() {
|
void exposesMatchabilityOfSelectedMapping() {
|
||||||
|
|
||||||
// Given:
|
// Given:
|
||||||
// A matching mapping that doesn't get selected
|
// A matching mapping that doesn't get selected
|
||||||
MatchableHandlerMapping third = mock(MatchableHandlerMapping.class);
|
MatchableHandlerMapping third = mock(MatchableHandlerMapping.class, withSettings().lenient());
|
||||||
doReturn(mock(RequestMatchResult.class)).when(third).match(any(), any(String.class));
|
doReturn(mock(RequestMatchResult.class)).when(third).match(any(), any(String.class));
|
||||||
|
|
||||||
// A matching mapping that gets selected
|
// A matching mapping that gets selected
|
||||||
@@ -83,16 +82,10 @@ public class DelegatingHandlerMappingUnitTests {
|
|||||||
|
|
||||||
when(first.getHandler(request)).thenThrow(type);
|
when(first.getHandler(request)).thenThrow(type);
|
||||||
|
|
||||||
try {
|
assertThatExceptionOfType(type)
|
||||||
|
.isThrownBy(() -> mapping.getHandler(request));
|
||||||
|
|
||||||
mapping.getHandler(request);
|
verify(second, times(1)).getHandler(request);
|
||||||
fail(String.format("Expected %s!", type.getSimpleName()));
|
reset(first, second);
|
||||||
|
|
||||||
} catch (Exception o_O) {
|
|
||||||
assertThat(o_O).isInstanceOf(type);
|
|
||||||
verify(second, times(1)).getHandler(request);
|
|
||||||
} finally {
|
|
||||||
reset(first, second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
|||||||
* @author Oliver Drotbohm
|
* @author Oliver Drotbohm
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
|
class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
|
||||||
|
|
||||||
HalFormsAdaptingResponseBodyAdvice<T> advice = new HalFormsAdaptingResponseBodyAdvice<>();
|
HalFormsAdaptingResponseBodyAdvice<T> advice = new HalFormsAdaptingResponseBodyAdvice<>();
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
@@ -53,15 +53,15 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
||||||
|
|
||||||
HttpMessageConverter<?> converter;
|
HttpMessageConverter<?> converter;
|
||||||
RootResourceInformationHandlerMethodArgumentResolver rootResourceResolver;
|
RootResourceInformationHandlerMethodArgumentResolver rootResourceResolver;
|
||||||
BackendIdHandlerMethodArgumentResolver backendIdResolver;
|
BackendIdHandlerMethodArgumentResolver backendIdResolver;
|
||||||
DomainObjectReader reader;
|
DomainObjectReader reader;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
|
|
||||||
this.converter = mock(HttpMessageConverter.class);
|
this.converter = mock(HttpMessageConverter.class);
|
||||||
when(this.converter.canRead((Class<?>) any(), (MediaType) any())).thenReturn(true);
|
when(this.converter.canRead((Class<?>) any(), (MediaType) any())).thenReturn(true);
|
||||||
@@ -75,7 +75,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-1050
|
@Test // DATAREST-1050
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception {
|
void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception {
|
||||||
|
|
||||||
PersistentEntityResourceHandlerMethodArgumentResolver argumentResolver = new PersistentEntityResourceHandlerMethodArgumentResolver(
|
PersistentEntityResourceHandlerMethodArgumentResolver argumentResolver = new PersistentEntityResourceHandlerMethodArgumentResolver(
|
||||||
Arrays.<HttpMessageConverter<?>> asList(converter), rootResourceResolver, backendIdResolver, reader,
|
Arrays.<HttpMessageConverter<?>> asList(converter), rootResourceResolver, backendIdResolver, reader,
|
||||||
@@ -95,7 +95,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-1304
|
@Test // DATAREST-1304
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception {
|
void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception {
|
||||||
|
|
||||||
EntityLookup<?> lookup = mock(EntityLookup.class);
|
EntityLookup<?> lookup = mock(EntityLookup.class);
|
||||||
doReturn(Optional.of("name")).when(lookup).getLookupProperty();
|
doReturn(Optional.of("name")).when(lookup).getLookupProperty();
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import java.util.List;
|
|||||||
import javax.naming.Name;
|
import javax.naming.Name;
|
||||||
import javax.naming.ldap.LdapName;
|
import javax.naming.ldap.LdapName;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
@@ -70,16 +70,16 @@ import com.jayway.jsonpath.JsonPath;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
*/
|
*/
|
||||||
public class RepositoryRestMvConfigurationIntegrationTests {
|
class RepositoryRestMvConfigurationIntegrationTests {
|
||||||
|
|
||||||
static AbstractApplicationContext context;
|
static AbstractApplicationContext context;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
context = new AnnotationConfigApplicationContext(ExtendingConfiguration.class);
|
context = new AnnotationConfigApplicationContext(ExtendingConfiguration.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterAll
|
||||||
public static void tearDown() {
|
public static void tearDown() {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.close();
|
context.close();
|
||||||
@@ -87,14 +87,14 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-210
|
@Test // DATAREST-210
|
||||||
public void assertEnableHypermediaSupportWorkingCorrectly() {
|
void assertEnableHypermediaSupportWorkingCorrectly() {
|
||||||
|
|
||||||
assertThat(context.getBean("entityLinksPluginRegistry")).isNotNull();
|
assertThat(context.getBean("entityLinksPluginRegistry")).isNotNull();
|
||||||
assertThat(context.getBean(LinkDiscoverers.class)).isNotNull();
|
assertThat(context.getBean(LinkDiscoverers.class)).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void assertBeansBeingSetUp() throws Exception {
|
void assertBeansBeingSetUp() throws Exception {
|
||||||
|
|
||||||
context.getBean(PageableHandlerMethodArgumentResolver.class);
|
context.getBean(PageableHandlerMethodArgumentResolver.class);
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-271
|
@Test // DATAREST-271
|
||||||
public void assetConsidersPaginationCustomization() {
|
void assetConsidersPaginationCustomization() {
|
||||||
|
|
||||||
HateoasPageableHandlerMethodArgumentResolver resolver = context
|
HateoasPageableHandlerMethodArgumentResolver resolver = context
|
||||||
.getBean(HateoasPageableHandlerMethodArgumentResolver.class);
|
.getBean(HateoasPageableHandlerMethodArgumentResolver.class);
|
||||||
@@ -121,7 +121,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-336 DATAREST-1509
|
@Test // DATAREST-336 DATAREST-1509
|
||||||
public void objectMapperRendersDatesInIsoByDefault() throws Exception {
|
void objectMapperRendersDatesInIsoByDefault() throws Exception {
|
||||||
|
|
||||||
Sample sample = new Sample();
|
Sample sample = new Sample();
|
||||||
sample.date = new Date();
|
sample.date = new Date();
|
||||||
@@ -135,13 +135,15 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
.or(suffix("+00:00")), "ISO-8601-TZ1, ISO-8601-TZ2, or ISO-8601-TZ3");
|
.or(suffix("+00:00")), "ISO-8601-TZ1, ISO-8601-TZ2, or ISO-8601-TZ3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NoSuchBeanDefinitionException.class) // DATAREST-362
|
@Test // DATAREST-362
|
||||||
public void doesNotExposePersistentEntityJackson2ModuleAsBean() {
|
void doesNotExposePersistentEntityJackson2ModuleAsBean() {
|
||||||
context.getBean(PersistentEntityJackson2Module.class);
|
|
||||||
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) //
|
||||||
|
.isThrownBy(() -> context.getBean(PersistentEntityJackson2Module.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-362
|
@Test // DATAREST-362
|
||||||
public void registeredHttpMessageConvertersAreTypeConstrained() {
|
void registeredHttpMessageConvertersAreTypeConstrained() {
|
||||||
|
|
||||||
Collection<MappingJackson2HttpMessageConverter> converters = context
|
Collection<MappingJackson2HttpMessageConverter> converters = context
|
||||||
.getBeansOfType(MappingJackson2HttpMessageConverter.class).values();
|
.getBeansOfType(MappingJackson2HttpMessageConverter.class).values();
|
||||||
@@ -153,7 +155,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-424
|
@Test // DATAREST-424
|
||||||
public void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() {
|
void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() {
|
||||||
|
|
||||||
CollectingComponent component = context.getBean(CollectingComponent.class);
|
CollectingComponent component = context.getBean(CollectingComponent.class);
|
||||||
List<HttpMessageConverter<?>> converters = component.converters;
|
List<HttpMessageConverter<?>> converters = component.converters;
|
||||||
@@ -163,7 +165,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-424
|
@Test // DATAREST-424
|
||||||
public void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() {
|
void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() {
|
||||||
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NonHalConfiguration.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NonHalConfiguration.class);
|
||||||
CollectingComponent component = context.getBean(CollectingComponent.class);
|
CollectingComponent component = context.getBean(CollectingComponent.class);
|
||||||
@@ -176,7 +178,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-431, DATACMNS-626
|
@Test // DATAREST-431, DATACMNS-626
|
||||||
public void hasConvertersForPointAndDistance() {
|
void hasConvertersForPointAndDistance() {
|
||||||
|
|
||||||
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
||||||
|
|
||||||
@@ -187,7 +189,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1198
|
@Test // DATAREST-1198
|
||||||
public void hasConvertersForNamAndLdapName() {
|
void hasConvertersForNamAndLdapName() {
|
||||||
|
|
||||||
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
||||||
|
|
||||||
@@ -197,7 +199,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
|
|
||||||
@Test // #1995
|
@Test // #1995
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void registersRepositoryRestConfigurersInDeclaredOrder() {
|
void registersRepositoryRestConfigurersInDeclaredOrder() {
|
||||||
|
|
||||||
RepositoryRestMvcConfiguration configuration = context.getBean(RepositoryRestMvcConfiguration.class);
|
RepositoryRestMvcConfiguration configuration = context.getBean(RepositoryRestMvcConfiguration.class);
|
||||||
ExtendingConfiguration userConfig = context.getBean(ExtendingConfiguration.class);
|
ExtendingConfiguration userConfig = context.getBean(ExtendingConfiguration.class);
|
||||||
@@ -278,7 +280,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
|||||||
List<HttpMessageConverter<?>> converters;
|
List<HttpMessageConverter<?>> converters;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setConverters(List<HttpMessageConverter<?>> converters) {
|
void setConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
this.converters = converters;
|
this.converters = converters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc.config;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.repository.support.Repositories;
|
import org.springframework.data.repository.support.Repositories;
|
||||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||||
@@ -31,10 +31,10 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class ResourceMetadataHandlerMethodArgumentResolverUnitTests {
|
class ResourceMetadataHandlerMethodArgumentResolverUnitTests {
|
||||||
|
|
||||||
@Test // DATAREST-1250
|
@Test // DATAREST-1250
|
||||||
public void supportsResourceMetadataParameterType() {
|
void supportsResourceMetadataParameterType() {
|
||||||
|
|
||||||
HandlerMethodArgumentResolver resolver = new ResourceMetadataHandlerMethodArgumentResolver(mock(Repositories.class),
|
HandlerMethodArgumentResolver resolver = new ResourceMetadataHandlerMethodArgumentResolver(mock(Repositories.class),
|
||||||
mock(ResourceMappings.class), BaseUri.NONE);
|
mock(ResourceMappings.class), BaseUri.NONE);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
* @author Oliver Drotbohm
|
* @author Oliver Drotbohm
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class AggregateReferenceResolvingModuleUnitTests {
|
class AggregateReferenceResolvingModuleUnitTests {
|
||||||
|
|
||||||
@Mock UriToEntityConverter uriToEntityConverter;
|
@Mock UriToEntityConverter uriToEntityConverter;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class AggregateReferenceResolvingModuleUnitTests {
|
|||||||
|
|
||||||
public static class SomeType {
|
public static class SomeType {
|
||||||
|
|
||||||
public void setSomeProperty(Other other) {}
|
void setSomeProperty(Other other) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestResource
|
@RestResource
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentMatchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Immutable;
|
import org.springframework.data.annotation.Immutable;
|
||||||
@@ -75,16 +75,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||||||
* @author Ken Dombeck
|
* @author Ken Dombeck
|
||||||
* @author Thomas Mrozinski
|
* @author Thomas Mrozinski
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DomainObjectReaderUnitTests {
|
class DomainObjectReaderUnitTests {
|
||||||
|
|
||||||
@Mock ResourceMappings mappings;
|
@Mock ResourceMappings mappings;
|
||||||
|
|
||||||
DomainObjectReader reader;
|
DomainObjectReader reader;
|
||||||
PersistentEntities entities;
|
PersistentEntities entities;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||||
mappingContext.getPersistentEntity(SampleUser.class);
|
mappingContext.getPersistentEntity(SampleUser.class);
|
||||||
@@ -111,7 +111,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-461
|
@Test // DATAREST-461
|
||||||
public void doesNotConsiderIgnoredProperties() throws Exception {
|
void doesNotConsiderIgnoredProperties() throws Exception {
|
||||||
|
|
||||||
SampleUser user = new SampleUser("firstname", "password");
|
SampleUser user = new SampleUser("firstname", "password");
|
||||||
JsonNode node = new ObjectMapper().readTree("{}");
|
JsonNode node = new ObjectMapper().readTree("{}");
|
||||||
@@ -123,7 +123,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-556
|
@Test // DATAREST-556
|
||||||
public void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception {
|
void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
|
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
|
||||||
@@ -137,7 +137,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-605
|
@Test // DATAREST-605
|
||||||
public void mergesMapCorrectly() throws Exception {
|
void mergesMapCorrectly() throws Exception {
|
||||||
|
|
||||||
SampleUser user = new SampleUser("firstname", "password");
|
SampleUser user = new SampleUser("firstname", "password");
|
||||||
user.relatedUsers = Collections.singletonMap("parent", new SampleUser("firstname", "password"));
|
user.relatedUsers = Collections.singletonMap("parent", new SampleUser("firstname", "password"));
|
||||||
@@ -154,7 +154,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-701
|
@Test // DATAREST-701
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void mergesNestedMapWithoutTypeInformation() throws Exception {
|
void mergesNestedMapWithoutTypeInformation() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode node = mapper.readTree("{\"map\" : {\"a\": \"1\", \"b\": {\"c\": \"2\"}}}");
|
JsonNode node = mapper.readTree("{\"map\" : {\"a\": \"1\", \"b\": {\"c\": \"2\"}}}");
|
||||||
@@ -172,17 +172,18 @@ public class DomainObjectReaderUnitTests {
|
|||||||
assertThat(((Map<Object, Object>) object).get("c")).isEqualTo("2");
|
assertThat(((Map<Object, Object>) object).get("c")).isEqualTo("2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JsonMappingException.class) // DATAREST-701
|
@Test // DATAREST-701
|
||||||
public void rejectsMergingUnknownDomainObject() throws Exception {
|
void rejectsMergingUnknownDomainObject() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
||||||
|
|
||||||
reader.readPut(node, "", mapper);
|
assertThatExceptionOfType(JsonMappingException.class) //
|
||||||
|
.isThrownBy(() -> reader.readPut(node, "", mapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-705
|
@Test // DATAREST-705
|
||||||
public void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
|
void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
|
||||||
|
|
||||||
VersionedType type = new VersionedType();
|
VersionedType type = new VersionedType();
|
||||||
type.id = 1L;
|
type.id = 1L;
|
||||||
@@ -201,7 +202,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1006
|
@Test // DATAREST-1006
|
||||||
public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {
|
void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {
|
||||||
|
|
||||||
SampleUser sampleUser = new SampleUser("name", "password");
|
SampleUser sampleUser = new SampleUser("name", "password");
|
||||||
sampleUser.lastLogin = new Date();
|
sampleUser.lastLogin = new Date();
|
||||||
@@ -217,7 +218,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-873
|
@Test // DATAREST-873
|
||||||
public void doesNotApplyInputToReadOnlyFields() throws Exception {
|
void doesNotApplyInputToReadOnlyFields() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
||||||
@@ -231,7 +232,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-931
|
@Test // DATAREST-931
|
||||||
public void readsPatchForEntityNestedInCollection() throws Exception {
|
void readsPatchForEntityNestedInCollection() throws Exception {
|
||||||
|
|
||||||
Phone phone = new Phone();
|
Phone phone = new Phone();
|
||||||
phone.creationDate = new GregorianCalendar();
|
phone.creationDate = new GregorianCalendar();
|
||||||
@@ -249,7 +250,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-919
|
@Test // DATAREST-919
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void readsComplexNestedMapsAndArrays() throws Exception {
|
void readsComplexNestedMapsAndArrays() throws Exception {
|
||||||
|
|
||||||
Map<String, Object> childMap = new HashMap<String, Object>();
|
Map<String, Object> childMap = new HashMap<String, Object>();
|
||||||
childMap.put("child1", "ok");
|
childMap.put("child1", "ok");
|
||||||
@@ -286,7 +287,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-938
|
@Test // DATAREST-938
|
||||||
public void nestedEntitiesAreUpdated() throws Exception {
|
void nestedEntitiesAreUpdated() throws Exception {
|
||||||
|
|
||||||
Inner inner = new Inner();
|
Inner inner = new Inner();
|
||||||
inner.name = "inner name";
|
inner.name = "inner name";
|
||||||
@@ -309,7 +310,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-937
|
@Test // DATAREST-937
|
||||||
public void considersTransientProperties() throws Exception {
|
void considersTransientProperties() throws Exception {
|
||||||
|
|
||||||
SampleWithTransient sample = new SampleWithTransient();
|
SampleWithTransient sample = new SampleWithTransient();
|
||||||
sample.name = "name";
|
sample.name = "name";
|
||||||
@@ -324,7 +325,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-953
|
@Test // DATAREST-953
|
||||||
public void writesArrayForPut() throws Exception {
|
void writesArrayForPut() throws Exception {
|
||||||
|
|
||||||
Child inner = new Child();
|
Child inner = new Child();
|
||||||
inner.items = new ArrayList<Item>();
|
inner.items = new ArrayList<Item>();
|
||||||
@@ -341,7 +342,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-956
|
@Test // DATAREST-956
|
||||||
public void writesArrayWithAddedItemForPut() throws Exception {
|
void writesArrayWithAddedItemForPut() throws Exception {
|
||||||
|
|
||||||
Child inner = new Child();
|
Child inner = new Child();
|
||||||
inner.items = new ArrayList<Item>();
|
inner.items = new ArrayList<Item>();
|
||||||
@@ -362,7 +363,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-956
|
@Test // DATAREST-956
|
||||||
public void writesArrayWithRemovedItemForPut() throws Exception {
|
void writesArrayWithRemovedItemForPut() throws Exception {
|
||||||
|
|
||||||
Child inner = new Child();
|
Child inner = new Child();
|
||||||
inner.items = new ArrayList<Item>();
|
inner.items = new ArrayList<Item>();
|
||||||
@@ -382,7 +383,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-959
|
@Test // DATAREST-959
|
||||||
public void addsElementToPreviouslyEmptyCollection() throws Exception {
|
void addsElementToPreviouslyEmptyCollection() throws Exception {
|
||||||
|
|
||||||
Parent source = new Parent();
|
Parent source = new Parent();
|
||||||
source.inner = new Child();
|
source.inner = new Child();
|
||||||
@@ -398,7 +399,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
|
|
||||||
@Test // DATAREST-959
|
@Test // DATAREST-959
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void turnsObjectIntoCollection() throws Exception {
|
void turnsObjectIntoCollection() throws Exception {
|
||||||
|
|
||||||
Parent source = new Parent();
|
Parent source = new Parent();
|
||||||
source.inner = new Child();
|
source.inner = new Child();
|
||||||
@@ -419,7 +420,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-965
|
@Test // DATAREST-965
|
||||||
public void writesObjectWithRemovedItemsForPut() throws Exception {
|
void writesObjectWithRemovedItemsForPut() throws Exception {
|
||||||
|
|
||||||
Child inner = new Child();
|
Child inner = new Child();
|
||||||
inner.items = new ArrayList<Item>();
|
inner.items = new ArrayList<Item>();
|
||||||
@@ -438,7 +439,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-965
|
@Test // DATAREST-965
|
||||||
public void writesArrayWithRemovedObjectForPut() throws Exception {
|
void writesArrayWithRemovedObjectForPut() throws Exception {
|
||||||
|
|
||||||
Child inner = new Child();
|
Child inner = new Child();
|
||||||
inner.object = "value";
|
inner.object = "value";
|
||||||
@@ -456,7 +457,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-986
|
@Test // DATAREST-986
|
||||||
public void readsComplexMap() throws Exception {
|
void readsComplexMap() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode node = mapper.readTree(
|
JsonNode node = mapper.readTree(
|
||||||
@@ -469,7 +470,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-987
|
@Test // DATAREST-987
|
||||||
public void handlesTransientPropertyWithoutFieldProperly() throws Exception {
|
void handlesTransientPropertyWithoutFieldProperly() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode node = mapper.readTree("{ \"name\" : \"Foo\" }");
|
JsonNode node = mapper.readTree("{ \"name\" : \"Foo\" }");
|
||||||
@@ -478,7 +479,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-977
|
@Test // DATAREST-977
|
||||||
public void readsCollectionOfComplexEnum() throws Exception {
|
void readsCollectionOfComplexEnum() throws Exception {
|
||||||
|
|
||||||
CollectionOfEnumWithMethods sample = new CollectionOfEnumWithMethods();
|
CollectionOfEnumWithMethods sample = new CollectionOfEnumWithMethods();
|
||||||
sample.enums.add(SampleEnum.FIRST);
|
sample.enums.add(SampleEnum.FIRST);
|
||||||
@@ -493,7 +494,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-944
|
@Test // DATAREST-944
|
||||||
public void mergesAssociations() {
|
void mergesAssociations() {
|
||||||
|
|
||||||
List<Nested> originalCollection = Arrays.asList(new Nested(2, 3));
|
List<Nested> originalCollection = Arrays.asList(new Nested(2, 3));
|
||||||
SampleWithReference source = new SampleWithReference(Arrays.asList(new Nested(1, 2), new Nested(2, 3)));
|
SampleWithReference source = new SampleWithReference(Arrays.asList(new Nested(1, 2), new Nested(2, 3)));
|
||||||
@@ -506,7 +507,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-944
|
@Test // DATAREST-944
|
||||||
public void mergesAssociationsAndKeepsMutableCollection() {
|
void mergesAssociationsAndKeepsMutableCollection() {
|
||||||
|
|
||||||
ArrayList<Nested> originalCollection = new ArrayList<Nested>(Arrays.asList(new Nested(2, 3)));
|
ArrayList<Nested> originalCollection = new ArrayList<Nested>(Arrays.asList(new Nested(2, 3)));
|
||||||
SampleWithReference source = new SampleWithReference(
|
SampleWithReference source = new SampleWithReference(
|
||||||
@@ -520,7 +521,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1030
|
@Test // DATAREST-1030
|
||||||
public void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception {
|
void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception {
|
||||||
|
|
||||||
Associations associations = mock(Associations.class);
|
Associations associations = mock(Associations.class);
|
||||||
PersistentProperty<?> any = ArgumentMatchers.any(PersistentProperty.class);
|
PersistentProperty<?> any = ArgumentMatchers.any(PersistentProperty.class);
|
||||||
@@ -549,7 +550,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1249
|
@Test // DATAREST-1249
|
||||||
public void mergesIntoUninitializedCollection() throws Exception {
|
void mergesIntoUninitializedCollection() throws Exception {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectNode source = (ObjectNode) mapper.readTree("{ \"strings\" : [ \"value\" ] }");
|
ObjectNode source = (ObjectNode) mapper.readTree("{ \"strings\" : [ \"value\" ] }");
|
||||||
@@ -560,7 +561,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1383
|
@Test // DATAREST-1383
|
||||||
public void doesNotWipeReadOnlyPropertyForPatch() throws Exception {
|
void doesNotWipeReadOnlyPropertyForPatch() throws Exception {
|
||||||
|
|
||||||
SampleUser user = new SampleUser("name", "password");
|
SampleUser user = new SampleUser("name", "password");
|
||||||
user.lastLogin = new Date();
|
user.lastLogin = new Date();
|
||||||
@@ -577,7 +578,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1068
|
@Test // DATAREST-1068
|
||||||
public void arraysCanBeResizedDuringMerge() throws Exception {
|
void arraysCanBeResizedDuringMerge() throws Exception {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ArrayHolder target = new ArrayHolder(new String[] {});
|
ArrayHolder target = new ArrayHolder(new String[] {});
|
||||||
JsonNode node = mapper.readTree("{ \"array\" : [ \"new\" ] }");
|
JsonNode node = mapper.readTree("{ \"array\" : [ \"new\" ] }");
|
||||||
@@ -724,7 +725,7 @@ public class DomainObjectReaderUnitTests {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {}
|
void setName(String name) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DATAREST-977
|
// DATAREST-977
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.context.support.StaticMessageSource;
|
import org.springframework.context.support.StaticMessageSource;
|
||||||
import org.springframework.hateoas.mediatype.MessageResolver;
|
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||||
@@ -30,13 +30,13 @@ import org.springframework.hateoas.mediatype.MessageResolver;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class EnumTranslatorUnitTests {
|
class EnumTranslatorUnitTests {
|
||||||
|
|
||||||
StaticMessageSource messageSource;
|
StaticMessageSource messageSource;
|
||||||
EnumTranslator configuration;
|
EnumTranslator configuration;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
LocaleContextHolder.setLocale(Locale.US);
|
LocaleContextHolder.setLocale(Locale.US);
|
||||||
|
|
||||||
@@ -46,28 +46,30 @@ public class EnumTranslatorUnitTests {
|
|||||||
this.configuration = new EnumTranslator(MessageResolver.of(messageSource));
|
this.configuration = new EnumTranslator(MessageResolver.of(messageSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class) // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void rejectsNullMessageSourceAccessor() {
|
void rejectsNullMessageSourceAccessor() {
|
||||||
new EnumTranslator(null);
|
|
||||||
|
assertThatIllegalArgumentException() //
|
||||||
|
.isThrownBy(() -> new EnumTranslator(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesNullForNullSource() {
|
void parsesNullForNullSource() {
|
||||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesNullForEmptySource() {
|
void parsesNullForEmptySource() {
|
||||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesNullForUnknownValue() {
|
void parsesNullForUnknownValue() {
|
||||||
assertThat(configuration.fromText(MyEnum.class, "Foobar")).isNull();
|
assertThat(configuration.fromText(MyEnum.class, "Foobar")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void returnsEnumNameIfDefaultTranslationIsDisabled() {
|
void returnsEnumNameIfDefaultTranslationIsDisabled() {
|
||||||
|
|
||||||
configuration.setEnableDefaultTranslation(false);
|
configuration.setEnableDefaultTranslation(false);
|
||||||
|
|
||||||
@@ -75,13 +77,13 @@ public class EnumTranslatorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void returnsDefaultTranslationByDefault() {
|
void returnsDefaultTranslationByDefault() {
|
||||||
|
|
||||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo("Second value");
|
assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo("Second value");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesEnumNameIfDefaultTranslationIsDisabled() {
|
void parsesEnumNameIfDefaultTranslationIsDisabled() {
|
||||||
|
|
||||||
configuration.setEnableDefaultTranslation(false);
|
configuration.setEnableDefaultTranslation(false);
|
||||||
|
|
||||||
@@ -89,14 +91,14 @@ public class EnumTranslatorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesStandardTranslationAndEnumNameByDefault() {
|
void parsesStandardTranslationAndEnumNameByDefault() {
|
||||||
|
|
||||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE);
|
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_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
|
@Test // DATAREST-654
|
||||||
public void translatesEnumName() {
|
void translatesEnumName() {
|
||||||
|
|
||||||
LocaleContextHolder.setLocale(Locale.US);
|
LocaleContextHolder.setLocale(Locale.US);
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ public class EnumTranslatorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesEnumNameByDefaultEvenIfMessageDefined() {
|
void parsesEnumNameByDefaultEvenIfMessageDefined() {
|
||||||
|
|
||||||
// Parses resolved message and enum name
|
// Parses resolved message and enum name
|
||||||
assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE);
|
assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||||
@@ -122,7 +124,7 @@ public class EnumTranslatorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-654
|
@Test // DATAREST-654
|
||||||
public void parsesEnumWithDefaultTranslationDisabled() {
|
void parsesEnumWithDefaultTranslationDisabled() {
|
||||||
|
|
||||||
configuration.setEnableDefaultTranslation(false);
|
configuration.setEnableDefaultTranslation(false);
|
||||||
|
|
||||||
@@ -132,7 +134,7 @@ public class EnumTranslatorUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesNotResolveEnumNameAsFallbackIfConfigured() {
|
void doesNotResolveEnumNameAsFallbackIfConfigured() {
|
||||||
|
|
||||||
configuration.setParseEnumNameAsFallback(false);
|
configuration.setParseEnumNameAsFallback(false);
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
import org.springframework.data.mapping.PersistentEntity;
|
import org.springframework.data.mapping.PersistentEntity;
|
||||||
import org.springframework.data.mapping.PersistentProperty;
|
import org.springframework.data.mapping.PersistentProperty;
|
||||||
@@ -42,13 +42,13 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack Four Sided Cube - Bad Day's Remembrance (Bunch of Sides)
|
* @soundtrack Four Sided Cube - Bad Day's Remembrance (Bunch of Sides)
|
||||||
*/
|
*/
|
||||||
public class JacksonMetadataUnitTests {
|
class JacksonMetadataUnitTests {
|
||||||
|
|
||||||
MappingContext<?, ?> context;
|
MappingContext<?, ?> context;
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
this.context = new KeyValueMappingContext<>();
|
this.context = new KeyValueMappingContext<>();
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class JacksonMetadataUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-644
|
@Test // DATAREST-644
|
||||||
public void detectsReadOnlyProperty() {
|
void detectsReadOnlyProperty() {
|
||||||
|
|
||||||
JacksonMetadata metadata = new JacksonMetadata(mapper, User.class);
|
JacksonMetadata metadata = new JacksonMetadata(mapper, User.class);
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class JacksonMetadataUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-644
|
@Test // DATAREST-644
|
||||||
public void reportsConstructorArgumentAsJacksonWritable() {
|
void reportsConstructorArgumentAsJacksonWritable() {
|
||||||
|
|
||||||
JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class);
|
JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class);
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class JacksonMetadataUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-644
|
@Test // DATAREST-644
|
||||||
public void detectsCustomSerializerFortType() {
|
void detectsCustomSerializerFortType() {
|
||||||
|
|
||||||
JsonSerializer<?> serializer = new JacksonMetadata(new ObjectMapper(), SomeBean.class)
|
JsonSerializer<?> serializer = new JacksonMetadata(new ObjectMapper(), SomeBean.class)
|
||||||
.getTypeSerializer(SomeBean.class);
|
.getTypeSerializer(SomeBean.class);
|
||||||
|
|||||||
@@ -21,9 +21,8 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.data.rest.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum;
|
import org.springframework.data.rest.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -34,12 +33,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @soundtrack James Bay - Move Together (Chaos And The Calm)
|
* @soundtrack James Bay - Move Together (Chaos And The Calm)
|
||||||
*/
|
*/
|
||||||
public class JacksonSerializersUnitTests {
|
class JacksonSerializersUnitTests {
|
||||||
|
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
EnumTranslator translator = mock(EnumTranslator.class);
|
EnumTranslator translator = mock(EnumTranslator.class);
|
||||||
doReturn(SampleEnum.VALUE).when(translator).fromText(SampleEnum.class, "value");
|
doReturn(SampleEnum.VALUE).when(translator).fromText(SampleEnum.class, "value");
|
||||||
@@ -49,7 +48,7 @@ public class JacksonSerializersUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-929
|
@Test // DATAREST-929
|
||||||
public void translatesPlainEnumCorrectly() throws Exception {
|
void translatesPlainEnumCorrectly() throws Exception {
|
||||||
|
|
||||||
Sample result = mapper.readValue("{ \"property\" : \"value\"}", Sample.class);
|
Sample result = mapper.readValue("{ \"property\" : \"value\"}", Sample.class);
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ public class JacksonSerializersUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-929
|
@Test // DATAREST-929
|
||||||
public void translatesCollectionOfEnumsCorrectly() throws Exception {
|
void translatesCollectionOfEnumsCorrectly() throws Exception {
|
||||||
|
|
||||||
Sample result = mapper.readValue("{ \"collection\" : [ \"value\" ] }", Sample.class);
|
Sample result = mapper.readValue("{ \"collection\" : [ \"value\" ] }", Sample.class);
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ public class JacksonSerializersUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-929
|
@Test // DATAREST-929
|
||||||
public void translatesEnumArraysCorrectly() throws Exception {
|
void translatesEnumArraysCorrectly() throws Exception {
|
||||||
|
|
||||||
Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class);
|
Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class);
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ public class JacksonSerializersUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-929
|
@Test // DATAREST-929
|
||||||
public void translatesMapEnumValueCorrectly() throws Exception {
|
void translatesMapEnumValueCorrectly() throws Exception {
|
||||||
|
|
||||||
Sample result = mapper.readValue("{ \"mapToEnum\" : { \"foo\" : \"value\" } }", Sample.class);
|
Sample result = mapper.readValue("{ \"mapToEnum\" : { \"foo\" : \"value\" } }", Sample.class);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.json;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
|
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
import org.springframework.data.util.ClassTypeInformation;
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
@@ -27,12 +27,12 @@ import org.springframework.data.util.TypeInformation;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class JsonSchemaUnitTests {
|
class JsonSchemaUnitTests {
|
||||||
|
|
||||||
static final TypeInformation<?> type = ClassTypeInformation.from(Sample.class);
|
static final TypeInformation<?> type = ClassTypeInformation.from(Sample.class);
|
||||||
|
|
||||||
@Test // DATAREST-492
|
@Test // DATAREST-492
|
||||||
public void considersNumberPrimitivesJsonSchemaNumbers() {
|
void considersNumberPrimitivesJsonSchemaNumbers() {
|
||||||
|
|
||||||
JsonSchemaProperty property = new JsonSchemaProperty("foo", null, "bar", false);
|
JsonSchemaProperty property = new JsonSchemaProperty("foo", null, "bar", false);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.json;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||||
@@ -34,7 +34,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*/
|
*/
|
||||||
public class MappedPropertiesUnitTests {
|
class MappedPropertiesUnitTests {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||||
@@ -42,28 +42,28 @@ public class MappedPropertiesUnitTests {
|
|||||||
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
||||||
|
|
||||||
@Test // DATAREST-575
|
@Test // DATAREST-575
|
||||||
public void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
||||||
|
|
||||||
assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData")).isFalse();
|
assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData")).isFalse();
|
||||||
assertThat(properties.getPersistentProperty("notExposedBySpringData")).isNull();
|
assertThat(properties.getPersistentProperty("notExposedBySpringData")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-575
|
@Test // DATAREST-575
|
||||||
public void doesNotExposeMappedPropertyForNonJacksonProperty() {
|
void doesNotExposeMappedPropertyForNonJacksonProperty() {
|
||||||
|
|
||||||
assertThat(properties.hasPersistentPropertyForField("notExposedByJackson")).isFalse();
|
assertThat(properties.hasPersistentPropertyForField("notExposedByJackson")).isFalse();
|
||||||
assertThat(properties.getPersistentProperty("notExposedByJackson")).isNull();
|
assertThat(properties.getPersistentProperty("notExposedByJackson")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-575
|
@Test // DATAREST-575
|
||||||
public void exposesProperty() {
|
void exposesProperty() {
|
||||||
|
|
||||||
assertThat(properties.hasPersistentPropertyForField("exposedProperty")).isTrue();
|
assertThat(properties.hasPersistentPropertyForField("exposedProperty")).isTrue();
|
||||||
assertThat(properties.getPersistentProperty("exposedProperty")).isNotNull();
|
assertThat(properties.getPersistentProperty("exposedProperty")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-575
|
@Test // DATAREST-575
|
||||||
public void exposesRenamedPropertyByExternalName() {
|
void exposesRenamedPropertyByExternalName() {
|
||||||
|
|
||||||
assertThat(properties.hasPersistentPropertyForField("email")).isTrue();
|
assertThat(properties.hasPersistentPropertyForField("email")).isTrue();
|
||||||
assertThat(properties.getPersistentProperty("email")).isNotNull();
|
assertThat(properties.getPersistentProperty("email")).isNotNull();
|
||||||
@@ -71,14 +71,14 @@ public class MappedPropertiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1006
|
@Test // DATAREST-1006
|
||||||
public void doesNotExposeIgnoredPropertyViaJsonProperty() {
|
void doesNotExposeIgnoredPropertyViaJsonProperty() {
|
||||||
|
|
||||||
assertThat(properties.hasPersistentPropertyForField("readOnlyProperty")).isFalse();
|
assertThat(properties.hasPersistentPropertyForField("readOnlyProperty")).isFalse();
|
||||||
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull();
|
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1248
|
@Test // DATAREST-1248
|
||||||
public void doesNotExcludeReadOnlyPropertiesForSerialization() {
|
void doesNotExcludeReadOnlyPropertiesForSerialization() {
|
||||||
|
|
||||||
MappedProperties properties = MappedProperties.forSerialization(entity, mapper);
|
MappedProperties properties = MappedProperties.forSerialization(entity, mapper);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class MappedPropertiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1383
|
@Test // DATAREST-1383
|
||||||
public void doesNotRegardReadOnlyPropertyForDeserialization() {
|
void doesNotRegardReadOnlyPropertyForDeserialization() {
|
||||||
|
|
||||||
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public class MappedPropertiesUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-1440
|
@Test // DATAREST-1440
|
||||||
public void exposesExistanceOfCatchAllMethod() {
|
void exposesExistanceOfCatchAllMethod() {
|
||||||
|
|
||||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(SampleWithJsonAnySetter.class);
|
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(SampleWithJsonAnySetter.class);
|
||||||
|
|
||||||
@@ -132,6 +132,6 @@ public class MappedPropertiesUnitTests {
|
|||||||
public @ReadOnlyProperty String anotherReadOnlyProperty;
|
public @ReadOnlyProperty String anotherReadOnlyProperty;
|
||||||
|
|
||||||
@JsonAnySetter
|
@JsonAnySetter
|
||||||
public void set(String key, String value) {}
|
void set(String key, String value) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ package org.springframework.data.rest.webmvc.json;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@@ -39,8 +39,8 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Oliver Drotbohm
|
* @author Oliver Drotbohm
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class MappingAwarePageableArgumentResolverUnitTests {
|
class MappingAwarePageableArgumentResolverUnitTests {
|
||||||
|
|
||||||
@Mock JacksonMappingAwareSortTranslator translator;
|
@Mock JacksonMappingAwareSortTranslator translator;
|
||||||
@Mock PageableHandlerMethodArgumentResolver delegate;
|
@Mock PageableHandlerMethodArgumentResolver delegate;
|
||||||
@@ -51,13 +51,13 @@ public class MappingAwarePageableArgumentResolverUnitTests {
|
|||||||
|
|
||||||
MappingAwarePageableArgumentResolver resolver;
|
MappingAwarePageableArgumentResolver resolver;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
resolver = new MappingAwarePageableArgumentResolver(translator, delegate);
|
resolver = new MappingAwarePageableArgumentResolver(translator, delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void resolveArgumentShouldReturnTranslatedPageable() throws Exception {
|
void resolveArgumentShouldReturnTranslatedPageable() throws Exception {
|
||||||
|
|
||||||
Sort translated = Sort.by("world");
|
Sort translated = Sort.by("world");
|
||||||
Pageable pageable = PageRequest.of(0, 1, Direction.ASC, "hello");
|
Pageable pageable = PageRequest.of(0, 1, Direction.ASC, "hello");
|
||||||
@@ -73,7 +73,7 @@ public class MappingAwarePageableArgumentResolverUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void resolveArgumentShouldReturnPageableWithoutSort() throws Exception {
|
void resolveArgumentShouldReturnPageableWithoutSort() throws Exception {
|
||||||
|
|
||||||
Pageable pageable = PageRequest.of(0, 1);
|
Pageable pageable = PageRequest.of(0, 1);
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class MappingAwarePageableArgumentResolverUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREST-906
|
@Test // DATAREST-906
|
||||||
public void resolveArgumentShouldReturnUnpagedPageable() throws Exception {
|
void resolveArgumentShouldReturnUnpagedPageable() throws Exception {
|
||||||
|
|
||||||
when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory))
|
when(delegate.resolveArgument(parameter, modelAndViewContainer, webRequest, binderFactory))
|
||||||
.thenReturn(Pageable.unpaged());
|
.thenReturn(Pageable.unpaged());
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user