View Javadoc
1   package net.rakugakibox.spring.boot.orika;
2   
3   import java.util.Optional;
4   
5   import ma.glasnost.orika.MapperFacade;
6   import ma.glasnost.orika.MapperFactory;
7   import ma.glasnost.orika.impl.DefaultMapperFactory.MapperFactoryBuilder;
8   import org.junit.Test;
9   import org.junit.runner.RunWith;
10  import org.springframework.beans.factory.annotation.Autowired;
11  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
12  import org.springframework.boot.test.context.SpringBootTest;
13  import org.springframework.context.annotation.Configuration;
14  import org.springframework.test.context.junit4.SpringRunner;
15  import static org.assertj.core.api.Assertions.assertThat;
16  
17  /**
18   * The test of {@link OrikaAutoConfiguration}.
19   */
20  @RunWith(SpringRunner.class)
21  @SpringBootTest
22  public class OrikaAutoConfigurationTest {
23  
24      /**
25       * The configuration properties for Orika.
26       */
27      @Autowired
28      protected Optional<OrikaProperties> orikaProperties;
29  
30      /**
31       * The {@link MapperFactoryBuilder}.
32       */
33      @Autowired
34      protected Optional<MapperFactoryBuilder<?, ?>> orikaMapperFactoryBuilder;
35  
36      /**
37       * The {@link MapperFactory}.
38       */
39      @Autowired
40      protected Optional<MapperFactory> orikaMapperFactory;
41  
42      /**
43       * The {@link MapperFacade}.
44       */
45      @Autowired
46      protected Optional<MapperFacade> orikaMapperFacade;
47  
48      /**
49       * Tests the configuration properties for Orika.
50       */
51      @Test
52      public void orikaProperties() {
53          assertThat(orikaProperties).isPresent();
54      }
55  
56      /**
57       * Tests the {@link MapperFactoryBuilder}.
58       */
59      @Test
60      public void orikaMapperFactoryBuilder() {
61          assertThat(orikaMapperFactoryBuilder)
62                  .isPresent()
63                  .hasValueSatisfying(value ->
64                      assertThat(value)
65                              .hasFieldOrPropertyWithValue("useBuiltinConverters", true)
66                              .hasFieldOrPropertyWithValue("useAutoMapping", true)
67                              .hasFieldOrPropertyWithValue("mapNulls", true)
68                              .hasFieldOrPropertyWithValue("dumpStateOnException", false)
69                              .hasFieldOrPropertyWithValue("favorExtension", false)
70                              .hasFieldOrPropertyWithValue("captureFieldContext", false)
71                  );
72      }
73  
74      /**
75       * Tests the {@link MapperFactory}.
76       */
77      @Test
78      public void orikaMapperFactory() {
79          assertThat(orikaMapperFactory).isPresent();
80      }
81  
82      /**
83       * Tests the {@link MapperFacade}.
84       */
85      @Test
86      public void orikaMapperFacade() {
87          assertThat(orikaMapperFacade).isPresent();
88      }
89  
90      /**
91       * The context configuration.
92       */
93      @EnableAutoConfiguration
94      @Configuration
95      public static class ContextConfiguration {
96      }
97  
98  }