View Javadoc
1   /*
2    *    Copyright 2015-2022 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    *       https://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.autoconfigure;
17  
18  import static org.assertj.core.api.Assertions.assertThat;
19  import static org.junit.jupiter.api.Assertions.assertAll;
20  
21  import com.jayway.jsonpath.DocumentContext;
22  import com.jayway.jsonpath.JsonPath;
23  
24  import java.io.IOException;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.junit.jupiter.api.Test;
29  import org.springframework.core.io.FileSystemResource;
30  
31  /**
32   * Tests for definition of additional-spring-configuration-metadata.json.
33   *
34   * @author Kazuki Shimizu
35   *
36   * @since 1.3.1
37   */
38  class AdditionalConfigurationMetadataTest {
39  
40    @Test
41    void testProperties() throws IOException {
42  
43      DocumentContext documentContext = JsonPath
44          .parse(new FileSystemResource("src/main/resources/META-INF/additional-spring-configuration-metadata.json")
45              .getInputStream());
46  
47      List<Map<String, Object>> properties = documentContext.read("$.properties");
48  
49      assertAll(() -> assertThat(properties.size()).isEqualTo(4), () -> {
50        // assert for mybatis.lazy-initialization
51        Map<String, Object> element = properties.get(0);
52        assertThat(element.get("defaultValue")).isEqualTo(false);
53        assertThat(element.get("name")).isEqualTo("mybatis.lazy-initialization");
54        assertThat(element.get("type")).isEqualTo("java.lang.Boolean");
55      }, () -> {
56        // assert for mybatis.mapper-default-scope
57        Map<String, Object> element = properties.get(1);
58        assertThat(element.get("defaultValue")).isEqualTo("");
59        assertThat(element.get("name")).isEqualTo("mybatis.mapper-default-scope");
60        assertThat(element.get("type")).isEqualTo("java.lang.String");
61      }, () -> {
62        // assert for mybatis.inject-sql-session-on-mapper-scan
63        Map<String, Object> element = properties.get(2);
64        assertThat(element.get("defaultValue")).isEqualTo(true);
65        assertThat(element.get("name")).isEqualTo("mybatis.inject-sql-session-on-mapper-scan");
66        assertThat(element.get("type")).isEqualTo("java.lang.Boolean");
67      }, () -> {
68        // assert for mybatis.scripting-language-driver.velocity.userdirective
69        Map<String, Object> element = properties.get(3);
70        assertThat(element.get("name")).isEqualTo("mybatis.scripting-language-driver.velocity.userdirective");
71        @SuppressWarnings("unchecked")
72        Map<String, Object> deprecation = (Map<String, Object>) element.get("deprecation");
73        assertThat(deprecation.get("level")).isEqualTo("error");
74        assertThat(deprecation.get("reason")).isEqualTo(
75            "The 'userdirective' is deprecated since Velocity 2.x. This property defined for keeping backward compatibility with older velocity version.");
76        assertThat(deprecation.get("replacement"))
77            .isEqualTo("mybatis.scripting-language-driver.velocity.velocity-settings.runtime.custom_directives");
78      });
79    }
80  }