1. Project Clover database Wed Nov 12 2025 05:07:35 UTC
  2. Package guru.mikelue.foxglove.jdbc

File MetaDataCacheTest.java

 

Code metrics

2
9
5
1
76
60
6
0.67
1.8
5
1.2

Classes

Class Line # Actions
MetaDataCacheTest 23 9 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

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   
 
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   
 
31  3 toggle public MetaDataCacheTest() {}
32   
 
33  3 toggle @BeforeEach
34    void setup() {}
35   
 
36  3 toggle @AfterEach
37    void tearDown() {}
38   
39    /**
40    * Tests the checking of existence of column defined by {@link JdbcTableFacet} on database.
41    */
 
42  3 toggle @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    {
 
53  3 toggle 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    }