| 1 |
|
package guru.mikelue.foxglove.jdbc; |
| 2 |
|
|
| 3 |
|
import java.util.function.Consumer; |
| 4 |
|
import java.util.function.Supplier; |
| 5 |
|
import java.util.stream.IntStream; |
| 6 |
|
|
| 7 |
|
import org.apache.commons.lang3.mutable.MutableObject; |
| 8 |
|
import org.junit.jupiter.api.AfterEach; |
| 9 |
|
import org.junit.jupiter.api.BeforeEach; |
| 10 |
|
import org.junit.jupiter.api.Test; |
| 11 |
|
|
| 12 |
|
import guru.mikelue.misc.testlib.AbstractTestBase; |
| 13 |
|
|
| 14 |
|
import static org.assertj.core.api.Assertions.assertThat; |
| 15 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 7 |
Complexity Density: 0.32 |
|
| 16 |
|
public class ColumnFromStepImplTest extends AbstractTestBase { |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 17 |
3 |
public ColumnFromStepImplTest() {}... |
| 18 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 19 |
3 |
@BeforeEach... |
| 20 |
|
void setup() {} |
| 21 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 22 |
3 |
@AfterEach... |
| 23 |
|
void tearDown() {} |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 28 |
1 |
@Test... |
| 29 |
|
void roundRobin() |
| 30 |
|
{ |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
1 |
var supplierHolder = new MutableObject<Supplier<?>>(); |
| 35 |
1 |
var parentTable = prepareStep( |
| 36 |
|
"pt_source", supplierHolder, |
| 37 |
|
step -> step.roundRobin() |
| 38 |
|
); |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
1 |
TombTestUtils.setupTomb( |
| 45 |
|
parentTable.getValueTomb(), "pt_source", |
| 46 |
|
"Value-1", "Value-2", "Value-3" |
| 47 |
|
); |
| 48 |
|
|
| 49 |
|
|
| 50 |
1 |
@SuppressWarnings("unchecked") |
| 51 |
|
var testedSupplier = (Supplier<String>)supplierHolder.get(); |
| 52 |
|
|
| 53 |
1 |
assertThat( |
| 54 |
|
IntStream.range(0, 4) |
| 55 |
|
.mapToObj(i -> testedSupplier.get()) |
| 56 |
|
) |
| 57 |
|
.containsExactly( |
| 58 |
|
"Value-1", "Value-2", "Value-3", "Value-1" |
| 59 |
|
); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 65 |
1 |
@Test... |
| 66 |
|
void random() |
| 67 |
|
{ |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
1 |
var supplierHolder = new MutableObject<Supplier<?>>(); |
| 72 |
1 |
var parentTable = prepareStep( |
| 73 |
|
"pt_source", supplierHolder, |
| 74 |
|
step -> step.random() |
| 75 |
|
); |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
1 |
var sampleValues = IntStream.range(0, 10) |
| 82 |
|
.mapToObj(i -> "Value-" + (i + 1)) |
| 83 |
|
.toArray(String[]::new); |
| 84 |
|
|
| 85 |
1 |
TombTestUtils.setupTomb( |
| 86 |
|
parentTable.getValueTomb(), "pt_source", |
| 87 |
|
sampleValues |
| 88 |
|
); |
| 89 |
|
|
| 90 |
|
|
| 91 |
1 |
@SuppressWarnings("unchecked") |
| 92 |
|
var testedSupplier = (Supplier<String>)supplierHolder.get(); |
| 93 |
|
|
| 94 |
1 |
assertThat( |
| 95 |
|
IntStream.range(0, 50) |
| 96 |
|
.mapToObj(i -> testedSupplier.get()) |
| 97 |
|
) |
| 98 |
|
.containsAnyOf(sampleValues) |
| 99 |
|
.doesNotContainSequence(sampleValues); |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 105 |
1 |
@Test... |
| 106 |
|
void transformDomain() |
| 107 |
|
{ |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
1 |
var supplierHolder = new MutableObject<Supplier<?>>(); |
| 112 |
1 |
var parentTable = ColumnFromStepImplTest.<Integer>prepareStep( |
| 113 |
|
"pt_source", supplierHolder, |
| 114 |
|
step -> step |
| 115 |
|
.transformDomain( |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
domainStream -> domainStream |
| 120 |
|
.map(i -> "Transformed-" + (i + 1)) |
| 121 |
|
|
| 122 |
|
) |
| 123 |
|
.roundRobin() |
| 124 |
|
); |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
1 |
var sampleValues = IntStream.range(0, 3) |
| 131 |
|
.boxed() |
| 132 |
|
.toArray(Integer[]::new); |
| 133 |
|
|
| 134 |
1 |
TombTestUtils.setupTomb( |
| 135 |
|
parentTable.getValueTomb(), "pt_source", |
| 136 |
|
sampleValues |
| 137 |
|
); |
| 138 |
|
|
| 139 |
|
|
| 140 |
1 |
@SuppressWarnings("unchecked") |
| 141 |
|
var testedSupplier = (Supplier<String>)supplierHolder.get(); |
| 142 |
|
|
| 143 |
1 |
assertThat( |
| 144 |
|
IntStream.range(0, 3) |
| 145 |
|
.mapToObj(i -> testedSupplier.get()) |
| 146 |
|
) |
| 147 |
|
.containsExactly( |
| 148 |
|
"Transformed-1", "Transformed-2", "Transformed-3" |
| 149 |
|
); |
| 150 |
|
} |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 152 |
3 |
private static <T> JdbcTableFacet prepareStep(... |
| 153 |
|
String columnName, |
| 154 |
|
MutableObject<Supplier<?>> supplierHolder, |
| 155 |
|
Consumer<ColumnFromStepImpl<T>> stepCustomizer |
| 156 |
|
) { |
| 157 |
3 |
var parentTable = JdbcTableFacet.builder("sample_parent_table") |
| 158 |
|
.build(); |
| 159 |
3 |
parentTable.getValueTomb().keepColumn(columnName); |
| 160 |
|
|
| 161 |
3 |
var step = new ColumnFromStepImpl<T>( |
| 162 |
|
JdbcTableFacet.builder("sample_child_table"), |
| 163 |
|
parentTable, columnName, |
| 164 |
|
supplierHolder::setValue |
| 165 |
|
); |
| 166 |
|
|
| 167 |
3 |
stepCustomizer.accept(step); |
| 168 |
|
|
| 169 |
3 |
return parentTable; |
| 170 |
|
} |
| 171 |
|
} |