Skip to content

Commit

Permalink
[ISSUE: 658] Support the mapping-files attribute on dozer:mapper elem…
Browse files Browse the repository at this point in the history
…ent in dozer-spring4 module (#659)

* Support the mapping-files attribute on dozer:mapper element in dozer-spring4 module
Fixes gh-658

* Fix testcase name
See gh-658
  • Loading branch information
kazuki43zoo authored and garethahealy committed Jun 17, 2018
1 parent d9bf27c commit f69ba20
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;

/**
* {@link AbstractBeanDefinitionParser} which uses {@link BeanDefinitionBuilder#rootBeanDefinition(Class)}
Expand All @@ -31,6 +32,10 @@ public class MapperDefinitionParser extends AbstractBeanDefinitionParser {
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DozerBeanMapperFactoryBean.class);
String mappingFiles = element.getAttribute("mapping-files");
if (StringUtils.hasLength(mappingFiles)) {
builder.addPropertyValue("mappingFiles", mappingFiles);
}
return builder.getBeanDefinition();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#

http\://dozermapper.github.io/schema/dozer-spring.xsd=schema/dozer-spring.xsd
https\://dozermapper.github.io/schema/dozer-spring.xsd=schema/dozer-spring.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@
<xs:element name="mapper">
<xs:complexType>
<xs:complexContent>
<xs:extension base="beans:identifiedType"/>
<xs:extension base="beans:identifiedType">
<xs:attribute name="mapping-files" type="xs:string">
<xs:annotation>
<xs:documentation>
<![CDATA[
Spring resources definition for providing mapping file location.
Could be used for loading all mapping files by wildcard definition(e.g. classpath*:/*.dozer.xml).
]]>
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.dozermapper.spring.functional_tests;

import com.github.dozermapper.core.DozerBeanMapper;
import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.spring.functional_tests.support.ReferencingBean;

Expand All @@ -25,8 +26,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/springNameSpace.xml")
Expand All @@ -46,6 +48,13 @@ public void shouldRegisterMapper() {
Mapper mapper = referencingBean.getMapper();

assertNotNull(mapper);
assertEquals(beanMapper, mapper);
assertSame(beanMapper, mapper);
}

@Test
public void shouldApplyMappingFiles() {
DozerBeanMapper beanMapper = context.getBean("beanMapperWithMappingFiles", DozerBeanMapper.class);
assertTrue(beanMapper.getMappingFiles().stream().anyMatch(file -> file.contains("/mappings/")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
public class ReferencingBean {

@Autowired
Mapper mapper;
Mapper beanMapper;

public Mapper getMapper() {
return mapper;
return beanMapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@

<bean class="com.github.dozermapper.spring.functional_tests.support.ReferencingBean"/>

<dozer:mapper id="beanMapperWithMappingFiles" mapping-files="classpath*:/mappings/*.xml"/>

</beans>

0 comments on commit f69ba20

Please sign in to comment.