@@ -21,9 +21,8 @@ import java.util.Date;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
@@ -35,13 +34,13 @@ class DefaultIdentifierGeneratorUnitTests {
|
|||||||
@Test
|
@Test
|
||||||
void shouldThrowExceptionForUnsupportedType() {
|
void shouldThrowExceptionForUnsupportedType() {
|
||||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||||
.isThrownBy(() -> generator.generateIdentifierOfType(ClassTypeInformation.from(Date.class)));
|
.isThrownBy(() -> generator.generateIdentifierOfType(TypeInformation.of(Date.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAKV-136
|
@Test // DATAKV-136
|
||||||
void shouldGenerateUUIDValueCorrectly() {
|
void shouldGenerateUUIDValueCorrectly() {
|
||||||
|
|
||||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(UUID.class));
|
Object value = generator.generateIdentifierOfType(TypeInformation.of(UUID.class));
|
||||||
|
|
||||||
assertThat(value).isNotNull().isInstanceOf(UUID.class);
|
assertThat(value).isNotNull().isInstanceOf(UUID.class);
|
||||||
}
|
}
|
||||||
@@ -49,7 +48,7 @@ class DefaultIdentifierGeneratorUnitTests {
|
|||||||
@Test // DATAKV-136
|
@Test // DATAKV-136
|
||||||
void shouldGenerateStringValueCorrectly() {
|
void shouldGenerateStringValueCorrectly() {
|
||||||
|
|
||||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(String.class));
|
Object value = generator.generateIdentifierOfType(TypeInformation.of(String.class));
|
||||||
|
|
||||||
assertThat(value).isNotNull().isInstanceOf(String.class);
|
assertThat(value).isNotNull().isInstanceOf(String.class);
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,7 @@ class DefaultIdentifierGeneratorUnitTests {
|
|||||||
@Test // DATAKV-136
|
@Test // DATAKV-136
|
||||||
void shouldGenerateLongValueCorrectly() {
|
void shouldGenerateLongValueCorrectly() {
|
||||||
|
|
||||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Long.class));
|
Object value = generator.generateIdentifierOfType(TypeInformation.of(Long.class));
|
||||||
|
|
||||||
assertThat(value).isNotNull().isInstanceOf(Long.class);
|
assertThat(value).isNotNull().isInstanceOf(Long.class);
|
||||||
}
|
}
|
||||||
@@ -65,7 +64,7 @@ class DefaultIdentifierGeneratorUnitTests {
|
|||||||
@Test // DATAKV-136
|
@Test // DATAKV-136
|
||||||
void shouldGenerateIntValueCorrectly() {
|
void shouldGenerateIntValueCorrectly() {
|
||||||
|
|
||||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Integer.class));
|
Object value = generator.generateIdentifierOfType(TypeInformation.of(Integer.class));
|
||||||
|
|
||||||
assertThat(value).isNotNull().isInstanceOf(Integer.class);
|
assertThat(value).isNotNull().isInstanceOf(Integer.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.springframework.data.projection.ProjectionFactory;
|
|||||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||||
import org.springframework.data.repository.query.QueryMethod;
|
import org.springframework.data.repository.query.QueryMethod;
|
||||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,8 +55,7 @@ class KeyValuePartTreeQueryUnitTests {
|
|||||||
|
|
||||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||||
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
||||||
when(metadataMock.getReturnType(any(Method.class)))
|
when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(List.class));
|
||||||
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
|
|
||||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
||||||
|
|
||||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock,
|
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock,
|
||||||
@@ -80,8 +78,7 @@ class KeyValuePartTreeQueryUnitTests {
|
|||||||
|
|
||||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||||
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
||||||
when(metadataMock.getReturnType(any(Method.class)))
|
when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(List.class));
|
||||||
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
|
|
||||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
||||||
|
|
||||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findBy", Pageable.class), metadataMock,
|
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findBy", Pageable.class), metadataMock,
|
||||||
@@ -102,8 +99,7 @@ class KeyValuePartTreeQueryUnitTests {
|
|||||||
|
|
||||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||||
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
||||||
when(metadataMock.getReturnType(any(Method.class)))
|
when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(List.class));
|
||||||
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
|
|
||||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
||||||
|
|
||||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3By"), metadataMock, projectionFactoryMock);
|
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3By"), metadataMock, projectionFactoryMock);
|
||||||
@@ -122,8 +118,7 @@ class KeyValuePartTreeQueryUnitTests {
|
|||||||
|
|
||||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||||
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
||||||
when(metadataMock.getReturnType(any(Method.class)))
|
when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(List.class));
|
||||||
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
|
|
||||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
|
||||||
|
|
||||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3ByFirstname", String.class), metadataMock,
|
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3ByFirstname", String.class), metadataMock,
|
||||||
@@ -145,8 +140,7 @@ class KeyValuePartTreeQueryUnitTests {
|
|||||||
|
|
||||||
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
|
||||||
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
|
||||||
when(metadataMock.getReturnType(any(Method.class)))
|
when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(Boolean.class));
|
||||||
.thenReturn((TypeInformation) ClassTypeInformation.from(Boolean.class));
|
|
||||||
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);
|
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);
|
||||||
|
|
||||||
QueryMethod qm = new QueryMethod(Repo.class.getMethod("existsByFirstname", String.class), metadataMock,
|
QueryMethod qm = new QueryMethod(Repo.class.getMethod("existsByFirstname", String.class), metadataMock,
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import org.springframework.data.repository.core.RepositoryMetadata;
|
|||||||
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||||
import org.springframework.data.repository.query.QueryMethod;
|
import org.springframework.data.repository.query.QueryMethod;
|
||||||
import org.springframework.data.repository.query.parser.PartTree;
|
import org.springframework.data.repository.query.parser.PartTree;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
|
||||||
import org.springframework.data.util.TypeInformation;
|
import org.springframework.data.util.TypeInformation;
|
||||||
import org.springframework.expression.spel.standard.SpelExpression;
|
import org.springframework.expression.spel.standard.SpelExpression;
|
||||||
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
import org.springframework.expression.spel.support.SimpleEvaluationContext;
|
||||||
@@ -57,12 +56,10 @@ public class SpelQueryCreatorUnitTests {
|
|||||||
|
|
||||||
private static final Person RICKON = new Person("rickon", 4);
|
private static final Person RICKON = new Person("rickon", 4);
|
||||||
private static final Person BRAN = new Person("bran", 9)//
|
private static final Person BRAN = new Person("bran", 9)//
|
||||||
.skinChanger(true)
|
.skinChanger(true).bornAt(Date.from(ZonedDateTime.parse("2013-01-31T06:00:00Z", FORMATTER).toInstant()));
|
||||||
.bornAt(Date.from(ZonedDateTime.parse("2013-01-31T06:00:00Z", FORMATTER).toInstant()));
|
|
||||||
private static final Person ARYA = new Person("arya", 13);
|
private static final Person ARYA = new Person("arya", 13);
|
||||||
private static final Person ROBB = new Person("robb", 16)//
|
private static final Person ROBB = new Person("robb", 16)//
|
||||||
.named("stark")
|
.named("stark").bornAt(Date.from(ZonedDateTime.parse("2010-09-20T06:00:00Z", FORMATTER).toInstant()));
|
||||||
.bornAt(Date.from(ZonedDateTime.parse("2010-09-20T06:00:00Z", FORMATTER).toInstant()));
|
|
||||||
private static final Person JON = new Person("jon", 17).named("snow");
|
private static final Person JON = new Person("jon", 17).named("snow");
|
||||||
|
|
||||||
@Mock RepositoryMetadata metadataMock;
|
@Mock RepositoryMetadata metadataMock;
|
||||||
@@ -339,7 +336,7 @@ public class SpelQueryCreatorUnitTests {
|
|||||||
Method method = PersonRepository.class.getMethod(methodName, argTypes);
|
Method method = PersonRepository.class.getMethod(methodName, argTypes);
|
||||||
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
|
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
|
||||||
doReturn(TypeInformation.of(Person.class)).when(metadataMock).getDomainTypeInformation();
|
doReturn(TypeInformation.of(Person.class)).when(metadataMock).getDomainTypeInformation();
|
||||||
doReturn(ClassTypeInformation.from(Person.class)).when(metadataMock).getReturnType(method);
|
doReturn(TypeInformation.of(Person.class)).when(metadataMock).getReturnType(method);
|
||||||
|
|
||||||
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
|
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
|
||||||
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
|
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
|
||||||
|
|||||||
Reference in New Issue
Block a user