@ -1,11 +1,11 @@
/ *
/ *
* Copyright ( c ) 2011 by the original author ( s ) .
* Copyright 2011 - 2012 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
* You may obtain a copy of the License at
*
*
* http : //www.apache.org/licenses/LICENSE-2.0
* http : //www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing , software
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* distributed under the License is distributed on an "AS IS" BASIS ,
@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License .
* limitations under the License .
* /
* /
package org.springframework.data.mongodb.core.convert ;
package org.springframework.data.mongodb.core.convert ;
import static org.hamcrest.Matchers.* ;
import static org.hamcrest.Matchers.* ;
@ -42,6 +41,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock ;
import org.mockito.Mock ;
import org.mockito.runners.MockitoJUnitRunner ;
import org.mockito.runners.MockitoJUnitRunner ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.context.ApplicationContext ;
import org.springframework.context.event.ContextRefreshedEvent ;
import org.springframework.core.convert.converter.Converter ;
import org.springframework.core.convert.converter.Converter ;
import org.springframework.data.annotation.Id ;
import org.springframework.data.annotation.Id ;
import org.springframework.data.annotation.PersistenceConstructor ;
import org.springframework.data.annotation.PersistenceConstructor ;
@ -72,12 +73,15 @@ public class MappingMongoConverterUnitTests {
MongoMappingContext mappingContext ;
MongoMappingContext mappingContext ;
@Mock
@Mock
MongoDbFactory factory ;
MongoDbFactory factory ;
@Mock
ApplicationContext context ;
@Before
@Before
public void setUp ( ) {
public void setUp ( ) {
mappingContext = new MongoMappingContext ( ) ;
mappingContext = new MongoMappingContext ( ) ;
mappingContext . afterPropertiesSet ( ) ;
mappingContext . setApplicationContext ( context ) ;
mappingContext . onApplicationEvent ( new ContextRefreshedEvent ( context ) ) ;
converter = new MappingMongoConverter ( factory , mappingContext ) ;
converter = new MappingMongoConverter ( factory , mappingContext ) ;
converter . afterPropertiesSet ( ) ;
converter . afterPropertiesSet ( ) ;
@ -181,7 +185,6 @@ public class MappingMongoConverterUnitTests {
public void writesTypeDiscriminatorIntoRootObject ( ) {
public void writesTypeDiscriminatorIntoRootObject ( ) {
Person person = new Person ( ) ;
Person person = new Person ( ) ;
person . birthDate = new LocalDate ( ) ;
DBObject result = new BasicDBObject ( ) ;
DBObject result = new BasicDBObject ( ) ;
converter . write ( person , result ) ;
converter . write ( person , result ) ;
@ -302,8 +305,8 @@ public class MappingMongoConverterUnitTests {
* /
* /
@Test
@Test
public void writesCollectionWithInterfaceCorrectly ( ) {
public void writesCollectionWithInterfaceCorrectly ( ) {
Person person = new Person ( ) ;
Person person = new Person ( ) ;
person . birthDate = new LocalDate ( ) ;
person . firstname = "Oliver" ;
person . firstname = "Oliver" ;
CollectionWrapper wrapper = new CollectionWrapper ( ) ;
CollectionWrapper wrapper = new CollectionWrapper ( ) ;
@ -1065,6 +1068,20 @@ public class MappingMongoConverterUnitTests {
assertThat ( dbRef . getRef ( ) , is ( "person" ) ) ;
assertThat ( dbRef . getRef ( ) , is ( "person" ) ) ;
}
}
/ * *
* @see DATAMONGO - 458
* /
@Test
public void readEmptyCollectionIsModifiable ( ) {
DBObject dbObject = new BasicDBObject ( "contactsSet" , new BasicDBList ( ) ) ;
CollectionWrapper wrapper = converter . read ( CollectionWrapper . class , dbObject ) ;
assertThat ( wrapper . contactsSet , is ( notNullValue ( ) ) ) ;
wrapper . contactsSet . add ( new Contact ( ) {
} ) ;
}
private static void assertSyntheticFieldValueOf ( Object target , Object expected ) {
private static void assertSyntheticFieldValueOf ( Object target , Object expected ) {
for ( int i = 0 ; i < 10 ; i + + ) {
for ( int i = 0 ; i < 10 ; i + + ) {
@ -1164,6 +1181,7 @@ public class MappingMongoConverterUnitTests {
List < Contact > contacts ;
List < Contact > contacts ;
List < List < String > > strings ;
List < List < String > > strings ;
List < Map < String , Locale > > listOfMaps ;
List < Map < String , Locale > > listOfMaps ;
Set < Contact > contactsSet ;
}
}
static class LocaleWrapper {
static class LocaleWrapper {