-
Notifications
You must be signed in to change notification settings - Fork 65
feat: flamingock test support AuditSequenceStrictValidator #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dieppa
merged 5 commits into
develop
from
features/flamingock-test-support-audit-sequence-strict-validator
Dec 12, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8a46a7
feat: flamingock test support AuditSequenceStrictValidator
davidfrigolet 087445a
Merge branch 'develop' into features/flamingock-test-support-audit-se…
dieppa 4d89588
feat: flamingock test support AuditSequenceStrictValidator changes af…
davidfrigolet b9f000c
feat: flamingock test support AuditSequenceStrictValidatorTest change…
davidfrigolet 10710cc
feat: flamingock test support AuditSequenceStrictValidator changes af…
davidfrigolet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
266 changes: 266 additions & 0 deletions
266
...src/test/java/io/flamingock/support/validation/impl/AuditSequenceStrictValidatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| /* | ||
| * Copyright 2025 Flamingock (https://www.flamingock.io) | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.flamingock.support.validation.impl; | ||
|
|
||
| import io.flamingock.internal.common.core.audit.AuditEntry; | ||
| import io.flamingock.support.domain.AuditEntryDefinition; | ||
| import io.flamingock.support.validation.error.CountMismatchError; | ||
| import io.flamingock.support.validation.error.FieldMismatchError; | ||
| import io.flamingock.support.validation.error.ValidationResult; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static io.flamingock.internal.common.core.audit.AuditEntry.ExecutionType.EXECUTION; | ||
| import static io.flamingock.internal.common.core.audit.AuditEntry.Status.APPLIED; | ||
| import static io.flamingock.internal.common.core.audit.AuditEntry.Status.FAILED; | ||
| import static io.flamingock.support.domain.AuditEntryDefinition.APPLIED; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class AuditSequenceStrictValidatorTest { | ||
|
|
||
| private List<AuditEntry> actualEntries; | ||
|
|
||
| @BeforeEach | ||
|
davidfrigolet marked this conversation as resolved.
|
||
| void setUp() { | ||
| actualEntries = Arrays.asList( | ||
| createAuditEntry("change-1", APPLIED), | ||
| createAuditEntry("change-2", APPLIED), | ||
| createAuditEntry("change-3", FAILED) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldPassValidation_whenEntriesMatchExactly() { | ||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("change-2"), | ||
| AuditEntryDefinition.FAILED("change-3") | ||
|
davidfrigolet marked this conversation as resolved.
Outdated
|
||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntries); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertTrue(result.isSuccess()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFailValidation_whenCountMismatch() { | ||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("change-2") | ||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntries); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertEquals(1, result.getErrors().size()); | ||
| assertInstanceOf(CountMismatchError.class, result.getErrors().get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFailValidation_whenStatusMismatch() { | ||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("change-2"), | ||
| APPLIED("change-3") // Expected APPLIED but actual is FAILED | ||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntries); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertEquals(1, result.getErrors().size()); | ||
| assertInstanceOf(FieldMismatchError.class, result.getErrors().get(0)); | ||
|
|
||
| FieldMismatchError error = (FieldMismatchError) result.getErrors().get(0); | ||
| assertEquals("status", error.getFieldName()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFailValidation_whenChangeIdMismatch() { | ||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("wrong-id"), // Mismatch | ||
| AuditEntryDefinition.FAILED("change-3") | ||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntries); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertEquals(1, result.getErrors().size()); | ||
| assertInstanceOf(FieldMismatchError.class, result.getErrors().get(0)); | ||
|
|
||
| FieldMismatchError error = (FieldMismatchError) result.getErrors().get(0); | ||
| assertEquals("changeId", error.getFieldName()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFailValidation_whenMissingEntry() { | ||
| List<AuditEntry> actualEntriesSubset = Arrays.asList( | ||
| createAuditEntry("change-1", APPLIED), | ||
| createAuditEntry("change-2", APPLIED) | ||
| ); | ||
|
|
||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("change-2"), | ||
| AuditEntryDefinition.FAILED("change-3") | ||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntriesSubset); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertTrue(result.getErrors().stream().anyMatch(e -> e instanceof CountMismatchError)); | ||
| } | ||
|
davidfrigolet marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| void shouldFailValidation_whenUnexpectedEntry() { | ||
| List<AuditEntry> actualEntriesExtra = Arrays.asList( | ||
| createAuditEntry("change-1", APPLIED), | ||
| createAuditEntry("change-2", APPLIED), | ||
| createAuditEntry("change-3", FAILED), | ||
| createAuditEntry("change-4", APPLIED) | ||
| ); | ||
|
|
||
| List<AuditEntryDefinition> expectedDefinitions = Arrays.asList( | ||
| APPLIED("change-1"), | ||
| APPLIED("change-2"), | ||
| AuditEntryDefinition.FAILED("change-3") | ||
| ); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator(expectedDefinitions, actualEntriesExtra); | ||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertTrue(result.getErrors().stream().anyMatch(e -> e instanceof CountMismatchError)); | ||
| } | ||
|
davidfrigolet marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| void shouldPassValidation_whenOptionalFieldsMatch() { | ||
| AuditEntry actualWithOptionalFields = new AuditEntry( | ||
| "exec-1", | ||
| "stage-1", | ||
| "change-1", | ||
| "author", | ||
| LocalDateTime.now(), | ||
| APPLIED, | ||
| EXECUTION, | ||
| "com.example.Change", | ||
| "apply", | ||
| 100L, | ||
| "host", | ||
| null, | ||
| false, | ||
| null, | ||
| null, | ||
| "target-1", | ||
| "1", | ||
| null, | ||
| true | ||
| ); | ||
|
|
||
| AuditEntryDefinition expectedWithOptionalFields = APPLIED("change-1") | ||
| .withAuthor("author") | ||
| .withClassName("com.example.Change") | ||
| .withMethodName("apply") | ||
| .withTargetSystemId("target-1") | ||
| .withOrder("1") | ||
| .withTransactional(true); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator( | ||
| Collections.singletonList(expectedWithOptionalFields), | ||
| Collections.singletonList(actualWithOptionalFields) | ||
| ); | ||
|
|
||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertTrue(result.isSuccess()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldFailValidation_whenOptionalFieldMismatch() { | ||
| AuditEntry actualEntry = new AuditEntry( | ||
| "exec-1", | ||
| "stage-1", | ||
| "change-1", | ||
| "author", | ||
| LocalDateTime.now(), | ||
| APPLIED, | ||
| EXECUTION, | ||
| "com.example.Change", | ||
| "apply", | ||
| 100L, | ||
| "host", | ||
| null, | ||
| false, | ||
| null, | ||
| null, | ||
| "target-1", | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
|
|
||
| AuditEntryDefinition expectedWithDifferentOptional = APPLIED("change-1") | ||
| .withTargetSystemId("different-target"); | ||
|
|
||
| AuditSequenceStrictValidator validator = new AuditSequenceStrictValidator( | ||
| Collections.singletonList(expectedWithDifferentOptional), | ||
| Collections.singletonList(actualEntry) | ||
| ); | ||
|
|
||
| ValidationResult result = validator.validate(); | ||
|
|
||
| assertFalse(result.isSuccess()); | ||
| assertEquals(1, result.getErrors().size()); | ||
| assertInstanceOf(FieldMismatchError.class, result.getErrors().get(0)); | ||
|
|
||
| FieldMismatchError error = (FieldMismatchError) result.getErrors().get(0); | ||
| assertEquals("targetSystemId", error.getFieldName()); | ||
| } | ||
|
|
||
| private AuditEntry createAuditEntry(String changeId, AuditEntry.Status status) { | ||
| return new AuditEntry( | ||
| "exec-id", | ||
| "stage-id", | ||
| changeId, | ||
| "test-author", | ||
| LocalDateTime.now(), | ||
| status, | ||
| EXECUTION, | ||
| "com.example.TestChange", | ||
| "apply", | ||
| 100L, | ||
| "localhost", | ||
| null, | ||
| false, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.