Skip to content

Commit 827cb5a

Browse files
authored
chore: add test-support validation foundation (#752)
1 parent 8ba0fbe commit 827cb5a

File tree

20 files changed

+368
-52
lines changed

20 files changed

+368
-52
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
- name: Unit and Integration tests
1919
run: |
2020
./gradlew clean build \
21-
-Psql.test.dialects=mysql,oracle
21+
-Psql.test.dialects=mysql

core/flamingock-test-support/src/main/java/io/flamingock/internal/core/builder/BuilderAccessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ public BuilderAccessor(AbstractChangeRunnerBuilder<?,?> builder) {
2828
public AuditStore<?> getAuditStore(){
2929
return builder.auditStore;
3030
}
31+
32+
33+
public void run() {
34+
builder.build().run();
35+
}
36+
37+
3138
}

core/flamingock-test-support/src/main/java/io/flamingock/support/FlamingockTestSupport.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import io.flamingock.internal.core.builder.AbstractChangeRunnerBuilder;
2020
import io.flamingock.internal.core.builder.BuilderAccessor;
21-
import io.flamingock.support.impl.GivenStageImpl;
21+
import io.flamingock.support.stages.GivenStage;
22+
import io.flamingock.support.stages.GivenStageImpl;
23+
import io.flamingock.support.stages.ThenStage;
24+
import io.flamingock.support.stages.WhenStage;
2225

2326
/**
2427
* Entry point for the Flamingock BDD-style test support framework.
@@ -82,6 +85,6 @@ public static GivenStage given(AbstractChangeRunnerBuilder<?, ?> builder) {
8285
throw new NullPointerException("builder must not be null");
8386
}
8487
BuilderAccessor builderAccessor = new BuilderAccessor(builder);
85-
return new GivenStageImpl();
88+
return new GivenStageImpl(new BuilderAccessor(builder));
8689
}
8790
}

core/flamingock-test-support/src/main/java/io/flamingock/support/domain/AuditEntryExpectation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import io.flamingock.api.annotations.Apply;
1919
import io.flamingock.internal.common.core.audit.AuditEntry;
2020
import io.flamingock.internal.common.core.audit.AuditTxType;
21+
import io.flamingock.support.stages.ThenStage;
22+
import io.flamingock.support.stages.WhenStage;
2123

2224
import java.time.LocalDateTime;
2325

@@ -65,8 +67,8 @@
6567
* <li>{@link #ROLLBACK_FAILED(String)} - Expect a change whose rollback failed</li>
6668
* </ul>
6769
*
68-
* @see io.flamingock.support.WhenStage#thenExpectAuditSequenceStrict(AuditEntryExpectation...)
69-
* @see io.flamingock.support.ThenStage#andExpectAuditSequenceStrict(AuditEntryExpectation...)
70+
* @see WhenStage#thenExpectAuditSequenceStrict(AuditEntryExpectation...)
71+
* @see ThenStage#andExpectAuditSequenceStrict(AuditEntryExpectation...)
7072
*/
7173
public class AuditEntryExpectation {
7274

core/flamingock-test-support/src/main/java/io/flamingock/support/GivenStage.java renamed to core/flamingock-test-support/src/main/java/io/flamingock/support/stages/GivenStage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.support;
16+
package io.flamingock.support.stages;
17+
18+
import io.flamingock.support.FlamingockTestSupport;
1719

1820
/**
1921
* Represents the "Given" phase of the BDD test flow for setting up preconditions.

core/flamingock-test-support/src/main/java/io/flamingock/support/impl/GivenStageImpl.java renamed to core/flamingock-test-support/src/main/java/io/flamingock/support/stages/GivenStageImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.support.impl;
16+
package io.flamingock.support.stages;
1717

18-
import io.flamingock.internal.core.builder.AbstractChangeRunnerBuilder;
19-
import io.flamingock.support.GivenStage;
20-
import io.flamingock.support.ThenStage;
21-
import io.flamingock.support.WhenStage;
18+
import io.flamingock.internal.core.builder.BuilderAccessor;
2219

2320
import java.util.ArrayList;
2421
import java.util.Arrays;
2522
import java.util.List;
2623

2724
public class GivenStageImpl implements GivenStage {
2825

26+
private final BuilderAccessor builderAccessor;
2927
private final List<Class<?>> applied = new ArrayList<>();
3028
private final List<Class<?>> failed = new ArrayList<>();
3129
private final List<Class<?>> rolledBack = new ArrayList<>();
3230

33-
public GivenStageImpl() {
31+
public GivenStageImpl(BuilderAccessor builderAccessor) {
32+
this.builderAccessor = builderAccessor;
3433
}
3534

3635
@Override
@@ -59,6 +58,6 @@ public GivenStage andRolledBackChanges(Class<?>... changes) {
5958

6059
@Override
6160
public WhenStage whenRun() {
62-
return new WhenStageImpl();
61+
return new WhenStageImpl(builderAccessor);
6362
}
6463
}

core/flamingock-test-support/src/main/java/io/flamingock/support/ThenStage.java renamed to core/flamingock-test-support/src/main/java/io/flamingock/support/stages/ThenStage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.support;
16+
package io.flamingock.support.stages;
1717

1818
import io.flamingock.support.domain.AuditEntryExpectation;
1919

@@ -79,11 +79,11 @@ public interface ThenStage {
7979
* but allows chaining after other assertions.</p>
8080
*
8181
* @param exceptionClass the expected exception type
82-
* @param validator a consumer to perform additional assertions on the thrown exception;
82+
* @param exceptionConsumer a consumer to perform additional assertions on the thrown exception;
8383
* may be {@code null} if no additional validation is needed
8484
* @return this stage for method chaining
8585
*/
86-
ThenStage andExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> validator);
86+
ThenStage andExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> exceptionConsumer);
8787

8888
/**
8989
* Terminal operation that executes the change runner and verifies all expectations.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2025 Flamingock (https://www.flamingock.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.flamingock.support.stages;
17+
18+
import io.flamingock.internal.core.builder.BuilderAccessor;
19+
import io.flamingock.support.domain.AuditEntryExpectation;
20+
import io.flamingock.support.validation.ValidationHandler;
21+
import io.flamingock.support.validation.Validator;
22+
import io.flamingock.support.validation.ValidatorFactory;
23+
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.function.Consumer;
27+
28+
final class ThenStageImpl implements ThenStage {
29+
30+
private final List<Validator> validators = new ArrayList<>();
31+
private final ValidatorFactory validatorFactory;
32+
private final BuilderAccessor builderAccessor;
33+
34+
ThenStageImpl(BuilderAccessor builderAccessor) {
35+
this.builderAccessor = builderAccessor;
36+
validatorFactory = new ValidatorFactory(builderAccessor);
37+
}
38+
39+
@Override
40+
public ThenStage andExpectAuditSequenceStrict(AuditEntryExpectation... expectations) {
41+
validators.add(validatorFactory.getAuditSeqStrictValidator(expectations));
42+
return this;
43+
}
44+
45+
@Override
46+
public ThenStage andExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> exceptionConsumer) {
47+
validators.add(validatorFactory.getExceptionValidator(exceptionClass, exceptionConsumer));
48+
return this;
49+
}
50+
51+
@Override
52+
public void verify() throws AssertionError {
53+
54+
ValidationHandler validationHandler;
55+
try {
56+
builderAccessor.run();
57+
validationHandler = new ValidationHandler(validators);
58+
59+
} catch (Throwable actualException) {
60+
validationHandler = new ValidationHandler(validators, actualException);
61+
62+
}
63+
64+
validationHandler.validate();
65+
}
66+
}

core/flamingock-test-support/src/main/java/io/flamingock/support/WhenStage.java renamed to core/flamingock-test-support/src/main/java/io/flamingock/support/stages/WhenStage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.support;
16+
package io.flamingock.support.stages;
1717

1818
import io.flamingock.support.domain.AuditEntryExpectation;
1919

core/flamingock-test-support/src/main/java/io/flamingock/support/impl/WhenStageImpl.java renamed to core/flamingock-test-support/src/main/java/io/flamingock/support/stages/WhenStageImpl.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,29 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.flamingock.support.impl;
16+
package io.flamingock.support.stages;
1717

18-
import io.flamingock.internal.common.core.audit.AuditEntry;
19-
import io.flamingock.support.ThenStage;
20-
import io.flamingock.support.WhenStage;
18+
import io.flamingock.internal.core.builder.BuilderAccessor;
2119
import io.flamingock.support.domain.AuditEntryExpectation;
2220

23-
import java.util.List;
2421
import java.util.function.Consumer;
2522

2623
public class WhenStageImpl implements WhenStage {
2724

28-
WhenStageImpl() {}
25+
private final BuilderAccessor builderAccessor;
26+
27+
WhenStageImpl(BuilderAccessor builderAccessor) {
28+
this.builderAccessor = builderAccessor;
29+
}
2930

3031
@Override
3132
public ThenStage thenExpectAuditSequenceStrict(AuditEntryExpectation... expectations) {
32-
return new ThenStageImpl()
33-
.andExpectAuditSequenceStrict(expectations);
33+
return new ThenStageImpl(builderAccessor).andExpectAuditSequenceStrict(expectations);
3434
}
3535

3636
@Override
3737
public ThenStage thenExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> validator) {
38-
return new ThenStageImpl()
39-
.andExpectException(exceptionClass, validator);
38+
return new ThenStageImpl(builderAccessor).andExpectException(exceptionClass, validator);
4039
}
4140

4241
}

0 commit comments

Comments
 (0)