Add test case for demonstrating how the ignoreByDefault can be overridden from the base configuration

This commit is contained in:
Filip Hrisafov 2020-07-19 15:01:49 +02:00
parent 36349c49e9
commit 28017e2b0c
2 changed files with 31 additions and 2 deletions

View File

@ -56,7 +56,7 @@ public class IgnorePropertyTest {
@Test
@IssueKey("1933")
public void shouldIgnoreBase() {
public void shouldInheritIgnoreByDefaultFromBase() {
WorkBenchDto workBenchDto = new WorkBenchDto();
workBenchDto.setArticleName( "MyBench" );
@ -74,4 +74,24 @@ public class IgnorePropertyTest {
assertThat( benchTarget.getCreationDate() ).isNull();
}
@Test
@IssueKey("1933")
public void shouldOnlyIgnoreBase() {
WorkBenchDto workBenchDto = new WorkBenchDto();
workBenchDto.setArticleName( "MyBench" );
workBenchDto.setArticleDescription( "Beautiful" );
workBenchDto.setCreationDate( new Date() );
workBenchDto.setModificationDate( new Date() );
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBenchWithImplicit( workBenchDto );
assertThat( benchTarget ).isNotNull();
assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" );
assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" );
assertThat( benchTarget.getKey() ).isNull();
assertThat( benchTarget.getModificationDate() ).isNull();
assertThat( benchTarget.getCreationDate() ).isNull();
}
}

View File

@ -29,12 +29,21 @@ public interface ToolMapper {
@InheritConfiguration( name = "mapBase" )
ToolEntity mapTool(ToolDto source);
// demonstrates that all the business stuff is mapped (implicit-by-name and defined)
// demonstrates that all the business stuff is mapped only defined because BeanMapping#ignoreByDefault
@InheritConfiguration( name = "mapBase" )
@Mapping(target = "description", source = "articleDescription")
WorkBenchEntity mapBench(WorkBenchDto source);
// demonstrates that all the business stuff is mapped (implicit-by-name and defined)
@BeanMapping( ignoreByDefault = false ) // needed to override the one from the BeanMapping mapBase
@InheritConfiguration( name = "mapBase" )
@Mapping(target = "description", source = "articleDescription")
WorkBenchEntity mapBenchWithImplicit(WorkBenchDto source);
// ignore all the base properties by default
@BeanMapping( ignoreByDefault = true )
@Mapping( target = "key", ignore = true)
@Mapping( target = "modificationDate", ignore = true)
@Mapping( target = "creationDate", ignore = true)
BaseEntity mapBase(Object o);
}