Skip to content

Commit b1d4d72

Browse files
committed
feat: add validation foundation
1 parent 8ba0fbe commit b1d4d72

File tree

15 files changed

+203
-19
lines changed

15 files changed

+203
-19
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ public static GivenStage given(AbstractChangeRunnerBuilder<?, ?> builder) {
8282
throw new NullPointerException("builder must not be null");
8383
}
8484
BuilderAccessor builderAccessor = new BuilderAccessor(builder);
85-
return new GivenStageImpl();
85+
return new GivenStageImpl(new BuilderAccessor(builder));
8686
}
8787
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.flamingock.support.impl;
1717

1818
import io.flamingock.internal.core.builder.AbstractChangeRunnerBuilder;
19+
import io.flamingock.internal.core.builder.BuilderAccessor;
1920
import io.flamingock.support.GivenStage;
2021
import io.flamingock.support.ThenStage;
2122
import io.flamingock.support.WhenStage;
@@ -26,11 +27,13 @@
2627

2728
public class GivenStageImpl implements GivenStage {
2829

30+
private final BuilderAccessor builderAccessor;
2931
private final List<Class<?>> applied = new ArrayList<>();
3032
private final List<Class<?>> failed = new ArrayList<>();
3133
private final List<Class<?>> rolledBack = new ArrayList<>();
3234

33-
public GivenStageImpl() {
35+
public GivenStageImpl(BuilderAccessor builderAccessor) {
36+
this.builderAccessor = builderAccessor;
3437
}
3538

3639
@Override
@@ -59,6 +62,6 @@ public GivenStage andRolledBackChanges(Class<?>... changes) {
5962

6063
@Override
6164
public WhenStage whenRun() {
62-
return new WhenStageImpl();
65+
return new WhenStageImpl(builderAccessor);
6366
}
6467
}

core/flamingock-test-support/src/main/java/io/flamingock/support/impl/ThenStageImpl.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,53 @@
1515
*/
1616
package io.flamingock.support.impl;
1717

18-
import java.util.function.Consumer;
19-
import java.util.List;
20-
import io.flamingock.internal.common.core.audit.AuditEntry;
18+
import io.flamingock.internal.core.builder.BuilderAccessor;
2119
import io.flamingock.support.ThenStage;
2220
import io.flamingock.support.domain.AuditEntryExpectation;
21+
import io.flamingock.support.validation.ValidationHandler;
22+
import io.flamingock.support.validation.Validator;
23+
import io.flamingock.support.validation.ValidatorFactory;
2324

24-
final class ThenStageImpl implements ThenStage {
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.function.Consumer;
2528

29+
final class ThenStageImpl implements ThenStage {
2630

31+
private final List<Validator> validators = new ArrayList<>();
32+
private final ValidatorFactory validatorFactory;
33+
private final BuilderAccessor builderAccesor;
2734

28-
ThenStageImpl() {
35+
ThenStageImpl(BuilderAccessor builderAccessor) {
36+
this.builderAccesor = builderAccessor;
37+
validatorFactory = new ValidatorFactory(builderAccessor);
2938
}
3039

3140
@Override
3241
public ThenStage andExpectAuditSequenceStrict(AuditEntryExpectation... expectations) {
33-
42+
validators.add(validatorFactory.getAuditSeqStrictValidator(expectations));
3443
return this;
3544
}
3645

3746
@Override
38-
public ThenStage andExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> validator) {
39-
47+
public ThenStage andExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> exceptionConsumer) {
48+
validators.add(validatorFactory.getExceptionValidator(exceptionClass, exceptionConsumer));
4049
return this;
4150
}
4251

4352
@Override
44-
public void verify() {
53+
public void verify() throws AssertionError {
54+
55+
ValidationHandler validationHandler;
56+
try {
57+
builderAccesor.run();
58+
validationHandler = new ValidationHandler(validators);
59+
60+
} catch (Throwable actualException) {
61+
validationHandler = new ValidationHandler(validators, actualException);
62+
63+
}
64+
65+
validationHandler.validate();
4566
}
4667
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.flamingock.support.impl;
1717

1818
import io.flamingock.internal.common.core.audit.AuditEntry;
19+
import io.flamingock.internal.core.builder.BuilderAccessor;
1920
import io.flamingock.support.ThenStage;
2021
import io.flamingock.support.WhenStage;
2122
import io.flamingock.support.domain.AuditEntryExpectation;
@@ -25,18 +26,20 @@
2526

2627
public class WhenStageImpl implements WhenStage {
2728

28-
WhenStageImpl() {}
29+
private final BuilderAccessor builderAccessor;
30+
31+
WhenStageImpl(BuilderAccessor builderAccessor) {
32+
this.builderAccessor = builderAccessor;
33+
}
2934

3035
@Override
3136
public ThenStage thenExpectAuditSequenceStrict(AuditEntryExpectation... expectations) {
32-
return new ThenStageImpl()
33-
.andExpectAuditSequenceStrict(expectations);
37+
return new ThenStageImpl(builderAccessor).andExpectAuditSequenceStrict(expectations);
3438
}
3539

3640
@Override
3741
public ThenStage thenExpectException(Class<? extends Throwable> exceptionClass, Consumer<Throwable> validator) {
38-
return new ThenStageImpl()
39-
.andExpectException(exceptionClass, validator);
42+
return new ThenStageImpl(builderAccessor).andExpectException(exceptionClass, validator);
4043
}
4144

4245
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.flamingock.support.validation;
2+
3+
import io.flamingock.support.validation.error.ValidationResult;
4+
5+
public interface ExceptionValidator extends Validator {
6+
7+
ValidationResult validate(Throwable actualException);
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.flamingock.support.validation;
2+
3+
import io.flamingock.support.validation.error.ValidationResult;
4+
5+
public interface SimpleValidator extends Validator {
6+
7+
ValidationResult validate();
8+
9+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.flamingock.support.validation;
2+
3+
import java.util.List;
4+
5+
public class ValidationHandler {
6+
7+
private final List<Validator> validators;
8+
private final Throwable executionException;
9+
10+
public ValidationHandler(List<Validator> validators) {
11+
this(validators, null);
12+
}
13+
14+
public ValidationHandler(List<Validator> validators, Throwable executionException) {
15+
this.validators = validators;
16+
this.executionException = executionException;
17+
}
18+
19+
20+
public void validate() throws AssertionError {
21+
22+
//TODO process validator and grab the potential validation errors in a AssertionError
23+
// we probably need another class for building the validation result
24+
25+
26+
}
27+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.flamingock.support.validation;
2+
3+
/**
4+
* Marker interface for validator
5+
*/
6+
public interface Validator {
7+
8+
}

0 commit comments

Comments
 (0)