1515 */
1616package io .flamingock .support .domain ;
1717
18+ import io .flamingock .api .RecoveryStrategy ;
1819import io .flamingock .api .annotations .Apply ;
1920import io .flamingock .api .annotations .Change ;
21+ import io .flamingock .api .annotations .Recovery ;
2022import io .flamingock .api .annotations .Rollback ;
2123import io .flamingock .api .annotations .TargetSystem ;
2224import io .flamingock .internal .common .core .audit .AuditEntry ;
9092 */
9193public class AuditEntryExpectation {
9294
95+ private static final String ORDER_PATTERN_PREFIX = "_" ;
96+ private static final String ORDER_PATTERN_SEPARATOR = "__" ;
97+
9398 private final String expectedChangeId ;
9499 private final AuditEntry .Status expectedState ;
95100
@@ -104,6 +109,8 @@ public class AuditEntryExpectation {
104109 private String expectedExecutionHostname ;
105110 private String expectedErrorTrace ;
106111 private String expectedTargetSystemId ;
112+ private RecoveryStrategy expectedRecoveryStrategy ;
113+ private String expectedOrder ;
107114
108115 // Time range for flexible timestamp verification
109116 private LocalDateTime timestampAfter ;
@@ -279,6 +286,13 @@ private static AuditEntryExpectation fromChangeClass(Class<?> changeClass, Audit
279286 expectation .expectedTargetSystemId = targetSystem .id ();
280287 }
281288
289+ Recovery recovery = changeClass .getAnnotation (Recovery .class );
290+ expectation .expectedRecoveryStrategy = (recovery != null )
291+ ? recovery .strategy ()
292+ : RecoveryStrategy .MANUAL_INTERVENTION ;
293+
294+ expectation .expectedOrder = extractOrderFromClassName (changeClass .getSimpleName ());
295+
282296 return expectation ;
283297 }
284298
@@ -298,6 +312,17 @@ private static String findMethodName(Class<?> changeClass, AuditEntry.Status sta
298312 annotationClass .getSimpleName ()));
299313 }
300314
315+ private static String extractOrderFromClassName (String className ) {
316+ if (className == null || !className .startsWith (ORDER_PATTERN_PREFIX )) {
317+ return null ;
318+ }
319+ int separatorIndex = className .indexOf (ORDER_PATTERN_SEPARATOR );
320+ if (separatorIndex <= 1 ) {
321+ return null ;
322+ }
323+ return className .substring (1 , separatorIndex );
324+ }
325+
301326 /**
302327 * Sets the expected execution ID for verification.
303328 *
@@ -456,6 +481,33 @@ public AuditEntryExpectation withTargetSystemId(String targetSystemId) {
456481 return this ;
457482 }
458483
484+ /**
485+ * Sets the expected recovery strategy for verification.
486+ *
487+ * <p>Enables verification of the recovery strategy field.</p>
488+ *
489+ * @param recoveryStrategy the expected recovery strategy
490+ * @return this builder for method chaining
491+ */
492+ public AuditEntryExpectation withRecoveryStrategy (RecoveryStrategy recoveryStrategy ) {
493+ this .expectedRecoveryStrategy = recoveryStrategy ;
494+ return this ;
495+ }
496+
497+ /**
498+ * Sets the expected order value for verification.
499+ *
500+ * <p>The order is typically extracted from the class name pattern {@code _ORDER__CHANGE-NAME},
501+ * but can be overridden using this method.</p>
502+ *
503+ * @param order the expected order value
504+ * @return this builder for method chaining
505+ */
506+ public AuditEntryExpectation withOrder (String order ) {
507+ this .expectedOrder = order ;
508+ return this ;
509+ }
510+
459511 /**
460512 * Compares this expectation against an actual audit entry.
461513 *
@@ -531,6 +583,16 @@ public List<FieldMismatchError> compareWith(AuditEntry actual) {
531583 errors .add (new FieldMismatchError ("targetSystemId" , expectedTargetSystemId , actual .getTargetSystemId ()));
532584 }
533585
586+ if (expectedRecoveryStrategy != null && expectedRecoveryStrategy != actual .getRecoveryStrategy ()) {
587+ errors .add (new FieldMismatchError ("recoveryStrategy" ,
588+ expectedRecoveryStrategy .name (),
589+ actual .getRecoveryStrategy () != null ? actual .getRecoveryStrategy ().name () : null ));
590+ }
591+
592+ if (expectedOrder != null && !expectedOrder .equals (actual .getOrder ())) {
593+ errors .add (new FieldMismatchError ("order" , expectedOrder , actual .getOrder ()));
594+ }
595+
534596 errors .addAll (compareTimestamp (actual ));
535597
536598 return errors ;
0 commit comments