@ -130,10 +130,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test
@Test
public void shouldDetectAnnotatedLanguagePropertyCorrectly ( ) {
public void shouldDetectAnnotatedLanguagePropertyCorrectly ( ) {
BasicMongoPersistentEntity < DocumentWithLanguageProperty > persistentEntity = new BasicMongoPersistentEntity < DocumentWithLanguageProperty > (
MongoPersistentProperty property = getPropertyFor ( DocumentWithLanguageProperty . class , "lang" ) ;
ClassTypeInformation . from ( DocumentWithLanguageProperty . class ) ) ;
MongoPersistentProperty property = getPropertyFor ( persistentEntity , "lang" ) ;
assertThat ( property . isLanguageProperty ( ) , is ( true ) ) ;
assertThat ( property . isLanguageProperty ( ) , is ( true ) ) ;
}
}
@ -143,10 +140,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test
@Test
public void shouldDetectIplicitLanguagePropertyCorrectly ( ) {
public void shouldDetectIplicitLanguagePropertyCorrectly ( ) {
BasicMongoPersistentEntity < DocumentWithImplicitLanguageProperty > persistentEntity = new BasicMongoPersistentEntity < DocumentWithImplicitLanguageProperty > (
MongoPersistentProperty property = getPropertyFor ( DocumentWithImplicitLanguageProperty . class , "language" ) ;
ClassTypeInformation . from ( DocumentWithImplicitLanguageProperty . class ) ) ;
MongoPersistentProperty property = getPropertyFor ( persistentEntity , "language" ) ;
assertThat ( property . isLanguageProperty ( ) , is ( true ) ) ;
assertThat ( property . isLanguageProperty ( ) , is ( true ) ) ;
}
}
@ -156,10 +150,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test
@Test
public void shouldDetectTextScorePropertyCorrectly ( ) {
public void shouldDetectTextScorePropertyCorrectly ( ) {
BasicMongoPersistentEntity < DocumentWithTextScoreProperty > persistentEntity = new BasicMongoPersistentEntity < DocumentWithTextScoreProperty > (
MongoPersistentProperty property = getPropertyFor ( DocumentWithTextScoreProperty . class , "score" ) ;
ClassTypeInformation . from ( DocumentWithTextScoreProperty . class ) ) ;
MongoPersistentProperty property = getPropertyFor ( persistentEntity , "score" ) ;
assertThat ( property . isTextScoreProperty ( ) , is ( true ) ) ;
assertThat ( property . isTextScoreProperty ( ) , is ( true ) ) ;
}
}
@ -169,17 +160,39 @@ public class BasicMongoPersistentPropertyUnitTests {
@Test
@Test
public void shouldDetectTextScoreAsReadOnlyProperty ( ) {
public void shouldDetectTextScoreAsReadOnlyProperty ( ) {
BasicMongoPersistentEntity < DocumentWithTextScoreProperty > persistentEntity = new BasicMongoPersistentEntity < DocumentWithTextScoreProperty > (
MongoPersistentProperty property = getPropertyFor ( DocumentWithTextScoreProperty . class , "score" ) ;
ClassTypeInformation . from ( DocumentWithTextScoreProperty . class ) ) ;
MongoPersistentProperty property = getPropertyFor ( persistentEntity , "score" ) ;
assertThat ( property . isWritable ( ) , is ( false ) ) ;
assertThat ( property . isWritable ( ) , is ( false ) ) ;
}
}
/ * *
* @see DATAMONGO - 1050
* /
@Test
public void shouldNotConsiderExplicitlyNameFieldAsIdProperty ( ) {
MongoPersistentProperty property = getPropertyFor ( DocumentWithExplicitlyRenamedIdProperty . class , "id" ) ;
assertThat ( property . isIdProperty ( ) , is ( false ) ) ;
}
/ * *
* @see DATAMONGO - 1050
* /
@Test
public void shouldConsiderPropertyAsIdWhenExplicitlyAnnotatedWithIdEvenWhenExplicitlyNamePresent ( ) {
MongoPersistentProperty property = getPropertyFor ( DocumentWithExplicitlyRenamedIdPropertyHavingIdAnnotation . class ,
"id" ) ;
assertThat ( property . isIdProperty ( ) , is ( true ) ) ;
}
private MongoPersistentProperty getPropertyFor ( Field field ) {
private MongoPersistentProperty getPropertyFor ( Field field ) {
return getPropertyFor ( entity , field ) ;
return getPropertyFor ( entity , field ) ;
}
}
private < T > MongoPersistentProperty getPropertyFor ( Class < T > type , String fieldname ) {
return getPropertyFor ( new BasicMongoPersistentEntity < T > ( ClassTypeInformation . from ( type ) ) , fieldname ) ;
}
private MongoPersistentProperty getPropertyFor ( MongoPersistentEntity < ? > persistentEntity , String fieldname ) {
private MongoPersistentProperty getPropertyFor ( MongoPersistentEntity < ? > persistentEntity , String fieldname ) {
return getPropertyFor ( persistentEntity , ReflectionUtils . findField ( persistentEntity . getType ( ) , fieldname ) ) ;
return getPropertyFor ( persistentEntity , ReflectionUtils . findField ( persistentEntity . getType ( ) , fieldname ) ) ;
}
}
@ -230,4 +243,14 @@ public class BasicMongoPersistentPropertyUnitTests {
static class DocumentWithTextScoreProperty {
static class DocumentWithTextScoreProperty {
@TextScore Float score ;
@TextScore Float score ;
}
}
static class DocumentWithExplicitlyRenamedIdProperty {
@org.springframework.data.mongodb.core.mapping.Field ( "id" ) String id ;
}
static class DocumentWithExplicitlyRenamedIdPropertyHavingIdAnnotation {
@Id @org.springframework.data.mongodb.core.mapping.Field ( "id" ) String id ;
}
}
}