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