@ -874,7 +874,7 @@ public class UpdateMapperUnitTests {
assertThat ( mappedUpdate ) . containsEntry ( "$max" , new Document ( "maxfield" , 999 ) ) ;
assertThat ( mappedUpdate ) . containsEntry ( "$max" , new Document ( "maxfield" , 999 ) ) ;
}
}
@Test // DATAMONGO-1423
@Test // DATAMONGO-1423, DATAMONGO-2155
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
public void mappingShouldConsiderCustomConvertersForEnumMapKeys ( ) {
public void mappingShouldConsiderCustomConvertersForEnumMapKeys ( ) {
@ -898,8 +898,8 @@ public class UpdateMapperUnitTests {
Document $set = DocumentTestUtils . getAsDocument ( mappedUpdate , "$set" ) ;
Document $set = DocumentTestUtils . getAsDocument ( mappedUpdate , "$set" ) ;
assertThat ( $set . containsKey ( "enumAsMapKey" ) ) . isTrue ( ) ;
assertThat ( $set . containsKey ( "enumAsMapKey" ) ) . isTrue ( ) ;
Document enumAsMapKey = $set . get ( "enumAsMapKey" , Document . class ) ;
Map enumAsMapKey = $set . get ( "enumAsMapKey" , Map . class ) ;
assertThat ( enumAsMapKey . get ( "A VAILABLE " ) ) . isEqualTo ( 100 ) ;
assertThat ( enumAsMapKey . get ( "V" ) ) . isEqualTo ( 100 ) ;
}
}
@Test // DATAMONGO-1176
@Test // DATAMONGO-1176
@ -938,15 +938,17 @@ public class UpdateMapperUnitTests {
assertThat ( mappedObject ) . hasSize ( 2 ) ;
assertThat ( mappedObject ) . hasSize ( 2 ) ;
}
}
@Test // DATAMONGO-1486
@Test // DATAMONGO-1486, DATAMONGO-2155
public void mappingShouldConvertMapKeysToString ( ) {
public void mappingShouldConvertMapKeysToString ( ) {
Update update = new Update ( ) . set ( "map" , Collections . singletonMap ( 25 , "#StarTrek50" ) ) ;
Update update = new Update ( ) . set ( "map" , Collections . singletonMap ( 25 , "#StarTrek50" ) ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
context . getPersistentEntity ( EntityWithObjectMap . class ) ) ;
context . getPersistentEntity ( EntityWithObjectMap . class ) ) ;
Document mapToSet = getAsDocument ( getAsDocument ( mappedUpdate , "$set" ) , "map" ) ;
Document $set = DocumentTestUtils . getAsDocument ( mappedUpdate , "$set" ) ;
assertThat ( $set . containsKey ( "map" ) ) . isTrue ( ) ;
Map mapToSet = $set . get ( "map" , Map . class ) ;
for ( Object key : mapToSet . keySet ( ) ) {
for ( Object key : mapToSet . keySet ( ) ) {
assertThat ( key ) . isInstanceOf ( String . class ) ;
assertThat ( key ) . isInstanceOf ( String . class ) ;
}
}
@ -980,6 +982,44 @@ public class UpdateMapperUnitTests {
. doesNotContainKey ( "$set.concreteInnerList.[0]._class" ) ;
. doesNotContainKey ( "$set.concreteInnerList.[0]._class" ) ;
}
}
@Test // DATAMONGO-2155
public void shouldPreserveFieldNamesOfMapProperties ( ) {
Update update = Update
. fromDocument ( new Document ( "concreteMap" , new Document ( "Name" , new Document ( "name" , "fooo" ) ) ) ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
context . getPersistentEntity ( EntityWithObjectMap . class ) ) ;
assertThat ( mappedUpdate ) . isEqualTo ( new Document ( "concreteMap" , new Document ( "Name" , new Document ( "name" , "fooo" ) ) ) ) ;
}
@Test // DATAMONGO-2155
public void shouldPreserveExplicitFieldNamesInsideMapProperties ( ) {
Update update = Update
. fromDocument ( new Document ( "map" , new Document ( "Value" , new Document ( "renamed-value" , "fooo" ) ) ) ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
context . getPersistentEntity ( EntityWithMapOfAliased . class ) ) ;
assertThat ( mappedUpdate )
. isEqualTo ( new Document ( "map" , new Document ( "Value" , new Document ( "renamed-value" , "fooo" ) ) ) ) ;
}
@Test // DATAMONGO-2155
public void shouldMapAliasedFieldNamesInMapsCorrectly ( ) {
Update update = Update
. fromDocument ( new Document ( "map" , Collections . singletonMap ( "Value" , new Document ( "value" , "fooo" ) ) ) ) ;
Document mappedUpdate = mapper . getMappedObject ( update . getUpdateObject ( ) ,
context . getPersistentEntity ( EntityWithMapOfAliased . class ) ) ;
assertThat ( mappedUpdate )
. isEqualTo ( new Document ( "map" , new Document ( "Value" , new Document ( "renamed-value" , "fooo" ) ) ) ) ;
}
@Test // DATAMONGO-2174
@Test // DATAMONGO-2174
public void mappingUpdateDocumentWithExplicitFieldNameShouldBePossible ( ) {
public void mappingUpdateDocumentWithExplicitFieldNameShouldBePossible ( ) {
@ -1211,6 +1251,10 @@ public class UpdateMapperUnitTests {
Object field ;
Object field ;
}
}
static class EntityWithMapOfAliased {
Map < String , EntityWithAliasedObject > map ;
}
static class EntityWithObjectMap {
static class EntityWithObjectMap {
Map < Object , Object > map ;
Map < Object , Object > map ;