DATAREDIS-605 - Polishing
Some minor code and documentation changes. More interestingly obtain the RedisConverter instead of the KeyValueAdapter for IndexResolver resolution in QueryByExampleRedisExecutor and stick to findOne contract by throwing IncorrectResultSizeDataAccessException for queries returning non unique results. Original Pull Request: #301
This commit is contained in:
@@ -40,6 +40,7 @@ import org.springframework.data.redis.repository.query.RedisOperationChain.PathA
|
||||
* Unit tests for {@link ExampleQueryMapper}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ExampleQueryMapperUnitTests {
|
||||
|
||||
@@ -186,7 +187,7 @@ public class ExampleQueryMapperUnitTests {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Person {
|
||||
static class Person {
|
||||
|
||||
@Id String id;
|
||||
|
||||
@@ -204,7 +205,8 @@ public class ExampleQueryMapperUnitTests {
|
||||
Species species;
|
||||
}
|
||||
|
||||
public enum Gender {
|
||||
enum Gender {
|
||||
|
||||
MALE, FEMALE {
|
||||
|
||||
@Override
|
||||
@@ -214,7 +216,7 @@ public class ExampleQueryMapperUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Species {
|
||||
static class Species {
|
||||
|
||||
@Indexed String name;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Optional;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -48,6 +49,7 @@ import org.springframework.data.redis.repository.core.MappingRedisEntityInformat
|
||||
* Integration tests for {@link QueryByExampleRedisExecutor}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class QueryByExampleRedisExecutorTests {
|
||||
|
||||
@@ -101,6 +103,19 @@ public class QueryByExampleRedisExecutorTests {
|
||||
assertThat(result).contains(walt);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-605
|
||||
public void shouldThrowExceptionWhenFindOneByExampleReturnsNonUniqueResult() {
|
||||
|
||||
QueryByExampleRedisExecutor<Person> executor = new QueryByExampleRedisExecutor<>(getEntityInformation(Person.class),
|
||||
kvTemplate);
|
||||
|
||||
Person person = new Person();
|
||||
person.setHometown(walt.getHometown());
|
||||
|
||||
assertThatThrownBy(() -> executor.findOne(Example.of(person)))
|
||||
.isInstanceOf(IncorrectResultSizeDataAccessException.class);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-605
|
||||
public void shouldNotFindOneByExample() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user