1 |
|
package org.europa.together.application; |
2 |
|
|
3 |
|
import static com.google.code.beanmatchers.BeanMatchers.*; |
4 |
|
import java.sql.ResultSet; |
5 |
|
import org.europa.together.JUnit5Preperator; |
6 |
|
import org.europa.together.business.DatabaseActions; |
7 |
|
import org.europa.together.business.Logger; |
8 |
|
import org.europa.together.domain.JdbcConnection; |
9 |
|
import org.europa.together.domain.LogLevel; |
10 |
|
import org.europa.together.utils.Constraints; |
11 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
12 |
|
import org.junit.jupiter.api.AfterAll; |
13 |
|
import org.junit.jupiter.api.AfterEach; |
14 |
|
import static org.junit.jupiter.api.Assertions.*; |
15 |
|
import org.junit.jupiter.api.Assumptions; |
16 |
|
import org.junit.jupiter.api.BeforeAll; |
17 |
|
import org.junit.jupiter.api.BeforeEach; |
18 |
|
import org.junit.jupiter.api.Test; |
19 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
20 |
|
import org.springframework.test.context.ContextConfiguration; |
21 |
|
import org.springframework.test.context.junit.jupiter.SpringExtension; |
22 |
|
|
23 |
|
@SuppressWarnings("unchecked") |
24 |
|
@ExtendWith({JUnit5Preperator.class}) |
25 |
|
@ExtendWith(SpringExtension.class) |
26 |
|
@ContextConfiguration(locations = {"/applicationContext.xml"}) |
|
|
| 100% |
Uncovered Elements: 0 (75) |
Complexity: 16 |
Complexity Density: 0.27 |
|
27 |
|
public class JdbcActionsTest { |
28 |
|
|
29 |
|
private static final Logger LOGGER = new LogbackLogger(JdbcActionsTest.class); |
30 |
|
|
31 |
|
private final String sql_create |
32 |
|
= "CREATE TABLE IF NOT EXISTS test (column_01 int, column_02 char(255));"; |
33 |
|
private final String sql_drop = "DROP TABLE IF EXISTS test;"; |
34 |
|
|
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
36 |
1 |
@BeforeAll... |
37 |
|
static void setUp() { |
38 |
1 |
Assumptions.assumeTrue(true); |
39 |
|
|
40 |
1 |
LOGGER.log("Assumptions passed ...\n\n", LogLevel.DEBUG); |
41 |
|
} |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
1 |
@AfterAll... |
44 |
|
static void tearDown() { |
45 |
1 |
LOGGER.log("### TEST SUITE TERMINATED.\n", LogLevel.TRACE); |
46 |
|
} |
47 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
48 |
12 |
@BeforeEach... |
49 |
|
void testCaseInitialization() { |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
12 |
@AfterEach... |
53 |
|
void testCaseTermination() { |
54 |
12 |
LOGGER.log("TEST CASE TERMINATED.", LogLevel.TRACE); |
55 |
|
} |
56 |
|
|
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
58 |
1 |
@Test... |
59 |
|
void constructor() { |
60 |
1 |
LOGGER.log("TEST CASE: constructor", LogLevel.DEBUG); |
61 |
|
|
62 |
1 |
assertThat(JdbcActions.class, hasValidBeanConstructor()); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
65 |
1 |
@Test... |
66 |
|
void connect() { |
67 |
1 |
LOGGER.log("TEST CASE: connect", LogLevel.DEBUG); |
68 |
|
|
69 |
1 |
DatabaseActions dbms = new JdbcActions(); |
70 |
1 |
assertTrue(dbms.connect("test")); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
void failConnect() { |
75 |
1 |
LOGGER.log("TEST CASE: failConnect", LogLevel.DEBUG); |
76 |
|
|
77 |
1 |
DatabaseActions dbms = new JdbcActions(); |
78 |
1 |
assertFalse(dbms.connect(Constraints.SYSTEM_APP_DIR |
79 |
|
+ "/target/test-classes/" |
80 |
|
+ "org/europa/together/properties/jdbc-test-fail.properties")); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
void fallbackLoadProperties() { |
85 |
1 |
LOGGER.log("TEST CASE: fallbackLoadProperties", LogLevel.DEBUG); |
86 |
|
|
87 |
1 |
DatabaseActions dbms = new JdbcActions(); |
88 |
1 |
assertTrue(dbms.connect(null)); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
void executeQuery() throws Exception { |
93 |
1 |
LOGGER.log("TEST CASE: executeQuery", LogLevel.DEBUG); |
94 |
|
|
95 |
1 |
DatabaseActions dbms = new JdbcActions(); |
96 |
1 |
dbms.connect("test"); |
97 |
|
|
98 |
1 |
assertNull(dbms.executeQuery(sql_drop)); |
99 |
1 |
assertNull(dbms.executeQuery(sql_create)); |
100 |
1 |
dbms.executeQuery(sql_drop); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
103 |
1 |
@Test... |
104 |
|
void failExecuteQuery() throws Exception { |
105 |
1 |
LOGGER.log("TEST CASE: failExecuteQuery", LogLevel.DEBUG); |
106 |
|
|
107 |
1 |
DatabaseActions dbms = new JdbcActions(); |
108 |
1 |
dbms.connect("test"); |
109 |
1 |
assertThrows(Exception.class, () -> { |
110 |
1 |
dbms.executeQuery("SELECT * FROM foo;"); |
111 |
|
}); |
112 |
|
} |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
void failExecuteQueryNoConnection() throws Exception { |
116 |
1 |
LOGGER.log("TEST CASE: failExecuteQuery", LogLevel.DEBUG); |
117 |
|
|
118 |
1 |
DatabaseActions dbms = new JdbcActions(); |
119 |
1 |
assertNull(dbms.executeQuery("SELECT * FROM foo;")); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
void executeSqlFileFromClasspath() throws Exception { |
124 |
1 |
LOGGER.log("TEST CASE: executeSqlFileFromClasspath", LogLevel.DEBUG); |
125 |
|
|
126 |
1 |
DatabaseActions dbms = new JdbcActions(); |
127 |
1 |
dbms.connect("test"); |
128 |
1 |
dbms.executeQuery(sql_drop); |
129 |
1 |
String file = "org/europa/together/sql/test.sql"; |
130 |
1 |
assertTrue(dbms.executeSqlFromClasspath(file)); |
131 |
1 |
dbms.executeQuery(sql_drop); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
134 |
1 |
@Test... |
135 |
|
void sqlFileNotFound() { |
136 |
1 |
LOGGER.log("TEST CASE: sqlFileNotFound", LogLevel.DEBUG); |
137 |
|
|
138 |
1 |
DatabaseActions dbms = new JdbcActions(); |
139 |
1 |
dbms.connect("test"); |
140 |
1 |
String file = "org/europa/together/sql/file-not-exist.sql"; |
141 |
1 |
assertFalse(dbms.executeSqlFromClasspath(file)); |
142 |
|
} |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
144 |
1 |
@Test... |
145 |
|
void getResultSet() throws Exception { |
146 |
1 |
LOGGER.log("TEST CASE: getResultSet", LogLevel.DEBUG); |
147 |
|
|
148 |
1 |
String SQL_FILE |
149 |
|
= "org/europa/together/sql/test.sql"; |
150 |
1 |
DatabaseActions dbms = new JdbcActions(); |
151 |
1 |
dbms.connect("test"); |
152 |
|
|
153 |
1 |
assertTrue(dbms.executeSqlFromClasspath(SQL_FILE)); |
154 |
|
|
155 |
1 |
ResultSet results = dbms.executeQuery("SELECT * FROM test;"); |
156 |
1 |
assertEquals(1, dbms.countResultSets(results)); |
157 |
|
|
158 |
1 |
dbms.executeQuery(sql_drop); |
159 |
|
} |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
161 |
1 |
@Test... |
162 |
|
void getJdbcMetaData() throws Exception { |
163 |
1 |
LOGGER.log("TEST CASE: getJdbcMetaData", LogLevel.DEBUG); |
164 |
|
|
165 |
1 |
DatabaseActions dbms = new JdbcActions(); |
166 |
1 |
dbms.connect("test"); |
167 |
1 |
JdbcConnection metaData = dbms.getJdbcMetaData(); |
168 |
1 |
LOGGER.log(metaData.toString(), LogLevel.DEBUG); |
169 |
1 |
assertNotNull(metaData); |
170 |
|
} |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
172 |
1 |
@Test... |
173 |
|
void failGetJdbcMetaData() throws Exception { |
174 |
1 |
LOGGER.log("TEST CASE: failGetJdbcMetaData", LogLevel.DEBUG); |
175 |
|
|
176 |
1 |
DatabaseActions dbms = new JdbcActions(); |
177 |
1 |
assertThrows(Exception.class, () -> { |
178 |
1 |
dbms.getJdbcMetaData(); |
179 |
|
}); |
180 |
|
} |
181 |
|
} |