@ -44,9 +44,6 @@ import org.springframework.data.convert.WritingConverter;
@@ -44,9 +44,6 @@ import org.springframework.data.convert.WritingConverter;
import org.springframework.data.mapping.model.MappingException ;
import org.springframework.data.mongodb.MongoDbFactory ;
import org.springframework.data.mongodb.core.DBObjectTestUtils ;
import org.springframework.data.mongodb.core.convert.UpdateMapperUnitTests.ClassWithEnum.Allocation ;
import org.springframework.data.mongodb.core.convert.UpdateMapperUnitTests.ClassWithEnum.AllocationToStringConverter ;
import org.springframework.data.mongodb.core.convert.UpdateMapperUnitTests.ClassWithEnum.StringToAllocationConverter ;
import org.springframework.data.mongodb.core.mapping.Field ;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext ;
import org.springframework.data.mongodb.core.query.Criteria ;
@ -105,7 +102,7 @@ public class UpdateMapperUnitTests {
@@ -105,7 +102,7 @@ public class UpdateMapperUnitTests {
Document push = getAsDocument ( mappedObject , "$push" ) ;
Document list = getAsDocument ( push , "aliased" ) ;
assertThat ( list . get ( "_class" ) , is ( ( Object ) ConcreteChildClass . class . getName ( ) ) ) ;
assertThat ( list . get ( "_class" ) , is ( ConcreteChildClass . class . getName ( ) ) ) ;
}
/ * *
@ -171,7 +168,7 @@ public class UpdateMapperUnitTests {
@@ -171,7 +168,7 @@ public class UpdateMapperUnitTests {
Document set = getAsDocument ( mappedObject , "$set" ) ;
Document modelDbObject = getAsDocument ( set , "aliased.$" ) ;
assertThat ( modelDbObject . get ( "_class" ) , is ( ( Object ) ConcreteChildClass . class . getName ( ) ) ) ;
assertThat ( modelDbObject . get ( "_class" ) , is ( ConcreteChildClass . class . getName ( ) ) ) ;
}
/ * *
@ -187,8 +184,8 @@ public class UpdateMapperUnitTests {
@@ -187,8 +184,8 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( ParentClass . class ) ) ;
Document set = getAsDocument ( mappedObject , "$set" ) ;
assertThat ( set . get ( "aliased.$.value" ) , is ( ( Object ) "foo" ) ) ;
assertThat ( set . get ( "aliased.$.otherValue" ) , is ( ( Object ) "bar" ) ) ;
assertThat ( set . get ( "aliased.$.value" ) , is ( "foo" ) ) ;
assertThat ( set . get ( "aliased.$.otherValue" ) , is ( "bar" ) ) ;
}
/ * *
@ -204,12 +201,12 @@ public class UpdateMapperUnitTests {
@@ -204,12 +201,12 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( ParentClass . class ) ) ;
Document dbo = getAsDocument ( mappedObject , "$set" ) ;
assertThat ( dbo . get ( "aliased.$.value" ) , is ( ( Object ) "foo" ) ) ;
assertThat ( dbo . get ( "aliased.$.value" ) , is ( "foo" ) ) ;
Document someObject = getAsDocument ( dbo , "aliased.$.someObject" ) ;
assertThat ( someObject , is ( notNullValue ( ) ) ) ;
assertThat ( someObject . get ( "_class" ) , is ( ( Object ) ConcreteChildClass . class . getName ( ) ) ) ;
assertThat ( someObject . get ( "value" ) , is ( ( Object ) "bubu" ) ) ;
assertThat ( someObject . get ( "_class" ) , is ( ConcreteChildClass . class . getName ( ) ) ) ;
assertThat ( someObject . get ( "value" ) , is ( "bubu" ) ) ;
}
/ * *
@ -229,7 +226,7 @@ public class UpdateMapperUnitTests {
@@ -229,7 +226,7 @@ public class UpdateMapperUnitTests {
assertThat ( push . get ( "_class" ) , nullValue ( ) ) ;
assertThat ( values . get ( "_class" ) , nullValue ( ) ) ;
assertThat ( each , IsIterableContainingInOrder . < Object > contains ( "spring" , "data" , "mongodb" ) ) ;
assertThat ( each , IsIterableContainingInOrder . contains ( "spring" , "data" , "mongodb" ) ) ;
}
/ * *
@ -264,7 +261,7 @@ public class UpdateMapperUnitTests {
@@ -264,7 +261,7 @@ public class UpdateMapperUnitTests {
List < Object > each = getAsDBList ( model , "$each" ) ;
List < Object > values = getAsDBList ( ( Document ) each . get ( 0 ) , "values" ) ;
assertThat ( values , IsIterableContainingInOrder . < Object > contains ( "spring" , "data" , "mongodb" ) ) ;
assertThat ( values , IsIterableContainingInOrder . contains ( "spring" , "data" , "mongodb" ) ) ;
}
/ * *
@ -312,7 +309,7 @@ public class UpdateMapperUnitTests {
@@ -312,7 +309,7 @@ public class UpdateMapperUnitTests {
Document key = getAsDocument ( push , "key" ) ;
assertThat ( key . containsKey ( "$position" ) , is ( true ) ) ;
assertThat ( ( Integer ) key . get ( "$position" ) , is ( 2 ) ) ;
assertThat ( key . get ( "$position" ) , is ( 2 ) ) ;
assertThat ( getAsDocument ( push , "key" ) . containsKey ( "$each" ) , is ( true ) ) ;
}
@ -330,7 +327,7 @@ public class UpdateMapperUnitTests {
@@ -330,7 +327,7 @@ public class UpdateMapperUnitTests {
Document key = getAsDocument ( push , "key" ) ;
assertThat ( key . containsKey ( "$position" ) , is ( true ) ) ;
assertThat ( ( Integer ) key . get ( "$position" ) , is ( 0 ) ) ;
assertThat ( key . get ( "$position" ) , is ( 0 ) ) ;
assertThat ( getAsDocument ( push , "key" ) . containsKey ( "$each" ) , is ( true ) ) ;
}
@ -382,7 +379,7 @@ public class UpdateMapperUnitTests {
@@ -382,7 +379,7 @@ public class UpdateMapperUnitTests {
Document key = getAsDocument ( push , "key" ) ;
assertThat ( key . containsKey ( "$slice" ) , is ( true ) ) ;
assertThat ( ( Integer ) key . get ( "$slice" ) , is ( 5 ) ) ;
assertThat ( key . get ( "$slice" ) , is ( 5 ) ) ;
assertThat ( key . containsKey ( "$each" ) , is ( true ) ) ;
}
@ -401,13 +398,13 @@ public class UpdateMapperUnitTests {
@@ -401,13 +398,13 @@ public class UpdateMapperUnitTests {
Document key = getAsDocument ( push , "key" ) ;
assertThat ( key . containsKey ( "$slice" ) , is ( true ) ) ;
assertThat ( ( Integer ) key . get ( "$slice" ) , is ( 5 ) ) ;
assertThat ( key . get ( "$slice" ) , is ( 5 ) ) ;
assertThat ( key . containsKey ( "$each" ) , is ( true ) ) ;
Document key2 = getAsDocument ( push , "key-2" ) ;
assertThat ( key2 . containsKey ( "$slice" ) , is ( true ) ) ;
assertThat ( ( Integer ) key2 . get ( "$slice" ) , is ( - 2 ) ) ;
assertThat ( key2 . get ( "$slice" ) , is ( - 2 ) ) ;
assertThat ( key2 . containsKey ( "$each" ) , is ( true ) ) ;
}
@ -439,7 +436,7 @@ public class UpdateMapperUnitTests {
@@ -439,7 +436,7 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( DocumentWithDBRefCollection . class ) ) ;
Document pullClause = getAsDocument ( mappedObject , "$pull" ) ;
assertThat ( pullClause . get ( "dbRefAnnotatedList" ) , is ( ( Object ) new DBRef ( "entity" , "2" ) ) ) ;
assertThat ( pullClause . get ( "dbRefAnnotatedList" ) , is ( new DBRef ( "entity" , "2" ) ) ) ;
}
/ * *
@ -456,7 +453,7 @@ public class UpdateMapperUnitTests {
@@ -456,7 +453,7 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( DocumentWithDBRefCollection . class ) ) ;
Document pullClause = getAsDocument ( mappedObject , "$pull" ) ;
assertThat ( pullClause . get ( "dbRefAnnotatedList" ) , is ( ( Object ) new DBRef ( "entity" , entity . id ) ) ) ;
assertThat ( pullClause . get ( "dbRefAnnotatedList" ) , is ( new DBRef ( "entity" , entity . id ) ) ) ;
}
/ * *
@ -497,7 +494,7 @@ public class UpdateMapperUnitTests {
@@ -497,7 +494,7 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( DocumentWithDBRefCollection . class ) ) ;
Document setClause = getAsDocument ( mappedObject , "$set" ) ;
assertThat ( setClause . get ( "dbRefProperty" ) , is ( ( Object ) new DBRef ( "entity" , entity . id ) ) ) ;
assertThat ( setClause . get ( "dbRefProperty" ) , is ( new DBRef ( "entity" , entity . id ) ) ) ;
}
/ * *
@ -532,7 +529,7 @@ public class UpdateMapperUnitTests {
@@ -532,7 +529,7 @@ public class UpdateMapperUnitTests {
Document idClause = getAsDocument ( options , "_id" ) ;
List < Object > inClause = getAsDBList ( idClause , "$in" ) ;
assertThat ( inClause , IsIterableContainingInOrder . < Object > contains ( 1L , 2L ) ) ;
assertThat ( inClause , IsIterableContainingInOrder . contains ( 1L , 2L ) ) ;
}
/ * *
@ -550,7 +547,7 @@ public class UpdateMapperUnitTests {
@@ -550,7 +547,7 @@ public class UpdateMapperUnitTests {
Document values = getAsDocument ( addToSet , "values" ) ;
List < Object > each = getAsDBList ( values , "$each" ) ;
assertThat ( each , IsIterableContainingInOrder . < Object > contains ( "spring" , "data" , "mongodb" ) ) ;
assertThat ( each , IsIterableContainingInOrder . contains ( "spring" , "data" , "mongodb" ) ) ;
}
/ * *
@ -588,7 +585,7 @@ public class UpdateMapperUnitTests {
@@ -588,7 +585,7 @@ public class UpdateMapperUnitTests {
Object model = $set . get ( "referencedDocument" ) ;
DBRef expectedDBRef = new DBRef ( "interfaceDocumentDefinitionImpl" , "1" ) ;
assertThat ( model , allOf ( instanceOf ( DBRef . class ) , IsEqual . < Object > equalTo ( expectedDBRef ) ) ) ;
assertThat ( model , allOf ( instanceOf ( DBRef . class ) , IsEqual . equalTo ( expectedDBRef ) ) ) ;
}
/ * *
@ -606,7 +603,7 @@ public class UpdateMapperUnitTests {
@@ -606,7 +603,7 @@ public class UpdateMapperUnitTests {
Document value = DBObjectTestUtils . getAsDocument ( list , "value" ) ;
List < Object > $in = DBObjectTestUtils . getAsDBList ( value , "$in" ) ;
assertThat ( $in , IsIterableContainingInOrder . < Object > contains ( "foo" , "bar" ) ) ;
assertThat ( $in , IsIterableContainingInOrder . contains ( "foo" , "bar" ) ) ;
}
/ * *
@ -719,7 +716,7 @@ public class UpdateMapperUnitTests {
@@ -719,7 +716,7 @@ public class UpdateMapperUnitTests {
public void mappingShouldRetainTypeInformationOfNestedListWhenUpdatingConcreteyParentType ( ) {
ListModelWrapper lmw = new ListModelWrapper ( ) ;
lmw . models = Collections . < Model > singletonList ( new ModelImpl ( 1 ) ) ;
lmw . models = Collections . singletonList ( new ModelImpl ( 1 ) ) ;
Update update = new Update ( ) . set ( "concreteTypeWithListAttributeOfInterfaceType" , lmw ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
@ -778,7 +775,7 @@ public class UpdateMapperUnitTests {
@@ -778,7 +775,7 @@ public class UpdateMapperUnitTests {
@Test
public void mappingShouldRetrainTypeInformationWhenValueTypeOfMapDoesNotMatchItsDeclaration ( ) {
Map < Object , Object > map = Collections . < Object , Object > singletonMap ( "szeth" , new NestedDocument ( "son-son-vallano" ) ) ;
Map < Object , Object > map = Collections . singletonMap ( "szeth" , new NestedDocument ( "son-son-vallano" ) ) ;
Update update = new Update ( ) . set ( "map" , map ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
@ -794,7 +791,7 @@ public class UpdateMapperUnitTests {
@@ -794,7 +791,7 @@ public class UpdateMapperUnitTests {
@Test
public void mappingShouldNotContainTypeInformationWhenValueTypeOfMapMatchesDeclaration ( ) {
Map < Object , NestedDocument > map = Collections . < Object , NestedDocument > singletonMap ( "jasnah" ,
Map < Object , NestedDocument > map = Collections . singletonMap ( "jasnah" ,
new NestedDocument ( "kholin" ) ) ;
Update update = new Update ( ) . set ( "concreteMap" , map ) ;
@ -813,7 +810,7 @@ public class UpdateMapperUnitTests {
@@ -813,7 +810,7 @@ public class UpdateMapperUnitTests {
public void mapsUpdateWithBothReadingAndWritingConverterRegistered ( ) {
CustomConversions conversions = new CustomConversions (
Arrays . asList ( AllocationToStringConverter . INSTANCE , StringToAllocationConverter . INSTANCE ) ) ;
Arrays . asList ( ClassWithEnum . AllocationToStringConverter . INSTANCE , ClassWithEnum . StringToAllocationConverter . INSTANCE ) ) ;
MongoMappingContext mappingContext = new MongoMappingContext ( ) ;
mappingContext . setSimpleTypeHolder ( conversions . getSimpleTypeHolder ( ) ) ;
@ -825,11 +822,11 @@ public class UpdateMapperUnitTests {
@@ -825,11 +822,11 @@ public class UpdateMapperUnitTests {
UpdateMapper mapper = new UpdateMapper ( converter ) ;
Update update = new Update ( ) . set ( "allocation" , Allocation . AVAILABLE ) ;
Update update = new Update ( ) . set ( "allocation" , ClassWithEnum . Allocation . AVAILABLE ) ;
Document result = mapper . getMappedObject ( update . getUpdateObject ( ) ,
mappingContext . getPersistentEntity ( ClassWithEnum . class ) ) ;
assertThat ( result , isBsonObject ( ) . containing ( "$set.allocation" , Allocation . AVAILABLE . code ) ) ;
assertThat ( result , isBsonObject ( ) . containing ( "$set.allocation" , ClassWithEnum . Allocation . AVAILABLE . code ) ) ;
}
/ * *
@ -907,7 +904,7 @@ public class UpdateMapperUnitTests {
@@ -907,7 +904,7 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( SimpleValueHolder . class ) ) ;
Document $set = DBObjectTestUtils . getAsDocument ( mappedUpdate , "$set" ) ;
assertThat ( $set . get ( "intValue" ) , Is . < Object > is ( 10 ) ) ;
assertThat ( $set . get ( "intValue" ) , Is . is ( 10 ) ) ;
}
/ * *
@ -921,7 +918,7 @@ public class UpdateMapperUnitTests {
@@ -921,7 +918,7 @@ public class UpdateMapperUnitTests {
context . getPersistentEntity ( SimpleValueHolder . class ) ) ;
Document $set = DBObjectTestUtils . getAsDocument ( mappedUpdate , "$set" ) ;
assertThat ( $set . get ( "primIntValue" ) , Is . < Object > is ( 10 ) ) ;
assertThat ( $set . get ( "primIntValue" ) , Is . is ( 10 ) ) ;
}
/ * *
@ -958,7 +955,7 @@ public class UpdateMapperUnitTests {
@@ -958,7 +955,7 @@ public class UpdateMapperUnitTests {
public void mappingShouldConsiderCustomConvertersForEnumMapKeys ( ) {
CustomConversions conversions = new CustomConversions (
Arrays . asList ( AllocationToStringConverter . INSTANCE , StringToAllocationConverter . INSTANCE ) ) ;
Arrays . asList ( ClassWithEnum . AllocationToStringConverter . INSTANCE , ClassWithEnum . StringToAllocationConverter . INSTANCE ) ) ;
MongoMappingContext mappingContext = new MongoMappingContext ( ) ;
mappingContext . setSimpleTypeHolder ( conversions . getSimpleTypeHolder ( ) ) ;
@ -970,7 +967,7 @@ public class UpdateMapperUnitTests {
@@ -970,7 +967,7 @@ public class UpdateMapperUnitTests {
UpdateMapper mapper = new UpdateMapper ( converter ) ;
Update update = new Update ( ) . set ( "enumAsMapKey" , Collections . singletonMap ( Allocation . AVAILABLE , 100 ) ) ;
Update update = new Update ( ) . set ( "enumAsMapKey" , Collections . singletonMap ( ClassWithEnum . Allocation . AVAILABLE , 100 ) ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
mappingContext . getPersistentEntity ( ClassWithEnum . class ) ) ;
@ -981,6 +978,51 @@ public class UpdateMapperUnitTests {
@@ -981,6 +978,51 @@ public class UpdateMapperUnitTests {
assertThat ( enumAsMapKey . get ( "AVAILABLE" ) , is ( 100 ) ) ;
}
/ * *
* @see DATAMONGO - 1176
* /
@Test
public void mappingShouldPrepareUpdateObjectForMixedOperatorsAndFields ( ) {
Document document = new Document ( "key" , "value" ) . append ( "$set" , new Document ( "a" , "b" ) . append ( "x" , "y" ) ) ;
Document mappedObject = mapper . getMappedObject ( document , context . getPersistentEntity ( SimpleValueHolder . class ) ) ;
assertThat ( mappedObject . get ( "$set" ) , is ( equalTo ( new Document ( "a" , "b" ) . append ( "x" , "y" ) . append ( "key" , "value" ) ) ) ) ;
assertThat ( mappedObject . size ( ) , is ( 1 ) ) ;
}
/ * *
* @see DATAMONGO - 1176
* /
@Test
public void mappingShouldReturnReplaceObject ( ) {
Document document = new Document ( "key" , "value" ) . append ( "a" , "b" ) . append ( "x" , "y" ) ;
Document mappedObject = mapper . getMappedObject ( document , context . getPersistentEntity ( SimpleValueHolder . class ) ) ;
assertThat ( mappedObject . get ( "key" ) , is ( equalTo ( "value" ) ) ) ;
assertThat ( mappedObject . get ( "a" ) , is ( equalTo ( "b" ) ) ) ;
assertThat ( mappedObject . get ( "x" ) , is ( equalTo ( "y" ) ) ) ;
assertThat ( mappedObject . size ( ) , is ( 3 ) ) ;
}
/ * *
* @see DATAMONGO - 1176
* /
@Test
public void mappingShouldReturnUpdateObject ( ) {
Document document = new Document ( "$push" , new Document ( "x" , "y" ) ) . append ( "$set" , new Document ( "a" , "b" ) ) ;
Document mappedObject = mapper . getMappedObject ( document , context . getPersistentEntity ( SimpleValueHolder . class ) ) ;
assertThat ( mappedObject . get ( "$push" ) , is ( equalTo ( new Document ( "x" , "y" ) ) ) ) ;
assertThat ( mappedObject . get ( "$set" ) , is ( equalTo ( new Document ( "a" , "b" ) ) ) ) ;
assertThat ( mappedObject . size ( ) , is ( 2 ) ) ;
}
/ * *
* @see DATAMONGO - 1486
* /
@ -1011,7 +1053,7 @@ public class UpdateMapperUnitTests {
@@ -1011,7 +1053,7 @@ public class UpdateMapperUnitTests {
}
@org.springframework.data.mongodb.core.mapping.Document ( collection = "DocumentWithReferenceToInterface" )
static interface DocumentWithReferenceToInterface {
interface DocumentWithReferenceToInterface {
String getId ( ) ;
@ -1019,7 +1061,7 @@ public class UpdateMapperUnitTests {
@@ -1019,7 +1061,7 @@ public class UpdateMapperUnitTests {
}
static interface InterfaceDocumentDefinitionWithoutId {
interface InterfaceDocumentDefinitionWithoutId {
String getValue ( ) ;
}
@ -1068,7 +1110,7 @@ public class UpdateMapperUnitTests {
@@ -1068,7 +1110,7 @@ public class UpdateMapperUnitTests {
}
static interface Model { }
interface Model { }
static class ModelImpl implements Model {
public int value ;
@ -1226,13 +1268,13 @@ public class UpdateMapperUnitTests {
@@ -1226,13 +1268,13 @@ public class UpdateMapperUnitTests {
Allocation allocation ;
Map < Allocation , String > enumAsMapKey ;
static enum Allocation {
enum Allocation {
AVAILABLE ( "V" ) , ALLOCATED ( "A" ) ;
String code ;
private Allocation ( String code ) {
Allocation ( String code ) {
this . code = code ;
}
@ -1248,7 +1290,7 @@ public class UpdateMapperUnitTests {
@@ -1248,7 +1290,7 @@ public class UpdateMapperUnitTests {
}
}
static enum AllocationToStringConverter implements Converter < Allocation , String > {
enum AllocationToStringConverter implements Converter < Allocation , String > {
INSTANCE ;
@ -1258,7 +1300,7 @@ public class UpdateMapperUnitTests {
@@ -1258,7 +1300,7 @@ public class UpdateMapperUnitTests {
}
}
static enum StringToAllocationConverter implements Converter < String , Allocation > {
enum StringToAllocationConverter implements Converter < String , Allocation > {
INSTANCE ;