1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.configuration;
17
18 import static org.assertj.core.api.Assertions.assertThat;
19 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23
24 import org.junit.jupiter.api.Test;
25 import org.mybatis.dynamic.sql.exception.DynamicSqlException;
26 import org.mybatis.dynamic.sql.util.Messages;
27
28 class GlobalConfigurationTest {
29 @Test
30 void testAlternateConfigurationFileChangesDefaults() {
31 System.setProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY, "defaultTrue.properties");
32 GlobalConfiguration configuration = new GlobalConfiguration();
33 System.clearProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY);
34
35 assertThat(configuration.isIsNonRenderingWhereClauseAllowed()).isTrue();
36 }
37
38 @Test
39 void testMissingPropertyUsesDefaults() {
40 System.setProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY, "empty.properties");
41 GlobalConfiguration configuration = new GlobalConfiguration();
42 System.clearProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY);
43
44 assertThat(configuration.isIsNonRenderingWhereClauseAllowed()).isFalse();
45 }
46
47 @Test
48 void testMissingPropertyFileUsesDefaults() {
49 System.setProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY, "apfbsglf.properties");
50 GlobalConfiguration configuration = new GlobalConfiguration();
51 System.clearProperty(GlobalConfiguration.CONFIGURATION_FILE_PROPERTY);
52
53 assertThat(configuration.isIsNonRenderingWhereClauseAllowed()).isFalse();
54 }
55
56 @Test
57 void testBadPropertyFile() throws IOException {
58 GlobalConfiguration configuration = new GlobalConfiguration();
59 InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("empty.properties");
60 assert inputStream != null;
61 inputStream.close();
62
63 assertThatExceptionOfType(DynamicSqlException.class)
64 .isThrownBy(() -> configuration.loadProperties(inputStream, "empty.properties"))
65 .withMessage(Messages.getString("ERROR.3", "empty.properties"))
66 .withCauseInstanceOf(IOException.class);
67 }
68 }