DATACMNS-525 - Polishing.
Extracted KeySpaceUtils from KeyValueTemplate and pulled in the copy of MetaAnnotationUtils to hide it from the outside. Separated related test cases into dedicated test class. Renamed BasicMappingContext to KeyValueMappingContext and BasicPersistentProperty to KeyValuePersistentProperty. Fixed spelling in SpelQueryCreatorUnitTests. Moved MappingContext into separate package to satisfy architectural guidelines. Created dedicated KeyValueRepositoryNamespaceHandler to avoid a circular reference between commons and the key-value subsystem. Made the query creator type an annotation on @EnableKeyValueRepositories so that it's not exposed to the user to be configured. Added the necessary ImportBeanDefinitionRegistrars to the Hazelcast and EhCache implementation. Removed @since tags from those modules at they're not going to make it into Spring Data Commons. Renamed EnableEhCacheRepsotoriesUnitTests to EnableEhCacheRepositoriesIntegrationTests as well as the same for the Hazelcast specific test. The KeyValueRepositoryConfigurationExtension now explicitly registers a KeyValueMappingContext unless one is already registered. AnnotationRepositoryConfigurationSource now explicitly exposes an AnnotationMetadata instance for the annotation that triggered the configuration. Turned SpelCriteriaAccessor and SpelPropertyComparator into classes to be able to pass them a SpelExpressionParser to be able to get rid of SpelExpressionFactory eventually. Made both classes as well as SpelQueryEngine package protected for now. Moved repository implementations into support package. Updated architcture description JavaDoc polish, spacing, blank lines. Added TODOs. Original pull request: #95.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.keyvalue.core.KeySpaceUtils.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
import org.springframework.data.keyvalue.core.KeyValueTemplateUnitTests.AliasedEntity;
|
||||
import org.springframework.data.keyvalue.core.KeyValueTemplateUnitTests.ClassWithDirectKeySpaceAnnotation;
|
||||
import org.springframework.data.keyvalue.core.KeyValueTemplateUnitTests.EntityWithPersistentAnnotation;
|
||||
import org.springframework.data.keyvalue.core.KeyValueTemplateUnitTests.Foo;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link KeySpaceUtils}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class KeySpaceUtilsUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveKeySpaceDefaultValueCorrectly() {
|
||||
assertThat(getKeySpace(EntityWithDefaultKeySpace.class), is((Object) "daenerys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveKeySpaceCorrectly() {
|
||||
assertThat(getKeySpace(EntityWithSetKeySpace.class), is((Object) "viserys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenNoKeySpaceFoundOnComposedPersistentAnnotation() {
|
||||
assertThat(getKeySpace(AliasedEntity.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenPersistentIsFoundOnNonComposedAnnotation() {
|
||||
assertThat(getKeySpace(EntityWithPersistentAnnotation.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenPersistentIsNotFound() {
|
||||
assertThat(getKeySpace(Foo.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveInheritedKeySpaceCorrectly() {
|
||||
assertThat(getKeySpace(EntityWithInheritedKeySpace.class), is((Object) "viserys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveDirectKeySpaceAnnotationCorrectly() {
|
||||
assertThat(getKeySpace(ClassWithDirectKeySpaceAnnotation.class), is((Object) "rhaegar"));
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace
|
||||
static class EntityWithDefaultKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
|
||||
static class EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
static @interface PersistentAnnotationWithExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
String firstname() default "daenerys";
|
||||
|
||||
String lastnamne() default "targaryen";
|
||||
}
|
||||
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
static @interface ExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
String name() default "";
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import static org.hamcrest.core.IsSame.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -44,19 +43,19 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class KeyValueTemplateTests {
|
||||
|
||||
private static final Foo FOO_ONE = new Foo("one");
|
||||
private static final Foo FOO_TWO = new Foo("two");
|
||||
private static final Foo FOO_THREE = new Foo("three");
|
||||
private static final Bar BAR_ONE = new Bar("one");
|
||||
private static final ClassWithTypeAlias ALIASED = new ClassWithTypeAlias("super");
|
||||
private static final SubclassOfAliasedType SUBCLASS_OF_ALIASED = new SubclassOfAliasedType("sub");
|
||||
static final Foo FOO_ONE = new Foo("one");
|
||||
static final Foo FOO_TWO = new Foo("two");
|
||||
static final Foo FOO_THREE = new Foo("three");
|
||||
static final Bar BAR_ONE = new Bar("one");
|
||||
static final ClassWithTypeAlias ALIASED = new ClassWithTypeAlias("super");
|
||||
static final SubclassOfAliasedType SUBCLASS_OF_ALIASED = new SubclassOfAliasedType("sub");
|
||||
static final KeyValueQuery<String> STRING_QUERY = new KeyValueQuery<String>("foo == 'two'");
|
||||
|
||||
private static final KeyValueQuery<String> STRING_QUERY = new KeyValueQuery<String>("foo == 'two'");
|
||||
|
||||
private KeyValueTemplate operations;
|
||||
KeyValueTemplate operations;
|
||||
|
||||
@Before
|
||||
public void setUp() throws InstantiationException, IllegalAccessException {
|
||||
@@ -252,7 +251,7 @@ public class KeyValueTemplateTests {
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void deleteThrowsExceptionWhenIdCannotBeExctracted() {
|
||||
operations.delete(FOO_ONE);
|
||||
}
|
||||
@@ -455,11 +454,10 @@ public class KeyValueTemplateTests {
|
||||
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
private static @interface ExplicitKeySpace {
|
||||
static @interface ExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
String name() default "";
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -30,14 +29,12 @@ import java.lang.annotation.Target;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hamcrest.core.Is;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
@@ -146,7 +143,7 @@ public class KeyValueTemplateUnitTests {
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test(expected = DataAccessException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void insertShouldThrowErrorWhenIdCannotBeResolved() {
|
||||
template.insert(FOO_ONE);
|
||||
}
|
||||
@@ -328,7 +325,7 @@ public class KeyValueTemplateUnitTests {
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test(expected = DataAccessException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void deleteThrowsExceptionWhenIdCannotBeExctracted() {
|
||||
template.delete(FOO_ONE);
|
||||
}
|
||||
@@ -407,62 +404,6 @@ public class KeyValueTemplateUnitTests {
|
||||
assertThat(template.findById("1", SUBCLASS_OF_ALIASED.getClass()), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveKeySpaceDefaultValueCorrectly() {
|
||||
assertThat(template.getKeySpace(EntityWithDefaultKeySpace.class), Is.<Object> is("daenerys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveKeySpaceCorrectly() {
|
||||
assertThat(template.getKeySpace(EntityWithSetKeySpace.class), Is.<Object> is("viserys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenNoKeySpaceFoundOnComposedPersistentAnnotation() {
|
||||
assertThat(template.getKeySpace(AliasedEntity.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenPersistentIsFoundOnNonComposedAnnotation() {
|
||||
assertThat(template.getKeySpace(EntityWithPersistentAnnotation.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnNullWhenPersistentIsNotFound() {
|
||||
assertThat(template.getKeySpace(Foo.class), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveInheritedKeySpaceCorrectly() {
|
||||
assertThat(template.getKeySpace(EntityWithInheritedKeySpace.class), Is.<Object> is("viserys"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
*/
|
||||
@Test
|
||||
public void shouldResolveDirectKeySpaceAnnotationCorrectly() {
|
||||
assertThat(template.getKeySpace(ClassWithDirectKeySpaceAnnotation.class), Is.<Object> is("rhaegar"));
|
||||
}
|
||||
|
||||
static class Foo {
|
||||
|
||||
String foo;
|
||||
@@ -639,20 +580,6 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace
|
||||
private static class EntityWithDefaultKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpace(firstname = "viserys")
|
||||
private static class EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
private static class EntityWithInheritedKeySpace extends EntityWithSetKeySpace {
|
||||
|
||||
}
|
||||
|
||||
@TypeAlias("foo")
|
||||
static class AliasedEntity {
|
||||
|
||||
@@ -663,19 +590,6 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
private static @interface PersistentAnnotationWithExplicitKeySpace {
|
||||
|
||||
@KeySpace
|
||||
String firstname() default "daenerys";
|
||||
|
||||
String lastnamne() default "targaryen";
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Persistent
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE })
|
||||
@@ -683,6 +597,5 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
@KeySpace
|
||||
String name() default "";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,26 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static java.lang.Integer.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.number.OrderingComparison.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SpelPropertyComparator}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SpelPropertyComperatorUnitTests {
|
||||
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final SomeType ONE = new SomeType("one", Integer.valueOf(1), 1);
|
||||
private static final SomeType TWO = new SomeType("two", Integer.valueOf(2), 2);
|
||||
private static final WrapperType WRAPPER_ONE = new WrapperType("w-one", ONE);
|
||||
@@ -38,8 +46,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareStringAscCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("stringProperty").compare(ONE, TWO), is(ONE.getStringProperty()
|
||||
.compareTo(TWO.getStringProperty())));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO), is(ONE.getStringProperty().compareTo(TWO.getStringProperty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,8 +56,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareStringDescCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("stringProperty").desc().compare(ONE, TWO), is(TWO
|
||||
.getStringProperty().compareTo(ONE.getStringProperty())));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO), is(TWO.getStringProperty().compareTo(ONE.getStringProperty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,8 +66,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareIntegerAscCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("integerProperty").compare(ONE, TWO), is(ONE.getIntegerProperty()
|
||||
.compareTo(TWO.getIntegerProperty())));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("integerProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO), is(ONE.getIntegerProperty().compareTo(TWO.getIntegerProperty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,8 +76,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareIntegerDescCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("integerProperty").desc().compare(ONE, TWO), is(TWO
|
||||
.getIntegerProperty().compareTo(ONE.getIntegerProperty())));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("integerProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO), is(TWO.getIntegerProperty().compareTo(ONE.getIntegerProperty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +86,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldComparePrimitiveIntegerAscCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("primitiveProperty").compare(ONE, TWO),
|
||||
is(Integer.valueOf(ONE.getPrimitiveProperty()).compareTo(Integer.valueOf(TWO.getPrimitiveProperty()))));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("primitiveProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO),
|
||||
is(valueOf(ONE.getPrimitiveProperty()).compareTo(valueOf(TWO.getPrimitiveProperty()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +96,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotFailOnNullValues() {
|
||||
new SpelPropertyComperator<SomeType>("stringProperty").compare(ONE, new SomeType(null, null, 2));
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), is(1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +107,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldComparePrimitiveIntegerDescCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<SomeType>("primitiveProperty").desc().compare(ONE, TWO),
|
||||
is(Integer.valueOf(TWO.getPrimitiveProperty()).compareTo(Integer.valueOf(ONE.getPrimitiveProperty()))));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("primitiveProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO),
|
||||
is(valueOf(TWO.getPrimitiveProperty()).compareTo(valueOf(ONE.getPrimitiveProperty()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,9 +117,8 @@ public class SpelPropertyComperatorUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSortNullsFirstCorrectly() {
|
||||
assertThat(
|
||||
new SpelPropertyComperator<SomeType>("stringProperty").nullsFirst().compare(ONE, new SomeType(null, null, 2)),
|
||||
equalTo(1));
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).nullsFirst();
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), equalTo(1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,9 +126,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
*/
|
||||
@Test
|
||||
public void shouldSortNullsLastCorrectly() {
|
||||
assertThat(
|
||||
new SpelPropertyComperator<SomeType>("stringProperty").nullsLast().compare(ONE, new SomeType(null, null, 2)),
|
||||
equalTo(-1));
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).nullsLast();
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), equalTo(-1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +137,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareNestedTypesCorrectly() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<WrapperType>("nestedType.stringProperty").compare(WRAPPER_ONE, WRAPPER_TWO),
|
||||
is(WRAPPER_ONE.getNestedType().getStringProperty().compareTo(WRAPPER_TWO.getNestedType().getStringProperty())));
|
||||
Comparator<WrapperType> comparator = new SpelPropertyComparator<WrapperType>("nestedType.stringProperty", PARSER);
|
||||
assertThat(comparator.compare(WRAPPER_ONE, WRAPPER_TWO), is(WRAPPER_ONE.getNestedType().getStringProperty()
|
||||
.compareTo(WRAPPER_TWO.getNestedType().getStringProperty())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,8 +148,9 @@ public class SpelPropertyComperatorUnitTests {
|
||||
@Test
|
||||
public void shouldCompareNestedTypesCorrectlyWhenOneOfThemHasNullValue() {
|
||||
|
||||
assertThat(new SpelPropertyComperator<WrapperType>("nestedType.stringProperty").compare(WRAPPER_ONE,
|
||||
new WrapperType("two", null)), is(greaterThanOrEqualTo(1)));
|
||||
SpelPropertyComparator<WrapperType> comparator = new SpelPropertyComparator<WrapperType>(
|
||||
"nestedType.stringProperty", PARSER);
|
||||
assertThat(comparator.compare(WRAPPER_ONE, new WrapperType("two", null)), is(greaterThanOrEqualTo(1)));
|
||||
}
|
||||
|
||||
static class WrapperType {
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class EnableEhCacheRepositoriesUnitTests {
|
||||
public class EnableEhCacheRepositoriesIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableEhCacheRepositories(considerNestedRepositories = true)
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class EnableHazelcastRepositoriesUnitTests {
|
||||
public class EnableHazelcastRepositoriesIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableHazelcastRepositories(considerNestedRepositories = true)
|
||||
@@ -33,7 +33,7 @@ import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class QueryDslMapRepositoryUnitTests extends MapBackedKeyValueRepositoryUnitTests {
|
||||
public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.data.repository.CrudRepository;
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class MapBackedKeyValueRepositoryUnitTests {
|
||||
public class SimpleKeyValueRepositoryUnitTests {
|
||||
|
||||
protected static final Person CERSEI = new Person("cersei", 19);
|
||||
protected static final Person JAIME = new Person("jaime", 19);
|
||||
@@ -28,6 +28,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository;
|
||||
import org.springframework.data.repository.core.support.ReflectionEntityInformation;
|
||||
|
||||
/**
|
||||
@@ -36,14 +37,14 @@ import org.springframework.data.repository.core.support.ReflectionEntityInformat
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BasicKeyValueRepositoryUnitTests {
|
||||
|
||||
private BasicKeyValueRepository<Foo, String> repo;
|
||||
private SimpleKeyValueRepository<Foo, String> repo;
|
||||
private @Mock KeyValueOperations opsMock;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
ReflectionEntityInformation<Foo, String> ei = new ReflectionEntityInformation<Foo, String>(Foo.class);
|
||||
repo = new BasicKeyValueRepository<Foo, String>(ei, opsMock);
|
||||
repo = new SimpleKeyValueRepository<Foo, String>(ei, opsMock);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public class BasicKeyValueRepositoryUnitTests {
|
||||
|
||||
ReflectionEntityInformation<WithNumericId, Integer> ei = new ReflectionEntityInformation<WithNumericId, Integer>(
|
||||
WithNumericId.class);
|
||||
BasicKeyValueRepository<WithNumericId, Integer> temp = new BasicKeyValueRepository<WithNumericId, Integer>(ei,
|
||||
SimpleKeyValueRepository<WithNumericId, Integer> temp = new SimpleKeyValueRepository<WithNumericId, Integer>(ei,
|
||||
opsMock);
|
||||
|
||||
WithNumericId foo = temp.save(new WithNumericId());
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class KeyValueRepositoryRegistrarUnitTests {
|
||||
public class KeyValueRepositoryRegistrarIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableKeyValueRepositories(considerNestedRepositories = true)
|
||||
@@ -42,21 +42,21 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpELQueryCreatorUnitTests {
|
||||
public class SpelQueryCreatorUnitTests {
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
|
||||
static final DateTimeFormatter FORMATTER = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
|
||||
|
||||
private static final Person RICKON = new Person("rickon", 4);
|
||||
private static final Person BRAN = new Person("bran", 9)//
|
||||
static final Person RICKON = new Person("rickon", 4);
|
||||
static final Person BRAN = new Person("bran", 9)//
|
||||
.skinChanger(true)//
|
||||
.bornAt(FORMATTER.parseDateTime("2013-01-31T06:00:00Z").toDate());
|
||||
private static final Person ARYA = new Person("arya", 13);
|
||||
private static final Person ROBB = new Person("robb", 16)//
|
||||
static final Person ARYA = new Person("arya", 13);
|
||||
static final Person ROBB = new Person("robb", 16)//
|
||||
.named("stark")//
|
||||
.bornAt(FORMATTER.parseDateTime("2010-09-20T06:00:00Z").toDate());
|
||||
private static final Person JON = new Person("jon", 17).named("snow");
|
||||
static final Person JON = new Person("jon", 17).named("snow");
|
||||
|
||||
private @Mock RepositoryMetadata metadataMock;
|
||||
@Mock RepositoryMetadata metadataMock;
|
||||
|
||||
/**
|
||||
* @see DATACMNS-525
|
||||
@@ -378,7 +378,7 @@ public class SpELQueryCreatorUnitTests {
|
||||
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(ROBB), is(false));
|
||||
}
|
||||
|
||||
Evaluation evaluate(String methodName, Object... args) throws Exception {
|
||||
private Evaluation evaluate(String methodName, Object... args) throws Exception {
|
||||
return new Evaluation((SpelExpression) createQueryForMethodWithArgs(methodName, args).getCritieria());
|
||||
}
|
||||
|
||||
@@ -391,8 +391,8 @@ public class SpELQueryCreatorUnitTests {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
argTypes[i] = args[i].getClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Method method = PersonRepository.class.getMethod(methodName, argTypes);
|
||||
|
||||
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
|
||||
@@ -401,6 +401,7 @@ public class SpELQueryCreatorUnitTests {
|
||||
|
||||
KeyValueQuery<SpelExpression> q = creator.createQuery();
|
||||
q.getCritieria().setEvaluationContext(new StandardEvaluationContext(args));
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
@@ -561,7 +562,5 @@ public class SpELQueryCreatorUnitTests {
|
||||
this.birthday = date;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user