| 1 |
|
package guru.mikelue.foxglove.setting; |
| 2 |
|
|
| 3 |
|
import java.sql.JDBCType; |
| 4 |
|
|
| 5 |
|
import org.junit.jupiter.api.AfterEach; |
| 6 |
|
import org.junit.jupiter.api.BeforeEach; |
| 7 |
|
import org.junit.jupiter.api.Test; |
| 8 |
|
import org.junit.jupiter.params.ParameterizedTest; |
| 9 |
|
import org.junit.jupiter.params.provider.Arguments; |
| 10 |
|
import org.junit.jupiter.params.provider.MethodSource; |
| 11 |
|
|
| 12 |
|
import guru.mikelue.misc.testlib.AbstractTestBase; |
| 13 |
|
|
| 14 |
|
import guru.mikelue.foxglove.ColumnMeta; |
| 15 |
|
import guru.mikelue.foxglove.ColumnMeta.Property; |
| 16 |
|
|
| 17 |
|
import static guru.mikelue.foxglove.ColumnMeta.Property.*; |
| 18 |
|
import static guru.mikelue.foxglove.ColumnMetaTestUtils.newColumnMeta; |
| 19 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
| 20 |
|
import static org.assertj.core.api.Assertions.assertThat; |
| 21 |
|
import static org.awaitility.Awaitility.await; |
| 22 |
|
import static org.junit.jupiter.params.provider.Arguments.arguments; |
| 23 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 10 |
Complexity Density: 0.56 |
|
| 24 |
|
public class DataSettingTest extends AbstractTestBase { |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 25 |
11 |
public DataSettingTest() {}... |
| 26 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 27 |
11 |
@BeforeEach... |
| 28 |
|
void setup() {} |
| 29 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 30 |
11 |
@AfterEach... |
| 31 |
|
void tearDown() {} |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
4-
|
|
| 36 |
7 |
@ParameterizedTest... |
| 37 |
|
@MethodSource |
| 38 |
|
void isAutoGenerating( |
| 39 |
|
ColumnMeta sampleColumn, |
| 40 |
|
boolean expectedGenerating |
| 41 |
|
) { |
| 42 |
7 |
var testedSetting = DataSetting.defaults() |
| 43 |
|
.givenType("status") |
| 44 |
|
.useSupplier(() -> "ACTIVE") |
| 45 |
|
.columnMatcher(columnMeta -> |
| 46 |
|
columnMeta.jdbcType() == JDBCType.ARRAY |
| 47 |
|
) |
| 48 |
|
.decideSupplier(columnMeta -> () -> new Object[0]) |
| 49 |
|
.excludeWhen(columnMeta -> |
| 50 |
|
columnMeta.name().startsWith("audit_") |
| 51 |
|
); |
| 52 |
|
|
| 53 |
7 |
assertThat(testedSetting.isAutoGenerating(sampleColumn)) |
| 54 |
|
.isEqualTo(expectedGenerating); |
| 55 |
|
} |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 56 |
1 |
static Arguments[] isAutoGenerating()... |
| 57 |
|
{ |
| 58 |
1 |
return new Arguments[] { |
| 59 |
|
|
| 60 |
|
arguments(newColumnMeta("audit_not1"), false), |
| 61 |
|
|
| 62 |
|
arguments(sampleColumn(JDBCType.ARRAY, GENERATED), true), |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
arguments(sampleColumn(AUTO_INCREMENT), false), |
| 67 |
|
arguments(sampleColumn(GENERATED), false), |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
arguments(sampleColumn(JDBCType.VARCHAR, NULLABLE), true), |
| 71 |
|
|
| 72 |
|
arguments(newColumnMeta("status", NULLABLE), true), |
| 73 |
|
|
| 74 |
|
arguments(sampleColumn(JDBCType.ROWID, GENERATED), false) |
| 75 |
|
}; |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
4-
|
|
| 81 |
3 |
@ParameterizedTest... |
| 82 |
|
@MethodSource |
| 83 |
|
void resolveSupplier( |
| 84 |
|
ColumnMeta sampleColumnMeta, |
| 85 |
|
String expectedValue |
| 86 |
|
) |
| 87 |
|
{ |
| 88 |
3 |
var testedSetting = new DataSetting(); |
| 89 |
|
|
| 90 |
3 |
testedSetting.givenType(JDBCType.VARCHAR) |
| 91 |
|
.useSupplier(() -> "test-string-1"); |
| 92 |
3 |
testedSetting.givenType(JDBCType.OTHER) |
| 93 |
|
.useSupplier(() -> "test-string-error"); |
| 94 |
|
|
| 95 |
3 |
testedSetting.givenType("LINT CHAR") |
| 96 |
|
.useSupplier(() -> "test-string-2"); |
| 97 |
|
|
| 98 |
3 |
testedSetting.columnMatcher(c -> c.name().equals("cl_special")) |
| 99 |
|
.useSupplier(() -> "test-string-3"); |
| 100 |
|
|
| 101 |
3 |
var testedSupplier = testedSetting.resolveSupplier(sampleColumnMeta) |
| 102 |
|
.get(); |
| 103 |
|
|
| 104 |
3 |
assertThat(testedSupplier.get()) |
| 105 |
|
.isEqualTo(expectedValue); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 108 |
1 |
static Arguments[] resolveSupplier()... |
| 109 |
|
{ |
| 110 |
1 |
return new Arguments[] { |
| 111 |
|
arguments( |
| 112 |
|
newColumnMeta("cl_special", JDBCType.OTHER), |
| 113 |
|
"test-string-3" |
| 114 |
|
), |
| 115 |
|
arguments( |
| 116 |
|
newColumnMeta("cl_diff", "LINT CHAR", JDBCType.OTHER), |
| 117 |
|
"test-string-2" |
| 118 |
|
), |
| 119 |
|
arguments( |
| 120 |
|
newColumnMeta("cl_another", JDBCType.VARCHAR), |
| 121 |
|
"test-string-1" |
| 122 |
|
), |
| 123 |
|
}; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
4-
|
|
| 129 |
1 |
@Test... |
| 130 |
|
void generateNullable() |
| 131 |
|
{ |
| 132 |
1 |
var testedSetting = new DataSetting() |
| 133 |
|
.givenType(JDBCType.VARCHAR) |
| 134 |
|
.useSupplier(() -> "not-null-value") |
| 135 |
|
.generateNull(2); |
| 136 |
|
|
| 137 |
1 |
var sampleColumn = sampleColumn(NULLABLE); |
| 138 |
|
|
| 139 |
1 |
var supplier = testedSetting.resolveSupplier(sampleColumn) |
| 140 |
|
.get(); |
| 141 |
|
|
| 142 |
1 |
await() |
| 143 |
|
.atMost(5, SECONDS) |
| 144 |
|
.untilAsserted(() -> { |
| 145 |
1 |
assertThat(supplier.get()) |
| 146 |
|
.isNull(); |
| 147 |
|
}); |
| 148 |
|
} |
| 149 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 150 |
3 |
private static ColumnMeta sampleColumn(Property... properties)... |
| 151 |
|
{ |
| 152 |
3 |
return newColumnMeta("any_column", JDBCType.VARCHAR, properties); |
| 153 |
|
} |
| 154 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 155 |
3 |
private static ColumnMeta sampleColumn(JDBCType jdbcType, Property... properties)... |
| 156 |
|
{ |
| 157 |
3 |
return newColumnMeta("any_column", jdbcType, properties); |
| 158 |
|
} |
| 159 |
|
} |