1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration2.builder;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertSame;
21 import static org.mockito.Mockito.mock;
22
23 import java.util.Map;
24
25 import javax.sql.DataSource;
26
27 import org.apache.commons.configuration2.beanutils.BeanHelper;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34 public class TestDatabaseBuilderParametersImpl {
35
36
37 private DatabaseBuilderParametersImpl params;
38
39 @BeforeEach
40 public void setUp() throws Exception {
41 params = new DatabaseBuilderParametersImpl();
42 }
43
44
45
46
47 @Test
48 void testBeanProperties() throws Exception {
49 BeanHelper.setProperty(params, "table", "testTable");
50 BeanHelper.setProperty(params, "autoCommit", Boolean.FALSE);
51 final Map<String, Object> map = params.getParameters();
52 assertEquals("testTable", map.get("table"));
53 assertEquals(Boolean.FALSE, map.get("autoCommit"));
54 }
55
56
57
58
59 @Test
60 void testSetAutoCommit() {
61 assertSame(params, params.setAutoCommit(true));
62 assertEquals(Boolean.TRUE, params.getParameters().get("autoCommit"));
63 }
64
65
66
67
68 @Test
69 void testSetConfigurationName() {
70 final String confName = "TestConfiguration";
71 assertSame(params, params.setConfigurationName(confName));
72 assertEquals(confName, params.getParameters().get("configurationName"));
73 }
74
75
76
77
78 @Test
79 void testSetConfigurationNameColumn() {
80 final String colName = "CONFIG_COLUMN";
81 assertSame(params, params.setConfigurationNameColumn(colName));
82 assertEquals(colName, params.getParameters().get("configurationNameColumn"));
83 }
84
85
86
87
88 @Test
89 void testSetDataSource() {
90 final DataSource src = mock(DataSource.class);
91 assertSame(params, params.setDataSource(src));
92 assertSame(src, params.getParameters().get("dataSource"));
93 }
94
95
96
97
98 @Test
99 void testSetKeyColumn() {
100 final String colName = "KEY_COLUMN";
101 assertSame(params, params.setKeyColumn(colName));
102 assertEquals(colName, params.getParameters().get("keyColumn"));
103 }
104
105
106
107
108 @Test
109 void testSetTable() {
110 final String table = "TestTable";
111 assertSame(params, params.setTable(table));
112 assertEquals(table, params.getParameters().get("table"));
113 }
114
115
116
117
118 @Test
119 void testSetValueColumn() {
120 final String colName = "VALUE_COLUMN";
121 assertSame(params, params.setValueColumn(colName));
122 assertEquals(colName, params.getParameters().get("valueColumn"));
123 }
124 }