diff --git a/mpple-spring-boot-starter/pom.xml b/mpple-spring-boot-starter/pom.xml index fd56a94..95dc7c7 100644 --- a/mpple-spring-boot-starter/pom.xml +++ b/mpple-spring-boot-starter/pom.xml @@ -19,11 +19,28 @@ ml.wonwoo mpple-modelmapper + true + + + ml.wonwoo + mpple-dozer + true + + + org.slf4j + slf4j-log4j12 + + org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-configuration-processor + true + org.springframework.boot spring-boot-starter-test diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DefaultAutoConfiguration.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DefaultAutoConfiguration.java new file mode 100644 index 0000000..c990d4c --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DefaultAutoConfiguration.java @@ -0,0 +1,19 @@ +package ml.wonwoo.autoconfigure; + +import ml.wonwoo.mapped.DefaultMapped; +import ml.wonwoo.mapped.Mapped; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Conditional(MapperCondition.class) +public class DefaultAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(Mapped.class) + public Mapped mapped() { + return new DefaultMapped(); + } +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DozerAutoConfiguration.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DozerAutoConfiguration.java new file mode 100644 index 0000000..c603f83 --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/DozerAutoConfiguration.java @@ -0,0 +1,40 @@ +package ml.wonwoo.autoconfigure; + +import java.util.List; +import ml.wonwoo.autoconfigure.dozer.DozerCustomizer; +import ml.wonwoo.autoconfigure.dozer.DozerFactoryBean; +import ml.wonwoo.dozer.mapped.DozerMapped; +import ml.wonwoo.mapped.Mapped; +import org.dozer.DozerBeanMapper; +import org.dozer.Mapper; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnClass(DozerMapped.class) +@Conditional(MapperCondition.class) +public class DozerAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public FactoryBean mapperFactoryBean(ObjectProvider> provider) { + DozerFactoryBean dozerFactoryBean = new DozerFactoryBean(); + dozerFactoryBean.setDozerCustomizers(provider.getIfAvailable()); + return dozerFactoryBean; + } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(Mapper.class) + public Mapped mapped(Mapper mapper) { + DozerMapped dozerMapped = new DozerMapped(); + dozerMapped.setMapper(mapper); + return dozerMapped; + } +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperCondition.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperCondition.java new file mode 100644 index 0000000..6107755 --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperCondition.java @@ -0,0 +1,30 @@ +package ml.wonwoo.autoconfigure; + +import org.springframework.boot.autoconfigure.condition.ConditionMessage; +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.SpringBootCondition; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.core.type.ClassMetadata; + +class MapperCondition extends SpringBootCondition { + + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { + String sourceClass = ""; + if (metadata instanceof ClassMetadata) { + sourceClass = ((ClassMetadata) metadata).getClassName(); + } + ConditionMessage.Builder message = ConditionMessage.forCondition("Mapper", sourceClass); + MapperType specified = Binder.get(context.getEnvironment()) + .bind("mpple.mapper.type", MapperType.class) + .orElseGet(() -> MapperType.NONE); + MapperType storeType = MapperType.getType(((AnnotationMetadata) metadata).getClassName()); + if (specified == storeType) { + return ConditionOutcome.match(message.because(specified + " mapper type")); + } + return ConditionOutcome.noMatch(message.because("unknown mapper type")); + } +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperType.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperType.java new file mode 100644 index 0000000..737ede8 --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MapperType.java @@ -0,0 +1,25 @@ +package ml.wonwoo.autoconfigure; + +public enum MapperType { + + NONE(DefaultAutoConfiguration.class), + MODELMAPPER(ModelMapperAutoConfiguration.class), + DOZER(DozerAutoConfiguration.class); + + private final Class configClass; + + MapperType(Class configClass) { + this.configClass = configClass; + } + + public static MapperType getType(String configClass) { + for (MapperType mapperType : values()) { + if (mapperType.configClass != null) { + if (mapperType.configClass.getName().equals(configClass)) { + return mapperType; + } + } + } + throw new IllegalArgumentException(); + } +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MppleAutoConfiguration.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfiguration.java similarity index 80% rename from mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MppleAutoConfiguration.java rename to mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfiguration.java index 0cbbc58..fb569e5 100644 --- a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/MppleAutoConfiguration.java +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfiguration.java @@ -5,30 +5,35 @@ import ml.wonwoo.autoconfigure.modelmapper.ModelMapperCustomizer; import ml.wonwoo.autoconfigure.modelmapper.ModelMapperFactoryBean; import ml.wonwoo.autoconfigure.modelmapper.PropertyMapCustomizer; +import ml.wonwoo.mapped.Mapped; import ml.wonwoo.modelmapper.mapped.ModelMapperMapped; import org.modelmapper.Converter; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; +import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; +@ConditionalOnClass(ModelMapperMapped.class) +@Conditional(MapperCondition.class) @Configuration -@ConditionalOnClass(ModelMapper.class) -public class MppleAutoConfiguration { +public class ModelMapperAutoConfiguration { @Bean @ConditionalOnMissingBean - public ModelMapperMapped modelMapperMapped(ModelMapper modelMapper) { + public Mapped mapped(ModelMapper modelMapper) { ModelMapperMapped modelMapperMapped = new ModelMapperMapped(); modelMapperMapped.setModelMapper(modelMapper); return modelMapperMapped; } @Bean - public ModelMapperFactoryBean modelMapperFactoryBean(ObjectProvider> provider) { + @ConditionalOnMissingBean + public FactoryBean mapperFactoryBean(ObjectProvider> provider) { ModelMapperFactoryBean modelMapperFactoryBean = new ModelMapperFactoryBean(); modelMapperFactoryBean.setMapperCustomizers(provider.getIfAvailable()); return modelMapperFactoryBean; diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerCustomizer.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerCustomizer.java new file mode 100644 index 0000000..7796214 --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerCustomizer.java @@ -0,0 +1,9 @@ +package ml.wonwoo.autoconfigure.dozer; + +import org.dozer.DozerBeanMapper; + +@FunctionalInterface +public interface DozerCustomizer { + + void customize(DozerBeanMapper dozerBeanMapper); +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBean.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBean.java new file mode 100644 index 0000000..81e778f --- /dev/null +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBean.java @@ -0,0 +1,32 @@ +package ml.wonwoo.autoconfigure.dozer; + +import java.util.List; +import org.dozer.DozerBeanMapper; +import org.springframework.beans.factory.FactoryBean; + +public class DozerFactoryBean implements FactoryBean { + + private List dozerCustomizers; + + @Override + public DozerBeanMapper getObject() { + DozerBeanMapper dozerBeanMapper = new DozerBeanMapper(); + configure(dozerBeanMapper); + return dozerBeanMapper; + } + + @Override + public Class getObjectType() { + return DozerBeanMapper.class; + } + + private void configure(DozerBeanMapper dozerBeanMapper) { + if (dozerCustomizers != null) { + dozerCustomizers.forEach(dozerCustomizer -> dozerCustomizer.customize(dozerBeanMapper)); + } + } + + public void setDozerCustomizers(List dozerCustomizers) { + this.dozerCustomizers = dozerCustomizers; + } +} diff --git a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/registrar/SpringBootMppledsRegistrar.java b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/registrar/SpringBootMppledsRegistrar.java index 438bff8..57717bd 100644 --- a/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/registrar/SpringBootMppledsRegistrar.java +++ b/mpple-spring-boot-starter/src/main/java/ml/wonwoo/autoconfigure/registrar/SpringBootMppledsRegistrar.java @@ -31,7 +31,7 @@ protected void registerBeanDefinitionMppled(AnnotationMetadata metadata, BeanDef BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(MppleFactoryBean.class); AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); definition.addPropertyValue("type", className); - definition.addPropertyValue("beanName", "modelMapperMapped"); + definition.addPropertyValue("beanName", "mapped"); BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className); BeanDefinitionReaderUtils.registerBeanDefinition(holder, beanDefinitionRegistry); } diff --git a/mpple-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/mpple-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..42e8f72 --- /dev/null +++ b/mpple-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,10 @@ +{ + "properties": [ + { + "name": "mpple.mapper.type", + "type": "ml.wonwoo.autoconfigure.MapperType", + "description": "mapper.type", + "defaultValue": "none" + } + ] +} \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/main/resources/META-INF/spring.factories b/mpple-spring-boot-starter/src/main/resources/META-INF/spring.factories index 4d4c4dc..3aa5838 100644 --- a/mpple-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/mpple-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - ml.wonwoo.autoconfigure.MppleAutoConfiguration,\ + ml.wonwoo.autoconfigure.ModelMapperAutoConfiguration,\ + ml.wonwoo.autoconfigure.DozerAutoConfiguration,\ + ml.wonwoo.autoconfigure.DefaultAutoConfiguration,\ ml.wonwoo.autoconfigure.MppledsRegistrarAutoConfiguration \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DefaultAutoConfigurationTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DefaultAutoConfigurationTests.java new file mode 100644 index 0000000..5839890 --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DefaultAutoConfigurationTests.java @@ -0,0 +1,35 @@ +package ml.wonwoo.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import ml.wonwoo.mapped.DefaultMapped; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +public class DefaultAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(DefaultAutoConfiguration.class)); + + @Test + public void registersAutomatically() { + runner + .run(context -> assertThat(context).hasSingleBean(DefaultMapped.class)); + } + + @Test + public void registersAutomaticallyNone() { + runner + .withPropertyValues("mpple.mapper.type=none") + .run(context -> assertThat(context).hasSingleBean(DefaultMapped.class)); + } + + @Test + public void registersAutomaticallyMiss() { + runner + .withPropertyValues("mpple.mapper.type=modelmapper") + .run(context -> assertThat(context).doesNotHaveBean(DefaultMapped.class)); + } +} \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DozerAutoConfigurationTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DozerAutoConfigurationTests.java new file mode 100644 index 0000000..19a9d93 --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/DozerAutoConfigurationTests.java @@ -0,0 +1,33 @@ +package ml.wonwoo.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import ml.wonwoo.dozer.mapped.DozerMapped; +import org.dozer.DozerBeanMapper; +import org.junit.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +public class DozerAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(DozerAutoConfiguration.class)); + + @Test + public void registersAutomatically() { + runner + .withPropertyValues("mpple.mapper.type=dozer") + .run(context -> { + assertThat(context).hasSingleBean(DozerBeanMapper.class); + assertThat(context).hasSingleBean(DozerMapped.class); + }); + } + + @Test + public void registersAutomaticallyMiss() { + runner + .withPropertyValues("mpple.mapper.type=modelmapper") + .run(context -> assertThat(context).doesNotHaveBean(DozerBeanMapper.class)); + } +} \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfigurationTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfigurationTests.java new file mode 100644 index 0000000..f2de41e --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/ModelMapperAutoConfigurationTests.java @@ -0,0 +1,33 @@ +package ml.wonwoo.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import ml.wonwoo.modelmapper.mapped.ModelMapperMapped; +import org.junit.Test; +import org.modelmapper.ModelMapper; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +public class ModelMapperAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner() + .withConfiguration( + AutoConfigurations.of(ModelMapperAutoConfiguration.class)); + + @Test + public void registersAutomatically() { + runner + .withPropertyValues("mpple.mapper.type=modelmapper") + .run(context -> { + assertThat(context).hasSingleBean(ModelMapper.class); + assertThat(context).hasSingleBean(ModelMapperMapped.class); + }); + } + + @Test + public void registersAutomaticallyMiss() { + runner + .withPropertyValues("mpple.mapper.type=dozer") + .run(context -> assertThat(context).doesNotHaveBean(ModelMapper.class)); + } +} \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/MppleAutoConfigurationTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/MppleAutoConfigurationTests.java deleted file mode 100644 index 326e9a3..0000000 --- a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/MppleAutoConfigurationTests.java +++ /dev/null @@ -1,23 +0,0 @@ -package ml.wonwoo.autoconfigure; - -import static org.assertj.core.api.Assertions.assertThat; - -import ml.wonwoo.autoconfigure.modelmapper.ModelMapperCustomizer; -import org.junit.Test; -import org.modelmapper.ModelMapper; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -public class MppleAutoConfigurationTests { - - private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( - AutoConfigurations.of(MppleAutoConfiguration.class)); - - @Test - public void registersAutomatically() { - contextRunner.run(context -> { - assertThat(context).hasSingleBean(ModelMapper.class); - assertThat(context).getBeanNames(ModelMapperCustomizer.class).hasSize(2); - }); - } -} \ No newline at end of file diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDefaultTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDefaultTests.java new file mode 100644 index 0000000..e604bc6 --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDefaultTests.java @@ -0,0 +1,44 @@ +package ml.wonwoo.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import ml.wonwoo.autoconfigure.model.Foo; +import ml.wonwoo.autoconfigure.model.FooDto; +import ml.wonwoo.autoconfigure.model.FooMapper; +import ml.wonwoo.mapped.DefaultMapped; +import ml.wonwoo.mapped.Mapped; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class SpringBootDefaultTests { + + @Autowired + private FooMapper fooMapper; + + @Test + public void defaultTest() { + Foo foo = new Foo(); + foo.setFirstName("wonwoo"); + foo.setLastName("lee"); + FooDto fooDto = fooMapper.foo(foo); + assertThat(fooDto.getFirstName()).isEqualTo("wonwoo"); + assertThat(fooDto.getLastName()).isEqualTo("lee"); + } + + + @TestConfiguration + static class TestConfig { + + @Bean + public Mapped mapped() { + return new DefaultMapped(); + } + } +} diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDozerTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDozerTests.java new file mode 100644 index 0000000..31c6cd4 --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootDozerTests.java @@ -0,0 +1,31 @@ +package ml.wonwoo.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import ml.wonwoo.autoconfigure.model.Foo; +import ml.wonwoo.autoconfigure.model.FooDto; +import ml.wonwoo.autoconfigure.model.FooMapper; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(properties = "mpple.mapper.type=dozer") +@RunWith(SpringRunner.class) +public class SpringBootDozerTests { + + @Autowired + private FooMapper fooMapper; + + @Test + public void dozerTest() { + Foo foo = new Foo(); + foo.setFirstName("wonwoo"); + foo.setLastName("lee"); + FooDto fooDto = fooMapper.foo(foo); + assertThat(fooDto.getFirstName()).isEqualTo("wonwoo"); + assertThat(fooDto.getLastName()).isEqualTo("lee"); + } +} + diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootPropertyMapTest.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootModelMapperTests.java similarity index 91% rename from mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootPropertyMapTest.java rename to mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootModelMapperTests.java index 9982408..b4ae9ec 100644 --- a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootPropertyMapTest.java +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/SpringBootModelMapperTests.java @@ -14,15 +14,15 @@ import org.springframework.context.annotation.Bean; import org.springframework.test.context.junit4.SpringRunner; -@SpringBootTest +@SpringBootTest(properties = "mpple.mapper.type=modelmapper") @RunWith(SpringRunner.class) -public class SpringBootPropertyMapTest { +public class SpringBootModelMapperTests { @Autowired private FooMapper fooMapper; @Test - public void propertyMappingTest() { + public void modelmapperTest() { Foo foo = new Foo(); foo.setFirstName("wonwoo"); foo.setLastName("lee"); diff --git a/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBeanTests.java b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBeanTests.java new file mode 100644 index 0000000..45caf2b --- /dev/null +++ b/mpple-spring-boot-starter/src/test/java/ml/wonwoo/autoconfigure/dozer/DozerFactoryBeanTests.java @@ -0,0 +1,29 @@ +package ml.wonwoo.autoconfigure.dozer; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collections; +import org.dozer.DozerBeanMapper; +import org.junit.Test; + +public class DozerFactoryBeanTests { + + @Test + public void dozerMapperTest() { + DozerFactoryBean dozerFactoryBean = new DozerFactoryBean(); + DozerBeanMapper dozerBeanMapper = dozerFactoryBean.getObject(); + Class objectType = dozerFactoryBean.getObjectType(); + assertThat(dozerBeanMapper).isNotNull(); + assertThat(objectType).isEqualTo(DozerBeanMapper.class); + } + + @Test + public void dozerMapperCustomizerTest() { + DozerFactoryBean dozerFactoryBean = new DozerFactoryBean(); + dozerFactoryBean.setDozerCustomizers(Collections.singletonList(dozerBeanMapper -> assertThat(dozerBeanMapper).isNotNull())); + DozerBeanMapper dozerBeanMapper = dozerFactoryBean.getObject(); + Class objectType = dozerFactoryBean.getObjectType(); + assertThat(dozerBeanMapper).isNotNull(); + assertThat(objectType).isEqualTo(DozerBeanMapper.class); + } +} \ No newline at end of file