@ -289,9 +289,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
List < IndexDefinitionHolder > indexDefinitions = prepareMappingContextAndResolveIndexForType ( CompoundIndexOnLevelZero . class ) ;
List < IndexDefinitionHolder > indexDefinitions = prepareMappingContextAndResolveIndexForType ( CompoundIndexOnLevelZero . class ) ;
IndexDefinition indexDefinition = indexDefinitions . get ( 0 ) . getIndexDefinition ( ) ;
IndexDefinition indexDefinition = indexDefinitions . get ( 0 ) . getIndexDefinition ( ) ;
assertThat ( indexDefinition . getIndexOptions ( ) ,
assertThat ( indexDefinition . getIndexOptions ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "name" , "compound_index" )
equalTo ( new BasicDBObjectBuilder ( ) . add ( "name" , "compound_index" ) . add ( "unique" , true ) . add ( "dropDups" , true )
. add ( "unique" , true ) . add ( "dropDups" , true ) . add ( "sparse" , true ) . add ( "background" , true ) . get ( ) ) ) ;
. add ( "sparse" , true ) . add ( "background" , true ) . add ( "expireAfterSeconds" , 10L ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
}
}
@ -304,9 +303,8 @@ public class MongoPersistentEntityIndexResolverUnitTests {
List < IndexDefinitionHolder > indexDefinitions = prepareMappingContextAndResolveIndexForType ( IndexDefinedOnSuperClass . class ) ;
List < IndexDefinitionHolder > indexDefinitions = prepareMappingContextAndResolveIndexForType ( IndexDefinedOnSuperClass . class ) ;
IndexDefinition indexDefinition = indexDefinitions . get ( 0 ) . getIndexDefinition ( ) ;
IndexDefinition indexDefinition = indexDefinitions . get ( 0 ) . getIndexDefinition ( ) ;
assertThat ( indexDefinition . getIndexOptions ( ) ,
assertThat ( indexDefinition . getIndexOptions ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "name" , "compound_index" )
equalTo ( new BasicDBObjectBuilder ( ) . add ( "name" , "compound_index" ) . add ( "unique" , true ) . add ( "dropDups" , true )
. add ( "unique" , true ) . add ( "dropDups" , true ) . add ( "sparse" , true ) . add ( "background" , true ) . get ( ) ) ) ;
. add ( "sparse" , true ) . add ( "background" , true ) . add ( "expireAfterSeconds" , 10L ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
}
}
@ -322,7 +320,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
assertThat (
assertThat (
indexDefinition . getIndexOptions ( ) ,
indexDefinition . getIndexOptions ( ) ,
equalTo ( new BasicDBObjectBuilder ( ) . add ( "unique" , true ) . add ( "dropDups" , true ) . add ( "sparse" , true )
equalTo ( new BasicDBObjectBuilder ( ) . add ( "unique" , true ) . add ( "dropDups" , true ) . add ( "sparse" , true )
. add ( "background" , true ) . add ( "expireAfterSeconds" , 10L ) . get ( ) ) ) ;
. add ( "background" , true ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . add ( "bar" , - 1 ) . get ( ) ) ) ;
}
}
@ -364,6 +362,22 @@ public class MongoPersistentEntityIndexResolverUnitTests {
assertIndexPathAndCollection ( new String [ ] { "foo" , "bar" } , "CompoundIndexOnLevelZero" , indexDefinitions . get ( 0 ) ) ;
assertIndexPathAndCollection ( new String [ ] { "foo" , "bar" } , "CompoundIndexOnLevelZero" , indexDefinitions . get ( 0 ) ) ;
}
}
/ * *
* @see DATAMONGO - 963
* /
@Test
public void compoundIndexShouldIncludeTTLWhenConsistingOfOnlyOneKey ( ) {
List < IndexDefinitionHolder > indexDefinitions = prepareMappingContextAndResolveIndexForType ( CompoundIndexWithOnlyOneKeyAndTTL . class ) ;
IndexDefinition indexDefinition = indexDefinitions . get ( 0 ) . getIndexDefinition ( ) ;
assertThat (
indexDefinition . getIndexOptions ( ) ,
equalTo ( new BasicDBObjectBuilder ( ) . add ( "unique" , true ) . add ( "dropDups" , true ) . add ( "sparse" , true )
. add ( "background" , true ) . add ( "expireAfterSeconds" , 10L ) . get ( ) ) ) ;
assertThat ( indexDefinition . getIndexKeys ( ) , equalTo ( new BasicDBObjectBuilder ( ) . add ( "foo" , 1 ) . get ( ) ) ) ;
}
@Document ( collection = "CompoundIndexOnLevelOne" )
@Document ( collection = "CompoundIndexOnLevelOne" )
static class CompoundIndexOnLevelOne {
static class CompoundIndexOnLevelOne {
@ -400,6 +414,13 @@ public class MongoPersistentEntityIndexResolverUnitTests {
static class ComountIndexWithAutogeneratedName {
static class ComountIndexWithAutogeneratedName {
}
}
@Document ( collection = "CompoundIndexWithOnlyOneKeyAndTTL" )
@CompoundIndex ( def = "{'foo': 1}" , background = true , dropDups = true , expireAfterSeconds = 10 , sparse = true ,
unique = true )
static class CompoundIndexWithOnlyOneKeyAndTTL {
}
}
}
public static class MixedIndexResolutionTests {
public static class MixedIndexResolutionTests {