|
|
|
|
@@ -15,10 +15,8 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.springframework.data.mongodb.core.index;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
|
|
|
|
|
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
|
|
|
|
|
|
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
|
@@ -27,11 +25,11 @@ import java.lang.annotation.Target;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.api.Assertions;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Suite;
|
|
|
|
|
import org.junit.runners.Suite.SuiteClasses;
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.annotation.AliasFor;
|
|
|
|
|
import org.springframework.data.annotation.Id;
|
|
|
|
|
import org.springframework.data.geo.Point;
|
|
|
|
|
@@ -53,12 +51,15 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
|
|
|
|
import org.springframework.data.util.ClassTypeInformation;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests for {@link MongoPersistentEntityIndexResolver}.
|
|
|
|
|
*
|
|
|
|
|
* @author Christoph Strobl
|
|
|
|
|
* @author Mark Paluch
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(Suite.class)
|
|
|
|
|
@SuiteClasses({ IndexResolutionTests.class, GeoSpatialIndexResolutionTests.class, CompoundIndexResolutionTests.class,
|
|
|
|
|
TextIndexedResolutionTests.class, MixedIndexResolutionTests.class })
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -75,7 +76,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
IndexOnLevelZero.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("indexedProperty", "Zero", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -84,7 +85,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(IndexOnLevelOne.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("zero.indexedProperty", "One", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -95,7 +96,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
IndexResolver indexResolver = IndexResolver.create(mappingContext);
|
|
|
|
|
Iterable<? extends IndexDefinition> definitions = indexResolver.resolveIndexFor(IndexOnLevelOne.class);
|
|
|
|
|
|
|
|
|
|
assertThat(definitions.iterator().hasNext(), is(true));
|
|
|
|
|
assertThat(definitions).isNotEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-899
|
|
|
|
|
@@ -103,7 +104,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(IndexOnLevelTwo.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("one.zero.indexedProperty", "Two", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -113,7 +114,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
IndexOnLevelOneWithExplicitlyNamedField.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("customZero.customFieldName", "indexOnLevelOneWithExplicitlyNamedField",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
@@ -125,7 +126,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
IndexOnLevelZero.class);
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "indexedProperty")));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).isEqualTo(new org.bson.Document("name", "indexedProperty"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-899
|
|
|
|
|
@@ -135,8 +136,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
WithOptionsOnIndexedProperty.class);
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "indexedProperty")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true).append("expireAfterSeconds", 10L)));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).isEqualTo(new org.bson.Document().append("name", "indexedProperty")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true).append("expireAfterSeconds", 10L));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1297
|
|
|
|
|
@@ -144,9 +145,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(WithDbRef.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection(), equalTo("withDbRef"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys(), equalTo(new org.bson.Document().append("indexedDbRef", 1)));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection()).isEqualTo("withDbRef");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys()).isEqualTo(new org.bson.Document("indexedDbRef", 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1297
|
|
|
|
|
@@ -155,10 +156,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WrapperOfWithDbRef.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection(), equalTo("wrapperOfWithDbRef"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys(),
|
|
|
|
|
equalTo(new org.bson.Document().append("nested.indexedDbRef", 1)));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection()).isEqualTo("wrapperOfWithDbRef");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys()).isEqualTo(new org.bson.Document("nested.indexedDbRef", 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1163
|
|
|
|
|
@@ -167,9 +167,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
IndexOnMetaAnnotatedField.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection(), equalTo("indexOnMetaAnnotatedField"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions(), equalTo(new org.bson.Document().append("name", "_name")));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getCollection()).isEqualTo("indexOnMetaAnnotatedField");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).isEqualTo(new org.bson.Document("name", "_name"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1373
|
|
|
|
|
@@ -178,13 +178,15 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
IndexedDocumentWithComposedAnnotations.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
|
|
|
|
|
IndexDefinitionHolder indexDefinitionHolder = indexDefinitions.get(1);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexKeys(), isBsonObject().containing("fieldWithMyIndexName", 1));
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexOptions(),
|
|
|
|
|
isBsonObject().containing("sparse", true).containing("unique", true).containing("name", "my_index_name"));
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexKeys()).containsEntry("fieldWithMyIndexName", 1);
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexOptions()) //
|
|
|
|
|
.containsEntry("sparse", true) //
|
|
|
|
|
.containsEntry("unique", true) //
|
|
|
|
|
.containsEntry("name", "my_index_name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1373
|
|
|
|
|
@@ -193,13 +195,15 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
IndexedDocumentWithComposedAnnotations.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
|
|
|
|
|
IndexDefinitionHolder indexDefinitionHolder = indexDefinitions.get(0);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexKeys(), isBsonObject().containing("fieldWithDifferentIndexName", 1));
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexOptions(),
|
|
|
|
|
isBsonObject().containing("sparse", true).containing("name", "different_name").notContaining("unique"));
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexKeys()).containsEntry("fieldWithDifferentIndexName", 1);
|
|
|
|
|
assertThat(indexDefinitionHolder.getIndexOptions()) //
|
|
|
|
|
.containsEntry("sparse", true) //
|
|
|
|
|
.containsEntry("name", "different_name") //
|
|
|
|
|
.doesNotContainKey("unique");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -208,7 +212,16 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WithExpireAfterAsPlainString.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 600L);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 600L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
public void shouldResolveTimeoutFromIso8601String() {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WithIso8601Style.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 86400L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -217,7 +230,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WithExpireAfterAsExpression.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 11L);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 11L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -226,7 +239,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WithExpireAfterAsExpressionResultingInDuration.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 100L);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("expireAfterSeconds", 100L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -235,9 +248,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
MongoMappingContext mappingContext = prepareMappingContext(WithInvalidExpireAfter.class);
|
|
|
|
|
MongoPersistentEntityIndexResolver indexResolver = new MongoPersistentEntityIndexResolver(mappingContext);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> indexResolver
|
|
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> indexResolver
|
|
|
|
|
.resolveIndexForEntity(mappingContext.getRequiredPersistentEntity(WithInvalidExpireAfter.class)));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -246,7 +258,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
MongoMappingContext mappingContext = prepareMappingContext(WithDuplicateExpiry.class);
|
|
|
|
|
MongoPersistentEntityIndexResolver indexResolver = new MongoPersistentEntityIndexResolver(mappingContext);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> indexResolver
|
|
|
|
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> indexResolver
|
|
|
|
|
.resolveIndexForEntity(mappingContext.getRequiredPersistentEntity(WithDuplicateExpiry.class)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -256,7 +268,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
WithIndexNameAsExpression.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "my1st");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "my1st");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document("Zero")
|
|
|
|
|
@@ -322,13 +334,13 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target({ ElementType.FIELD })
|
|
|
|
|
@ComposedIndexedAnnotation(indexName = "different_name", beUnique = false)
|
|
|
|
|
static @interface CustomIndexedAnnotation {
|
|
|
|
|
@interface CustomIndexedAnnotation {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
|
|
|
|
|
@Indexed
|
|
|
|
|
static @interface ComposedIndexedAnnotation {
|
|
|
|
|
@interface ComposedIndexedAnnotation {
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = Indexed.class, attribute = "unique")
|
|
|
|
|
boolean beUnique() default true;
|
|
|
|
|
@@ -343,7 +355,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target(ElementType.FIELD)
|
|
|
|
|
@org.springframework.data.mongodb.core.mapping.Field
|
|
|
|
|
static @interface ComposedFieldAnnotation {
|
|
|
|
|
@interface ComposedFieldAnnotation {
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = org.springframework.data.mongodb.core.mapping.Field.class, attribute = "value")
|
|
|
|
|
String name() default "_id";
|
|
|
|
|
@@ -354,6 +366,11 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
@Indexed(expireAfter = "10m") String withTimeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document
|
|
|
|
|
class WithIso8601Style {
|
|
|
|
|
@Indexed(expireAfter = "P1D") String withTimeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document
|
|
|
|
|
static class WithExpireAfterAsExpression {
|
|
|
|
|
@Indexed(expireAfter = "#{10 + 1 + 's'}") String withTimeout;
|
|
|
|
|
@@ -384,7 +401,6 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Indexed
|
|
|
|
|
@interface IndexedFieldAnnotation {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document
|
|
|
|
|
@@ -405,7 +421,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
GeoSpatialIndexOnLevelZero.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("geoIndexedProperty", "Zero", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -415,7 +431,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
GeoSpatialIndexOnLevelOne.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("zero.geoIndexedProperty", "One", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -425,7 +441,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
GeoSpatialIndexOnLevelTwo.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("one.zero.geoIndexedProperty", "Two", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -437,8 +453,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(), equalTo(
|
|
|
|
|
new org.bson.Document().append("name", "location").append("min", 1).append("max", 100).append("bits", 2)));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).isEqualTo(
|
|
|
|
|
new org.bson.Document().append("name", "location").append("min", 1).append("max", 100).append("bits", 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1373
|
|
|
|
|
@@ -449,10 +465,10 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys(),
|
|
|
|
|
isBsonObject().containing("location", "geoHaystack").containing("What light?", 1));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(),
|
|
|
|
|
isBsonObject().containing("name", "my_geo_index_name").containing("bucketSize", 2.0));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys()).containsEntry("location", "geoHaystack").containsEntry("What light?",
|
|
|
|
|
1);
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).containsEntry("name", "my_geo_index_name")
|
|
|
|
|
.containsEntry("bucketSize", 2.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -461,7 +477,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
GeoIndexWithNameAsExpression.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "my1st");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "my1st");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document("Zero")
|
|
|
|
|
@@ -531,7 +547,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexOnLevelZero.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "foo", "bar" }, "CompoundIndexOnLevelZero", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -542,9 +558,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
CompoundIndexOnLevelZero.class);
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "compound_index")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true)));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1)));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).isEqualTo(new org.bson.Document("name", "compound_index")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys()).isEqualTo(new org.bson.Document().append("foo", 1).append("bar", -1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-909
|
|
|
|
|
@@ -554,9 +570,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
IndexDefinedOnSuperClass.class);
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(), equalTo(new org.bson.Document().append("name", "compound_index")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true)));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1)));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions()).isEqualTo(new org.bson.Document().append("name", "compound_index")
|
|
|
|
|
.append("unique", true).append("sparse", true).append("background", true));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys()).isEqualTo(new org.bson.Document().append("foo", 1).append("bar", -1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-827
|
|
|
|
|
@@ -566,9 +582,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
ComountIndexWithAutogeneratedName.class);
|
|
|
|
|
|
|
|
|
|
IndexDefinition indexDefinition = indexDefinitions.get(0).getIndexDefinition();
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions(),
|
|
|
|
|
equalTo(new org.bson.Document().append("unique", true).append("sparse", true).append("background", true)));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys(), equalTo(new org.bson.Document().append("foo", 1).append("bar", -1)));
|
|
|
|
|
assertThat(indexDefinition.getIndexOptions())
|
|
|
|
|
.isEqualTo(new org.bson.Document().append("unique", true).append("sparse", true).append("background", true));
|
|
|
|
|
assertThat(indexDefinition.getIndexKeys()).isEqualTo(new org.bson.Document().append("foo", 1).append("bar", -1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-929
|
|
|
|
|
@@ -577,7 +593,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexOnLevelOne.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "zero.foo", "zero.bar" }, "CompoundIndexOnLevelOne",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
@@ -588,7 +604,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexOnLevelOneWithEmptyIndexDefinition.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "zero" }, "CompoundIndexOnLevelZeroWithEmptyIndexDef",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
@@ -599,7 +615,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
SingleCompoundIndex.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "foo", "bar" }, "CompoundIndexOnLevelZero", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -609,10 +625,10 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexDocumentWithComposedAnnotation.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys(), isBsonObject().containing("foo", 1).containing("bar", -1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions(), isBsonObject().containing("name", "my_compound_index_name")
|
|
|
|
|
.containing("unique", true).containing("background", true));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexKeys()).containsEntry("foo", 1).containsEntry("bar", -1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "my_compound_index_name")
|
|
|
|
|
.containsEntry("unique", true).containsEntry("background", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -621,7 +637,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexWithNameExpression.class);
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "cmp2name");
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "cmp2name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2112
|
|
|
|
|
@@ -630,7 +646,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CompoundIndexWithDefExpression.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "foo", "bar" }, "compoundIndexWithDefExpression",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
@@ -660,22 +676,16 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
unique = true)
|
|
|
|
|
static class SingleCompoundIndex {}
|
|
|
|
|
|
|
|
|
|
static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static class IndexDefinedOnSuperClass extends CompoundIndexOnLevelZero {}
|
|
|
|
|
|
|
|
|
|
@Document("ComountIndexWithAutogeneratedName")
|
|
|
|
|
@CompoundIndexes({ @CompoundIndex(useGeneratedName = true, def = "{'foo': 1, 'bar': -1}", background = true,
|
|
|
|
|
sparse = true, unique = true) })
|
|
|
|
|
static class ComountIndexWithAutogeneratedName {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static class ComountIndexWithAutogeneratedName {}
|
|
|
|
|
|
|
|
|
|
@Document("WithComposedAnnotation")
|
|
|
|
|
@ComposedCompoundIndex
|
|
|
|
|
static class CompoundIndexDocumentWithComposedAnnotation {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static class CompoundIndexDocumentWithComposedAnnotation {}
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target({ ElementType.TYPE })
|
|
|
|
|
@@ -716,7 +726,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
TextIndexOnSinglePropertyInRoot.class);
|
|
|
|
|
assertThat(indexDefinitions.size(), equalTo(1));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection("bar", "textIndexOnSinglePropertyInRoot", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -725,7 +736,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
TextIndexOnMutiplePropertiesInRoot.class);
|
|
|
|
|
assertThat(indexDefinitions.size(), equalTo(1));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "foo", "bar" }, "textIndexOnMutiplePropertiesInRoot",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
@@ -735,7 +747,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
TextIndexOnNestedRoot.class);
|
|
|
|
|
assertThat(indexDefinitions.size(), equalTo(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "nested.foo" }, "textIndexOnNestedRoot", indexDefinitions.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -744,12 +756,12 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
TextIndexOnNestedWithWeightRoot.class);
|
|
|
|
|
assertThat(indexDefinitions.size(), equalTo(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "nested.foo" }, "textIndexOnNestedWithWeightRoot",
|
|
|
|
|
indexDefinitions.get(0));
|
|
|
|
|
|
|
|
|
|
org.bson.Document weights = DocumentTestUtils.getAsDocument(indexDefinitions.get(0).getIndexOptions(), "weights");
|
|
|
|
|
assertThat(weights.get("nested.foo"), is((Object) 5F));
|
|
|
|
|
assertThat(weights.get("nested.foo")).isEqualTo(5F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-937
|
|
|
|
|
@@ -757,13 +769,13 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
TextIndexOnNestedWithMostSpecificValueRoot.class);
|
|
|
|
|
assertThat(indexDefinitions.size(), equalTo(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertIndexPathAndCollection(new String[] { "nested.foo", "nested.bar" },
|
|
|
|
|
"textIndexOnNestedWithMostSpecificValueRoot", indexDefinitions.get(0));
|
|
|
|
|
|
|
|
|
|
org.bson.Document weights = DocumentTestUtils.getAsDocument(indexDefinitions.get(0).getIndexOptions(), "weights");
|
|
|
|
|
assertThat(weights.get("nested.foo"), is((Object) 5F));
|
|
|
|
|
assertThat(weights.get("nested.bar"), is((Object) 10F));
|
|
|
|
|
assertThat(weights.get("nested.foo")).isEqualTo(5F);
|
|
|
|
|
assertThat(weights.get("nested.bar")).isEqualTo(10F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-937
|
|
|
|
|
@@ -771,7 +783,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithDefaultLanguage.class);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions().get("default_language"), is((Object) "spanish"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("default_language", "spanish");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-937, DATAMONGO-1049
|
|
|
|
|
@@ -779,7 +791,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithLanguageOverride.class);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions().get("language_override"), is((Object) "lang"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("language_override", "lang");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1049
|
|
|
|
|
@@ -787,7 +799,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithLanguageOverrideOnNestedElement.class);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions().get("language_override"), is(nullValue()));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions().get("language_override")).isNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1049
|
|
|
|
|
@@ -795,7 +807,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNoTextIndexPropertyButReservedFieldLanguage.class);
|
|
|
|
|
assertThat(indexDefinitions, is(empty()));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1049
|
|
|
|
|
@@ -803,7 +816,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNoTextIndexPropertyButReservedFieldLanguageAnnotated.class);
|
|
|
|
|
assertThat(indexDefinitions, is(empty()));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1049
|
|
|
|
|
@@ -811,7 +825,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithOverlappingLanguageProps.class);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions().get("language_override"), is((Object) "lang"));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("language_override", "lang");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1373
|
|
|
|
|
@@ -821,7 +836,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
TextIndexedDocumentWithComposedAnnotation.class);
|
|
|
|
|
|
|
|
|
|
org.bson.Document weights = DocumentTestUtils.getAsDocument(indexDefinitions.get(0).getIndexOptions(), "weights");
|
|
|
|
|
assertThat(weights, isBsonObject().containing("foo", 99f));
|
|
|
|
|
assertThat(weights).containsEntry("foo", 99f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document
|
|
|
|
|
@@ -919,7 +934,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
|
|
|
|
|
@TextIndexed
|
|
|
|
|
static @interface ComposedTextIndexedAnnotation {
|
|
|
|
|
@interface ComposedTextIndexedAnnotation {
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = TextIndexed.class, attribute = "weight")
|
|
|
|
|
float heavyweight() default 99f;
|
|
|
|
|
@@ -933,25 +948,27 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(MixedIndexRoot.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexDefinition(), instanceOf(Index.class));
|
|
|
|
|
assertThat(indexDefinitions.get(1).getIndexDefinition(), instanceOf(GeospatialIndex.class));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexDefinition()).isInstanceOf(Index.class);
|
|
|
|
|
assertThat(indexDefinitions.get(1).getIndexDefinition()).isInstanceOf(GeospatialIndex.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-899
|
|
|
|
|
public void cyclicPropertyReferenceOverDBRefShouldNotBeTraversed() {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(Inner.class);
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexDefinition().getIndexKeys(),
|
|
|
|
|
equalTo(new org.bson.Document().append("outer", 1)));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexDefinition().getIndexKeys())
|
|
|
|
|
.isEqualTo(new org.bson.Document().append("outer", 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-899
|
|
|
|
|
public void associationsShouldNotBeTraversed() {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(Outer.class);
|
|
|
|
|
assertThat(indexDefinitions, empty());
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-926
|
|
|
|
|
@@ -959,7 +976,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
CycleStartingInBetween.class);
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-926
|
|
|
|
|
@@ -968,7 +986,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(CycleLevelZero.class);
|
|
|
|
|
assertIndexPathAndCollection("indexedProperty", "cycleLevelZero", indexDefinitions.get(0));
|
|
|
|
|
assertIndexPathAndCollection("cyclicReference.indexedProperty", "cycleLevelZero", indexDefinitions.get(1));
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-926
|
|
|
|
|
@@ -976,7 +994,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(CycleOnLevelOne.class);
|
|
|
|
|
assertIndexPathAndCollection("reference.indexedProperty", "cycleOnLevelOne", indexDefinitions.get(0));
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-926
|
|
|
|
|
@@ -984,11 +1002,12 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
NoCycleButIdenticallyNamedProperties.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(3);
|
|
|
|
|
assertIndexPathAndCollection("foo", "noCycleButIdenticallyNamedProperties", indexDefinitions.get(0));
|
|
|
|
|
assertIndexPathAndCollection("reference.foo", "noCycleButIdenticallyNamedProperties", indexDefinitions.get(1));
|
|
|
|
|
assertIndexPathAndCollection("reference.deep.foo", "noCycleButIdenticallyNamedProperties",
|
|
|
|
|
indexDefinitions.get(2));
|
|
|
|
|
assertThat(indexDefinitions, hasSize(3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-949
|
|
|
|
|
@@ -997,7 +1016,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
SimilarityHolingBean.class);
|
|
|
|
|
assertIndexPathAndCollection("norm", "similarityHolingBean", indexDefinitions.get(0));
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-962
|
|
|
|
|
@@ -1005,7 +1024,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
SelfCyclingViaCollectionType.class);
|
|
|
|
|
assertThat(indexDefinitions, empty());
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-962
|
|
|
|
|
@@ -1013,14 +1033,15 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
MultipleObjectsOfSameType.class);
|
|
|
|
|
assertThat(indexDefinitions, empty());
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-962
|
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
|
public void shouldCatchCyclicReferenceExceptionOnRoot() {
|
|
|
|
|
|
|
|
|
|
MongoPersistentEntity entity = new BasicMongoPersistentEntity<Object>(ClassTypeInformation.from(Object.class));
|
|
|
|
|
MongoPersistentEntity entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(Object.class));
|
|
|
|
|
|
|
|
|
|
MongoPersistentProperty propertyMock = mock(MongoPersistentProperty.class);
|
|
|
|
|
when(propertyMock.isEntity()).thenReturn(true);
|
|
|
|
|
@@ -1028,7 +1049,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
when(propertyMock.getActualType()).thenThrow(
|
|
|
|
|
new MongoPersistentEntityIndexResolver.CyclicPropertyReferenceException("foo", Object.class, "bar"));
|
|
|
|
|
|
|
|
|
|
MongoPersistentEntity<SelfCyclingViaCollectionType> selfCyclingEntity = new BasicMongoPersistentEntity<SelfCyclingViaCollectionType>(
|
|
|
|
|
MongoPersistentEntity<SelfCyclingViaCollectionType> selfCyclingEntity = new BasicMongoPersistentEntity<>(
|
|
|
|
|
ClassTypeInformation.from(SelfCyclingViaCollectionType.class));
|
|
|
|
|
|
|
|
|
|
new MongoPersistentEntityIndexResolver(prepareMappingContext(SelfCyclingViaCollectionType.class))
|
|
|
|
|
@@ -1041,9 +1062,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
NoCycleManyPathsToDeepValueObject.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
assertIndexPathAndCollection("l3.valueObject.value", "rules", indexDefinitions.get(0));
|
|
|
|
|
assertIndexPathAndCollection("l2.l3.valueObject.value", "rules", indexDefinitions.get(1));
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1025
|
|
|
|
|
@@ -1051,8 +1072,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNestedDocumentHavingNamedCompoundIndex.class);
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("propertyOfTypeHavingNamedCompoundIndex.c_index"));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"propertyOfTypeHavingNamedCompoundIndex.c_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1025
|
|
|
|
|
@@ -1060,8 +1082,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNestedTypeHavingNamedCompoundIndex.class);
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("propertyOfTypeHavingNamedCompoundIndex.c_index"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"propertyOfTypeHavingNamedCompoundIndex.c_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1025
|
|
|
|
|
@@ -1069,8 +1091,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNestedDocumentHavingNamedIndex.class);
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("propertyOfTypeHavingNamedIndex.property_index"));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"propertyOfTypeHavingNamedIndex.property_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1025
|
|
|
|
|
@@ -1078,8 +1101,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNestedTypeHavingNamedIndex.class);
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("propertyOfTypeHavingNamedIndex.property_index"));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"propertyOfTypeHavingNamedIndex.property_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1025
|
|
|
|
|
@@ -1087,7 +1111,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
DocumentWithNamedIndex.class);
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"), equalTo("property_index"));
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "property_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1087
|
|
|
|
|
@@ -1096,9 +1120,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
MultiplePropertiesOfSameTypeWithMatchingStartLetters.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"), equalTo("name.component"));
|
|
|
|
|
assertThat((String) indexDefinitions.get(1).getIndexOptions().get("name"), equalTo("nameLast.component"));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "name.component");
|
|
|
|
|
assertThat(indexDefinitions.get(1).getIndexOptions()).containsEntry("name", "nameLast.component");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1087
|
|
|
|
|
@@ -1107,9 +1131,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
MultiplePropertiesOfSameTypeWithMatchingStartLettersOnNestedProperty.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"), equalTo("component.nameLast"));
|
|
|
|
|
assertThat((String) indexDefinitions.get(1).getIndexOptions().get("name"), equalTo("component.name"));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "component.nameLast");
|
|
|
|
|
assertThat(indexDefinitions.get(1).getIndexOptions()).containsEntry("name", "component.name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1121
|
|
|
|
|
@@ -1118,11 +1142,10 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
OuterDocumentReferingToIndexedPropertyViaDifferentNonCyclingPaths.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(2));
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"), equalTo("path1.foo"));
|
|
|
|
|
assertThat((String) indexDefinitions.get(1).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("path2.propertyWithIndexedStructure.foo"));
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions).hasSize(2);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name", "path1.foo");
|
|
|
|
|
assertThat(indexDefinitions.get(1).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"path2.propertyWithIndexedStructure.foo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-1263
|
|
|
|
|
@@ -1131,9 +1154,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
List<IndexDefinitionHolder> indexDefinitions = prepareMappingContextAndResolveIndexForType(
|
|
|
|
|
EntityWithGenericTypeWrapperAsElement.class);
|
|
|
|
|
|
|
|
|
|
assertThat(indexDefinitions, hasSize(1));
|
|
|
|
|
assertThat((String) indexDefinitions.get(0).getIndexOptions().get("name"),
|
|
|
|
|
equalTo("listWithGeneircTypeElement.entity.property_index"));
|
|
|
|
|
assertThat(indexDefinitions).hasSize(1);
|
|
|
|
|
assertThat(indexDefinitions.get(0).getIndexOptions()).containsEntry("name",
|
|
|
|
|
"listWithGeneircTypeElement.entity.property_index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Document
|
|
|
|
|
@@ -1365,9 +1388,9 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
|
|
|
|
IndexDefinitionHolder holder) {
|
|
|
|
|
|
|
|
|
|
for (String expectedPath : expectedPaths) {
|
|
|
|
|
assertThat(holder.getIndexDefinition().getIndexKeys().containsKey(expectedPath), equalTo(true));
|
|
|
|
|
assertThat(holder.getIndexDefinition().getIndexKeys()).containsKey(expectedPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assertThat(holder.getCollection(), equalTo(expectedCollection));
|
|
|
|
|
assertThat(holder.getCollection()).isEqualTo(expectedCollection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|