@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.domain.PersonRepository;
|
||||
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}
|
||||
@@ -29,14 +29,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = RepositoryTestsConfig.class)
|
||||
public abstract class AbstractIntegrationTests {
|
||||
|
||||
@Autowired PersonRepository repository;
|
||||
|
||||
@Before
|
||||
public void populateDatabase() {
|
||||
@BeforeEach
|
||||
void populateDatabase() {
|
||||
repository.save(new Person("John", "Doe"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,63 +17,63 @@ package org.springframework.data.rest.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Path}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PathUnitTests {
|
||||
class PathUnitTests {
|
||||
|
||||
@Test
|
||||
public void combinesSimplePaths() {
|
||||
void combinesSimplePaths() {
|
||||
|
||||
Path builder = new Path("foo").slash("bar");
|
||||
assertThat(builder.toString()).isEqualTo("/foo/bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removesLeadingAndTrailingSlashes() {
|
||||
void removesLeadingAndTrailingSlashes() {
|
||||
|
||||
Path builder = new Path("foo/").slash("/bar").slash("//foobar///");
|
||||
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removesWhitespace() {
|
||||
void removesWhitespace() {
|
||||
|
||||
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
|
||||
assertThat(builder.toString()).isEqualTo("/foo/bar/foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWithLeadingSlash() {
|
||||
void matchesWithLeadingSlash() {
|
||||
assertThat(new Path("/foobar").matches("/foobar")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWithoutLeadingSlash() {
|
||||
void matchesWithoutLeadingSlash() {
|
||||
assertThat(new Path("/foobar").matches("foobar")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotMatchIfDifferent() {
|
||||
void doesNotMatchIfDifferent() {
|
||||
assertThat(new Path("/foobar").matches("barfoo")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotPrefixAbsoluteUris() {
|
||||
void doesNotPrefixAbsoluteUris() {
|
||||
assertThat(new Path("http://localhost").toString()).isEqualTo("http://localhost");
|
||||
}
|
||||
|
||||
@Test // DATAREST-222
|
||||
public void doesNotMatchIfReferenceContainsReservedCharacters() {
|
||||
void doesNotMatchIfReferenceContainsReservedCharacters() {
|
||||
assertThat(new Path("/foobar").matches("barfoo{?foo}")).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-222
|
||||
public void doesNotMatchNullReference() {
|
||||
void doesNotMatchNullReference() {
|
||||
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 org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
@@ -36,13 +36,13 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
|
||||
class RepositoryRestConfigurationIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@Autowired RepositoryRestConfiguration config;
|
||||
@Autowired Repositories repositories;
|
||||
|
||||
@Test
|
||||
public void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
|
||||
void shouldProvideResourceMappingForConfiguredRepository() throws Exception {
|
||||
|
||||
ResourceMapping mapping = config.getResourceMappingForRepository(ConfiguredPersonRepository.class);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RepositoryRestConfigurationIntegrationTests extends AbstractIntegra
|
||||
|
||||
@Test // DATAREST-1304
|
||||
@DirtiesContext
|
||||
public void exposesLookupPropertyFromLambda() {
|
||||
void exposesLookupPropertyFromLambda() {
|
||||
|
||||
config.withEntityLookup() //
|
||||
.forRepository(ProfileRepository.class) //
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.rest.core;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
|
||||
import org.springframework.data.rest.core.config.MetadataConfiguration;
|
||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
||||
@@ -37,40 +37,40 @@ import org.springframework.http.MediaType;
|
||||
* @author Mark Paluch
|
||||
* @soundtrack Adam F - Circles (Colors)
|
||||
*/
|
||||
public class RepositoryRestConfigurationUnitTests {
|
||||
class RepositoryRestConfigurationUnitTests {
|
||||
|
||||
RepositoryRestConfiguration configuration;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodiesIfAcceptHeaderPresentByDefault() {
|
||||
void returnsBodiesIfAcceptHeaderPresentByDefault() {
|
||||
|
||||
assertThat(configuration.returnBodyOnCreate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
||||
assertThat(configuration.returnBodyOnUpdate(MediaType.APPLICATION_JSON_VALUE)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
|
||||
void doesNotReturnBodiesIfNoAcceptHeaderPresentByDefault() {
|
||||
|
||||
assertThat(configuration.returnBodyOnCreate(null)).isFalse();
|
||||
assertThat(configuration.returnBodyOnUpdate(null)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
|
||||
void doesNotReturnBodiesIfEmptyAcceptHeaderPresentByDefault() {
|
||||
|
||||
assertThat(configuration.returnBodyOnCreate("")).isFalse();
|
||||
assertThat(configuration.returnBodyOnUpdate("")).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
|
||||
void doesNotReturnBodyForUpdateIfExplicitlyDeactivated() {
|
||||
|
||||
configuration.setReturnBodyOnUpdate(false);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class RepositoryRestConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
|
||||
void doesNotReturnBodyForCreateIfExplicitlyDeactivated() {
|
||||
|
||||
configuration.setReturnBodyOnCreate(false);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RepositoryRestConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodyForUpdateIfExplicitlyActivated() {
|
||||
void returnsBodyForUpdateIfExplicitlyActivated() {
|
||||
|
||||
configuration.setReturnBodyOnUpdate(true);
|
||||
|
||||
@@ -100,7 +100,7 @@ public class RepositoryRestConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodyForCreateIfExplicitlyActivated() {
|
||||
void returnsBodyForCreateIfExplicitlyActivated() {
|
||||
|
||||
configuration.setReturnBodyOnCreate(true);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class RepositoryRestConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-776
|
||||
public void considersDomainTypeOfValueRepositoryLookupTypes() {
|
||||
void considersDomainTypeOfValueRepositoryLookupTypes() {
|
||||
|
||||
configuration.withEntityLookup().forLookupRepository(ProfileRepository.class);
|
||||
|
||||
@@ -118,13 +118,13 @@ public class RepositoryRestConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1076
|
||||
public void rejectsNullRelProvider() {
|
||||
void rejectsNullRelProvider() {
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
.isThrownBy(() -> configuration.setLinkRelationProvider(null));
|
||||
}
|
||||
|
||||
@Test // #1974
|
||||
public void considersAtRelationOnTypesByDefault() {
|
||||
void considersAtRelationOnTypesByDefault() {
|
||||
assertThat(configuration.getLinkRelationProvider().getItemResourceRelFor(Sample.class))
|
||||
.isEqualTo(LinkRelation.of("something"));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import javax.naming.InvalidNameException;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
|
||||
/**
|
||||
@@ -29,10 +29,10 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class StringToLdapNameConverterUnitTests {
|
||||
class StringToLdapNameConverterUnitTests {
|
||||
|
||||
@Test // DATAREST-1198
|
||||
public void shouldCreateLdapName() throws InvalidNameException {
|
||||
void shouldCreateLdapName() throws InvalidNameException {
|
||||
|
||||
LdapName converted = StringToLdapNameConverter.INSTANCE.convert("dc=foo");
|
||||
|
||||
@@ -40,14 +40,14 @@ public class StringToLdapNameConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1198
|
||||
public void failedConversionShouldThrowIAE() {
|
||||
void failedConversionShouldThrowIAE() {
|
||||
|
||||
assertThatThrownBy(() -> StringToLdapNameConverter.INSTANCE.convert("foo"))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-1198
|
||||
public void shouldConvertStringInNameViaConversionService() {
|
||||
void shouldConvertStringInNameViaConversionService() {
|
||||
|
||||
DefaultConversionService conversionService = new DefaultConversionService();
|
||||
conversionService.addConverter(StringToLdapNameConverter.INSTANCE);
|
||||
|
||||
@@ -24,11 +24,11 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
|
||||
@@ -47,8 +47,8 @@ import org.springframework.data.util.Streamable;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UriToEntityConverterUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UriToEntityConverterUnitTests {
|
||||
|
||||
static final TypeDescriptor URI_TYPE = TypeDescriptor.valueOf(URI.class);
|
||||
static final TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
|
||||
@@ -60,8 +60,8 @@ public class UriToEntityConverterUnitTests {
|
||||
KeyValueMappingContext<?, ?> context;
|
||||
UriToEntityConverter converter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.context = new KeyValueMappingContext<>();
|
||||
this.context.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(Entity.class, NonEntity.class)));
|
||||
@@ -72,7 +72,7 @@ public class UriToEntityConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void supportsOnlyEntitiesWithIdProperty() {
|
||||
void supportsOnlyEntitiesWithIdProperty() {
|
||||
|
||||
Set<ConvertiblePair> result = converter.getConvertibleTypes();
|
||||
|
||||
@@ -81,12 +81,12 @@ public class UriToEntityConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
|
||||
void cannotConvertEntityWithIdPropertyIfStringConversionMissing() {
|
||||
assertThat(converter.matches(URI_TYPE, ENTITY_TYPE)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
|
||||
void canConvertEntityWithIdPropertyAndFromStringConversionPossible() {
|
||||
|
||||
doReturn(Optional.of(mock(RepositoryInformation.class))).when(repositories)
|
||||
.getRepositoryInformationFor(ENTITY_TYPE.getType());
|
||||
@@ -95,12 +95,12 @@ public class UriToEntityConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void cannotConvertEntityWithoutIdentifier() {
|
||||
void cannotConvertEntityWithoutIdentifier() {
|
||||
assertThat(converter.matches(URI_TYPE, TypeDescriptor.valueOf(NonEntity.class))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void invokesConverterWithLastUriPathSegment() {
|
||||
void invokesConverterWithLastUriPathSegment() {
|
||||
|
||||
Entity reference = new Entity();
|
||||
|
||||
@@ -108,39 +108,49 @@ public class UriToEntityConverterUnitTests {
|
||||
doReturn(Optional.of(reference)).when(invoker).invokeFindById("1");
|
||||
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
|
||||
public void rejectsUnknownType() {
|
||||
converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE);
|
||||
@Test // DATAREST-427
|
||||
void rejectsUnknownType() {
|
||||
|
||||
assertThatExceptionOfType(ConversionFailedException.class) //
|
||||
.isThrownBy(() -> converter.convert(URI.create("/foo/1"), URI_TYPE, STRING_TYPE));
|
||||
}
|
||||
|
||||
@Test(expected = ConversionFailedException.class) // DATAREST-427
|
||||
public void rejectsUriWithLessThanTwoSegments() {
|
||||
converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE);
|
||||
@Test // DATAREST-427
|
||||
void rejectsUriWithLessThanTwoSegments() {
|
||||
|
||||
assertThatExceptionOfType(ConversionFailedException.class) //
|
||||
.isThrownBy(() -> converter.convert(URI.create("1"), URI_TYPE, ENTITY_TYPE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
||||
public void rejectsNullPersistentEntities() {
|
||||
new UriToEntityConverter(null, invokerFactory, repositories);
|
||||
@Test // DATAREST-741
|
||||
void rejectsNullPersistentEntities() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new UriToEntityConverter(null, invokerFactory, repositories));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
||||
public void rejectsNullRepositoryInvokerFactory() {
|
||||
new UriToEntityConverter(mock(PersistentEntities.class), null, repositories);
|
||||
@Test // DATAREST-741
|
||||
void rejectsNullRepositoryInvokerFactory() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), null, repositories));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-741
|
||||
public void rejectsNullRepositories() {
|
||||
new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null);
|
||||
@Test // DATAREST-741
|
||||
void rejectsNullRepositories() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new UriToEntityConverter(mock(PersistentEntities.class), invokerFactory, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-1018
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRegisterTypeWithUnmanagedRawType() {
|
||||
void doesNotRegisterTypeWithUnmanagedRawType() {
|
||||
|
||||
PersistentEntities entities = mock(PersistentEntities.class);
|
||||
doReturn(Streamable.of(ClassTypeInformation.OBJECT)).when(entities).getManagedTypes();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.NotReadablePropertyException;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
@@ -33,12 +33,12 @@ import org.springframework.validation.Errors;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ValidationErrorsUnitTests {
|
||||
class ValidationErrorsUnitTests {
|
||||
|
||||
PersistentEntities entities;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
context.getPersistentEntity(Foo.class);
|
||||
@@ -47,7 +47,7 @@ public class ValidationErrorsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-798
|
||||
public void exposesNestedViolationsCorrectly() {
|
||||
void exposesNestedViolationsCorrectly() {
|
||||
|
||||
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
||||
|
||||
@@ -59,12 +59,12 @@ public class ValidationErrorsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-801
|
||||
public void getsTheNestedFieldsValue() {
|
||||
void getsTheNestedFieldsValue() {
|
||||
expectedErrorBehavior(new ValidationErrors(new Foo(), entities));
|
||||
}
|
||||
|
||||
@Test // DATAREST-1163
|
||||
public void returnsNullForPropertyValue() {
|
||||
void returnsNullForPropertyValue() {
|
||||
|
||||
ValidationErrors errors = new ValidationErrors(new Foo(), entities);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration.ProjectionDefinition;
|
||||
|
||||
/**
|
||||
@@ -27,40 +27,53 @@ import org.springframework.data.rest.core.config.ProjectionDefinitionConfigurati
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ProjectionDefinitionConfigurationUnitTests {
|
||||
class ProjectionDefinitionConfigurationUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
||||
public void rejectsNullProjectionTypeForAutoConfiguration() {
|
||||
new ProjectionDefinitionConfiguration().addProjection(null);
|
||||
}
|
||||
@Test // DATAREST-221
|
||||
void rejectsNullProjectionTypeForAutoConfiguration() {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-221
|
||||
public void rejectsUnannotatedClassForConfigurationShortcut() {
|
||||
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]);
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new ProjectionDefinitionConfiguration().addProjection(null));
|
||||
}
|
||||
|
||||
@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();
|
||||
configuration.addProjection(Integer.class, "name", String.class);
|
||||
@@ -69,7 +82,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void registersAnnotatedProjection() {
|
||||
void registersAnnotatedProjection() {
|
||||
|
||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||
configuration.addProjection(SampleProjection.class);
|
||||
@@ -78,7 +91,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void defaultsNameToSimpleClassNameIfNotAnnotated() {
|
||||
void defaultsNameToSimpleClassNameIfNotAnnotated() {
|
||||
|
||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||
configuration.addProjection(Default.class);
|
||||
@@ -87,7 +100,7 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void definitionEquals() {
|
||||
void definitionEquals() {
|
||||
|
||||
ProjectionDefinition objectName = 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
|
||||
public void returnsProjectionForParentClass() {
|
||||
void returnsProjectionForParentClass() {
|
||||
|
||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||
configuration.addProjection(ParentProjection.class);
|
||||
@@ -119,12 +132,12 @@ public class ProjectionDefinitionConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void defaultsParamternameToProjection() {
|
||||
void defaultsParamternameToProjection() {
|
||||
assertThat(new ProjectionDefinitionConfiguration().getParameterName()).isEqualTo("projection");
|
||||
}
|
||||
|
||||
@Test // DATAREST-747
|
||||
public void returnsMostConcreteProjectionForSourceType() {
|
||||
void returnsMostConcreteProjectionForSourceType() {
|
||||
|
||||
ProjectionDefinitionConfiguration configuration = new ProjectionDefinitionConfiguration();
|
||||
configuration.addProjection(ParentProjection.class);
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.springframework.data.rest.core.support.ResourceMappingUtils.*;
|
||||
|
||||
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.Pageable;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -36,12 +36,12 @@ import org.springframework.hateoas.server.core.EvoInflectorLinkRelationProvider;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ResourceMappingUnitTests {
|
||||
class ResourceMappingUnitTests {
|
||||
|
||||
LinkRelationProvider relProvider = new EvoInflectorLinkRelationProvider();
|
||||
|
||||
@Test
|
||||
public void shouldDetectPathAndRemoveLeadingSlashIfAny() {
|
||||
void shouldDetectPathAndRemoveLeadingSlashIfAny() {
|
||||
|
||||
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
||||
findRel(AnnotatedWithLeadingSlashPersonRepository.class),
|
||||
@@ -56,7 +56,7 @@ public class ResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
|
||||
void shouldDetectPathAndRemoveLeadingSlashIfAnyOnMethod() throws Exception {
|
||||
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByFirstName", String.class,
|
||||
Pageable.class);
|
||||
org.springframework.data.rest.core.config.ResourceMapping mapping = new org.springframework.data.rest.core.config.ResourceMapping(
|
||||
@@ -70,7 +70,7 @@ public class ResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
|
||||
void shouldReturnDefaultIfPathContainsOnlySlashTextOnMethod() throws Exception {
|
||||
Method method = AnnotatedWithLeadingSlashPersonRepository.class.getMethod("findByLastName", String.class,
|
||||
Pageable.class);
|
||||
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;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
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.context.ApplicationContext;
|
||||
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.event.*;
|
||||
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.
|
||||
@@ -40,9 +41,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
public class RepositoryEventIntegrationTests {
|
||||
class RepositoryEventIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ RepositoryTestsConfig.class })
|
||||
@@ -68,58 +69,78 @@ public class RepositoryEventIntegrationTests {
|
||||
@Autowired PersonRepository people;
|
||||
Person person;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
person = people.save(new Person("Jane", "Doe"));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchBeforeCreate() throws Exception {
|
||||
appCtx.publishEvent(new BeforeCreateEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchBeforeCreate() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new BeforeCreateEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchAfterCreate() throws Exception {
|
||||
appCtx.publishEvent(new AfterCreateEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchAfterCreate() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new AfterCreateEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchBeforeSave() throws Exception {
|
||||
appCtx.publishEvent(new BeforeSaveEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchBeforeSave() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new BeforeSaveEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchAfterSave() throws Exception {
|
||||
appCtx.publishEvent(new AfterSaveEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchAfterSave() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new AfterSaveEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchBeforeDelete() throws Exception {
|
||||
appCtx.publishEvent(new BeforeDeleteEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchBeforeDelete() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new BeforeDeleteEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchAfterDelete() throws Exception {
|
||||
appCtx.publishEvent(new AfterDeleteEvent(person));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchAfterDelete() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new AfterDeleteEvent(person)));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchBeforeLinkSave() throws Exception {
|
||||
appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object()));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchBeforeLinkSave() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkSaveEvent(person, new Object())));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchAfterLinkSave() throws Exception {
|
||||
appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object()));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchAfterLinkSave() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkSaveEvent(person, new Object())));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchBeforeLinkDelete() throws Exception {
|
||||
appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object()));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchBeforeLinkDelete() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new BeforeLinkDeleteEvent(person, new Object())));
|
||||
}
|
||||
|
||||
@Test(expected = EventHandlerInvokedException.class) // DATAREST-388
|
||||
public void shouldDispatchAfterLinkDelete() throws Exception {
|
||||
appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object()));
|
||||
@Test // DATAREST-388
|
||||
void shouldDispatchAfterLinkDelete() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(EventHandlerInvokedException.class) //
|
||||
.isThrownBy(() -> appCtx.publishEvent(new AfterLinkDeleteEvent(person, new Object())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.context;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.ValidatingRepositoryEventListener;
|
||||
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.
|
||||
@@ -41,9 +43,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
public class ValidatorIntegrationTests {
|
||||
class ValidatorIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ RepositoryTestsConfig.class, JpaRepositoryConfig.class })
|
||||
@@ -62,12 +64,14 @@ public class ValidatorIntegrationTests {
|
||||
@Autowired ConfigurableApplicationContext context;
|
||||
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
||||
|
||||
@Test(expected = RepositoryConstraintViolationException.class)
|
||||
public void shouldValidateLastName() throws Exception {
|
||||
@Test
|
||||
void shouldValidateLastName() throws Exception {
|
||||
|
||||
mappingContext.getPersistentEntity(Person.class);
|
||||
|
||||
// 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;
|
||||
|
||||
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
|
||||
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;
|
||||
import org.springframework.data.rest.core.annotation.*;
|
||||
|
||||
/**
|
||||
* Sample annotation-based event handler.
|
||||
@@ -39,26 +29,26 @@ public class AnnotatedPersonEventHandler {
|
||||
@HandleAfterCreate
|
||||
@HandleAfterDelete
|
||||
@HandleAfterSave
|
||||
public void handleAfter(Person p) {
|
||||
void handleAfter(Person p) {
|
||||
throw new EventHandlerInvokedException();
|
||||
}
|
||||
|
||||
@HandleAfterLinkDelete
|
||||
@HandleAfterLinkSave
|
||||
public void handleAfterLink(Person p, Object o) {
|
||||
void handleAfterLink(Person p, Object o) {
|
||||
throw new EventHandlerInvokedException();
|
||||
}
|
||||
|
||||
@HandleBeforeCreate
|
||||
@HandleBeforeDelete
|
||||
@HandleBeforeSave
|
||||
public void handleBefore(Person p) {
|
||||
void handleBefore(Person p) {
|
||||
throw new EventHandlerInvokedException();
|
||||
}
|
||||
|
||||
@HandleBeforeLinkDelete
|
||||
@HandleBeforeLinkSave
|
||||
public void handleBeforeLink(Person p, Object o) {
|
||||
void handleBeforeLink(Person p, Object o) {
|
||||
throw new EventHandlerInvokedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.annotation.Reference;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Value
|
||||
public class Order {
|
||||
class Order {
|
||||
|
||||
@Id UUID id = UUID.randomUUID();
|
||||
@Reference Person creator;
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.validation.Validator;
|
||||
|
||||
/**
|
||||
* A test {@link Validator} that checks for non-blank names.
|
||||
*
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Component;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
public class ProfileLoader implements InitializingBean {
|
||||
class ProfileLoader implements InitializingBean {
|
||||
|
||||
@Autowired ProfileRepository profiles;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
|
||||
@@ -43,11 +43,11 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Fabian Trampusch
|
||||
* @author Joseph Valerio
|
||||
*/
|
||||
public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
class AnnotatedEventHandlerInvokerUnitTests {
|
||||
|
||||
@Test // DATAREST-582
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doesNotDiscoverMethodsOnProxyClasses() {
|
||||
void doesNotDiscoverMethodsOnProxyClasses() {
|
||||
|
||||
ProxyFactory factory = new ProxyFactory();
|
||||
factory.setTarget(new Sample());
|
||||
@@ -63,7 +63,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-606
|
||||
public void invokesPrivateEventHandlerMethods() {
|
||||
void invokesPrivateEventHandlerMethods() {
|
||||
|
||||
SampleWithPrivateHandler sampleHandler = new SampleWithPrivateHandler();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-970
|
||||
public void invokesEventHandlerInOrderMethods() {
|
||||
void invokesEventHandlerInOrderMethods() {
|
||||
|
||||
SampleOrderEventHandler1 orderHandler1 = new SampleOrderEventHandler1();
|
||||
SampleOrderEventHandler2 orderHandler2 = new SampleOrderEventHandler2();
|
||||
@@ -94,7 +94,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-983
|
||||
public void invokesEventHandlerOnParentClass() {
|
||||
void invokesEventHandlerOnParentClass() {
|
||||
|
||||
FirstEventHandler firstHandler = new FirstEventHandler();
|
||||
SecondEventHandler secondHandler = new SecondEventHandler();
|
||||
@@ -111,7 +111,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1075
|
||||
public void doesInvokeMethodOnlyOnceForMockitoSpy() {
|
||||
void doesInvokeMethodOnlyOnceForMockitoSpy() {
|
||||
|
||||
EventHandler handler = spy(new EventHandler());
|
||||
AnnotatedEventHandlerInvoker invoker = new AnnotatedEventHandlerInvoker();
|
||||
@@ -124,7 +124,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-582
|
||||
public void invocesInterceptorForProxiedListener() {
|
||||
void invocesInterceptorForProxiedListener() {
|
||||
|
||||
SampleInterceptor interceptor = new SampleInterceptor();
|
||||
|
||||
@@ -147,7 +147,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
static class Sample {
|
||||
|
||||
@HandleBeforeCreate
|
||||
public void method(Sample sample) {}
|
||||
void method(Sample sample) {}
|
||||
}
|
||||
|
||||
@RepositoryEventHandler
|
||||
@@ -216,7 +216,7 @@ public class AnnotatedEventHandlerInvokerUnitTests {
|
||||
static class EventHandler {
|
||||
|
||||
@HandleAfterCreate
|
||||
public void doAfterCreate(Payload bar) {}
|
||||
void doAfterCreate(Payload bar) {}
|
||||
}
|
||||
|
||||
static class Payload {}
|
||||
|
||||
@@ -23,11 +23,11 @@ import static org.springframework.http.HttpMethod.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
@@ -46,18 +46,18 @@ import org.springframework.http.HttpMethod;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
|
||||
@Mock RepositoryResourceMappings mappings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
when(mappings.exposeMethodsByDefault()).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-589, DATAREST-409
|
||||
public void doesNotSupportAnyHttpMethodForEmptyRepository() {
|
||||
void doesNotSupportAnyHttpMethodForEmptyRepository() {
|
||||
|
||||
SupportedHttpMethods supportedMethods = getSupportedHttpMethodsFor(RawRepository.class);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
||||
public void defaultsSupportedHttpMethodsForItemResource() {
|
||||
void defaultsSupportedHttpMethodsForItemResource() {
|
||||
|
||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-217, DATAREST-330, DATACMNS-589, DATAREST-409
|
||||
public void defaultsSupportedHttpMethodsForCollectionResource() {
|
||||
void defaultsSupportedHttpMethodsForCollectionResource() {
|
||||
|
||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(SampleRepository.class);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-589, DATAREST-409
|
||||
public void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
|
||||
void doesNotSupportDeleteIfDeleteMethodIsNotExported() {
|
||||
|
||||
SupportedHttpMethods supportedHttpMethods = getSupportedHttpMethodsFor(HidesDelete.class);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-523
|
||||
public void exposesMethodsForProperties() {
|
||||
void exposesMethodsForProperties() {
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
KeyValuePersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
@@ -118,17 +118,17 @@ public class CrudMethodsSupportedHttpMethodsUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-825
|
||||
public void supportsDeleteIfFindOneIsHidden() {
|
||||
void supportsDeleteIfFindOneIsHidden() {
|
||||
assertMethodsSupported(getSupportedHttpMethodsFor(HidesFindOne.class), ITEM, true, DELETE, PATCH, PUT, OPTIONS);
|
||||
}
|
||||
|
||||
@Test // DATAREST-825
|
||||
public void doesNotSupportDeleteIfNoFindOneAvailable() {
|
||||
void doesNotSupportDeleteIfNoFindOneAvailable() {
|
||||
assertMethodsSupported(getSupportedHttpMethodsFor(NoFindOne.class), ITEM, false, DELETE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-1176
|
||||
public void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
|
||||
void onlyExposesExplicitlyAnnotatedMethodsIfConfigured() {
|
||||
|
||||
reset(mappings);
|
||||
when(mappings.exposeMethodsByDefault()).thenReturn(false);
|
||||
|
||||
@@ -19,17 +19,17 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ExposureConfiguration}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ExposureConfigurationUnitTests {
|
||||
class ExposureConfigurationUnitTests {
|
||||
|
||||
@Test // DATAREST-948
|
||||
public void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
|
||||
void appliesTypeBasedCollectionFiltersOnlyForMatchingTypes() {
|
||||
|
||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ExposureConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-948
|
||||
public void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
|
||||
void appliesTypeBasedItemFiltersOnlyForMatchingTypes() {
|
||||
|
||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ExposureConfigurationUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-948
|
||||
public void appliesTypeSpecificFilterForAggregateSubTypes() {
|
||||
void appliesTypeSpecificFilterForAggregateSubTypes() {
|
||||
|
||||
ExposureConfiguration configuration = new ExposureConfiguration();
|
||||
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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||
@@ -34,8 +34,8 @@ import org.springframework.data.rest.core.annotation.RestResource;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MappingResourceMetadataUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MappingResourceMetadataUnitTests {
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class MappingResourceMetadataUnitTests {
|
||||
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
|
||||
|
||||
@Test // DATAREST-514
|
||||
public void allowsLookupOfPropertyByMappedName() {
|
||||
void allowsLookupOfPropertyByMappedName() {
|
||||
|
||||
KeyValuePersistentProperty<?> property = entity.getRequiredPersistentProperty("related");
|
||||
|
||||
@@ -57,13 +57,13 @@ public class MappingResourceMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-518
|
||||
public void isNotExportedByDefault() {
|
||||
void isNotExportedByDefault() {
|
||||
|
||||
assertThat(metadata.isExported()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-518
|
||||
public void isExportedIfExplicitlyAnnotated() {
|
||||
void isExportedIfExplicitlyAnnotated() {
|
||||
|
||||
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getRequiredPersistentEntity(Related.class),
|
||||
resourceMappings);
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
||||
|
||||
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.mapping.context.PersistentEntities;
|
||||
|
||||
@@ -26,10 +26,10 @@ import org.springframework.data.mapping.context.PersistentEntities;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PersistentEntitiesResourceMappingsUnitTests {
|
||||
class PersistentEntitiesResourceMappingsUnitTests {
|
||||
|
||||
@Test // DATAREST-1320
|
||||
public void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
|
||||
void doesNotConsiderCachedNullValuesToIndicateMappingAvailable() {
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PersistentEntitiesResourceMappingsUnitTests {
|
||||
}
|
||||
|
||||
@Test // GH-2033
|
||||
public void transparentlyAddsValueToCacheOnHasMappingRequests() {
|
||||
void transparentlyAddsValueToCacheOnHasMappingRequests() {
|
||||
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
context.getPersistentEntity(Sample.class);
|
||||
|
||||
@@ -21,9 +21,9 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.annotation.Reference;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
|
||||
@@ -42,13 +42,13 @@ import org.springframework.hateoas.LinkRelation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PersistentPropertyResourceMappingUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PersistentPropertyResourceMappingUnitTests {
|
||||
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
|
||||
@Test // DATAREST-175
|
||||
public void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
|
||||
void usesPropertyNameAsDefaultResourceMappingRelAndPath() {
|
||||
|
||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "first");
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-175
|
||||
public void considersMappingAnnotationOnDomainClassProperty() {
|
||||
void considersMappingAnnotationOnDomainClassProperty() {
|
||||
|
||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
||||
|
||||
@@ -70,7 +70,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-175
|
||||
public void considersMappingAnnotationOnDomainClassPropertyMethod() {
|
||||
void considersMappingAnnotationOnDomainClassPropertyMethod() {
|
||||
|
||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "third");
|
||||
|
||||
@@ -81,7 +81,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-233
|
||||
public void returnsDefaultDescriptionKey() {
|
||||
void returnsDefaultDescriptionKey() {
|
||||
|
||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "second");
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-233
|
||||
public void considersAtDescription() {
|
||||
void considersAtDescription() {
|
||||
|
||||
ResourceMapping mapping = getPropertyMappingFor(Entity.class, "fourth");
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PersistentPropertyResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // #1994
|
||||
public void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
|
||||
void doesNotConsiderPropertyExportedIfTargetTypeIsNotMapped() {
|
||||
|
||||
PersistentEntity<?, ?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("third");
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.core.mapping;
|
||||
|
||||
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.Pageable;
|
||||
import org.springframework.data.repository.Repository;
|
||||
@@ -34,10 +34,10 @@ import org.springframework.hateoas.LinkRelation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryCollectionResourceMappingUnitTests {
|
||||
class RepositoryCollectionResourceMappingUnitTests {
|
||||
|
||||
@Test
|
||||
public void buildsDefaultMappingForRepository() {
|
||||
void buildsDefaultMappingForRepository() {
|
||||
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(PersonRepository.class);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void honorsAnnotatedsMapping() {
|
||||
void honorsAnnotatedsMapping() {
|
||||
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedPersonRepository.class);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repositoryAnnotationTrumpsDomainTypeMapping() {
|
||||
void repositoryAnnotationTrumpsDomainTypeMapping() {
|
||||
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(AnnotatedAnnotatedPersonRepository.class);
|
||||
|
||||
@@ -70,19 +70,19 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
|
||||
void doesNotExposeRepositoryForPublicDomainTypeIfRepoIsPackageProtected() {
|
||||
|
||||
ResourceMapping mapping = getResourceMappingFor(PackageProtectedRepository.class);
|
||||
assertThat(mapping.isExported()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-229
|
||||
public void detectsPagingRepository() {
|
||||
void detectsPagingRepository() {
|
||||
assertThat(getResourceMappingFor(PersonRepository.class).isPagingResource()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoversCustomizationsUsingRestRepositoryResource() {
|
||||
void discoversCustomizationsUsingRestRepositoryResource() {
|
||||
|
||||
CollectionResourceMapping mapping = getResourceMappingFor(RepositoryAnnotatedRepository.class);
|
||||
assertThat(mapping.getRel()).isEqualTo(LinkRelation.of("foo"));
|
||||
@@ -90,7 +90,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-445
|
||||
public void usesDomainTypeFromRepositoryMetadata() {
|
||||
void usesDomainTypeFromRepositoryMetadata() {
|
||||
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class) {
|
||||
|
||||
@@ -107,7 +107,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1401
|
||||
public void rejectsPathsWithMultipleSegments() {
|
||||
void rejectsPathsWithMultipleSegments() {
|
||||
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(InvalidPath.class);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1401
|
||||
public void exposesProjectionTypeIfConfigured() {
|
||||
void exposesProjectionTypeIfConfigured() {
|
||||
|
||||
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).hasValue(Object.class);
|
||||
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isEmpty();
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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.core.support.DefaultRepositoryMetadata;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
@@ -35,10 +35,10 @@ import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.Re
|
||||
* @soundtrack Katinka - Ausverkauf
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class RepositoryDetectionStrategiesUnitTests {
|
||||
class RepositoryDetectionStrategiesUnitTests {
|
||||
|
||||
@Test // DATAREST-473
|
||||
public void allExposesAllRepositories() {
|
||||
void allExposesAllRepositories() {
|
||||
|
||||
assertExposures(ALL, new HashMap<Class<?>, Boolean>() {
|
||||
{
|
||||
@@ -51,7 +51,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-473
|
||||
public void defaultHonorsVisibilityAndAnnotations() {
|
||||
void defaultHonorsVisibilityAndAnnotations() {
|
||||
|
||||
assertExposures(DEFAULT, new HashMap<Class<?>, Boolean>() {
|
||||
{
|
||||
@@ -64,7 +64,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-473
|
||||
public void visibilityHonorsTypeVisibilityOnly() {
|
||||
void visibilityHonorsTypeVisibilityOnly() {
|
||||
|
||||
assertExposures(VISIBILITY, new HashMap<Class<?>, Boolean>() {
|
||||
{
|
||||
@@ -77,7 +77,7 @@ public class RepositoryDetectionStrategiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-473
|
||||
public void annotatedHonorsAnnotationsOnly() {
|
||||
void annotatedHonorsAnnotationsOnly() {
|
||||
|
||||
assertExposures(ANNOTATED, new HashMap<Class<?>, Boolean>() {
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
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.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -37,14 +37,14 @@ import org.springframework.hateoas.LinkRelation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryMethodResourceMappingUnitTests {
|
||||
class RepositoryMethodResourceMappingUnitTests {
|
||||
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(PersonRepository.class);
|
||||
RepositoryCollectionResourceMapping resourceMapping = new RepositoryCollectionResourceMapping(metadata,
|
||||
RepositoryDetectionStrategies.DEFAULT);
|
||||
|
||||
@Test
|
||||
public void defaultsMappingToMethodName() throws Exception {
|
||||
void defaultsMappingToMethodName() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||
ResourceMapping mapping = getMappingFor(method);
|
||||
@@ -53,7 +53,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesConfiguredNameWithLeadingSlash() throws Exception {
|
||||
void usesConfiguredNameWithLeadingSlash() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
||||
ResourceMapping mapping = getMappingFor(method);
|
||||
@@ -62,7 +62,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-31
|
||||
public void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
|
||||
void discoversParametersIfCompiledWithCorrespondingFlag() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -71,7 +71,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-31
|
||||
public void resolvesParameterNamesIfNotAnnotated() throws Exception {
|
||||
void resolvesParameterNamesIfNotAnnotated() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByFirstname", String.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -81,7 +81,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-229
|
||||
public void considersPagingFinderAPagingResource() throws Exception {
|
||||
void considersPagingFinderAPagingResource() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -90,7 +90,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
|
||||
void usesMethodNameAsRelFallbackEvenIfPathIsConfigured() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Pageable.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -99,7 +99,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-384
|
||||
public void considersResourceSortableIfSortParameterIsPresent() throws Exception {
|
||||
void considersResourceSortableIfSortParameterIsPresent() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByEmailAddress", String.class, Sort.class);
|
||||
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -113,7 +113,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void returnsDomainTypeAsProjectionSourceType() throws Exception {
|
||||
void returnsDomainTypeAsProjectionSourceType() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class);
|
||||
MethodResourceMapping mapping = getMappingFor(method);
|
||||
@@ -122,7 +122,7 @@ public class RepositoryMethodResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-699
|
||||
public void doesNotIncludePageableAsParameter() throws Exception {
|
||||
void doesNotIncludePageableAsParameter() throws Exception {
|
||||
|
||||
Method method = PersonRepository.class.getMethod("findByLastname", String.class, Pageable.class);
|
||||
RepositoryMethodResourceMapping mapping = getMappingFor(method);
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
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.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.hateoas.LinkRelation;
|
||||
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}.
|
||||
@@ -52,17 +52,17 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
public class RepositoryResourceMappingsIntegrationTests {
|
||||
class RepositoryResourceMappingsIntegrationTests {
|
||||
|
||||
@Autowired ListableBeanFactory factory;
|
||||
@Autowired KeyValueMappingContext<?, ?> mappingContext;
|
||||
|
||||
ResourceMappings mappings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
mappingContext.getPersistentEntity(Profile.class);
|
||||
|
||||
@@ -75,12 +75,12 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsAllMappings() {
|
||||
void detectsAllMappings() {
|
||||
assertThat(mappings).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportsResourceAndSearchesForPersons() {
|
||||
void exportsResourceAndSearchesForPersons() {
|
||||
|
||||
ResourceMetadata personMappings = mappings.getMetadataFor(Person.class);
|
||||
|
||||
@@ -89,7 +89,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotExportAnyMappingsForHiddenRepository() {
|
||||
void doesNotExportAnyMappingsForHiddenRepository() {
|
||||
|
||||
ResourceMetadata creditCardMapping = mappings.getMetadataFor(CreditCard.class);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-112
|
||||
public void usesPropertyNameAsRelForPropertyResourceMapping() {
|
||||
void usesPropertyNameAsRelForPropertyResourceMapping() {
|
||||
|
||||
Repositories repositories = new Repositories(factory);
|
||||
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(Person.class);
|
||||
@@ -113,7 +113,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-111
|
||||
public void exposesResourceByPath() {
|
||||
void exposesResourceByPath() {
|
||||
|
||||
assertThat(mappings.exportsTopLevelResourceFor("people")).isTrue();
|
||||
assertThat(mappings.exportsTopLevelResourceFor("orders")).isTrue();
|
||||
@@ -126,7 +126,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-107
|
||||
public void skipsSearchMethodsNotExported() {
|
||||
void skipsSearchMethodsNotExported() {
|
||||
|
||||
ResourceMetadata creditCardMetadata = mappings.getMetadataFor(CreditCard.class);
|
||||
SearchResourceMappings searchResourceMappings = creditCardMetadata.getSearchResourceMappings();
|
||||
@@ -145,7 +145,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-325
|
||||
public void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
|
||||
void exposesMethodResourceMappingInPackageProtectedButExportedRepo() {
|
||||
|
||||
ResourceMetadata metadata = mappings.getMetadataFor(Author.class);
|
||||
assertThat(metadata.isExported()).isTrue();
|
||||
@@ -163,7 +163,7 @@ public class RepositoryResourceMappingsIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname() {
|
||||
void testname() {
|
||||
|
||||
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 org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
@@ -27,10 +27,10 @@ import org.springframework.hateoas.LinkRelation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
class TypeBasedCollectionResourceMappingUnitTests {
|
||||
|
||||
@Test
|
||||
public void defaultsMappingsByType() {
|
||||
void defaultsMappingsByType() {
|
||||
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomizedRel() {
|
||||
void usesCustomizedRel() {
|
||||
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(CustomizedSample.class);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-99
|
||||
public void doesNotExportNonPublicTypesByDefault() {
|
||||
void doesNotExportNonPublicTypesByDefault() {
|
||||
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(HiddenSample.class);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TypeBasedCollectionResourceMappingUnitTests {
|
||||
* @see
|
||||
*/
|
||||
@Test
|
||||
public void usesDefaultDescriptionIfNoAnnotationPresent() {
|
||||
void usesDefaultDescriptionIfNoAnnotationPresent() {
|
||||
|
||||
CollectionResourceMapping mapping = new TypeBasedCollectionResourceMapping(Sample.class);
|
||||
ResourceDescription description = mapping.getDescription();
|
||||
|
||||
@@ -23,11 +23,11 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
@@ -44,18 +44,18 @@ import org.springframework.hateoas.server.EntityLinks;
|
||||
* @author Mark Paluch
|
||||
* @soundtrack Trio Rotation - Triopane
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DefaultSelfLinkProviderUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DefaultSelfLinkProviderUnitTests {
|
||||
|
||||
SelfLinkProvider provider;
|
||||
|
||||
@Mock EntityLinks entityLinks;
|
||||
@Mock(lenient = true) EntityLinks entityLinks;
|
||||
PersistentEntities entities;
|
||||
List<EntityLookup<?>> lookups;
|
||||
ConversionService conversionService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
||||
public void rejectsNullEntities() {
|
||||
new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService);
|
||||
}
|
||||
@Test // DATAREST-724
|
||||
void rejectsNullEntities() {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
||||
public void rejectsNullEntityLinks() {
|
||||
new DefaultSelfLinkProvider(entities, null, lookups, conversionService);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-724
|
||||
public void rejectsNullEntityLookups() {
|
||||
new DefaultSelfLinkProvider(entities, entityLinks, null, conversionService);
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new DefaultSelfLinkProvider(null, entityLinks, lookups, conversionService));
|
||||
}
|
||||
|
||||
@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");
|
||||
Link link = provider.createSelfLinkFor(profile);
|
||||
@@ -101,7 +107,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
|
||||
@Test // DATAREST-724
|
||||
@SuppressWarnings("unchecked")
|
||||
public void usesEntityLookupIfDefined() {
|
||||
void usesEntityLookupIfDefined() {
|
||||
|
||||
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
||||
when(lookup.supports(Profile.class)).thenReturn(true);
|
||||
@@ -116,7 +122,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-724, DATAREST-1549
|
||||
public void rejectsLinkCreationForUnknownEntity() {
|
||||
void rejectsLinkCreationForUnknownEntity() {
|
||||
|
||||
assertThatExceptionOfType(MappingException.class) //
|
||||
.isThrownBy(() -> provider.createSelfLinkFor(new Object())) //
|
||||
|
||||
@@ -17,54 +17,53 @@ package org.springframework.data.rest.core.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import lombok.Value;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
/**
|
||||
* Ensures proper detection and removal of leading slash in strings.
|
||||
*
|
||||
* @author Florent Biville
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class ResourceStringUtilsTests {
|
||||
class ResourceStringUtilsTests {
|
||||
|
||||
final String actual;
|
||||
final String expected;
|
||||
final boolean hasText;
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldDetectTextPresence() {
|
||||
|
||||
public ResourceStringUtilsTests(String testDescription, String actual, String expected, boolean hasText) {
|
||||
|
||||
this.actual = actual;
|
||||
this.expected = expected;
|
||||
this.hasText = hasText;
|
||||
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
|
||||
assertThat(ResourceStringUtils.hasTextExceptSlash(it.getActual())).isEqualTo(it.hasText);
|
||||
});
|
||||
}
|
||||
|
||||
@Parameters(name = "{0}")
|
||||
public static Collection<?> parameters() {
|
||||
return Arrays
|
||||
.asList(
|
||||
new Object[][] { { "empty string has no text and should remain empty", "", "", false },
|
||||
{ "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 }, });
|
||||
@TestFactory
|
||||
Stream<DynamicTest> shouldRemoveLeadingSlashIfAny() {
|
||||
|
||||
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
|
||||
assertThat(ResourceStringUtils.removeLeadingSlash(it.getActual())).isEqualTo(it.getExpected());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDetectTextPresence() {
|
||||
assertThat(ResourceStringUtils.hasTextExceptSlash(actual)).isEqualTo(hasText);
|
||||
static Stream<Fixture> fixtures() {
|
||||
|
||||
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
|
||||
public void shouldRemoveLeadingSlashIfAny() {
|
||||
assertThat(ResourceStringUtils.removeLeadingSlash(actual)).isEqualTo(expected);
|
||||
@Value(staticConstructor = "of")
|
||||
static class Fixture {
|
||||
|
||||
String name, actual, expected;
|
||||
boolean hasText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,10 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.assertj.core.api.AbstractOptionalAssert;
|
||||
import org.junit.Before;
|
||||
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.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.domain.Profile;
|
||||
@@ -41,8 +33,7 @@ import org.springframework.data.rest.core.domain.Profile;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
|
||||
static final Object REFERENCE = new Object();
|
||||
|
||||
@@ -52,11 +43,8 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
RepositoryInvokerFactory factory;
|
||||
Method method;
|
||||
|
||||
public @Parameter(0) Object source;
|
||||
public @Parameter(1) Consumer<AbstractOptionalAssert<?, Object>> value;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
|
||||
when(delegate.getInvokerFor(Object.class)).thenReturn(invoker);
|
||||
|
||||
@@ -64,21 +52,9 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
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
|
||||
@SuppressWarnings("unchecked")
|
||||
public void usesRegisteredEntityLookup() {
|
||||
void usesRegisteredEntityLookup() {
|
||||
|
||||
EntityLookup<Object> lookup = mock(EntityLookup.class);
|
||||
|
||||
@@ -91,8 +67,4 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests {
|
||||
verify(lookup, times(1)).lookupEntity(eq(1L));
|
||||
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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
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.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -45,10 +45,10 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Miles Davis - Blue in green (Kind of blue)
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration
|
||||
public class HalExplorerIntegrationTests {
|
||||
class HalExplorerIntegrationTests {
|
||||
|
||||
static final String BASE_PATH = "/api";
|
||||
static final String EXPLORER_INDEX = "/explorer/index.html";
|
||||
@@ -69,14 +69,14 @@ public class HalExplorerIntegrationTests {
|
||||
|
||||
MockMvc mvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.mvc = MockMvcBuilders.webAppContextSetup(context).//
|
||||
defaultRequest(get(BASE_PATH).accept(MediaType.TEXT_HTML)).build();
|
||||
}
|
||||
|
||||
@Test // DATAREST-293
|
||||
public void exposesJsonUnderApiRootByDefault() throws Exception {
|
||||
void exposesJsonUnderApiRootByDefault() throws Exception {
|
||||
|
||||
mvc.perform(get(BASE_PATH).accept(MediaType.ALL)).//
|
||||
andExpect(status().isOk()).//
|
||||
@@ -84,7 +84,7 @@ public class HalExplorerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-293
|
||||
public void redirectsToBrowserForApiRootAndHtml() throws Exception {
|
||||
void redirectsToBrowserForApiRootAndHtml() throws Exception {
|
||||
|
||||
mvc.perform(get(BASE_PATH).accept(MediaType.TEXT_HTML)).//
|
||||
andExpect(status().isFound()).//
|
||||
@@ -92,7 +92,7 @@ public class HalExplorerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-293
|
||||
public void forwardsBrowserToIndexHtml() throws Exception {
|
||||
void forwardsBrowserToIndexHtml() throws Exception {
|
||||
|
||||
mvc.perform(get(BASE_PATH.concat("/explorer"))).//
|
||||
andExpect(status().isFound()).//
|
||||
@@ -100,7 +100,7 @@ public class HalExplorerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-293
|
||||
public void exposesHalBrowser() throws Exception {
|
||||
void exposesHalBrowser() throws Exception {
|
||||
|
||||
mvc.perform(get(BASE_PATH.concat("/explorer/index.html"))).//
|
||||
andExpect(status().isOk()).//
|
||||
@@ -108,7 +108,7 @@ public class HalExplorerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-293
|
||||
public void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception {
|
||||
void retrunsApiIfHtmlIsNotExplicitlyListed() throws Exception {
|
||||
|
||||
mvc.perform(get(BASE_PATH).accept(MediaType.APPLICATION_JSON, MediaType.ALL)).//
|
||||
andExpect(status().isOk()).//
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.Collections;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -41,10 +40,10 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* @author Mark Paluch
|
||||
* @soundtrack Nils Wülker - Homeless Diamond (feat. Lauren Flynn)
|
||||
*/
|
||||
public class HalExplorerUnitTests {
|
||||
class HalExplorerUnitTests {
|
||||
|
||||
@Test // DATAREST-565, DATAREST-720
|
||||
public void createsContextRelativeRedirectForBrowser() throws Exception {
|
||||
void createsContextRelativeRedirectForBrowser() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -64,7 +63,7 @@ public class HalExplorerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1264
|
||||
public void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException {
|
||||
void producesProxyRelativeRedirectIfNecessary() throws ServletException, IOException {
|
||||
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/explorer");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
package org.springframework.data.rest.tests;
|
||||
/*
|
||||
* 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
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.mock.web.MockHttpServletRequest;
|
||||
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.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -53,7 +53,7 @@ import org.springframework.web.context.request.WebRequest;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
public abstract class AbstractControllerIntegrationTests {
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class AbstractControllerIntegrationTests {
|
||||
@Autowired RepositoryInvokerFactory invokerFactory;
|
||||
@Autowired ResourceMappings mappings;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void initWebInfrastructure() {
|
||||
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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
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.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
@@ -61,7 +62,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Christoph Strobl
|
||||
* @author Ľubomír Varga
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { RepositoryRestMvcConfiguration.class, DelegatingWebMvcConfiguration.class })
|
||||
public abstract class AbstractWebIntegrationTests {
|
||||
@@ -74,7 +75,7 @@ public abstract class AbstractWebIntegrationTests {
|
||||
protected TestMvcClient client;
|
||||
protected MockMvc mvc;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
setupMockMvc();
|
||||
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.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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
@@ -57,7 +58,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
// Root test cases
|
||||
|
||||
@Test
|
||||
public void exposesRootResource() throws Exception {
|
||||
void exposesRootResource() throws Exception {
|
||||
|
||||
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
|
||||
public void exposesSchemasForResourcesExposed() throws Exception {
|
||||
void exposesSchemasForResourcesExposed() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
|
||||
@@ -92,7 +93,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-203
|
||||
public void servesHalWhenRequested() throws Exception {
|
||||
void servesHalWhenRequested() throws Exception {
|
||||
|
||||
mvc.perform(get("/")). //
|
||||
andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)). //
|
||||
@@ -100,7 +101,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-203
|
||||
public void servesHalWhenJsonIsRequested() throws Exception {
|
||||
void servesHalWhenJsonIsRequested() throws Exception {
|
||||
|
||||
mvc.perform(get("/").accept(MediaType.APPLICATION_JSON)). //
|
||||
andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)). //
|
||||
@@ -108,7 +109,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-203
|
||||
public void exposesSearchesForRootResources() throws Exception {
|
||||
void exposesSearchesForRootResources() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
|
||||
@@ -135,7 +136,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nic() throws Exception {
|
||||
void nic() throws Exception {
|
||||
|
||||
Map<LinkRelation, String> payloads = getPayloadToPost();
|
||||
assumeFalse(payloads.isEmpty());
|
||||
@@ -162,7 +163,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-198
|
||||
public void accessLinkedResources() throws Exception {
|
||||
void accessLinkedResources() throws Exception {
|
||||
|
||||
MockHttpServletResponse rootResource = client.request("/");
|
||||
|
||||
@@ -188,7 +189,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-230
|
||||
public void exposesDescriptionAsAlpsDocuments() throws Exception {
|
||||
void exposesDescriptionAsAlpsDocuments() throws Exception {
|
||||
|
||||
MediaType ALPS_MEDIA_TYPE = MediaType.valueOf("application/alps+json");
|
||||
|
||||
@@ -204,14 +205,14 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-448
|
||||
public void returnsNotFoundForUriNotBackedByARepository() throws Exception {
|
||||
void returnsNotFoundForUriNotBackedByARepository() throws Exception {
|
||||
|
||||
mvc.perform(get("/index.html")).//
|
||||
andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test // DATAREST-658
|
||||
public void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception {
|
||||
void collectionResourcesExposeLinksAsHeadersForHeadRequest() throws Exception {
|
||||
|
||||
for (LinkRelation rel : expectedRootLinkRels()) {
|
||||
|
||||
@@ -229,7 +230,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-661
|
||||
public void patchToNonExistingResourceReturnsNotFound() throws Exception {
|
||||
void patchToNonExistingResourceReturnsNotFound() throws Exception {
|
||||
|
||||
LinkRelation rel = expectedRootLinkRels().iterator().next();
|
||||
String uri = client.discoverUnique(rel).expand().getHref().concat("/");
|
||||
@@ -249,7 +250,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1003
|
||||
public void rejectsUnsupportedAcceptTypeForResources() throws Exception {
|
||||
void rejectsUnsupportedAcceptTypeForResources() throws Exception {
|
||||
|
||||
for (LinkRelation string : expectedRootLinkRels()) {
|
||||
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.tests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -26,10 +24,10 @@ import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
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.Links;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -85,8 +83,8 @@ public class TestMvcClient {
|
||||
|
||||
HttpHeaders headers = response.getHeaders();
|
||||
|
||||
assertThat(headers.getAllow(), hasSize(methods.length));
|
||||
assertThat(headers.getAllow(), hasItems(methods));
|
||||
assertThat(headers.getAllow()).hasSize(methods.length);
|
||||
assertThat(headers.getAllow()).contains(methods);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,8 +354,10 @@ public class TestMvcClient {
|
||||
MockHttpServletResponse response = result.getResponse();
|
||||
String s = response.getContentAsString();
|
||||
|
||||
assertThat("Expected to find link with rel " + rel + " but found none in " + s, //
|
||||
getDiscoverer(response).findLinkWithRel(rel, s), notNullValue());
|
||||
assertThat(getDiscoverer(response).findLinkWithRel(rel, s)) //
|
||||
.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
|
||||
@ImportResource("classpath:META-INF/spring/cache-config.xml")
|
||||
@EnableGemfireRepositories
|
||||
public class GeodeRepositoryConfig {
|
||||
class GeodeRepositoryConfig {
|
||||
|
||||
/**
|
||||
* TODO: Remove, once Spring Data Gemfire exposes a mapping context.
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration(classes = GeodeRepositoryConfig.class)
|
||||
public class GeodeWebTests extends CommonWebTests {
|
||||
class GeodeWebTests extends CommonWebTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
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.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
@@ -36,24 +36,24 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
@Transactional
|
||||
public class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositoryControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired RepositoryController controller;
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void rootResourceExposesGetOnly() {
|
||||
void rootResourceExposesGetOnly() {
|
||||
|
||||
HttpEntity<?> response = controller.optionsForRepositories();
|
||||
assertAllowHeaders(response, HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test // DATAREST-333, DATAREST-330
|
||||
public void headRequestReturnsNoContent() {
|
||||
void headRequestReturnsNoContent() {
|
||||
assertThat(controller.headForRepositories().getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Test // DATAREST-160, DATAREST-333, DATAREST-463
|
||||
public void exposesLinksToRepositories() {
|
||||
void exposesLinksToRepositories() {
|
||||
|
||||
RepositoryLinksResource resource = controller.listRepositories().getBody();
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import static org.springframework.http.HttpMethod.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -62,7 +62,7 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
*/
|
||||
@ContextConfiguration(classes = { ConfigurationCustomizer.class, JpaRepositoryConfig.class })
|
||||
@Transactional
|
||||
public class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositoryEntityControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired RepositoryEntityController controller;
|
||||
@Autowired AddressRepository repository;
|
||||
@@ -82,25 +82,28 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = HttpRequestMethodNotSupportedException.class) // DATAREST-217
|
||||
public void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception {
|
||||
@Test // DATAREST-217
|
||||
void returnsNotFoundForListingEntitiesIfFindAllNotExported() throws Exception {
|
||||
|
||||
repository.save(new Address());
|
||||
|
||||
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
|
||||
public void rejectsEntityCreationIfSaveIsNotExported() throws Exception {
|
||||
@Test // DATAREST-217
|
||||
void rejectsEntityCreationIfSaveIsNotExported() throws Exception {
|
||||
|
||||
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
|
||||
public void setsExpandedSelfUriInLocationHeader() throws Exception {
|
||||
void setsExpandedSelfUriInLocationHeader() throws Exception {
|
||||
|
||||
RootResourceInformation information = getResourceInformation(Order.class);
|
||||
|
||||
@@ -114,20 +117,25 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-330
|
||||
public void exposesHeadForCollectionResourceIfExported() throws Exception {
|
||||
void exposesHeadForCollectionResourceIfExported() throws Exception {
|
||||
ResponseEntity<?> entity = controller.headCollectionResource(getResourceInformation(Person.class),
|
||||
new DefaultedPageable(Pageable.unpaged(), false));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception {
|
||||
controller.headCollectionResource(getResourceInformation(CreditCard.class),
|
||||
new DefaultedPageable(Pageable.unpaged(), false));
|
||||
@Test // DATAREST-330
|
||||
void doesNotExposeHeadForCollectionResourceIfNotExported() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> {
|
||||
|
||||
controller.headCollectionResource(getResourceInformation(CreditCard.class),
|
||||
new DefaultedPageable(Pageable.unpaged(), false));
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATAREST-330
|
||||
public void exposesHeadForItemResourceIfExported() throws Exception {
|
||||
void exposesHeadForItemResourceIfExported() throws Exception {
|
||||
|
||||
Address address = repository.save(new Address());
|
||||
|
||||
@@ -137,34 +145,36 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception {
|
||||
controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler);
|
||||
@Test // DATAREST-330
|
||||
void doesNotExposeHeadForItemResourceIfNotExisting() throws Exception {
|
||||
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.headForItemResource(getResourceInformation(CreditCard.class), 1L, assembler));
|
||||
}
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() {
|
||||
void doesNotExposeMethodsForOptionsIfNotHttpMethodsSupportedForCollectionResource() {
|
||||
|
||||
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Address.class));
|
||||
assertAllowHeaders(response, OPTIONS);
|
||||
}
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() {
|
||||
void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToCollectionResource() {
|
||||
|
||||
HttpEntity<?> response = controller.optionsForCollectionResource(getResourceInformation(Person.class));
|
||||
assertAllowHeaders(response, GET, POST, HEAD, OPTIONS);
|
||||
}
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() {
|
||||
void exposesSupportedHttpMethodsInAllowHeaderForOptionsRequestToItemResource() {
|
||||
|
||||
HttpEntity<?> response = controller.optionsForItemResource(getResourceInformation(Person.class));
|
||||
assertAllowHeaders(response, GET, PUT, PATCH, DELETE, HEAD, OPTIONS);
|
||||
}
|
||||
|
||||
@Test // DATAREST-333, DATAREST-348
|
||||
public void optionsForItermResourceSetsAllowPatchHeader() {
|
||||
void optionsForItermResourceSetsAllowPatchHeader() {
|
||||
|
||||
ResponseEntity<?> entity = controller.optionsForItemResource(getResourceInformation(Person.class));
|
||||
|
||||
@@ -176,7 +186,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception {
|
||||
void returnsBodyOnPutForUpdateIfAcceptHeaderPresentByDefault() throws Exception {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Order.class);
|
||||
Order order = request.getInvoker().invokeSave(new Order(new Person()));
|
||||
@@ -189,7 +199,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException {
|
||||
void returnsBodyForCreatingPutIfAcceptHeaderPresentByDefault() throws HttpRequestMethodNotSupportedException {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Order.class);
|
||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||
@@ -200,7 +210,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception {
|
||||
void returnsBodyForPostIfAcceptHeaderIsPresentByDefault() throws Exception {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Order.class);
|
||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||
@@ -212,7 +222,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-34
|
||||
public void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception {
|
||||
void doesNotReturnBodyForPostIfNoAcceptHeaderPresentByDefault() throws Exception {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Order.class);
|
||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||
@@ -224,7 +234,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-581
|
||||
public void createsEtagForProjectedEntityCorrectly() throws Exception {
|
||||
void createsEtagForProjectedEntityCorrectly() throws Exception {
|
||||
|
||||
Address address = repository.save(new Address());
|
||||
|
||||
@@ -244,7 +254,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-724
|
||||
public void deletesEntityWithCustomLookupCorrectly() throws Exception {
|
||||
void deletesEntityWithCustomLookupCorrectly() throws Exception {
|
||||
|
||||
Address address = repository.save(new Address());
|
||||
assertThat(repository.findById(address.id)).isNotNull();
|
||||
@@ -262,7 +272,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-948
|
||||
public void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException {
|
||||
void rejectsPutForCreationIfConfigured() throws HttpRequestMethodNotSupportedException {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Address.class);
|
||||
PersistentEntityResource persistentEntityResource = PersistentEntityResource
|
||||
|
||||
@@ -18,9 +18,8 @@ package org.springframework.data.rest.webmvc;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.jpa.Book;
|
||||
@@ -36,7 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
@Transactional
|
||||
public class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositoryPropertyReferenceControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired RepositoryPropertyReferenceController controller;
|
||||
@Autowired TestDataPopulator populator;
|
||||
@@ -45,8 +44,8 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
||||
PersistentEntityResourceAssembler assembler;
|
||||
RootResourceInformation information;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.assembler = mock(PersistentEntityResourceAssembler.class);
|
||||
this.information = getResourceInformation(Book.class);
|
||||
@@ -54,7 +53,7 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exposesResourceForCustomizedPropertyResourcePath() throws Exception {
|
||||
void exposesResourceForCustomizedPropertyResourcePath() throws Exception {
|
||||
|
||||
Book book = books.findAll().iterator().next();
|
||||
|
||||
@@ -62,11 +61,12 @@ public class RepositoryPropertyReferenceControllerIntegrationTests extends Abstr
|
||||
.isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
public void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() throws Exception {
|
||||
@Test
|
||||
void doesNotExposeOriginalPathIfPropertyResourcePathIsCustomized() {
|
||||
|
||||
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.springframework.data.rest.tests.TestMvcClient.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
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.TestDataPopulator;
|
||||
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -55,7 +55,7 @@ import org.springframework.util.MultiValueMap;
|
||||
*/
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
@Transactional
|
||||
public class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositorySearchControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
static final DefaultedPageable PAGEABLE = new DefaultedPageable(PageRequest.of(0, 10), true);
|
||||
|
||||
@@ -63,16 +63,16 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
@Autowired RepositorySearchController controller;
|
||||
@Autowired PersistentEntityResourceAssembler assembler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
loader.populateRepositories();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rendersCorrectSearchLinksForPersons() throws Exception {
|
||||
void rendersCorrectSearchLinksForPersons() throws Exception {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Person.class);
|
||||
RepresentationModel resource = controller.listSearches(request);
|
||||
RepresentationModel<?> resource = controller.listSearches(request);
|
||||
|
||||
ResourceTester tester = ResourceTester.of(resource);
|
||||
tester.assertNumberOfLinks(7); // Self link included
|
||||
@@ -86,18 +86,22 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
tester.assertHasLinkEndingWith("findCreatedDateByLastName", "findCreatedDateByLastName{?lastname}");
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
public void returns404ForUnexportedRepository() {
|
||||
controller.listSearches(getResourceInformation(CreditCard.class));
|
||||
}
|
||||
@Test
|
||||
void returns404ForUnexportedRepository() {
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class)
|
||||
public void returns404ForRepositoryWithoutSearches() {
|
||||
controller.listSearches(getResourceInformation(Author.class));
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.listSearches(getResourceInformation(CreditCard.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executesSearchAgainstRepository() {
|
||||
void returns404ForRepositoryWithoutSearches() {
|
||||
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.listSearches(getResourceInformation(Author.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void executesSearchAgainstRepository() {
|
||||
|
||||
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
||||
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}")));
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() {
|
||||
controller.headForSearches(getResourceInformation(Author.class));
|
||||
}
|
||||
@Test // DATAREST-330
|
||||
void doesNotExposeHeadForSearchResourceIfResourceDoesnHaveSearches() {
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void exposesHeadForSearchResourceIfResourceIsNotExposed() {
|
||||
controller.headForSearches(getResourceInformation(CreditCard.class));
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.headForSearches(getResourceInformation(Author.class)));
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@Test // DATAREST-330
|
||||
public void exposesHeadForExistingQueryMethodResource() {
|
||||
void exposesHeadForExistingQueryMethodResource() {
|
||||
controller.headForSearch(getResourceInformation(Person.class), "findByCreatedUsingISO8601Date");
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void doesNotExposeHeadForInvalidQueryMethodResource() {
|
||||
controller.headForSearch(getResourceInformation(Person.class), "foobar");
|
||||
@Test // DATAREST-330
|
||||
void doesNotExposeHeadForInvalidQueryMethodResource() {
|
||||
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.headForSearch(getResourceInformation(Person.class), "foobar"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void searchResourceSupportsGetOnly() {
|
||||
void searchResourceSupportsGetOnly() {
|
||||
assertAllowHeaders(controller.optionsForSearches(getResourceInformation(Person.class)), HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-333
|
||||
public void returns404ForOptionsForRepositoryWithoutSearches() {
|
||||
controller.optionsForSearches(getResourceInformation(Address.class));
|
||||
@Test // DATAREST-333
|
||||
void returns404ForOptionsForRepositoryWithoutSearches() {
|
||||
|
||||
assertThatExceptionOfType(ResourceNotFoundException.class) //
|
||||
.isThrownBy(() -> controller.optionsForSearches(getResourceInformation(Address.class)));
|
||||
}
|
||||
|
||||
@Test // DATAREST-333
|
||||
public void queryMethodResourceSupportsGetOnly() {
|
||||
void queryMethodResourceSupportsGetOnly() {
|
||||
|
||||
RootResourceInformation resourceInformation = getResourceInformation(Person.class);
|
||||
HttpEntity<Object> response = controller.optionsForSearch(resourceInformation, "firstname");
|
||||
@@ -159,7 +171,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-502
|
||||
public void interpretsUriAsReferenceToRelatedEntity() {
|
||||
void interpretsUriAsReferenceToRelatedEntity() {
|
||||
|
||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(1);
|
||||
parameters.add("author", "/author/1");
|
||||
@@ -173,7 +185,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-515
|
||||
public void repositorySearchResourceExposesDomainType() {
|
||||
void repositorySearchResourceExposesDomainType() {
|
||||
|
||||
RepositorySearchesResource searches = controller.listSearches(getResourceInformation(Person.class));
|
||||
|
||||
@@ -181,7 +193,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
}
|
||||
|
||||
@Test // DATAREST-1121
|
||||
public void returnsSimpleResponseEntityForQueryMethod() {
|
||||
void returnsSimpleResponseEntityForQueryMethod() {
|
||||
|
||||
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
|
||||
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.http.HttpMethod.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
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.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.jpa.Address;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -34,20 +35,20 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
@Transactional
|
||||
public class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RootResourceInformationIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Test // DATAREST-217
|
||||
public void getIsNotSupportedIfFindAllIsNotExported() {
|
||||
void getIsNotSupportedIfFindAllIsNotExported() {
|
||||
|
||||
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
||||
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(GET);
|
||||
}
|
||||
|
||||
@Test // DATAREST-217
|
||||
public void postIsNotSupportedIfSaveIsNotExported() {
|
||||
void postIsNotSupportedIfSaveIsNotExported() {
|
||||
|
||||
SupportedHttpMethods supportedMethods = getResourceInformation(Address.class).getSupportedMethods();
|
||||
assertThat(supportedMethods.getMethodsFor(COLLECTION)).doesNotContain(POST);
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
*/
|
||||
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.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import net.minidev.json.JSONArray;
|
||||
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -48,8 +49,6 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link AlpsController}.
|
||||
*
|
||||
@@ -58,7 +57,7 @@ import net.minidev.json.JSONArray;
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, AlpsControllerIntegrationTests.Config.class })
|
||||
public class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class AlpsControllerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired WebApplicationContext context;
|
||||
@Autowired LinkDiscoverers discoverers;
|
||||
@@ -81,20 +80,20 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
|
||||
TestMvcClient client;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||
this.client = new TestMvcClient(mvc, this.discoverers);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
configuration.setEnableEnumTranslation(false);
|
||||
}
|
||||
|
||||
@Test // DATAREST-230
|
||||
public void exposesAlpsCollectionResources() throws Exception {
|
||||
void exposesAlpsCollectionResources() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||
@@ -105,7 +104,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-638
|
||||
public void verifyThatAlpsIsDefaultProfileFormat() throws Exception {
|
||||
void verifyThatAlpsIsDefaultProfileFormat() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||
@@ -117,7 +116,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-463
|
||||
public void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception {
|
||||
void verifyThatAttributesIgnoredDontAppearInAlps() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
||||
@@ -132,7 +131,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-494
|
||||
public void linksToJsonSchemaFromRepresentationDescriptor() throws Exception {
|
||||
void linksToJsonSchemaFromRepresentationDescriptor() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
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)
|
||||
.toString();
|
||||
|
||||
assertThat(href, endsWith("/profile/items"));
|
||||
assertThat(href).endsWith("/profile/items");
|
||||
}
|
||||
|
||||
@Test // DATAREST-516
|
||||
public void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
|
||||
void referenceToAssociatedEntityDesciptorPointsToRepresentationDescriptor() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
Link usersLink = client.discoverUnique(profileLink, "people", MediaType.ALL);
|
||||
@@ -164,7 +163,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-630
|
||||
public void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception {
|
||||
void onlyExposesIdAttributesWhenExposedInTheConfiguration() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL);
|
||||
@@ -175,7 +174,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-683
|
||||
public void enumValueListingsAreTranslatedIfEnabled() throws Exception {
|
||||
void enumValueListingsAreTranslatedIfEnabled() throws Exception {
|
||||
|
||||
configuration.setEnableEnumTranslation(true);
|
||||
|
||||
@@ -193,7 +192,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio
|
||||
}
|
||||
|
||||
@Test // DATAREST-753
|
||||
public void alpsCanHandleGroovyDomainObjects() throws Exception {
|
||||
void alpsCanHandleGroovyDomainObjects() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profile");
|
||||
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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||
@@ -48,7 +48,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
* @soundtrack 2 Unlimited - No Limit
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
static class CorsConfig extends JpaRepositoryConfig {
|
||||
@@ -81,7 +81,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
public void appliesSelectiveDefaultCorsConfiguration() throws Exception {
|
||||
void appliesSelectiveDefaultCorsConfiguration() throws Exception {
|
||||
|
||||
Link findItems = client.discoverUnique(LinkRelation.of("items"));
|
||||
|
||||
@@ -98,7 +98,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
public void appliesGlobalCorsConfiguration() throws Exception {
|
||||
void appliesGlobalCorsConfiguration() throws Exception {
|
||||
|
||||
Link findBooks = client.discoverUnique(LinkRelation.of("books"));
|
||||
|
||||
@@ -119,7 +119,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
* @see BooksXmlController
|
||||
*/
|
||||
@Test // DATAREST-573
|
||||
public void appliesCorsConfigurationOnCustomControllers() throws Exception {
|
||||
void appliesCorsConfigurationOnCustomControllers() throws Exception {
|
||||
|
||||
// Preflight request
|
||||
mvc.perform(options("/books/xml/1234") //
|
||||
@@ -143,7 +143,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
* @see BooksPdfController
|
||||
*/
|
||||
@Test // DATAREST-573
|
||||
public void appliesCorsConfigurationOnCustomControllerMethod() throws Exception {
|
||||
void appliesCorsConfigurationOnCustomControllerMethod() throws Exception {
|
||||
|
||||
// Preflight request
|
||||
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
|
||||
public void appliesCorsConfigurationOnRepository() throws Exception {
|
||||
void appliesCorsConfigurationOnRepository() throws Exception {
|
||||
|
||||
Link authorsLink = client.discoverUnique(LinkRelation.of("authors"));
|
||||
|
||||
@@ -170,7 +170,7 @@ public class CorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
public void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception {
|
||||
void appliesCorsConfigurationOnRepositoryToCustomControllers() throws Exception {
|
||||
|
||||
// Preflight request
|
||||
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.validation.constraints.NotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.ApplicationContext;
|
||||
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.mock.web.MockHttpServletRequest;
|
||||
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.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -61,9 +60,9 @@ import com.jayway.jsonpath.JsonPath;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
public class DataRest262Tests {
|
||||
class DataRest262Tests {
|
||||
|
||||
@Configuration
|
||||
@Import({ RepositoryRestMvcConfiguration.class, JpaInfrastructureConfig.class })
|
||||
@@ -78,8 +77,8 @@ public class DataRest262Tests {
|
||||
|
||||
ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.mapper = beanFactory //
|
||||
.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class) //
|
||||
@@ -90,7 +89,7 @@ public class DataRest262Tests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void deserializesNestedAssociation() throws Exception {
|
||||
void deserializesNestedAssociation() throws Exception {
|
||||
|
||||
Airport airport = repository.save(new Airport());
|
||||
String payload = "{\"orgOrDstFlightPart\":{\"airport\":\"/api/airports/" + airport.id + "\"}}";
|
||||
@@ -100,7 +99,7 @@ public class DataRest262Tests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void serializesLinksToNestedAssociations() throws Exception {
|
||||
void serializesLinksToNestedAssociations() throws Exception {
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.annotation.Bean;
|
||||
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.http.MediaType;
|
||||
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.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
@@ -47,11 +46,11 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(
|
||||
classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class, DataRest363Tests.Config.class })
|
||||
public class DataRest363Tests {
|
||||
class DataRest363Tests {
|
||||
|
||||
private static MediaType MEDIA_TYPE = MediaType.APPLICATION_JSON;
|
||||
|
||||
@@ -78,8 +77,8 @@ public class DataRest363Tests {
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).//
|
||||
defaultRequest(get("/")).build();
|
||||
@@ -89,7 +88,7 @@ public class DataRest363Tests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-363
|
||||
public void testBasics() throws Exception {
|
||||
void testBasics() throws Exception {
|
||||
|
||||
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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -50,7 +50,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import({ RepositoryRestMvcConfiguration.class, JpaRepositoryConfig.class })
|
||||
@@ -87,14 +87,14 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
@Autowired ApplicationContext context;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
loader.populateRepositories();
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Test // DATAREST-906
|
||||
public void executesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||
void executesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||
|
||||
Link findBySortedLink = client.discoverUnique(LinkRelation.of("books"), IanaLinkRelations.SEARCH,
|
||||
LinkRelation.of("find-spring-books-sorted"));
|
||||
@@ -114,7 +114,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-906
|
||||
public void shouldApplyDefaultPageable() throws Exception {
|
||||
void shouldApplyDefaultPageable() throws Exception {
|
||||
|
||||
mvc.perform(get("/books/default-pageable"))//
|
||||
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
||||
@@ -122,7 +122,7 @@ public class JpaDefaultPageableWebTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-906
|
||||
public void shouldOverrideDefaultPageable() throws Exception {
|
||||
void shouldOverrideDefaultPageable() throws Exception {
|
||||
|
||||
mvc.perform(get("/books/default-pageable?size=10"))//
|
||||
.andExpect(jsonPath("$.content[0].sales").value(0)) //
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
public class JpaInfrastructureConfig {
|
||||
class JpaInfrastructureConfig {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
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.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.data.rest.webmvc.util.TestUtils.*;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
|
||||
import static org.springframework.http.HttpHeaders.*;
|
||||
@@ -33,8 +32,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@@ -123,7 +122,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#setUp()
|
||||
*/
|
||||
@Override
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
loader.populateRepositories();
|
||||
super.setUp();
|
||||
@@ -162,7 +161,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-99
|
||||
public void doesNotExposeCreditCardRepository() throws Exception {
|
||||
void doesNotExposeCreditCardRepository() throws Exception {
|
||||
|
||||
mvc.perform(get("/")). //
|
||||
andExpect(status().isOk()). //
|
||||
@@ -170,7 +169,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessPersons() throws Exception {
|
||||
void accessPersons() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/people?page=0&size=1");
|
||||
|
||||
@@ -187,7 +186,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-169
|
||||
public void exposesLinkForRelatedResource() throws Exception {
|
||||
void exposesLinkForRelatedResource() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||
@@ -199,7 +198,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-200
|
||||
public void exposesInlinedEntities() throws Exception {
|
||||
void exposesInlinedEntities() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request("/");
|
||||
Link ordersLink = client.assertHasLinkWithRel(LinkRelation.of("orders"), response);
|
||||
@@ -209,7 +208,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-199
|
||||
public void createsOrderUsingPut() throws Exception {
|
||||
void createsOrderUsingPut() throws Exception {
|
||||
|
||||
mvc.perform(//
|
||||
put("/orders/{id}", 4711).//
|
||||
@@ -218,7 +217,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-117
|
||||
public void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception {
|
||||
void createPersonThenVerifyIgnoredAttributesDontExist() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -238,7 +237,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-95
|
||||
public void createThenPatch() throws Exception {
|
||||
void createThenPatch() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
@@ -262,7 +261,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-150
|
||||
public void createThenPut() throws Exception {
|
||||
void createThenPut() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
@@ -272,29 +271,29 @@ public class JpaWebTests extends CommonWebTests {
|
||||
|
||||
Link bilboLink = client.assertHasLinkWithRel(IanaLinkRelations.SELF, bilbo);
|
||||
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName"), equalTo("Bilbo"));
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName"), equalTo("Baggins"));
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.firstName")).isEqualTo("Bilbo");
|
||||
assertThat((String) JsonPath.read(bilbo.getContentAsString(), "$.lastName")).isEqualTo("Baggins");
|
||||
|
||||
MockHttpServletResponse frodo = putAndGet(bilboLink, //
|
||||
"{ \"firstName\" : \"Frodo\" }", //
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName"), equalTo("Frodo"));
|
||||
assertNull(JsonPath.read(frodo.getContentAsString(), "$.lastName"));
|
||||
assertThat((String) JsonPath.read(frodo.getContentAsString(), "$.firstName")).isEqualTo("Frodo");
|
||||
assertThat(JsonPath.<Object> read(frodo.getContentAsString(), "$.lastName")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listsSiblingsWithContentCorrectly() throws Exception {
|
||||
void listsSiblingsWithContentCorrectly() throws Exception {
|
||||
assertPersonWithNameAndSiblingLink("John");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listsEmptySiblingsCorrectly() throws Exception {
|
||||
void listsEmptySiblingsCorrectly() throws Exception {
|
||||
assertPersonWithNameAndSiblingLink("Billy Bob");
|
||||
}
|
||||
|
||||
@Test // DATAREST-219
|
||||
public void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception {
|
||||
void manipulatePropertyCollectionRestfullyWithMultiplePosts() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||
new Person("Bilbo", "Baggins"), //
|
||||
@@ -311,7 +310,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-219
|
||||
public void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception {
|
||||
void manipulatePropertyCollectionRestfullyWithSinglePost() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||
new Person("Bilbo", "Baggins"), //
|
||||
@@ -326,7 +325,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-219
|
||||
public void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception {
|
||||
void manipulatePropertyCollectionRestfullyWithMultiplePuts() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||
new Person("Bilbo", "Baggins"), //
|
||||
@@ -345,7 +344,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-219
|
||||
public void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception {
|
||||
void manipulatePropertyCollectionRestfullyWithSinglePut() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "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.
|
||||
*/
|
||||
@Test // DATAREST-1356
|
||||
public void associateCreatorToOrderWithSinglePut() throws Exception {
|
||||
void associateCreatorToOrderWithSinglePut() throws Exception {
|
||||
|
||||
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
||||
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
||||
@@ -387,7 +386,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* will contain "send only 1 link" substring.
|
||||
*/
|
||||
@Test // DATAREST-1356
|
||||
public void associateTwoCreatorsToOrderWithSinglePut() throws Exception {
|
||||
void associateTwoCreatorsToOrderWithSinglePut() throws Exception {
|
||||
|
||||
Link firstCreatorLink = preparePersonResource(new Person("Frodo", "Baggins"));
|
||||
Link secondCreatorLink = preparePersonResource(new Person("Pippin", "Baggins"));
|
||||
@@ -399,7 +398,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-219
|
||||
public void manipulatePropertyCollectionRestfullyWithDelete() throws Exception {
|
||||
void manipulatePropertyCollectionRestfullyWithDelete() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||
new Person("Bilbo", "Baggins"), //
|
||||
@@ -419,7 +418,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-50
|
||||
public void propertiesCanHaveNulls() throws Exception {
|
||||
void propertiesCanHaveNulls() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
@@ -436,7 +435,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-238
|
||||
public void putShouldWorkDespiteExistingLinks() throws Exception {
|
||||
void putShouldWorkDespiteExistingLinks() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
|
||||
@@ -458,7 +457,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-217
|
||||
public void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception {
|
||||
void doesNotAllowGetToCollectionResourceIfFindAllIsNotExported() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||
|
||||
@@ -467,7 +466,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-217
|
||||
public void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception {
|
||||
void doesNotAllowPostToCollectionResourceIfSaveIsNotExported() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique(LinkRelation.of("addresses"));
|
||||
|
||||
@@ -481,7 +480,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
* @see OrderSummary
|
||||
*/
|
||||
@Test // DATAREST-221
|
||||
public void returnsProjectionIfRequested() throws Exception {
|
||||
void returnsProjectionIfRequested() throws Exception {
|
||||
|
||||
Link orders = client.discoverUnique(LinkRelation.of("orders"));
|
||||
|
||||
@@ -500,12 +499,12 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-261
|
||||
public void relProviderDetectsCustomizedMapping() {
|
||||
void relProviderDetectsCustomizedMapping() {
|
||||
assertThat(relProvider.getCollectionResourceRelFor(Person.class)).isEqualTo(LinkRelation.of("people"));
|
||||
}
|
||||
|
||||
@Test // DATAREST-311
|
||||
public void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
|
||||
void onlyLinksShouldAppearWhenExecuteSearchCompact() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));
|
||||
Person daenerys = new Person("Daenerys", "Targaryen");
|
||||
@@ -531,7 +530,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-317
|
||||
public void rendersExcerptProjectionsCorrectly() throws Exception {
|
||||
void rendersExcerptProjectionsCorrectly() throws Exception {
|
||||
|
||||
Link authorsLink = client.discoverUnique("authors");
|
||||
|
||||
@@ -554,7 +553,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-353
|
||||
public void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
|
||||
void returns404WhenTryingToDeleteANonExistingResource() throws Exception {
|
||||
|
||||
Link receiptsLink = client.discoverUnique("receipts");
|
||||
|
||||
@@ -563,7 +562,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-384
|
||||
public void exectuesSearchThatTakesASort() throws Exception {
|
||||
void exectuesSearchThatTakesASort() throws Exception {
|
||||
|
||||
Link booksLink = client.discoverUnique("books");
|
||||
Link searchLink = client.discoverUnique(booksLink, "search");
|
||||
@@ -586,7 +585,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||
void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||
|
||||
Link receiptLink = client.discoverUnique("receipts");
|
||||
|
||||
@@ -613,7 +612,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-423
|
||||
public void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception {
|
||||
void invokesCustomControllerAndBindsDomainObjectCorrectly() throws Exception {
|
||||
|
||||
MockHttpServletResponse authorsResponse = client.request(client.discoverUnique("authors"));
|
||||
|
||||
@@ -624,7 +623,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-523
|
||||
public void augmentsCollectionAssociationUsingPost() throws Exception {
|
||||
void augmentsCollectionAssociationUsingPost() throws Exception {
|
||||
|
||||
List<Link> links = preparePersonResources(new Person("Frodo", "Baggins"), //
|
||||
new Person("Bilbo", "Baggins"));
|
||||
@@ -645,7 +644,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-658
|
||||
public void returnsLinkHeadersForHeadRequestToItemResource() throws Exception {
|
||||
void returnsLinkHeadersForHeadRequestToItemResource() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = client.request(client.discoverUnique(LinkRelation.of("people")));
|
||||
String personHref = JsonPath.read(response.getContentAsString(), "$._embedded.people[0]._links.self.href");
|
||||
@@ -660,7 +659,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
public void exectuesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||
void exectuesSearchThatTakesAMappedSortProperty() throws Exception {
|
||||
|
||||
Link findBySortedLink = client.discoverUnique("books", "search", "find-by-sorted");
|
||||
|
||||
@@ -681,7 +680,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-883
|
||||
public void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception {
|
||||
void exectuesCustomQuerySearchThatTakesAMappedSortProperty() throws Exception {
|
||||
|
||||
Link findByLink = client.discoverUnique("books", "search", "find-spring-books-sorted");
|
||||
|
||||
@@ -701,14 +700,14 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@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?sort=type&page=1&size=10")).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test // DATAREST-976
|
||||
public void appliesSortByEmbeddedAssociation() throws Exception {
|
||||
void appliesSortByEmbeddedAssociation() throws Exception {
|
||||
|
||||
Link booksLink = client.discoverUnique("books");
|
||||
Link searchLink = client.discoverUnique(booksLink, "search");
|
||||
@@ -731,7 +730,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1213
|
||||
public void createThenPatchWithProjection() throws Exception {
|
||||
void createThenPatchWithProjection() throws Exception {
|
||||
|
||||
Link link = createCategory();
|
||||
String payload = "{ \"name\" : \"patched\" }";
|
||||
@@ -744,7 +743,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1213
|
||||
public void createThenPutWithProjection() throws Exception {
|
||||
void createThenPutWithProjection() throws Exception {
|
||||
|
||||
Link link = createCategory();
|
||||
String payload = "{ \"name\" : \"put\" }";
|
||||
@@ -757,7 +756,7 @@ public class JpaWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // #1991
|
||||
public void answersToHalFormsRequests() throws Exception {
|
||||
void answersToHalFormsRequests() throws Exception {
|
||||
|
||||
mvc.perform(get("/")
|
||||
.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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||
import org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping;
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @soundtrack RFLKTD - Liquid Crystals
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
static class CorsConfig extends JpaRepositoryConfig {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class LocalConfigCorsIntegrationTests extends AbstractWebIntegrationTests
|
||||
* @see ItemRepository
|
||||
*/
|
||||
@Test // DATAREST-1397
|
||||
public void appliesRepositoryCorsConfiguration() throws Exception {
|
||||
void appliesRepositoryCorsConfiguration() throws Exception {
|
||||
|
||||
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.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -49,7 +49,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*/
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, ProfileIntegrationTests.Config.class })
|
||||
public class ProfileIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class ProfileIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired WebApplicationContext context;
|
||||
@Autowired LinkDiscoverers discoverers;
|
||||
@@ -67,15 +67,15 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
|
||||
TestMvcClient client;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
MockMvc mvc = MockMvcBuilders.webAppContextSetup(context).build();
|
||||
this.client = new TestMvcClient(mvc, this.discoverers);
|
||||
}
|
||||
|
||||
@Test // DATAREST-230, DATAREST-638
|
||||
public void exposesProfileLink() throws Exception {
|
||||
void exposesProfileLink() throws Exception {
|
||||
|
||||
client.follow(ROOT_URI)//
|
||||
.andExpect(status().is2xxSuccessful())//
|
||||
@@ -83,7 +83,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests
|
||||
}
|
||||
|
||||
@Test // DATAREST-638
|
||||
public void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception {
|
||||
void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception {
|
||||
|
||||
Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people");
|
||||
Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL);
|
||||
|
||||
@@ -29,7 +29,7 @@ import javax.persistence.Id;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Entity
|
||||
public class SimulatedGroovyDomainClass implements GroovyObject {
|
||||
class SimulatedGroovyDomainClass implements GroovyObject {
|
||||
|
||||
private @Id @GeneratedValue Long id;
|
||||
private String name;
|
||||
@@ -38,7 +38,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.rest.webmvc.jpa.groovy;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.webmvc.jpa.groovy.SimulatedGroovyDomainClass;
|
||||
|
||||
/**
|
||||
* 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 org.junit.Before;
|
||||
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.context.ApplicationContext;
|
||||
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.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
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 com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -46,10 +46,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, RepositoryRestMvcConfiguration.class })
|
||||
@Transactional
|
||||
public class Jackson2DatatypeHelperIntegrationTests {
|
||||
class Jackson2DatatypeHelperIntegrationTests {
|
||||
|
||||
@Autowired PersistentEntities entities;
|
||||
@Autowired ApplicationContext context;
|
||||
@@ -62,8 +62,8 @@ public class Jackson2DatatypeHelperIntegrationTests {
|
||||
|
||||
Order order;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.order = orders.save(new Order(people.save(new Person("Dave", "Matthews"))));
|
||||
this.objectMapper = context.getBean("halJacksonHttpMessageConverter", AbstractJackson2HttpMessageConverter.class)
|
||||
@@ -75,7 +75,7 @@ public class Jackson2DatatypeHelperIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-500
|
||||
public void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception {
|
||||
void configuresHibernate4ModuleToLoadLazyLoadingProxies() throws Exception {
|
||||
|
||||
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(Order.class);
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("creator");
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.annotation.Bean;
|
||||
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.mock.web.MockHttpServletRequest;
|
||||
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.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
@@ -65,10 +65,10 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Oliver Gierke
|
||||
* @author Alex Leigh
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { JpaRepositoryConfig.class, PersistentEntitySerializationTests.TestConfig.class })
|
||||
@Transactional
|
||||
public class PersistentEntitySerializationTests {
|
||||
class PersistentEntitySerializationTests {
|
||||
|
||||
private static final String PERSON_JSON_IN = "{\"firstName\": \"John\",\"lastName\": \"Doe\"}";
|
||||
|
||||
@@ -94,8 +94,8 @@ public class PersistentEntitySerializationTests {
|
||||
LinkDiscoverer discoverer;
|
||||
ProjectionFactory projectionFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
||||
|
||||
@@ -104,7 +104,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deserializesPersonEntity() throws IOException {
|
||||
void deserializesPersonEntity() throws IOException {
|
||||
|
||||
Person p = mapper.readValue(PERSON_JSON_IN, Person.class);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-238
|
||||
public void deserializePersonWithLinks() throws IOException {
|
||||
void deserializePersonWithLinks() throws IOException {
|
||||
|
||||
String bilbo = "{\n" + " \"_links\" : {\n" + " \"self\" : {\n"
|
||||
+ " \"href\" : \"http://localhost/people/4\"\n" + " },\n" + " \"siblings\" : {\n"
|
||||
@@ -129,7 +129,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-238
|
||||
public void serializesPersonEntity() throws IOException, InterruptedException {
|
||||
void serializesPersonEntity() throws IOException, InterruptedException {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(Person.class);
|
||||
Person person = people.save(new Person("John", "Doe"));
|
||||
@@ -154,7 +154,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-248
|
||||
public void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception {
|
||||
void deserializesPersonWithLinkToOtherPersonCorrectly() throws Exception {
|
||||
|
||||
Person father = people.save(new Person("John", "Doe"));
|
||||
|
||||
@@ -165,7 +165,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-248
|
||||
public void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception {
|
||||
void deserializesPersonWithLinkToOtherPersonsCorrectly() throws Exception {
|
||||
|
||||
Person firstSibling = people.save(new Person("John", "Doe"));
|
||||
Person secondSibling = people.save(new Person("Dave", "Doe"));
|
||||
@@ -178,7 +178,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-248
|
||||
public void deserializesEmbeddedAssociationsCorrectly() throws Exception {
|
||||
void deserializesEmbeddedAssociationsCorrectly() throws Exception {
|
||||
|
||||
String content = TestUtils.readFileFromClasspath("order.json");
|
||||
|
||||
@@ -187,7 +187,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-250
|
||||
public void serializesReferencesWithinPagedResourceCorrectly() throws Exception {
|
||||
void serializesReferencesWithinPagedResourceCorrectly() throws Exception {
|
||||
|
||||
Person creator = new Person("Dave", "Matthews");
|
||||
|
||||
@@ -209,7 +209,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-521
|
||||
public void serializesLinksForExcerpts() throws Exception {
|
||||
void serializesLinksForExcerpts() throws Exception {
|
||||
|
||||
Person dave = new Person("Dave", "Matthews");
|
||||
dave.setId(1L);
|
||||
@@ -232,7 +232,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-521
|
||||
public void rendersAdditionalLinksRegisteredWithResource() throws Exception {
|
||||
void rendersAdditionalLinksRegisteredWithResource() throws Exception {
|
||||
|
||||
Person dave = new Person("Dave", "Matthews");
|
||||
|
||||
@@ -248,7 +248,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-697
|
||||
public void rendersProjectionWithinSimpleResourceCorrectly() throws Exception {
|
||||
void rendersProjectionWithinSimpleResourceCorrectly() throws Exception {
|
||||
|
||||
Person person = new Person("Dave", "Matthews");
|
||||
person.setId(1L);
|
||||
@@ -262,7 +262,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-880
|
||||
public void unwrapsNestedTypeCorrectly() throws Exception {
|
||||
void unwrapsNestedTypeCorrectly() throws Exception {
|
||||
|
||||
CreditCard creditCard = new CreditCard(new CreditCard.CCN("1234123412341234"));
|
||||
|
||||
@@ -270,7 +270,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-872
|
||||
public void serializesInheritance() throws Exception {
|
||||
void serializesInheritance() throws Exception {
|
||||
|
||||
Suite suite = new Suite();
|
||||
suite.setSuiteCode("Suite 42");
|
||||
|
||||
@@ -72,7 +72,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*/
|
||||
@Configuration
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RepositoryTestsConfig {
|
||||
class RepositoryTestsConfig {
|
||||
|
||||
@Autowired ApplicationContext appCtx;
|
||||
@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.lang.reflect.Method;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
@@ -38,13 +38,13 @@ import org.springframework.web.context.request.ServletWebRequest;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
public class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests
|
||||
class BackendIdConverterHandlerMethodArgumentResolverIntegrationTests
|
||||
extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired BackendIdHandlerMethodArgumentResolver resolver;
|
||||
|
||||
@Test // DATAREST-155
|
||||
public void translatesUriToBackendId() throws Exception {
|
||||
void translatesUriToBackendId() throws Exception {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(SampleController.class, "resolveId", Serializable.class);
|
||||
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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests {
|
||||
class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@Import(JpaRepositoryConfig.class)
|
||||
@@ -63,7 +63,7 @@ public class ExceptionHandlingCustomizationIntegrationTests extends AbstractWebI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception {
|
||||
void httpRequestMethodNotSupportedExceptionShouldNowReturnHttpStatus500Over405() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("addresses");
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.support;
|
||||
|
||||
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.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -40,13 +40,13 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration(classes = JpaRepositoryConfig.class)
|
||||
public class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositoryEntityLinksIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired RepositoryRestConfiguration configuration;
|
||||
@Autowired RepositoryEntityLinks entityLinks;
|
||||
|
||||
@Test
|
||||
public void returnsLinkToSingleResource() {
|
||||
void returnsLinkToSingleResource() {
|
||||
|
||||
Link link = entityLinks.linkToItemResource(Person.class, 1);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsTemplatedLinkForPagingResource() {
|
||||
void returnsTemplatedLinkForPagingResource() {
|
||||
|
||||
Link link = entityLinks.linkToCollectionResource(Person.class);
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
|
||||
void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
|
||||
|
||||
Link link = entityLinks.linkToItemResource(Order.class, 1);
|
||||
|
||||
@@ -74,14 +74,14 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-155
|
||||
public void usesCustomGeneratedBackendId() {
|
||||
void usesCustomGeneratedBackendId() {
|
||||
|
||||
Link link = entityLinks.linkToItemResource(Book.class, 7L);
|
||||
assertThat(link.expand().getHref()).endsWith("/7-7-7-7-7-7-7");
|
||||
}
|
||||
|
||||
@Test // DATAREST-317
|
||||
public void adaptsToExistingPageable() {
|
||||
void adaptsToExistingPageable() {
|
||||
|
||||
Link link = entityLinks.linkToPagedResource(Person.class, PageRequest.of(0, 10));
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void returnsLinksToSearchResources() {
|
||||
void returnsLinksToSearchResources() {
|
||||
|
||||
Links links = entityLinks.linksToSearchResources(Person.class);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void returnsLinkToSearchResource() {
|
||||
void returnsLinkToSearchResource() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("firstname"));
|
||||
|
||||
@@ -113,7 +113,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-467, DATAREST-519
|
||||
public void prepopulatesPaginationInformationForSearchResourceLink() {
|
||||
void prepopulatesPaginationInformationForSearchResourceLink() {
|
||||
|
||||
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
|
||||
public void returnsTemplatedLinkForSortedSearchResource() {
|
||||
void returnsTemplatedLinkForSortedSearchResource() {
|
||||
|
||||
Link link = entityLinks.linkToSearchResource(Person.class, LinkRelation.of("lastname"));
|
||||
|
||||
@@ -136,7 +136,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // DATAREST-467, DATAREST-519
|
||||
public void prepopulatesSortInformationForSearchResourceLink() {
|
||||
void prepopulatesSortInformationForSearchResourceLink() {
|
||||
|
||||
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
|
||||
public void addsProjectVariableToSearchResourceIfAvailable() {
|
||||
void addsProjectVariableToSearchResourceIfAvailable() {
|
||||
|
||||
for (Link link : entityLinks.linksToSearchResources(Book.class)) {
|
||||
assertThat(link.getVariableNames()).contains("projection");
|
||||
@@ -158,7 +158,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
}
|
||||
|
||||
@Test // #1980
|
||||
public void considersIdConverterInLinkForItemResource() {
|
||||
void considersIdConverterInLinkForItemResource() {
|
||||
|
||||
Link link = entityLinks.linkForItemResource(Book.class, 7L).withSelfRel();
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.After;
|
||||
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.data.rest.tests.CommonWebTests;
|
||||
import org.springframework.data.rest.tests.TestMatchers;
|
||||
@@ -62,7 +62,7 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@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");
|
||||
|
||||
@@ -72,8 +72,8 @@ public class MongoWebTests extends CommonWebTests {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void populateProfiles() {
|
||||
@BeforeEach
|
||||
void populateProfiles() {
|
||||
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
|
||||
@@ -122,8 +122,8 @@ public class MongoWebTests extends CommonWebTests {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
repository.deleteAll();
|
||||
userRepository.deleteAll();
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foo() throws Exception {
|
||||
void foo() throws Exception {
|
||||
|
||||
Link profileLink = client.discoverUnique("profiles");
|
||||
client.follow(profileLink).//
|
||||
@@ -146,7 +146,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rendersEmbeddedDocuments() throws Exception {
|
||||
void rendersEmbeddedDocuments() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -155,7 +155,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-247
|
||||
public void executeQueryMethodWithPrimitiveReturnType() throws Exception {
|
||||
void executeQueryMethodWithPrimitiveReturnType() throws Exception {
|
||||
|
||||
Link profiles = client.discoverUnique("profiles");
|
||||
Link profileSearches = client.discoverUnique(profiles, "search");
|
||||
@@ -169,7 +169,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname() throws Exception {
|
||||
void testname() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -183,7 +183,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname2() throws Exception {
|
||||
void testname2() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -199,7 +199,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-160
|
||||
public void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||
void returnConflictWhenConcurrentlyEditingVersionedEntity() throws Exception {
|
||||
|
||||
Link receiptLink = client.discoverUnique("receipts");
|
||||
|
||||
@@ -226,7 +226,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-471
|
||||
public void auditableResourceHasLastModifiedHeaderSet() throws Exception {
|
||||
void auditableResourceHasLastModifiedHeaderSet() throws Exception {
|
||||
|
||||
Profile profile = repository.findAll().iterator().next();
|
||||
|
||||
@@ -237,7 +237,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-482
|
||||
public void putDoesNotRemoveAssociations() throws Exception {
|
||||
void putDoesNotRemoveAssociations() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -260,7 +260,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-482
|
||||
public void emptiesAssociationForEmptyUriList() throws Exception {
|
||||
void emptiesAssociationForEmptyUriList() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -274,7 +274,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-491
|
||||
public void updatesMapPropertyCorrectly() throws Exception {
|
||||
void updatesMapPropertyCorrectly() throws Exception {
|
||||
|
||||
Link profilesLink = client.discoverUnique("profiles");
|
||||
Link profileLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(profilesLink));
|
||||
@@ -288,7 +288,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-506
|
||||
public void supportsConditionalGetsOnItemResource() throws Exception {
|
||||
void supportsConditionalGetsOnItemResource() throws Exception {
|
||||
|
||||
Receipt receipt = new Receipt();
|
||||
receipt.amount = new BigDecimal(50);
|
||||
@@ -313,7 +313,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-511
|
||||
public void invokesQueryResourceReturningAnOptional() throws Exception {
|
||||
void invokesQueryResourceReturningAnOptional() throws Exception {
|
||||
|
||||
Profile profile = repository.findAll().iterator().next();
|
||||
|
||||
@@ -324,7 +324,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-517
|
||||
public void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception {
|
||||
void returnsNotFoundIfQueryExecutionDoesNotReturnResult() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
||||
|
||||
@@ -333,7 +333,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-712
|
||||
public void invokesQueryMethodTakingAReferenceCorrectly() throws Exception {
|
||||
void invokesQueryMethodTakingAReferenceCorrectly() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("users", "search", "findByColleaguesContains");
|
||||
|
||||
@@ -346,7 +346,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-835
|
||||
public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
|
||||
void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("profiles", "search", "findProfileById");
|
||||
|
||||
@@ -358,7 +358,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-835
|
||||
public void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
|
||||
void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("profiles", "search", "findByType");
|
||||
|
||||
@@ -370,7 +370,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1458
|
||||
public void accessCollectionAssociationResourceAsUriList() throws Exception {
|
||||
void accessCollectionAssociationResourceAsUriList() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -383,7 +383,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1458
|
||||
public void accessAssociationResourceAsUriList() throws Exception {
|
||||
void accessAssociationResourceAsUriList() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -395,7 +395,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1458
|
||||
public void accessMapCollectionAssociationResourceAsUriList() throws Exception {
|
||||
void accessMapCollectionAssociationResourceAsUriList() throws Exception {
|
||||
|
||||
Link usersLink = client.discoverUnique("users");
|
||||
Link userLink = assertHasContentLinkWithRel(IanaLinkRelations.SELF, client.request(usersLink));
|
||||
@@ -409,7 +409,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-762
|
||||
public void paginatedLinksContainQuerydslPropertyReferences() throws Exception {
|
||||
void paginatedLinksContainQuerydslPropertyReferences() throws Exception {
|
||||
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("page", "0");
|
||||
|
||||
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.*;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -46,14 +46,14 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration(classes = { TestConfiguration.class, MongoDbRepositoryConfig.class })
|
||||
public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class PersistentEntityResourceAssemblerIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired PersistentEntities entities;
|
||||
@Autowired EntityLinks entityLinks;
|
||||
@Autowired Associations associations;
|
||||
|
||||
@Test // DATAREST-609
|
||||
public void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception {
|
||||
void addsSelfAndSingleResourceLinkToResourceByDefault() throws Exception {
|
||||
|
||||
Projector projector = mock(Projector.class);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc;
|
||||
|
||||
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.data.rest.tests.AbstractControllerIntegrationTests;
|
||||
import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
|
||||
@@ -34,12 +34,12 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
* @soundtrack Elephants Crossing - Echo (Irrelephant)
|
||||
*/
|
||||
@ContextConfiguration(classes = MongoDbRepositoryConfig.class)
|
||||
public class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
class RepositoryRestHandlerMappingIntegrationTests extends AbstractControllerIntegrationTests {
|
||||
|
||||
@Autowired HandlerMapping mapping;
|
||||
|
||||
@Test // DATAREST-617
|
||||
public void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception {
|
||||
void usesMethodsWithoutProducesClauseForGeneralJsonRequests() throws Exception {
|
||||
|
||||
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "/users");
|
||||
mockRequest.addHeader("Accept", "application/*+json");
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.config;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -29,15 +29,15 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@WebAppConfiguration
|
||||
public abstract class AbstractRepositoryRestMvcConfigurationIntegrationTests {
|
||||
|
||||
@Autowired WebApplicationContext context;
|
||||
protected MockMvc mvc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
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.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
@@ -47,17 +45,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JsonPatchHandlerUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class JsonPatchHandlerUnitTests {
|
||||
|
||||
JsonPatchHandler handler;
|
||||
User user;
|
||||
|
||||
@Mock ResourceMappings mappings;
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
context.getPersistentEntity(User.class);
|
||||
@@ -79,7 +76,7 @@ public class JsonPatchHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-348
|
||||
public void appliesRemoveOperationCorrectly() throws Exception {
|
||||
void appliesRemoveOperationCorrectly() throws Exception {
|
||||
|
||||
String input = "[{ \"op\": \"replace\", \"path\": \"/address/zipCode\", \"value\": \"ZIP\" },"
|
||||
+ "{ \"op\": \"remove\", \"path\": \"/lastname\" }]";
|
||||
@@ -91,7 +88,7 @@ public class JsonPatchHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-348
|
||||
public void appliesMergePatchCorrectly() throws Exception {
|
||||
void appliesMergePatchCorrectly() throws Exception {
|
||||
|
||||
String input = "{ \"address\" : { \"zipCode\" : \"ZIP\"}, \"lastname\" : null }";
|
||||
|
||||
@@ -105,7 +102,7 @@ public class JsonPatchHandlerUnitTests {
|
||||
* DATAREST-537
|
||||
*/
|
||||
@Test
|
||||
public void removesArrayItemCorrectly() throws Exception {
|
||||
void removesArrayItemCorrectly() throws Exception {
|
||||
|
||||
User thomas = new User();
|
||||
thomas.firstname = "Thomas";
|
||||
@@ -124,11 +121,10 @@ public class JsonPatchHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-609
|
||||
public void hintsToMediaTypeIfBodyCantBeRead() throws Exception {
|
||||
void hintsToMediaTypeIfBodyCantBeRead() throws Exception {
|
||||
|
||||
exception.expect(HttpMessageNotReadableException.class);
|
||||
exception.expectMessage(RestMediaTypes.JSON_PATCH_JSON.toString());
|
||||
|
||||
handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User());
|
||||
assertThatExceptionOfType(HttpMessageNotReadableException.class)
|
||||
.isThrownBy(() -> handler.applyPatch(asStream("{ \"foo\" : \"bar\" }"), new User()))
|
||||
.withMessageContaining(RestMediaTypes.JSON_PATCH_JSON.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.QuerydslRepositoryInvokerAdapter;
|
||||
@@ -54,23 +54,23 @@ import com.querydsl.core.types.Predicate;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
static final Map<String, String[]> NO_PARAMETERS = Collections.emptyMap();
|
||||
|
||||
@Mock Repositories repositories;
|
||||
@Mock RepositoryInvokerFactory invokerFactory;
|
||||
@Mock ResourceMetadataHandlerMethodArgumentResolver resourceMetadataResolver;
|
||||
@Mock QuerydslPredicateBuilder builder;
|
||||
@Mock(lenient = true) QuerydslPredicateBuilder builder;
|
||||
|
||||
@Mock RepositoryInvoker invoker;
|
||||
@Mock MethodParameter parameter;
|
||||
|
||||
QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver resolver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
||||
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
|
||||
@@ -83,7 +83,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
||||
}
|
||||
|
||||
@Test // DATAREST-616
|
||||
public void returnsInvokerIfRepositoryIsNotQuerydslAware() {
|
||||
void returnsInvokerIfRepositoryIsNotQuerydslAware() {
|
||||
|
||||
ReceiptRepository repository = mock(ReceiptRepository.class);
|
||||
when(repositories.getRepositoryFor(Receipt.class)).thenReturn(Optional.of(repository));
|
||||
@@ -94,7 +94,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
||||
}
|
||||
|
||||
@Test // DATAREST-616
|
||||
public void wrapsInvokerInQuerydslAdapter() {
|
||||
void wrapsInvokerInQuerydslAdapter() {
|
||||
|
||||
Object repository = mock(QuerydslUserRepository.class);
|
||||
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(repository));
|
||||
@@ -105,7 +105,7 @@ public class QuerydslAwareRootResourceInformationHandlerMethodArgumentResolverUn
|
||||
}
|
||||
|
||||
@Test // DATAREST-616
|
||||
public void invokesCustomizationOnRepositoryIfItImplementsCustomizer() {
|
||||
void invokesCustomizationOnRepositoryIfItImplementsCustomizer() {
|
||||
|
||||
QuerydslCustomizingUserRepository repository = mock(QuerydslCustomizingUserRepository.class);
|
||||
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.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.annotation.Bean;
|
||||
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.mock.web.MockHttpServletRequest;
|
||||
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.ServletWebRequest;
|
||||
|
||||
@@ -60,10 +60,10 @@ import com.jayway.jsonpath.ReadContext;
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, RepositoryTestsConfig.class,
|
||||
PersistentEntitySerializationTests.TestConfig.class })
|
||||
public class PersistentEntitySerializationTests {
|
||||
class PersistentEntitySerializationTests {
|
||||
|
||||
@Autowired ObjectMapper mapper;
|
||||
@Autowired Repositories repositories;
|
||||
@@ -86,8 +86,8 @@ public class PersistentEntitySerializationTests {
|
||||
LinkDiscoverer linkDiscoverer;
|
||||
ProjectionFactory projectionFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
RequestContextHolder.setRequestAttributes(new ServletWebRequest(new MockHttpServletRequest()));
|
||||
|
||||
@@ -96,7 +96,7 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-250
|
||||
public void serializesEmbeddedReferencesCorrectly() throws Exception {
|
||||
void serializesEmbeddedReferencesCorrectly() throws Exception {
|
||||
|
||||
User user = new User();
|
||||
user.address = new Address();
|
||||
@@ -116,12 +116,12 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void deserializesTranslatedEnumProperty() throws Exception {
|
||||
void deserializesTranslatedEnumProperty() throws Exception {
|
||||
assertThat(mapper.readValue("{ \"gender\" : \"Male\" }", User.class).gender).isEqualTo(Gender.MALE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-864
|
||||
public void createsNestedResourceForMap() throws Exception {
|
||||
void createsNestedResourceForMap() throws Exception {
|
||||
|
||||
User dave = users.save(new User());
|
||||
dave.colleaguesMap = new HashMap<String, Nested>();
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
*/
|
||||
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.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
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.context.annotation.Bean;
|
||||
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.hateoas.mediatype.MessageResolver;
|
||||
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.databind.ObjectMapper;
|
||||
@@ -59,9 +59,9 @@ import com.jayway.jsonpath.PathNotFoundException;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { MongoDbRepositoryConfig.class, TestConfiguration.class })
|
||||
public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
|
||||
@Autowired MessageResolver resolver;
|
||||
@Autowired RepositoryRestConfiguration configuration;
|
||||
@@ -89,8 +89,8 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
|
||||
PersistentEntityToJsonSchemaConverter converter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
TestMvcClient.initWebTest();
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-631, DATAREST-632
|
||||
public void fulfillsConstraintsForProfile() {
|
||||
void fulfillsConstraintsForProfile() {
|
||||
|
||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||
constraints.add(new Constraint("$.properties.id", is(notNullValue()), "Has descriptor for id property"));
|
||||
@@ -114,7 +114,7 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-632
|
||||
public void fulfillsConstraintsForUser() throws Exception {
|
||||
void fulfillsConstraintsForUser() throws Exception {
|
||||
|
||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||
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
|
||||
public void handlesGroovyDomainObjects() {
|
||||
void handlesGroovyDomainObjects() {
|
||||
|
||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||
constraints.add(new Constraint("$.properties.name", is(notNullValue()), "Has descriptor for name property"));
|
||||
@@ -182,11 +182,12 @@ public class PersistentEntityToJsonSchemaConverterUnitTests {
|
||||
for (Constraint constraint : constraints) {
|
||||
|
||||
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) {
|
||||
assertThat(constraint.matcher.matches(null)).isTrue();
|
||||
} 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 org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.rest.core.mapping.PersistentEntitiesResourceMappings;
|
||||
@@ -34,12 +34,12 @@ import org.springframework.hateoas.Link;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryLinkBuildUnitTests {
|
||||
class RepositoryLinkBuildUnitTests {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
|
||||
@Test // DATAREST-292
|
||||
public void usesCurrentRequestsUriBaseForRelativeBaseUri() {
|
||||
void usesCurrentRequestsUriBaseForRelativeBaseUri() {
|
||||
|
||||
TestMvcClient.initWebTest();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class RepositoryLinkBuildUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-292, DATAREST-296
|
||||
public void usesBaseUriOnlyIfItIsAbsolute() {
|
||||
void usesBaseUriOnlyIfItIsAbsolute() {
|
||||
assertRootUriFor("http://foobar/api", "http://foobar/api/profile");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
|
||||
@Configuration // <1>
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) // <2>
|
||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3>
|
||||
class SecurityConfiguration extends WebSecurityConfigurerAdapter { // <3>
|
||||
// end::code[]
|
||||
@Autowired
|
||||
public void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
|
||||
void configureAuth(AuthenticationManagerBuilder auth) throws Exception {
|
||||
|
||||
auth.inMemoryAuthentication()
|
||||
.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.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.Before;
|
||||
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.context.annotation.Configuration;
|
||||
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.context.SecurityContextHolder;
|
||||
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.web.context.WebApplicationContext;
|
||||
|
||||
@@ -48,10 +48,10 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
* @author Greg Turnquist
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SecurityIntegrationTests.Config.class, SecurityConfiguration.class,
|
||||
RepositoryRestMvcConfiguration.class })
|
||||
public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Autowired WebApplicationContext context;
|
||||
@Autowired MethodSecurityInterceptor methodSecurityInterceptor;
|
||||
@@ -63,7 +63,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
@EnableMapRepositories
|
||||
static class Config {}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
@Override
|
||||
public void setUp() {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@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
|
||||
final String people = client.discoverUnique("people").expand().getHref();
|
||||
@@ -113,7 +113,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void deletePersonAccessDeniedForUsers() throws Exception {
|
||||
void deletePersonAccessDeniedForUsers() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
@@ -128,7 +128,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void deletePersonAccessGrantedForAdmins() throws Exception {
|
||||
void deletePersonAccessGrantedForAdmins() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER", "ADMIN"))).//
|
||||
@@ -143,14 +143,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllPeopleAccessDeniedForNoCredentials() throws Throwable {
|
||||
void findAllPeopleAccessDeniedForNoCredentials() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("people").expand().getHref())).//
|
||||
andExpect(status().isUnauthorized());
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllPeopleAccessGrantedForUsers() throws Throwable {
|
||||
void findAllPeopleAccessGrantedForUsers() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
@@ -158,7 +158,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllPeopleAccessGrantedForAdmins() throws Throwable {
|
||||
void findAllPeopleAccessGrantedForAdmins() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("people").expand().getHref()).//
|
||||
with(user("user").roles("USER", "ADMIN"))).//
|
||||
@@ -166,7 +166,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@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
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
@@ -181,7 +181,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void deleteOrderAccessDeniedForUsers() throws Exception {
|
||||
void deleteOrderAccessDeniedForUsers() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
@@ -193,7 +193,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void deleteOrderAccessGrantedForAdmins() throws Exception {
|
||||
void deleteOrderAccessGrantedForAdmins() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
@@ -208,14 +208,14 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllOrdersAccessDeniedForNoCredentials() throws Throwable {
|
||||
void findAllOrdersAccessDeniedForNoCredentials() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref())).//
|
||||
andExpect(status().isUnauthorized());
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllOrdersAccessGrantedForUsers() throws Throwable {
|
||||
void findAllOrdersAccessGrantedForUsers() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER"))).//
|
||||
@@ -223,7 +223,7 @@ public class SecurityIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-327
|
||||
public void findAllOrdersAccessGrantedForAdmins() throws Throwable {
|
||||
void findAllOrdersAccessGrantedForAdmins() throws Throwable {
|
||||
|
||||
mvc.perform(get(client.discoverUnique("orders").expand().getHref()).//
|
||||
with(user("user").roles("USER", "ADMIN"))).//
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
*/
|
||||
@Configuration
|
||||
@EnableMapRepositories
|
||||
public class ShopConfiguration {
|
||||
class ShopConfiguration {
|
||||
|
||||
@Autowired CustomerRepository customers;
|
||||
@Autowired OrderRepository orders;
|
||||
@@ -77,7 +77,7 @@ public class ShopConfiguration {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
void init() {
|
||||
|
||||
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.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
|
||||
import org.springframework.hateoas.Link;
|
||||
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 com.jayway.jsonpath.JsonPath;
|
||||
@@ -37,12 +37,12 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Oliver Gierke
|
||||
* @author Craig Andrews
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = ShopConfiguration.class)
|
||||
public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void rendersRepresentationCorrectly() throws Exception {
|
||||
void rendersRepresentationCorrectly() throws Exception {
|
||||
|
||||
Link ordersLink = client.discoverUnique("orders");
|
||||
String selfLink = JsonPath.parse(client.request(ordersLink).getContentAsString())
|
||||
@@ -63,7 +63,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void renderProductNameOnlyProjection() throws Exception {
|
||||
void renderProductNameOnlyProjection() throws Exception {
|
||||
|
||||
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void renderProductNameOnlyProjectionResourceProcessor() throws Exception {
|
||||
void renderProductNameOnlyProjectionResourceProcessor() throws Exception {
|
||||
|
||||
Map<String, Object> arguments = Collections.singletonMap("projection", "nameOnly");
|
||||
|
||||
@@ -84,7 +84,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-221
|
||||
public void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception {
|
||||
void renderOrderItemsOnlyProjectionResourceProcessor() throws Exception {
|
||||
|
||||
Map<String, Object> arguments = Collections.singletonMap("projection", "itemsOnly");
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
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.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.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -47,8 +49,9 @@ import org.springframework.hateoas.Link;
|
||||
* @author Oliver Gierke
|
||||
* @author Haroun Pacquee
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AssociationLinksUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class AssociationLinksUnitTests {
|
||||
|
||||
Associations links;
|
||||
|
||||
@@ -60,8 +63,8 @@ public class AssociationLinksUnitTests {
|
||||
@Mock RepositoryRestConfiguration config;
|
||||
@Mock ProjectionDefinitionConfiguration projectionDefinitionConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
doReturn(projectionDefinitionConfig).when(config).getProjectionConfiguration();
|
||||
|
||||
@@ -71,18 +74,22 @@ public class AssociationLinksUnitTests {
|
||||
this.links = new Associations(mappings, config);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-262
|
||||
public void rejectsNullMappings() {
|
||||
new Associations(null, mock(RepositoryRestConfiguration.class));
|
||||
@Test // DATAREST-262
|
||||
void rejectsNullMappings() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new Associations(null, mock(RepositoryRestConfiguration.class)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullConfiguration() {
|
||||
new Associations(mappings, null);
|
||||
@Test
|
||||
void rejectsNullConfiguration() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new Associations(mappings, null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void rejectsNullPropertyForIsLinkable() {
|
||||
void rejectsNullPropertyForIsLinkable() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
links.isLinkableAssociation((PersistentProperty<?>) null);
|
||||
@@ -90,12 +97,12 @@ public class AssociationLinksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void consideredHiddenPropertyUnlinkable() {
|
||||
void consideredHiddenPropertyUnlinkable() {
|
||||
assertThat(links.isLinkableAssociation(entity.getRequiredPersistentProperty("hiddenProperty"))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void createsLinkToAssociationProperty() {
|
||||
void createsLinkToAssociationProperty() {
|
||||
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("property");
|
||||
List<Link> associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base"));
|
||||
@@ -105,14 +112,14 @@ public class AssociationLinksUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-262
|
||||
public void doesNotCreateLinksForHiddenProperty() {
|
||||
void doesNotCreateLinksForHiddenProperty() {
|
||||
|
||||
PersistentProperty<?> property = entity.getRequiredPersistentProperty("hiddenProperty");
|
||||
assertThat(links.getLinksFor(property.getRequiredAssociation(), new Path("/sample"))).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void detectsLookupTypes() {
|
||||
void detectsLookupTypes() {
|
||||
|
||||
doReturn(true).when(config).isLookupType(Property.class);
|
||||
|
||||
@@ -120,7 +127,7 @@ public class AssociationLinksUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegatesResourceMetadataLookupToMappings() {
|
||||
void delegatesResourceMetadataLookupToMappings() {
|
||||
assertThat(links.getMetadataFor(Property.class)).isEqualTo(mappings.getMetadataFor(Property.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
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.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -39,7 +39,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class AugmentingHandlerMappingUnitTests {
|
||||
class AugmentingHandlerMappingUnitTests {
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@@ -51,7 +51,7 @@ public class AugmentingHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void augmentsRequestMappingsWithBaseUriFromConfiguration() {
|
||||
void augmentsRequestMappingsWithBaseUriFromConfiguration() {
|
||||
|
||||
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||
|
||||
@@ -20,8 +20,8 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
@@ -33,12 +33,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class BasePathAwareHandlerMappingUnitTests {
|
||||
class BasePathAwareHandlerMappingUnitTests {
|
||||
|
||||
HandlerMappingStub mapping;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
RepositoryRestConfiguration configuration = mock(RepositoryRestConfiguration.class);
|
||||
doReturn(URI.create("")).when(configuration).getBasePath();
|
||||
@@ -47,7 +47,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1132
|
||||
public void detectsAnnotationsOnProxies() {
|
||||
void detectsAnnotationsOnProxies() {
|
||||
|
||||
Class<?> type = createProxy(new SomeController());
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1132
|
||||
public void doesNotConsiderMetaAnnotation() {
|
||||
void doesNotConsiderMetaAnnotation() {
|
||||
|
||||
Class<?> type = createProxy(new RepositoryController());
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // #1342, #1628, #1686, #1946
|
||||
public void rejectsAtRequestMappingOnCustomController() {
|
||||
void rejectsAtRequestMappingOnCustomController() {
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> {
|
||||
@@ -73,7 +73,7 @@ public class BasePathAwareHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // #1342, #1628, #1686, #1946
|
||||
public void doesNotRejectAtRequestMappingOnStandardMvcController() {
|
||||
void doesNotRejectAtRequestMappingOnStandardMvcController() {
|
||||
|
||||
assertThatNoException()
|
||||
.isThrownBy(() -> mapping.isHandler(ValidController.class));
|
||||
|
||||
@@ -19,24 +19,24 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BaseUri}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class BaseUriUnitTests {
|
||||
class BaseUriUnitTests {
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void doesNotMatchNonOverlap() {
|
||||
void doesNotMatchNonOverlap() {
|
||||
|
||||
assertThat(new BaseUri(URI.create("foo")).getRepositoryLookupPath("/bar")).isNull();
|
||||
assertThat(new BaseUri(URI.create("http://localhost:8080/foo/")).getRepositoryLookupPath("/bar")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void matchesSimpleBaseUri() {
|
||||
void matchesSimpleBaseUri() {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("foo"));
|
||||
|
||||
@@ -44,7 +44,7 @@ public class BaseUriUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void ignoresTrailingSlash() {
|
||||
void ignoresTrailingSlash() {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("foo/"));
|
||||
|
||||
@@ -53,7 +53,7 @@ public class BaseUriUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void ignoresLeadingSlash() {
|
||||
void ignoresLeadingSlash() {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("/foo"));
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BaseUriUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void matchesAbsoluteBaseUriOnOverlap() {
|
||||
void matchesAbsoluteBaseUriOnOverlap() {
|
||||
|
||||
BaseUri uri = new BaseUri(URI.create("http://localhost:8080/foo/"));
|
||||
|
||||
@@ -73,7 +73,7 @@ public class BaseUriUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-674, SPR-13455
|
||||
public void repositoryLookupPathHandlesDoubleSlashes() {
|
||||
void repositoryLookupPathHandlesDoubleSlashes() {
|
||||
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1")).isEqualTo("/books/1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.List;
|
||||
|
||||
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.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -37,12 +36,12 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Spring engineering team meeting @ SpringOne Platform 2016
|
||||
*/
|
||||
public class CustomAcceptHeaderHttpServletRequestUnitTests {
|
||||
class CustomAcceptHeaderHttpServletRequestUnitTests {
|
||||
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@Test // DATAREST-863
|
||||
public void returnsRegisterdHeadersOnAccessForMultipleOnes() {
|
||||
void returnsRegisterdHeadersOnAccessForMultipleOnes() {
|
||||
|
||||
List<MediaType> mediaTypes = Arrays.asList(MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_ATOM_XML);
|
||||
HttpServletRequest servletRequest = new CustomAcceptHeaderHttpServletRequest(request, mediaTypes);
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
@@ -27,17 +27,17 @@ import org.springframework.mock.web.MockHttpServletRequest;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class IncomingRequestUnitTests {
|
||||
class IncomingRequestUnitTests {
|
||||
|
||||
MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.request = new MockHttpServletRequest("PATCH", "/");
|
||||
}
|
||||
|
||||
@Test // DATAREST-498
|
||||
public void identifiesJsonPatchRequestForRequestWithContentTypeParameters() {
|
||||
void identifiesJsonPatchRequestForRequestWithContentTypeParameters() {
|
||||
|
||||
request.addHeader("Content-Type", "application/json-patch+json;charset=UTF-8");
|
||||
|
||||
@@ -48,7 +48,7 @@ public class IncomingRequestUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-498
|
||||
public void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() {
|
||||
void identifiesJsonMergePatchRequestForRequestWithContentTypeParameters() {
|
||||
|
||||
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 org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
@@ -36,8 +36,8 @@ import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PersistentEntityResourceUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PersistentEntityResourceUnitTests {
|
||||
|
||||
@Mock Object payload;
|
||||
@Mock PersistentEntity<?, ?> entity;
|
||||
@@ -45,26 +45,30 @@ public class PersistentEntityResourceUnitTests {
|
||||
CollectionModel<EmbeddedWrapper> resources;
|
||||
Link link = Link.of("http://localhost", "foo");
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
|
||||
EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo"));
|
||||
this.resources = CollectionModel.of(Collections.singleton(wrapper));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-317
|
||||
public void rejectsNullPayload() {
|
||||
PersistentEntityResource.build(null, entity);
|
||||
}
|
||||
@Test // DATAREST-317
|
||||
void rejectsNullPayload() {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-317
|
||||
public void rejectsNullPersistentEntity() {
|
||||
PersistentEntityResource.build(payload, null);
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> PersistentEntityResource.build(null, entity));
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
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)
|
||||
* @since 2.6
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
|
||||
RepositoryCorsConfigurationAccessor accessor;
|
||||
|
||||
@Mock ResourceMappings mappings;
|
||||
@Mock Repositories repositories;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
@BeforeEach
|
||||
void before() throws Exception {
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE,
|
||||
Optional.of(repositories));
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
public void createConfigurationShouldConstructCorsConfiguration() {
|
||||
void createConfigurationShouldConstructCorsConfiguration() {
|
||||
|
||||
CorsConfiguration configuration = accessor.createConfiguration(AnnotatedRepository.class);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-573
|
||||
public void createConfigurationShouldConstructFullCorsConfiguration() {
|
||||
void createConfigurationShouldConstructFullCorsConfiguration() {
|
||||
|
||||
CorsConfiguration configuration = accessor.createConfiguration(FullyConfiguredCorsRepository.class);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class RepositoryCorsConfigurationAccessorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-994
|
||||
public void returnsNoCorsConfigurationWithNoRepositories() {
|
||||
void returnsNoCorsConfigurationWithNoRepositories() {
|
||||
|
||||
accessor = new RepositoryCorsConfigurationAccessor(mappings, NoOpStringValueResolver.INSTANCE, Optional.empty());
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
@@ -41,8 +41,8 @@ import org.springframework.data.web.PagedResourcesAssembler;
|
||||
*
|
||||
* @author Jeroen Reijn
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryEntityControllerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RepositoryEntityControllerTest {
|
||||
|
||||
@Mock Repositories repositories;
|
||||
@Mock RepositoryRestConfiguration restConfiguration;
|
||||
@@ -54,7 +54,7 @@ public class RepositoryEntityControllerTest {
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
|
||||
@Test // DATAREST-1143
|
||||
public void testUnknownItemThrowsResourceNotFound() throws Exception {
|
||||
void testUnknownItemThrowsResourceNotFound() throws Exception {
|
||||
|
||||
KeyValuePersistentEntity<?, ?> entity = mappingContext
|
||||
.getRequiredPersistentEntity(RepositoryPropertyReferenceControllerUnitTests.Sample.class);
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
@@ -53,8 +53,8 @@ import org.springframework.http.HttpMethod;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RepositoryPropertyReferenceControllerUnitTests {
|
||||
|
||||
@Mock Repositories repositories;
|
||||
@Mock PagedResourcesAssembler<Object> assembler;
|
||||
@@ -65,7 +65,7 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
|
||||
@Test // DATAREST-791
|
||||
public void usesRepositoryInvokerToLookupRelatedInstance() throws Exception {
|
||||
void usesRepositoryInvokerToLookupRelatedInstance() throws Exception {
|
||||
|
||||
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.Logger;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
@@ -37,14 +37,14 @@ import org.springframework.mock.http.MockHttpInputMessage;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryRestExceptionHandlerUnitTests {
|
||||
class RepositoryRestExceptionHandlerUnitTests {
|
||||
|
||||
static final RepositoryRestExceptionHandler HANDLER = new RepositoryRestExceptionHandler(new StaticMessageSource());
|
||||
|
||||
static Logger logger;
|
||||
static Level logLevel;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void silenceLog() {
|
||||
|
||||
logger = (Logger) LoggerFactory.getLogger(RepositoryRestExceptionHandler.class);
|
||||
@@ -52,13 +52,13 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
logger.setLevel(Level.OFF);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void enableLogging() {
|
||||
logger.setLevel(logLevel);
|
||||
}
|
||||
|
||||
@Test // DATAREST-427
|
||||
public void handlesHttpMessageNotReadableException() {
|
||||
void handlesHttpMessageNotReadableException() {
|
||||
|
||||
ResponseEntity<ExceptionMessage> result = HANDLER
|
||||
.handleNotReadable(new HttpMessageNotReadableException("Message!", new MockHttpInputMessage(new byte[0])));
|
||||
@@ -67,7 +67,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-507
|
||||
public void handlesConflictCorrectly() {
|
||||
void handlesConflictCorrectly() {
|
||||
|
||||
ResponseEntity<ExceptionMessage> result = HANDLER.handleConflict(new DataIntegrityViolationException("Message!"));
|
||||
|
||||
@@ -75,7 +75,7 @@ public class RepositoryRestExceptionHandlerUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-706
|
||||
public void forwardsExceptionForMiscellaneousFailure() {
|
||||
void forwardsExceptionForMiscellaneousFailure() {
|
||||
|
||||
String message = "My Message!";
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -57,8 +57,8 @@ import org.springframework.web.util.pattern.PathPattern;
|
||||
* @author Greg Turnquist
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class RepositoryRestHandlerMappingUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RepositoryRestHandlerMappingUnitTests {
|
||||
|
||||
static final AnnotationConfigWebApplicationContext CONTEXT = new AnnotationConfigWebApplicationContext();
|
||||
|
||||
@@ -68,8 +68,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
CONTEXT.refresh();
|
||||
}
|
||||
|
||||
@Mock ResourceMappings mappings;
|
||||
@Mock ResourceMetadata resourceMetadata;
|
||||
@Mock(lenient = true) ResourceMappings mappings;
|
||||
@Mock(lenient = true) ResourceMetadata resourceMetadata;
|
||||
@Mock Repositories repositories;
|
||||
|
||||
RepositoryRestConfiguration configuration;
|
||||
@@ -77,8 +77,8 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
MockHttpServletRequest mockRequest;
|
||||
Method listEntitiesMethod, rootHandlerMethod;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
|
||||
configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||
@@ -99,23 +99,27 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
rootHandlerMethod = RepositoryController.class.getMethod("listRepositories");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullMappings() {
|
||||
new RepositoryRestHandlerMapping(null, configuration);
|
||||
@Test
|
||||
void rejectsNullMappings() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new RepositoryRestHandlerMapping(null, configuration));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNullConfiguration() {
|
||||
new RepositoryRestHandlerMapping(mappings, null);
|
||||
@Test
|
||||
void rejectsNullConfiguration() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new RepositoryRestHandlerMapping(mappings, null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-111
|
||||
public void returnsNullForUriNotMapped() throws Exception {
|
||||
void returnsNullForUriNotMapped() throws Exception {
|
||||
assertThat(handlerMapping.get().getHandler(mockRequest)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-111
|
||||
public void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception {
|
||||
void looksUpRepositoryEntityControllerMethodCorrectly() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/people");
|
||||
@@ -127,7 +131,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-292
|
||||
public void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||
void returnsRepositoryHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
||||
@@ -141,7 +145,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-292
|
||||
public void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||
void returnsRootHandlerMethodWithBaseUriConfigured() throws Exception {
|
||||
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base");
|
||||
|
||||
@@ -154,7 +158,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception {
|
||||
void returnsRepositoryHandlerMethodForAbsoluteBaseUri() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base/people/");
|
||||
@@ -168,7 +172,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception {
|
||||
void returnsRepositoryHandlerMethodForAbsoluteBaseUriWithServletMapping() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
mockRequest = new MockHttpServletRequest("GET", "/base/people");
|
||||
@@ -183,7 +187,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
||||
void refrainsFromMappingIfTheRequestDoesNotPointIntoAbsolutelyDefinedUriSpace() throws Exception {
|
||||
|
||||
mockRequest = new MockHttpServletRequest("GET", "/servlet-path");
|
||||
mockRequest.setServletPath("/servlet-path");
|
||||
@@ -196,7 +200,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-276
|
||||
public void refrainsFromMappingWhenUrisDontMatch() throws Exception {
|
||||
void refrainsFromMappingWhenUrisDontMatch() throws Exception {
|
||||
|
||||
String baseUri = "foo";
|
||||
String uri = baseUri.concat("/people");
|
||||
@@ -213,7 +217,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-609
|
||||
public void rejectsUnexpandedUriTemplateWithNotFound() throws Exception {
|
||||
void rejectsUnexpandedUriTemplateWithNotFound() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
|
||||
@@ -223,7 +227,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1019
|
||||
public void resolvesCorsConfigurationFromRequestUri() {
|
||||
void resolvesCorsConfigurationFromRequestUri() {
|
||||
|
||||
String uri = "/people";
|
||||
|
||||
@@ -240,7 +244,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1019
|
||||
public void stripsBaseUriForCorsConfigurationResolution() {
|
||||
void stripsBaseUriForCorsConfigurationResolution() {
|
||||
|
||||
String baseUri = "/foo";
|
||||
String uri = baseUri.concat("/people");
|
||||
@@ -260,12 +264,12 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-994
|
||||
public void twoArgumentConstructorDoesNotThrowException() {
|
||||
void twoArgumentConstructorDoesNotThrowException() {
|
||||
new RepositoryRestHandlerMapping(mappings, configuration);
|
||||
}
|
||||
|
||||
@Test // DATAREST-1132
|
||||
public void detectsAnnotationsOnProxies() {
|
||||
void detectsAnnotationsOnProxies() {
|
||||
|
||||
Class<?> type = createProxy(new SomeController());
|
||||
|
||||
@@ -278,7 +282,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1294
|
||||
public void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception {
|
||||
void exposesEffectiveRepositoryLookupPathAsRequestAttribute() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
|
||||
@@ -293,7 +297,7 @@ public class RepositoryRestHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1332
|
||||
public void handlesCorsPreflightRequestsProperly() throws Exception {
|
||||
void handlesCorsPreflightRequestsProperly() throws Exception {
|
||||
|
||||
when(mappings.exportsTopLevelResourceFor("/people")).thenReturn(true);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RepositorySearchesResource}
|
||||
@@ -25,15 +25,17 @@ import org.junit.Test;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Bakkushan - Gefahr (Bakkushan)
|
||||
*/
|
||||
public class RepositorySearchesResourceUnitTests {
|
||||
class RepositorySearchesResourceUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-515
|
||||
public void rejectsNullDomainType() {
|
||||
new RepositorySearchesResource(null);
|
||||
@Test // DATAREST-515
|
||||
void rejectsNullDomainType() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new RepositorySearchesResource(null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-515
|
||||
public void returnsConfiguredDomainType() {
|
||||
void returnsConfiguredDomainType() {
|
||||
assertThat(new RepositorySearchesResource(String.class).getDomainType()).isAssignableFrom(String.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ import lombok.Value;
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
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.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.keyvalue.core.mapping.KeyValuePersistentEntity;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
@@ -43,8 +43,9 @@ import org.springframework.http.HttpStatus;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ResourceStatusUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class ResourceStatusUnitTests {
|
||||
|
||||
ResourceStatus status;
|
||||
KeyValuePersistentEntity<?, ?> entity;
|
||||
@@ -52,10 +53,8 @@ public class ResourceStatusUnitTests {
|
||||
@Mock HttpHeadersPreparer preparer;
|
||||
@Mock Supplier<PersistentEntityResource> supplier;
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.status = ResourceStatus.of(preparer);
|
||||
|
||||
@@ -65,18 +64,20 @@ public class ResourceStatusUnitTests {
|
||||
doReturn(new HttpHeaders()).when(preparer).prepareHeaders(eq(entity), any());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-835
|
||||
public void rejectsNullPreparer() {
|
||||
ResourceStatus.of(null);
|
||||
@Test // DATAREST-835
|
||||
void rejectsNullPreparer() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> ResourceStatus.of(null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-835
|
||||
public void returnsModifiedIfNoHeadersGiven() {
|
||||
void returnsModifiedIfNoHeadersGiven() {
|
||||
assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Sample(0), entity));
|
||||
}
|
||||
|
||||
@Test // DATAREST-835
|
||||
public void returnsNotModifiedForEntityWithRequestedETag() {
|
||||
void returnsNotModifiedForEntityWithRequestedETag() {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setIfNoneMatch("\"1\"");
|
||||
@@ -85,7 +86,7 @@ public class ResourceStatusUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-835
|
||||
public void returnsNotModifiedIfEntityIsStillConsideredValid() {
|
||||
void returnsNotModifiedIfEntityIsStillConsideredValid() {
|
||||
|
||||
doReturn(true).when(preparer).isObjectStillValid(any(), any(HttpHeaders.class));
|
||||
|
||||
@@ -93,12 +94,11 @@ public class ResourceStatusUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1121
|
||||
public void rejectsInvalidPersistentEntityDomainObjectCombination() {
|
||||
void rejectsInvalidPersistentEntityDomainObjectCombination() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage(entity.getType().getName());
|
||||
|
||||
assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity));
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> assertModified(status.getStatusAndHeaders(new HttpHeaders(), new Date(), entity)))
|
||||
.withMessageContaining(entity.getType().getName());
|
||||
}
|
||||
|
||||
private void assertModified(StatusAndHeaders statusAndHeaders) {
|
||||
|
||||
@@ -15,21 +15,22 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.rest.core.mapping.ResourceType.*;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.repository.support.RepositoryInvoker;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.core.mapping.ResourceType;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
|
||||
/**
|
||||
@@ -37,8 +38,8 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RootResourceInformationUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RootResourceInformationUnitTests {
|
||||
|
||||
@Mock ResourceMetadata metadata;
|
||||
@Mock PersistentEntity<?, ?> entity;
|
||||
@@ -46,18 +47,21 @@ public class RootResourceInformationUnitTests {
|
||||
|
||||
RootResourceInformation information;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.invoker = mock(RepositoryInvoker.class, new DefaultBooleanToTrue());
|
||||
this.information = new RootResourceInformation(metadata, entity, invoker);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceNotFoundException.class) // DATAREST-330
|
||||
public void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException {
|
||||
@Test // DATAREST-330
|
||||
void throwsExceptionOnVerificationIfResourceIsNotExported() throws HttpRequestMethodNotSupportedException {
|
||||
|
||||
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.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -39,25 +39,29 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||
|
||||
@Mock HateoasPageableHandlerMethodArgumentResolver pageableResolver;
|
||||
@Mock HateoasSortHandlerMethodArgumentResolver sortResolver;
|
||||
@Mock UriComponentsBuilder builder;
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-467
|
||||
public void rejectsNullArgumentResolverForPageable() {
|
||||
new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver);
|
||||
}
|
||||
@Test // DATAREST-467
|
||||
void rejectsNullArgumentResolverForPageable() {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-467
|
||||
public void rejectsNullArgumentResolverForSort() {
|
||||
new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null);
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(null, sortResolver));
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void supportsPageableAndSortMethodParameters() {
|
||||
void rejectsNullArgumentResolverForSort() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new ArgumentResolverPagingAndSortingTemplateVariables(pageableResolver, null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
void supportsPageableAndSortMethodParameters() {
|
||||
|
||||
PagingAndSortingTemplateVariables variables = new ArgumentResolverPagingAndSortingTemplateVariables(
|
||||
pageableResolver, sortResolver);
|
||||
@@ -68,12 +72,12 @@ public class ArgumentResolverPagingAndSortingTemplateVariablesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void forwardsEnhanceRequestForPageable() {
|
||||
void forwardsEnhanceRequestForPageable() {
|
||||
assertForwardsEnhanceFor(PageRequest.of(0, 10), pageableResolver, sortResolver);
|
||||
}
|
||||
|
||||
@Test // DATAREST-467
|
||||
public void forwardsEnhanceRequestForSort() {
|
||||
void forwardsEnhanceRequestForSort() {
|
||||
assertForwardsEnhanceFor(Sort.by("property"), sortResolver, pageableResolver);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -24,11 +23,11 @@ import java.util.Arrays;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@@ -43,14 +42,14 @@ import org.springframework.web.servlet.handler.RequestMatchResult;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Benny Greb - Stabila (Moving Parts)
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class DelegatingHandlerMappingUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DelegatingHandlerMappingUnitTests {
|
||||
|
||||
@Mock HandlerMapping first, second;
|
||||
@Mock HttpServletRequest request;
|
||||
|
||||
@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);
|
||||
|
||||
@@ -61,11 +60,11 @@ public class DelegatingHandlerMappingUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1193
|
||||
public void exposesMatchabilityOfSelectedMapping() {
|
||||
void exposesMatchabilityOfSelectedMapping() {
|
||||
|
||||
// Given:
|
||||
// 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));
|
||||
|
||||
// A matching mapping that gets selected
|
||||
@@ -83,16 +82,10 @@ public class DelegatingHandlerMappingUnitTests {
|
||||
|
||||
when(first.getHandler(request)).thenThrow(type);
|
||||
|
||||
try {
|
||||
assertThatExceptionOfType(type)
|
||||
.isThrownBy(() -> mapping.getHandler(request));
|
||||
|
||||
mapping.getHandler(request);
|
||||
fail(String.format("Expected %s!", type.getSimpleName()));
|
||||
|
||||
} catch (Exception o_O) {
|
||||
assertThat(o_O).isInstanceOf(type);
|
||||
verify(second, times(1)).getHandler(request);
|
||||
} finally {
|
||||
reset(first, second);
|
||||
}
|
||||
verify(second, times(1)).getHandler(request);
|
||||
reset(first, second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
|
||||
class HalFormsAdaptingResponseBodyAdviceTests<T extends RepresentationModel<T>> {
|
||||
|
||||
HalFormsAdaptingResponseBodyAdvice<T> advice = new HalFormsAdaptingResponseBodyAdvice<>();
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -53,15 +53,15 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
||||
class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
HttpMessageConverter<?> converter;
|
||||
RootResourceInformationHandlerMethodArgumentResolver rootResourceResolver;
|
||||
BackendIdHandlerMethodArgumentResolver backendIdResolver;
|
||||
DomainObjectReader reader;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
|
||||
this.converter = mock(HttpMessageConverter.class);
|
||||
when(this.converter.canRead((Class<?>) any(), (MediaType) any())).thenReturn(true);
|
||||
@@ -75,7 +75,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Test // DATAREST-1050
|
||||
@SuppressWarnings("unchecked")
|
||||
public void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception {
|
||||
void returnsAggregateInstanceWithIdentifierPopulatedForPutRequests() throws Exception {
|
||||
|
||||
PersistentEntityResourceHandlerMethodArgumentResolver argumentResolver = new PersistentEntityResourceHandlerMethodArgumentResolver(
|
||||
Arrays.<HttpMessageConverter<?>> asList(converter), rootResourceResolver, backendIdResolver, reader,
|
||||
@@ -95,7 +95,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Test // DATAREST-1304
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception {
|
||||
void setsLookupPropertyForEntitiesWithCustomLookup() throws Exception {
|
||||
|
||||
EntityLookup<?> lookup = mock(EntityLookup.class);
|
||||
doReturn(Optional.of("name")).when(lookup).getLookupProperty();
|
||||
|
||||
@@ -25,9 +25,9 @@ import java.util.List;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.ldap.LdapName;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -70,16 +70,16 @@ import com.jayway.jsonpath.JsonPath;
|
||||
* @author Mark Paluch
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
class RepositoryRestMvConfigurationIntegrationTests {
|
||||
|
||||
static AbstractApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUp() {
|
||||
context = new AnnotationConfigApplicationContext(ExtendingConfiguration.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void tearDown() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
@@ -87,14 +87,14 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-210
|
||||
public void assertEnableHypermediaSupportWorkingCorrectly() {
|
||||
void assertEnableHypermediaSupportWorkingCorrectly() {
|
||||
|
||||
assertThat(context.getBean("entityLinksPluginRegistry")).isNotNull();
|
||||
assertThat(context.getBean(LinkDiscoverers.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertBeansBeingSetUp() throws Exception {
|
||||
void assertBeansBeingSetUp() throws Exception {
|
||||
|
||||
context.getBean(PageableHandlerMethodArgumentResolver.class);
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-271
|
||||
public void assetConsidersPaginationCustomization() {
|
||||
void assetConsidersPaginationCustomization() {
|
||||
|
||||
HateoasPageableHandlerMethodArgumentResolver resolver = context
|
||||
.getBean(HateoasPageableHandlerMethodArgumentResolver.class);
|
||||
@@ -121,7 +121,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-336 DATAREST-1509
|
||||
public void objectMapperRendersDatesInIsoByDefault() throws Exception {
|
||||
void objectMapperRendersDatesInIsoByDefault() throws Exception {
|
||||
|
||||
Sample sample = new Sample();
|
||||
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");
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class) // DATAREST-362
|
||||
public void doesNotExposePersistentEntityJackson2ModuleAsBean() {
|
||||
context.getBean(PersistentEntityJackson2Module.class);
|
||||
@Test // DATAREST-362
|
||||
void doesNotExposePersistentEntityJackson2ModuleAsBean() {
|
||||
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) //
|
||||
.isThrownBy(() -> context.getBean(PersistentEntityJackson2Module.class));
|
||||
}
|
||||
|
||||
@Test // DATAREST-362
|
||||
public void registeredHttpMessageConvertersAreTypeConstrained() {
|
||||
void registeredHttpMessageConvertersAreTypeConstrained() {
|
||||
|
||||
Collection<MappingJackson2HttpMessageConverter> converters = context
|
||||
.getBeansOfType(MappingJackson2HttpMessageConverter.class).values();
|
||||
@@ -153,7 +155,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-424
|
||||
public void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() {
|
||||
void halHttpMethodConverterIsRegisteredBeforeTheGeneralOne() {
|
||||
|
||||
CollectingComponent component = context.getBean(CollectingComponent.class);
|
||||
List<HttpMessageConverter<?>> converters = component.converters;
|
||||
@@ -163,7 +165,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-424
|
||||
public void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() {
|
||||
void halHttpMethodConverterIsRegisteredAfterTheGeneralOneIfHalIsDisabledAsDefaultMediaType() {
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NonHalConfiguration.class);
|
||||
CollectingComponent component = context.getBean(CollectingComponent.class);
|
||||
@@ -176,7 +178,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-431, DATACMNS-626
|
||||
public void hasConvertersForPointAndDistance() {
|
||||
void hasConvertersForPointAndDistance() {
|
||||
|
||||
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
||||
|
||||
@@ -187,7 +189,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1198
|
||||
public void hasConvertersForNamAndLdapName() {
|
||||
void hasConvertersForNamAndLdapName() {
|
||||
|
||||
ConversionService service = context.getBean("defaultConversionService", ConversionService.class);
|
||||
|
||||
@@ -197,7 +199,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
|
||||
@Test // #1995
|
||||
@SuppressWarnings("unchecked")
|
||||
public void registersRepositoryRestConfigurersInDeclaredOrder() {
|
||||
void registersRepositoryRestConfigurersInDeclaredOrder() {
|
||||
|
||||
RepositoryRestMvcConfiguration configuration = context.getBean(RepositoryRestMvcConfiguration.class);
|
||||
ExtendingConfiguration userConfig = context.getBean(ExtendingConfiguration.class);
|
||||
@@ -278,7 +280,7 @@ public class RepositoryRestMvConfigurationIntegrationTests {
|
||||
List<HttpMessageConverter<?>> converters;
|
||||
|
||||
@Autowired
|
||||
public void setConverters(List<HttpMessageConverter<?>> converters) {
|
||||
void setConverters(List<HttpMessageConverter<?>> 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.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
@@ -31,10 +31,10 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ResourceMetadataHandlerMethodArgumentResolverUnitTests {
|
||||
class ResourceMetadataHandlerMethodArgumentResolverUnitTests {
|
||||
|
||||
@Test // DATAREST-1250
|
||||
public void supportsResourceMetadataParameterType() {
|
||||
void supportsResourceMetadataParameterType() {
|
||||
|
||||
HandlerMethodArgumentResolver resolver = new ResourceMetadataHandlerMethodArgumentResolver(mock(Repositories.class),
|
||||
mock(ResourceMappings.class), BaseUri.NONE);
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AggregateReferenceResolvingModuleUnitTests {
|
||||
class AggregateReferenceResolvingModuleUnitTests {
|
||||
|
||||
@Mock UriToEntityConverter uriToEntityConverter;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class AggregateReferenceResolvingModuleUnitTests {
|
||||
|
||||
public static class SomeType {
|
||||
|
||||
public void setSomeProperty(Other other) {}
|
||||
void setSomeProperty(Other other) {}
|
||||
}
|
||||
|
||||
@RestResource
|
||||
|
||||
@@ -31,12 +31,12 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import org.junit.Before;
|
||||
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.mockito.ArgumentMatchers;
|
||||
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.Id;
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
@@ -75,16 +75,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
* @author Ken Dombeck
|
||||
* @author Thomas Mrozinski
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DomainObjectReaderUnitTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DomainObjectReaderUnitTests {
|
||||
|
||||
@Mock ResourceMappings mappings;
|
||||
|
||||
DomainObjectReader reader;
|
||||
PersistentEntities entities;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
KeyValueMappingContext<?, ?> mappingContext = new KeyValueMappingContext<>();
|
||||
mappingContext.getPersistentEntity(SampleUser.class);
|
||||
@@ -111,7 +111,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-461
|
||||
public void doesNotConsiderIgnoredProperties() throws Exception {
|
||||
void doesNotConsiderIgnoredProperties() throws Exception {
|
||||
|
||||
SampleUser user = new SampleUser("firstname", "password");
|
||||
JsonNode node = new ObjectMapper().readTree("{}");
|
||||
@@ -123,7 +123,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-556
|
||||
public void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception {
|
||||
void considersMappedFieldNamesWhenApplyingNodeToDomainObject() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
|
||||
@@ -137,7 +137,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-605
|
||||
public void mergesMapCorrectly() throws Exception {
|
||||
void mergesMapCorrectly() throws Exception {
|
||||
|
||||
SampleUser user = new SampleUser("firstname", "password");
|
||||
user.relatedUsers = Collections.singletonMap("parent", new SampleUser("firstname", "password"));
|
||||
@@ -154,7 +154,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
@Test // DATAREST-701
|
||||
@SuppressWarnings("unchecked")
|
||||
public void mergesNestedMapWithoutTypeInformation() throws Exception {
|
||||
void mergesNestedMapWithoutTypeInformation() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
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");
|
||||
}
|
||||
|
||||
@Test(expected = JsonMappingException.class) // DATAREST-701
|
||||
public void rejectsMergingUnknownDomainObject() throws Exception {
|
||||
@Test // DATAREST-701
|
||||
void rejectsMergingUnknownDomainObject() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
||||
|
||||
reader.readPut(node, "", mapper);
|
||||
assertThatExceptionOfType(JsonMappingException.class) //
|
||||
.isThrownBy(() -> reader.readPut(node, "", mapper));
|
||||
}
|
||||
|
||||
@Test // DATAREST-705
|
||||
public void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
|
||||
void doesNotWipeIdAndVersionPropertyForPut() throws Exception {
|
||||
|
||||
VersionedType type = new VersionedType();
|
||||
type.id = 1L;
|
||||
@@ -201,7 +202,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1006
|
||||
public void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {
|
||||
void doesNotWipeReadOnlyJsonPropertyForPut() throws Exception {
|
||||
|
||||
SampleUser sampleUser = new SampleUser("name", "password");
|
||||
sampleUser.lastLogin = new Date();
|
||||
@@ -217,7 +218,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-873
|
||||
public void doesNotApplyInputToReadOnlyFields() throws Exception {
|
||||
void doesNotApplyInputToReadOnlyFields() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode node = (ObjectNode) mapper.readTree("{}");
|
||||
@@ -231,7 +232,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-931
|
||||
public void readsPatchForEntityNestedInCollection() throws Exception {
|
||||
void readsPatchForEntityNestedInCollection() throws Exception {
|
||||
|
||||
Phone phone = new Phone();
|
||||
phone.creationDate = new GregorianCalendar();
|
||||
@@ -249,7 +250,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
@Test // DATAREST-919
|
||||
@SuppressWarnings("unchecked")
|
||||
public void readsComplexNestedMapsAndArrays() throws Exception {
|
||||
void readsComplexNestedMapsAndArrays() throws Exception {
|
||||
|
||||
Map<String, Object> childMap = new HashMap<String, Object>();
|
||||
childMap.put("child1", "ok");
|
||||
@@ -286,7 +287,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-938
|
||||
public void nestedEntitiesAreUpdated() throws Exception {
|
||||
void nestedEntitiesAreUpdated() throws Exception {
|
||||
|
||||
Inner inner = new Inner();
|
||||
inner.name = "inner name";
|
||||
@@ -309,7 +310,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-937
|
||||
public void considersTransientProperties() throws Exception {
|
||||
void considersTransientProperties() throws Exception {
|
||||
|
||||
SampleWithTransient sample = new SampleWithTransient();
|
||||
sample.name = "name";
|
||||
@@ -324,7 +325,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-953
|
||||
public void writesArrayForPut() throws Exception {
|
||||
void writesArrayForPut() throws Exception {
|
||||
|
||||
Child inner = new Child();
|
||||
inner.items = new ArrayList<Item>();
|
||||
@@ -341,7 +342,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-956
|
||||
public void writesArrayWithAddedItemForPut() throws Exception {
|
||||
void writesArrayWithAddedItemForPut() throws Exception {
|
||||
|
||||
Child inner = new Child();
|
||||
inner.items = new ArrayList<Item>();
|
||||
@@ -362,7 +363,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-956
|
||||
public void writesArrayWithRemovedItemForPut() throws Exception {
|
||||
void writesArrayWithRemovedItemForPut() throws Exception {
|
||||
|
||||
Child inner = new Child();
|
||||
inner.items = new ArrayList<Item>();
|
||||
@@ -382,7 +383,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-959
|
||||
public void addsElementToPreviouslyEmptyCollection() throws Exception {
|
||||
void addsElementToPreviouslyEmptyCollection() throws Exception {
|
||||
|
||||
Parent source = new Parent();
|
||||
source.inner = new Child();
|
||||
@@ -398,7 +399,7 @@ public class DomainObjectReaderUnitTests {
|
||||
|
||||
@Test // DATAREST-959
|
||||
@SuppressWarnings("unchecked")
|
||||
public void turnsObjectIntoCollection() throws Exception {
|
||||
void turnsObjectIntoCollection() throws Exception {
|
||||
|
||||
Parent source = new Parent();
|
||||
source.inner = new Child();
|
||||
@@ -419,7 +420,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-965
|
||||
public void writesObjectWithRemovedItemsForPut() throws Exception {
|
||||
void writesObjectWithRemovedItemsForPut() throws Exception {
|
||||
|
||||
Child inner = new Child();
|
||||
inner.items = new ArrayList<Item>();
|
||||
@@ -438,7 +439,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-965
|
||||
public void writesArrayWithRemovedObjectForPut() throws Exception {
|
||||
void writesArrayWithRemovedObjectForPut() throws Exception {
|
||||
|
||||
Child inner = new Child();
|
||||
inner.object = "value";
|
||||
@@ -456,7 +457,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-986
|
||||
public void readsComplexMap() throws Exception {
|
||||
void readsComplexMap() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = mapper.readTree(
|
||||
@@ -469,7 +470,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-987
|
||||
public void handlesTransientPropertyWithoutFieldProperly() throws Exception {
|
||||
void handlesTransientPropertyWithoutFieldProperly() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode node = mapper.readTree("{ \"name\" : \"Foo\" }");
|
||||
@@ -478,7 +479,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-977
|
||||
public void readsCollectionOfComplexEnum() throws Exception {
|
||||
void readsCollectionOfComplexEnum() throws Exception {
|
||||
|
||||
CollectionOfEnumWithMethods sample = new CollectionOfEnumWithMethods();
|
||||
sample.enums.add(SampleEnum.FIRST);
|
||||
@@ -493,7 +494,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-944
|
||||
public void mergesAssociations() {
|
||||
void mergesAssociations() {
|
||||
|
||||
List<Nested> originalCollection = Arrays.asList(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
|
||||
public void mergesAssociationsAndKeepsMutableCollection() {
|
||||
void mergesAssociationsAndKeepsMutableCollection() {
|
||||
|
||||
ArrayList<Nested> originalCollection = new ArrayList<Nested>(Arrays.asList(new Nested(2, 3)));
|
||||
SampleWithReference source = new SampleWithReference(
|
||||
@@ -520,7 +521,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1030
|
||||
public void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception {
|
||||
void patchWithReferenceToRelatedEntityIsResolvedCorrectly() throws Exception {
|
||||
|
||||
Associations associations = mock(Associations.class);
|
||||
PersistentProperty<?> any = ArgumentMatchers.any(PersistentProperty.class);
|
||||
@@ -549,7 +550,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1249
|
||||
public void mergesIntoUninitializedCollection() throws Exception {
|
||||
void mergesIntoUninitializedCollection() throws Exception {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode source = (ObjectNode) mapper.readTree("{ \"strings\" : [ \"value\" ] }");
|
||||
@@ -560,7 +561,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1383
|
||||
public void doesNotWipeReadOnlyPropertyForPatch() throws Exception {
|
||||
void doesNotWipeReadOnlyPropertyForPatch() throws Exception {
|
||||
|
||||
SampleUser user = new SampleUser("name", "password");
|
||||
user.lastLogin = new Date();
|
||||
@@ -577,7 +578,7 @@ public class DomainObjectReaderUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1068
|
||||
public void arraysCanBeResizedDuringMerge() throws Exception {
|
||||
void arraysCanBeResizedDuringMerge() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ArrayHolder target = new ArrayHolder(new String[] {});
|
||||
JsonNode node = mapper.readTree("{ \"array\" : [ \"new\" ] }");
|
||||
@@ -724,7 +725,7 @@ public class DomainObjectReaderUnitTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setName(String name) {}
|
||||
void setName(String name) {}
|
||||
}
|
||||
|
||||
// DATAREST-977
|
||||
|
||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||
@@ -30,13 +30,13 @@ import org.springframework.hateoas.mediatype.MessageResolver;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class EnumTranslatorUnitTests {
|
||||
class EnumTranslatorUnitTests {
|
||||
|
||||
StaticMessageSource messageSource;
|
||||
EnumTranslator configuration;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
LocaleContextHolder.setLocale(Locale.US);
|
||||
|
||||
@@ -46,28 +46,30 @@ public class EnumTranslatorUnitTests {
|
||||
this.configuration = new EnumTranslator(MessageResolver.of(messageSource));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-654
|
||||
public void rejectsNullMessageSourceAccessor() {
|
||||
new EnumTranslator(null);
|
||||
@Test // DATAREST-654
|
||||
void rejectsNullMessageSourceAccessor() {
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new EnumTranslator(null));
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForNullSource() {
|
||||
void parsesNullForNullSource() {
|
||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForEmptySource() {
|
||||
void parsesNullForEmptySource() {
|
||||
assertThat(configuration.fromText(MyEnum.class, null)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesNullForUnknownValue() {
|
||||
void parsesNullForUnknownValue() {
|
||||
assertThat(configuration.fromText(MyEnum.class, "Foobar")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void returnsEnumNameIfDefaultTranslationIsDisabled() {
|
||||
void returnsEnumNameIfDefaultTranslationIsDisabled() {
|
||||
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
@@ -75,13 +77,13 @@ public class EnumTranslatorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void returnsDefaultTranslationByDefault() {
|
||||
void returnsDefaultTranslationByDefault() {
|
||||
|
||||
assertThat(configuration.asText(MyEnum.SECOND_VALUE)).isEqualTo("Second value");
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesEnumNameIfDefaultTranslationIsDisabled() {
|
||||
void parsesEnumNameIfDefaultTranslationIsDisabled() {
|
||||
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
@@ -89,14 +91,14 @@ public class EnumTranslatorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesStandardTranslationAndEnumNameByDefault() {
|
||||
void parsesStandardTranslationAndEnumNameByDefault() {
|
||||
|
||||
assertThat(configuration.fromText(MyEnum.class, "FIRST_VALUE")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
assertThat(configuration.fromText(MyEnum.class, "Second value")).isEqualTo(MyEnum.SECOND_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void translatesEnumName() {
|
||||
void translatesEnumName() {
|
||||
|
||||
LocaleContextHolder.setLocale(Locale.US);
|
||||
|
||||
@@ -107,7 +109,7 @@ public class EnumTranslatorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesEnumNameByDefaultEvenIfMessageDefined() {
|
||||
void parsesEnumNameByDefaultEvenIfMessageDefined() {
|
||||
|
||||
// Parses resolved message and enum name
|
||||
assertThat(configuration.fromText(MyEnum.class, "Translated")).isEqualTo(MyEnum.FIRST_VALUE);
|
||||
@@ -122,7 +124,7 @@ public class EnumTranslatorUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-654
|
||||
public void parsesEnumWithDefaultTranslationDisabled() {
|
||||
void parsesEnumWithDefaultTranslationDisabled() {
|
||||
|
||||
configuration.setEnableDefaultTranslation(false);
|
||||
|
||||
@@ -132,7 +134,7 @@ public class EnumTranslatorUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotResolveEnumNameAsFallbackIfConfigured() {
|
||||
void doesNotResolveEnumNameAsFallbackIfConfigured() {
|
||||
|
||||
configuration.setParseEnumNameAsFallback(false);
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@@ -42,13 +42,13 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack Four Sided Cube - Bad Day's Remembrance (Bunch of Sides)
|
||||
*/
|
||||
public class JacksonMetadataUnitTests {
|
||||
class JacksonMetadataUnitTests {
|
||||
|
||||
MappingContext<?, ?> context;
|
||||
ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
this.context = new KeyValueMappingContext<>();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class JacksonMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-644
|
||||
public void detectsReadOnlyProperty() {
|
||||
void detectsReadOnlyProperty() {
|
||||
|
||||
JacksonMetadata metadata = new JacksonMetadata(mapper, User.class);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JacksonMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-644
|
||||
public void reportsConstructorArgumentAsJacksonWritable() {
|
||||
void reportsConstructorArgumentAsJacksonWritable() {
|
||||
|
||||
JacksonMetadata metadata = new JacksonMetadata(mapper, Value.class);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JacksonMetadataUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-644
|
||||
public void detectsCustomSerializerFortType() {
|
||||
void detectsCustomSerializerFortType() {
|
||||
|
||||
JsonSerializer<?> serializer = new JacksonMetadata(new ObjectMapper(), SomeBean.class)
|
||||
.getTypeSerializer(SomeBean.class);
|
||||
|
||||
@@ -21,9 +21,8 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.webmvc.json.JacksonSerializersUnitTests.Sample.SampleEnum;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -34,12 +33,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Oliver Gierke
|
||||
* @soundtrack James Bay - Move Together (Chaos And The Calm)
|
||||
*/
|
||||
public class JacksonSerializersUnitTests {
|
||||
class JacksonSerializersUnitTests {
|
||||
|
||||
ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
EnumTranslator translator = mock(EnumTranslator.class);
|
||||
doReturn(SampleEnum.VALUE).when(translator).fromText(SampleEnum.class, "value");
|
||||
@@ -49,7 +48,7 @@ public class JacksonSerializersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
public void translatesPlainEnumCorrectly() throws Exception {
|
||||
void translatesPlainEnumCorrectly() throws Exception {
|
||||
|
||||
Sample result = mapper.readValue("{ \"property\" : \"value\"}", Sample.class);
|
||||
|
||||
@@ -57,7 +56,7 @@ public class JacksonSerializersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
public void translatesCollectionOfEnumsCorrectly() throws Exception {
|
||||
void translatesCollectionOfEnumsCorrectly() throws Exception {
|
||||
|
||||
Sample result = mapper.readValue("{ \"collection\" : [ \"value\" ] }", Sample.class);
|
||||
|
||||
@@ -65,7 +64,7 @@ public class JacksonSerializersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
public void translatesEnumArraysCorrectly() throws Exception {
|
||||
void translatesEnumArraysCorrectly() throws Exception {
|
||||
|
||||
Sample result = mapper.readValue("{ \"array\" : [ \"value\" ] }", Sample.class);
|
||||
|
||||
@@ -73,7 +72,7 @@ public class JacksonSerializersUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-929
|
||||
public void translatesMapEnumValueCorrectly() throws Exception {
|
||||
void translatesMapEnumValueCorrectly() throws Exception {
|
||||
|
||||
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 org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.rest.webmvc.json.JsonSchema.JsonSchemaProperty;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -27,12 +27,12 @@ import org.springframework.data.util.TypeInformation;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class JsonSchemaUnitTests {
|
||||
class JsonSchemaUnitTests {
|
||||
|
||||
static final TypeInformation<?> type = ClassTypeInformation.from(Sample.class);
|
||||
|
||||
@Test // DATAREST-492
|
||||
public void considersNumberPrimitivesJsonSchemaNumbers() {
|
||||
void considersNumberPrimitivesJsonSchemaNumbers() {
|
||||
|
||||
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 org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
@@ -34,7 +34,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class MappedPropertiesUnitTests {
|
||||
class MappedPropertiesUnitTests {
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
KeyValueMappingContext<?, ?> context = new KeyValueMappingContext<>();
|
||||
@@ -42,28 +42,28 @@ public class MappedPropertiesUnitTests {
|
||||
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
||||
void doesNotExposeMappedPropertyForNonSpringDataPersistentProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedBySpringData")).isFalse();
|
||||
assertThat(properties.getPersistentProperty("notExposedBySpringData")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void doesNotExposeMappedPropertyForNonJacksonProperty() {
|
||||
void doesNotExposeMappedPropertyForNonJacksonProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("notExposedByJackson")).isFalse();
|
||||
assertThat(properties.getPersistentProperty("notExposedByJackson")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void exposesProperty() {
|
||||
void exposesProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("exposedProperty")).isTrue();
|
||||
assertThat(properties.getPersistentProperty("exposedProperty")).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-575
|
||||
public void exposesRenamedPropertyByExternalName() {
|
||||
void exposesRenamedPropertyByExternalName() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("email")).isTrue();
|
||||
assertThat(properties.getPersistentProperty("email")).isNotNull();
|
||||
@@ -71,14 +71,14 @@ public class MappedPropertiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1006
|
||||
public void doesNotExposeIgnoredPropertyViaJsonProperty() {
|
||||
void doesNotExposeIgnoredPropertyViaJsonProperty() {
|
||||
|
||||
assertThat(properties.hasPersistentPropertyForField("readOnlyProperty")).isFalse();
|
||||
assertThat(properties.getPersistentProperty("readOnlyProperty")).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAREST-1248
|
||||
public void doesNotExcludeReadOnlyPropertiesForSerialization() {
|
||||
void doesNotExcludeReadOnlyPropertiesForSerialization() {
|
||||
|
||||
MappedProperties properties = MappedProperties.forSerialization(entity, mapper);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class MappedPropertiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1383
|
||||
public void doesNotRegardReadOnlyPropertyForDeserialization() {
|
||||
void doesNotRegardReadOnlyPropertyForDeserialization() {
|
||||
|
||||
MappedProperties properties = MappedProperties.forDeserialization(entity, mapper);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class MappedPropertiesUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATAREST-1440
|
||||
public void exposesExistanceOfCatchAllMethod() {
|
||||
void exposesExistanceOfCatchAllMethod() {
|
||||
|
||||
PersistentEntity<?, ?> entity = context.getRequiredPersistentEntity(SampleWithJsonAnySetter.class);
|
||||
|
||||
@@ -132,6 +132,6 @@ public class MappedPropertiesUnitTests {
|
||||
public @ReadOnlyProperty String anotherReadOnlyProperty;
|
||||
|
||||
@JsonAnySetter
|
||||
public void set(String key, String value) {}
|
||||
void set(String key, String value) {}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user