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 private DatabaseBuilderParametersImpl params;
37
38 @BeforeEach
39 public void setUp() throws Exception {
40 params = new DatabaseBuilderParametersImpl();
41 }
42
43
44
45
46 @Test
47 public void testBeanProperties() throws Exception {
48 BeanHelper.setProperty(params, "table", "testTable");
49 BeanHelper.setProperty(params, "autoCommit", Boolean.FALSE);
50 final Map<String, Object> map = params.getParameters();
51 assertEquals("testTable", map.get("table"));
52 assertEquals(Boolean.FALSE, map.get("autoCommit"));
53 }
54
55
56
57
58 @Test
59 public void testSetAutoCommit() {
60 assertSame(params, params.setAutoCommit(true));
61 assertEquals(Boolean.TRUE, params.getParameters().get("autoCommit"));
62 }
63
64
65
66
67 @Test
68 public void testSetConfigurationName() {
69 final String confName = "TestConfiguration";
70 assertSame(params, params.setConfigurationName(confName));
71 assertEquals(confName, params.getParameters().get("configurationName"));
72 }
73
74
75
76
77 @Test
78 public void testSetConfigurationNameColumn() {
79 final String colName = "CONFIG_COLUMN";
80 assertSame(params, params.setConfigurationNameColumn(colName));
81 assertEquals(colName, params.getParameters().get("configurationNameColumn"));
82 }
83
84
85
86
87 @Test
88 public void testSetDataSource() {
89 final DataSource src = mock(DataSource.class);
90 assertSame(params, params.setDataSource(src));
91 assertSame(src, params.getParameters().get("dataSource"));
92 }
93
94
95
96
97 @Test
98 public void testSetKeyColumn() {
99 final String colName = "KEY_COLUMN";
100 assertSame(params, params.setKeyColumn(colName));
101 assertEquals(colName, params.getParameters().get("keyColumn"));
102 }
103
104
105
106
107 @Test
108 public void testSetTable() {
109 final String table = "TestTable";
110 assertSame(params, params.setTable(table));
111 assertEquals(table, params.getParameters().get("table"));
112 }
113
114
115
116
117 @Test
118 public void testSetValueColumn() {
119 final String colName = "VALUE_COLUMN";
120 assertSame(params, params.setValueColumn(colName));
121 assertEquals(colName, params.getParameters().get("valueColumn"));
122 }
123 }