| 1 |
|
package guru.mikelue.foxglove.examples; |
| 2 |
|
|
| 3 |
|
import org.junit.jupiter.api.AfterEach; |
| 4 |
|
import org.junit.jupiter.api.BeforeEach; |
| 5 |
|
import org.junit.jupiter.api.Test; |
| 6 |
|
import org.junit.jupiter.api.extension.ExtendWith; |
| 7 |
|
|
| 8 |
|
import guru.mikelue.foxglove.DataGenerator; |
| 9 |
|
import guru.mikelue.foxglove.TableFacet; |
| 10 |
|
import guru.mikelue.foxglove.annotation.DataGeneratorSource; |
| 11 |
|
import guru.mikelue.foxglove.annotation.GenData; |
| 12 |
|
import guru.mikelue.foxglove.annotation.TableFacetsSource; |
| 13 |
|
import guru.mikelue.foxglove.jdbc.JdbcDataGenerator; |
| 14 |
|
import guru.mikelue.foxglove.jdbc.JdbcTableFacet; |
| 15 |
|
import guru.mikelue.foxglove.junit.FoxgloveJUnitExtension; |
| 16 |
|
import guru.mikelue.foxglove.test.AbstractJdbcTestBase; |
| 17 |
|
|
| 18 |
|
import static guru.mikelue.foxglove.test.SampleSchema.TABLE_CAR; |
| 19 |
|
import static guru.mikelue.foxglove.test.SampleSchema.TABLE_CAR_FEATURE; |
| 20 |
|
import static org.assertj.core.api.Assertions.assertThat; |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
@ExtendWith(FoxgloveJUnitExtension.class) |
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 6 |
Complexity Density: 0.75 |
|
| 24 |
|
public class JUnit5Test extends AbstractJdbcTestBase { |
| 25 |
|
private final static int RANDOM_ROWS = gen().ints().range(5, 10).get(); |
| 26 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 27 |
1 |
public JUnit5Test() {}... |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 32 |
1 |
@Test... |
| 33 |
|
@GenData(facetsNames = { "carsWithFeature" }) |
| 34 |
|
void junit5Method() |
| 35 |
|
{ |
| 36 |
1 |
int testedCount = getJdbcTemplate().query( |
| 37 |
|
"""
SELECT COUNT(DISTINCT cr_id)
FROM ap_car
INNER JOIN
ap_car_feature
ON cr_id = cf_cr_id
AND cf_feature_name = 'Sunroof'
""", |
| 38 |
|
rs -> { |
| 39 |
|
rs.next(); |
| 40 |
|
return rs.getInt(1); |
| 41 |
|
} |
| 42 |
|
); |
| 43 |
|
|
| 44 |
|
assertThat(testedCount) |
| 45 |
1 |
.isEqualTo(RANDOM_ROWS); |
| 46 |
1 |
} |
| 47 |
|
|
| 48 |
|
@TableFacetsSource |
| 49 |
|
TableFacet[] carsWithFeature() |
| 50 |
1 |
{ |
| 51 |
|
var carFacet = JdbcTableFacet.builder(TABLE_CAR) |
| 52 |
|
.numberOfRows(RANDOM_ROWS) |
| 53 |
|
.build(); |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
1 |
... |
| 55 |
|
return new TableFacet[] { |
| 56 |
|
carFacet, |
| 57 |
1 |
JdbcTableFacet.builder(TABLE_CAR_FEATURE) |
| 58 |
|
.referencing("cf_cr_id") |
| 59 |
|
.parent(carFacet, "cr_id") |
| 60 |
|
.cardinality(2) |
| 61 |
1 |
.column("cf_feature_name") |
| 62 |
|
.roundRobin("Sunroof", "Leather Seats") |
| 63 |
|
.build() |
| 64 |
|
}; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@DataGeneratorSource |
| 71 |
|
DataGenerator<?> defaultDataGenerator() |
| 72 |
|
{ |
| 73 |
|
return new JdbcDataGenerator(getDataSource()); |
| 74 |
|
} |
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
1 |
@BeforeEach... |
| 77 |
|
void setup() {} |
| 78 |
|
|
| 79 |
1 |
@AfterEach |
| 80 |
|
void tearDown() |
| 81 |
|
{ |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 82 |
1 |
deleteAll(TABLE_CAR);... |
| 83 |
|
} |
| 84 |
|
} |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 85 |
1 |
... |