File tree 3 files changed +48
-7
lines changed
mybatis-spring-boot-test-autoconfigure/src
main/java/org/mybatis/spring/boot/test/autoconfigure
test/java/org/mybatis/spring/boot/test/autoconfigure
3 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 31
31
import org .springframework .boot .test .autoconfigure .filter .TypeExcludeFilters ;
32
32
import org .springframework .boot .test .autoconfigure .jdbc .AutoConfigureTestDatabase ;
33
33
import org .springframework .boot .test .context .SpringBootTest ;
34
- import org .springframework .boot .test .context .SpringBootTestContextBootstrapper ;
35
34
import org .springframework .context .annotation .ComponentScan .Filter ;
36
35
import org .springframework .core .annotation .AliasFor ;
36
+ import org .springframework .core .env .Environment ;
37
37
import org .springframework .test .context .BootstrapWith ;
38
38
import org .springframework .test .context .junit .jupiter .SpringExtension ;
39
39
import org .springframework .transaction .annotation .Transactional ;
63
63
@ Retention (RetentionPolicy .RUNTIME )
64
64
@ Documented
65
65
@ Inherited
66
- @ BootstrapWith (SpringBootTestContextBootstrapper .class )
66
+ @ BootstrapWith (MybatisTestContextBootstrapper .class )
67
67
@ ExtendWith (SpringExtension .class )
68
68
@ OverrideAutoConfiguration (enabled = false )
69
69
@ TypeExcludeFilters (MybatisTypeExcludeFilter .class )
74
74
@ ImportAutoConfiguration
75
75
public @interface MybatisTest {
76
76
77
+ /**
78
+ * Properties in form {@literal key=value} that should be added to the Spring {@link Environment} before the test
79
+ * runs.
80
+ *
81
+ * @return the properties to add
82
+ * @since 2.1.0
83
+ */
84
+ String [] properties () default {};
85
+
77
86
/**
78
87
* Determines if default filtering should be used with {@link SpringBootApplication @SpringBootApplication}. By
79
88
* default no beans are included.
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright 2015-2019 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .mybatis .spring .boot .test .autoconfigure ;
17
+
18
+ import org .springframework .boot .test .context .SpringBootTestContextBootstrapper ;
19
+ import org .springframework .core .annotation .AnnotatedElementUtils ;
20
+ import org .springframework .test .context .TestContextBootstrapper ;
21
+
22
+ /**
23
+ * {@link TestContextBootstrapper} for {@link MybatisTest @MybatisTest} support.
24
+ *
25
+ * @author Kazuki Shimizu
26
+ * @since 2.1.0
27
+ */
28
+ class MybatisTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29
+
30
+ @ Override
31
+ protected String [] getProperties (Class <?> testClass ) {
32
+ MybatisTest annotation = AnnotatedElementUtils .getMergedAnnotation (testClass , MybatisTest .class );
33
+ return (annotation != null ) ? annotation .properties () : null ;
34
+ }
35
+
36
+ }
Original file line number Diff line number Diff line change 23
23
import org .apache .ibatis .session .SqlSession ;
24
24
import org .junit .jupiter .api .Assertions ;
25
25
import org .junit .jupiter .api .Test ;
26
- import org .junit .jupiter .api .extension .ExtendWith ;
27
26
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
28
27
import org .springframework .beans .factory .annotation .Autowired ;
29
28
import org .springframework .cache .CacheManager ;
32
31
import org .springframework .jdbc .core .JdbcTemplate ;
33
32
import org .springframework .jdbc .core .namedparam .NamedParameterJdbcTemplate ;
34
33
import org .springframework .jdbc .datasource .DataSourceTransactionManager ;
35
- import org .springframework .test .context .TestPropertySource ;
36
- import org .springframework .test .context .junit .jupiter .SpringExtension ;
37
34
import org .springframework .transaction .interceptor .TransactionInterceptor ;
38
35
39
36
/**
42
39
* @author wonwoo
43
40
* @since 1.2.1
44
41
*/
45
- @ MybatisTest
46
- @ TestPropertySource (properties = { "mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure" ,
42
+ @ MybatisTest (properties = { "mybatis.type-aliases-package=org.mybatis.spring.boot.test.autoconfigure" ,
47
43
"logging.level.org.springframework.jdbc=debug" ,
48
44
"spring.datasource.schema=classpath:org/mybatis/spring/boot/test/autoconfigure/schema.sql" })
49
45
class MybatisTestIntegrationTest {
You can’t perform that action at this time.
0 commit comments