@ -21,7 +21,6 @@ import static org.junit.Assert.*;
import java.util.Collections ;
import java.util.Collections ;
import java.util.Set ;
import java.util.Set ;
import org.junit.Before ;
import org.junit.Rule ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.Test ;
import org.junit.rules.ExpectedException ;
import org.junit.rules.ExpectedException ;
@ -49,18 +48,13 @@ import com.mongodb.DBObject;
*
*
* @author Oliver Gierke
* @author Oliver Gierke
* @author Thomas Darimont
* @author Thomas Darimont
* @author Christoph Strobl
* /
* /
public class MappingMongoConverterParserIntegrationTests {
public class MappingMongoConverterParserIntegrationTests {
DefaultListableBeanFactory factory ;
@Rule public ExpectedException exception = ExpectedException . none ( ) ;
public @Rule ExpectedException exception = ExpectedException . none ( ) ;
@Before
DefaultListableBeanFactory factory ;
public void setUp ( ) {
factory = new DefaultListableBeanFactory ( ) ;
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader ( factory ) ;
reader . loadBeanDefinitions ( new ClassPathResource ( "namespace/converter.xml" ) ) ;
}
/ * *
/ * *
* @see DATAMONGO - 243
* @see DATAMONGO - 243
@ -68,6 +62,7 @@ public class MappingMongoConverterParserIntegrationTests {
@Test
@Test
public void allowsDbFactoryRefAttribute ( ) {
public void allowsDbFactoryRefAttribute ( ) {
loadValidConfiguration ( ) ;
factory . getBeanDefinition ( "converter" ) ;
factory . getBeanDefinition ( "converter" ) ;
factory . getBean ( "converter" ) ;
factory . getBean ( "converter" ) ;
}
}
@ -78,6 +73,7 @@ public class MappingMongoConverterParserIntegrationTests {
@Test
@Test
public void hasCustomTypeMapper ( ) {
public void hasCustomTypeMapper ( ) {
loadValidConfiguration ( ) ;
MappingMongoConverter converter = factory . getBean ( "converter" , MappingMongoConverter . class ) ;
MappingMongoConverter converter = factory . getBean ( "converter" , MappingMongoConverter . class ) ;
MongoTypeMapper customMongoTypeMapper = factory . getBean ( CustomMongoTypeMapper . class ) ;
MongoTypeMapper customMongoTypeMapper = factory . getBean ( CustomMongoTypeMapper . class ) ;
@ -90,6 +86,7 @@ public class MappingMongoConverterParserIntegrationTests {
@Test
@Test
public void scansForConverterAndSetsUpCustomConversionsAccordingly ( ) {
public void scansForConverterAndSetsUpCustomConversionsAccordingly ( ) {
loadValidConfiguration ( ) ;
CustomConversions conversions = factory . getBean ( CustomConversions . class ) ;
CustomConversions conversions = factory . getBean ( CustomConversions . class ) ;
assertThat ( conversions . hasCustomWriteTarget ( Person . class ) , is ( true ) ) ;
assertThat ( conversions . hasCustomWriteTarget ( Person . class ) , is ( true ) ) ;
assertThat ( conversions . hasCustomWriteTarget ( Account . class ) , is ( true ) ) ;
assertThat ( conversions . hasCustomWriteTarget ( Account . class ) , is ( true ) ) ;
@ -101,6 +98,7 @@ public class MappingMongoConverterParserIntegrationTests {
@Test
@Test
public void activatesAbbreviatingPropertiesCorrectly ( ) {
public void activatesAbbreviatingPropertiesCorrectly ( ) {
loadValidConfiguration ( ) ;
BeanDefinition definition = factory . getBeanDefinition ( "abbreviatingConverter.mongoMappingContext" ) ;
BeanDefinition definition = factory . getBeanDefinition ( "abbreviatingConverter.mongoMappingContext" ) ;
Object value = definition . getPropertyValues ( ) . getPropertyValue ( "fieldNamingStrategy" ) . getValue ( ) ;
Object value = definition . getPropertyValues ( ) . getPropertyValue ( "fieldNamingStrategy" ) . getValue ( ) ;
@ -124,6 +122,32 @@ public class MappingMongoConverterParserIntegrationTests {
reader . loadBeanDefinitions ( new ClassPathResource ( "namespace/converter-invalid.xml" ) ) ;
reader . loadBeanDefinitions ( new ClassPathResource ( "namespace/converter-invalid.xml" ) ) ;
}
}
/ * *
* @see DATAMONGO - 892
* /
@Test
public void shouldThrowBeanDefinitionParsingExceptionIfConverterDefinedAsNestedBean ( ) {
exception . expect ( BeanDefinitionParsingException . class ) ;
exception . expectMessage ( "Mongo Converter must not be defined as nested bean." ) ;
loadNestedBeanConfiguration ( ) ;
}
private void loadValidConfiguration ( ) {
this . loadConfiguration ( "namespace/converter.xml" ) ;
}
private void loadNestedBeanConfiguration ( ) {
this . loadConfiguration ( "namespace/converter-nested-bean-definition.xml" ) ;
}
private void loadConfiguration ( String configLocation ) {
factory = new DefaultListableBeanFactory ( ) ;
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader ( factory ) ;
reader . loadBeanDefinitions ( new ClassPathResource ( configLocation ) ) ;
}
@Component
@Component
public static class SampleConverter implements Converter < Person , DBObject > {
public static class SampleConverter implements Converter < Person , DBObject > {
public DBObject convert ( Person source ) {
public DBObject convert ( Person source ) {