| 1 |
|
package guru.mikelue.foxglove.jdbc; |
| 2 |
|
|
| 3 |
|
import java.sql.Connection; |
| 4 |
|
import java.sql.DatabaseMetaData; |
| 5 |
|
import java.sql.JDBCType; |
| 6 |
|
import java.sql.SQLException; |
| 7 |
|
import java.util.List; |
| 8 |
|
|
| 9 |
|
import org.junit.jupiter.api.AfterEach; |
| 10 |
|
import org.junit.jupiter.api.BeforeEach; |
| 11 |
|
import org.junit.jupiter.params.ParameterizedTest; |
| 12 |
|
import org.junit.jupiter.params.provider.CsvSource; |
| 13 |
|
|
| 14 |
|
import guru.mikelue.misc.testlib.AbstractTestBase; |
| 15 |
|
|
| 16 |
|
import mockit.Expectations; |
| 17 |
|
import mockit.Mocked; |
| 18 |
|
|
| 19 |
|
import static guru.mikelue.foxglove.ColumnMetaTestUtils.newColumnMeta; |
| 20 |
|
import static org.assertj.core.api.Assertions.assertThatNoException; |
| 21 |
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 22 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 6 |
Complexity Density: 0.67 |
|
| 23 |
|
public class MetaDataCacheTest extends AbstractTestBase { |
| 24 |
|
private final static String TEST_TABLE = "ap_table"; |
| 25 |
|
|
| 26 |
|
@Mocked |
| 27 |
|
private Connection mockConn; |
| 28 |
|
@Mocked |
| 29 |
|
private MetaUtils mockMetaUtils; |
| 30 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 31 |
3 |
public MetaDataCacheTest() {}... |
| 32 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 33 |
3 |
@BeforeEach... |
| 34 |
|
void setup() {} |
| 35 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 36 |
3 |
@AfterEach... |
| 37 |
|
void tearDown() {} |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@link |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
4-
|
|
| 42 |
3 |
@ParameterizedTest... |
| 43 |
|
@CsvSource({ |
| 44 |
|
"col_existing,col_existing,true", |
| 45 |
|
"col_existing,COL_EXISTING,true", |
| 46 |
|
"col_not_existing,col_existing,false" |
| 47 |
|
}) |
| 48 |
|
void existingOnDatabase( |
| 49 |
|
String columnName, String metaColumName, |
| 50 |
|
boolean expectedExistence |
| 51 |
|
) throws SQLException |
| 52 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 53 |
3 |
new Expectations() {{... |
| 54 |
3 |
MetaUtils.getColumnMetaList((DatabaseMetaData)any, TEST_TABLE); |
| 55 |
3 |
result = List.of(newColumnMeta( |
| 56 |
|
metaColumName, JDBCType.VARCHAR |
| 57 |
|
)); |
| 58 |
|
}}; |
| 59 |
|
|
| 60 |
3 |
var testedMeta = new MetaDataCache(mockConn); |
| 61 |
3 |
var sampleTable = JdbcTableFacet.builder(TEST_TABLE) |
| 62 |
|
.includeColumns(columnName) |
| 63 |
|
.build(); |
| 64 |
|
|
| 65 |
3 |
if (expectedExistence) { |
| 66 |
2 |
testedMeta.loadMetadata(List.of(sampleTable), mockConn); |
| 67 |
2 |
assertThatNoException(); |
| 68 |
|
} else { |
| 69 |
1 |
assertThatThrownBy(() -> |
| 70 |
|
testedMeta.loadMetadata(List.of(sampleTable), mockConn) |
| 71 |
|
) |
| 72 |
|
.isInstanceOf(IllegalArgumentException.class) |
| 73 |
|
.hasMessageContaining(columnName); |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
|
} |