From 27e3a65a46499e02615508ddb004b531ddc3c944 Mon Sep 17 00:00:00 2001 From: davidfrigolet Date: Tue, 11 Aug 2026 16:14:12 +0100 Subject: [PATCH] feat(cli): remove audi-list --- .../common/core/operation/OperationType.java | 1 - .../response/data/AuditListResponseData.java | 181 ------------------ .../response/ResponseSerializationTest.java | 48 ----- .../core/operation/OperationResolver.java | 17 -- .../core/operation/audit/AuditListArgs.java | 49 ----- .../operation/audit/AuditListOperation.java | 50 ----- .../core/operation/audit/AuditListResult.java | 81 -------- .../builder/runner/DefaultRunnerTest.java | 18 +- .../operation/AuditListOperationTest.java | 175 ----------------- 9 files changed, 9 insertions(+), 611 deletions(-) delete mode 100644 core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/AuditListResponseData.java delete mode 100644 core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListArgs.java delete mode 100644 core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListOperation.java delete mode 100644 core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListResult.java delete mode 100644 core/flamingock-core/src/test/java/io/flamingock/internal/core/operation/AuditListOperationTest.java diff --git a/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/operation/OperationType.java b/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/operation/OperationType.java index 933f7b1d9..350fdf92c 100644 --- a/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/operation/OperationType.java +++ b/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/operation/OperationType.java @@ -20,7 +20,6 @@ public enum OperationType { EXECUTE_ROLLBACK, EXECUTE_DRYRUN, VALIDATE_APPLY, - AUDIT_LIST, AUDIT_FIX, ISSUE_LIST, ISSUE_GET diff --git a/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/AuditListResponseData.java b/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/AuditListResponseData.java deleted file mode 100644 index e093c27be..000000000 --- a/core/flamingock-core-commons/src/main/java/io/flamingock/internal/common/core/response/data/AuditListResponseData.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2026 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.internal.common.core.response.data; - -import com.fasterxml.jackson.annotation.JsonTypeName; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -/** - * Response data for the LIST operation containing audit entries. - */ -@JsonTypeName("audit_list") -public class AuditListResponseData { - - private List entries; - - public AuditListResponseData() { - this.entries = new ArrayList<>(); - } - - public AuditListResponseData(List entries) { - this.entries = entries != null ? entries : new ArrayList<>(); - } - - public List getEntries() { - return entries; - } - - public void setEntries(List entries) { - this.entries = entries; - } - - /** - * DTO representing a single audit entry for CLI response. - */ - public static class AuditEntryDto { - private String changeId; - private String author; - private String state; - private String stageId; - private LocalDateTime createdAt; - private long executionMillis; - - // Extended fields (nullable for non-extended mode) - private String executionId; - private String className; - private String methodName; - private String executionHostname; - private String targetSystemId; - - public AuditEntryDto() { - } - - public AuditEntryDto(String changeId, String author, String state, String stageId, LocalDateTime createdAt, long executionMillis) { - this.changeId = changeId; - this.author = author; - this.state = state; - this.stageId = stageId; - this.createdAt = createdAt; - this.executionMillis = executionMillis; - } - - public AuditEntryDto(String changeId, String author, String state, String stageId, LocalDateTime createdAt, long executionMillis, - String executionId, String className, String methodName, String executionHostname, String targetSystemId) { - this.changeId = changeId; - this.author = author; - this.state = state; - this.stageId = stageId; - this.createdAt = createdAt; - this.executionMillis = executionMillis; - this.executionId = executionId; - this.className = className; - this.methodName = methodName; - this.executionHostname = executionHostname; - this.targetSystemId = targetSystemId; - } - - public String getChangeId() { - return changeId; - } - - public void setChangeId(String changeId) { - this.changeId = changeId; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getStageId() { - return stageId; - } - - public void setStageId(String stageId) { - this.stageId = stageId; - } - - public LocalDateTime getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(LocalDateTime createdAt) { - this.createdAt = createdAt; - } - - public long getExecutionMillis() { - return executionMillis; - } - - public void setExecutionMillis(long executionMillis) { - this.executionMillis = executionMillis; - } - - public String getExecutionId() { - return executionId; - } - - public void setExecutionId(String executionId) { - this.executionId = executionId; - } - - public String getClassName() { - return className; - } - - public void setClassName(String className) { - this.className = className; - } - - public String getMethodName() { - return methodName; - } - - public void setMethodName(String methodName) { - this.methodName = methodName; - } - - public String getExecutionHostname() { - return executionHostname; - } - - public void setExecutionHostname(String executionHostname) { - this.executionHostname = executionHostname; - } - - public String getTargetSystemId() { - return targetSystemId; - } - - public void setTargetSystemId(String targetSystemId) { - this.targetSystemId = targetSystemId; - } - } -} diff --git a/core/flamingock-core-commons/src/test/java/io/flamingock/internal/common/core/response/ResponseSerializationTest.java b/core/flamingock-core-commons/src/test/java/io/flamingock/internal/common/core/response/ResponseSerializationTest.java index 97aecc339..057eddec5 100644 --- a/core/flamingock-core-commons/src/test/java/io/flamingock/internal/common/core/response/ResponseSerializationTest.java +++ b/core/flamingock-core-commons/src/test/java/io/flamingock/internal/common/core/response/ResponseSerializationTest.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsontype.NamedType; -import io.flamingock.internal.common.core.response.data.AuditListResponseData; import io.flamingock.internal.common.core.response.data.ChangeResult; import io.flamingock.internal.common.core.response.data.ChangeStatus; import io.flamingock.internal.common.core.response.data.ExecuteResponseData; @@ -30,8 +29,6 @@ import org.junit.jupiter.api.Test; import java.time.Instant; -import java.time.LocalDateTime; -import java.util.Arrays; import static org.junit.jupiter.api.Assertions.*; @@ -47,7 +44,6 @@ void setUp() { // JsonObjectMapper.DEFAULT_INSTANCE already includes JavaTimeModule objectMapper = JsonObjectMapper.DEFAULT_INSTANCE.copy(); objectMapper.registerSubtypes( - new NamedType(AuditListResponseData.class, "audit_list"), new NamedType(ExecuteResponseData.class, "execute") ); } @@ -102,50 +98,6 @@ void shouldSerializeAndDeserializeExecuteResponseData() throws Exception { assertEquals("change-001", deserialized.getStages().get(0).getChanges().get(0).getChangeId()); } - @Test - @DisplayName("Should serialize and deserialize AuditListResponseData") - void shouldSerializeAndDeserializeAuditListResponseData() throws Exception { - // Given - AuditListResponseData original = new AuditListResponseData(Arrays.asList( - new AuditListResponseData.AuditEntryDto( - "change-001", - "developer", - "APPLIED", - "stage-1", - LocalDateTime.of(2026, 2, 9, 10, 0, 0), - 100 - ), - new AuditListResponseData.AuditEntryDto( - "change-002", - "developer", - "APPLIED", - "stage-1", - LocalDateTime.of(2026, 2, 9, 10, 0, 1), - 150 - ) - )); - - // When - String json = objectMapper.writeValueAsString(original); - AuditListResponseData deserialized = objectMapper.readValue(json, AuditListResponseData.class); - - // Then - assertNotNull(deserialized); - assertNotNull(deserialized.getEntries()); - assertEquals(2, deserialized.getEntries().size()); - - AuditListResponseData.AuditEntryDto first = deserialized.getEntries().get(0); - assertEquals("change-001", first.getChangeId()); - assertEquals("developer", first.getAuthor()); - assertEquals("APPLIED", first.getState()); - assertEquals("stage-1", first.getStageId()); - assertEquals(100, first.getExecutionMillis()); - - AuditListResponseData.AuditEntryDto second = deserialized.getEntries().get(1); - assertEquals("change-002", second.getChangeId()); - assertEquals(150, second.getExecutionMillis()); - } - @Test @DisplayName("Should serialize ResponseEnvelope with polymorphic data") void shouldSerializeResponseEnvelopeWithPolymorphicData() throws Exception { diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/OperationResolver.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/OperationResolver.java index 7ed67bbd3..ea402dbdc 100644 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/OperationResolver.java +++ b/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/OperationResolver.java @@ -21,15 +21,11 @@ import io.flamingock.internal.core.builder.args.FlamingockArguments; import io.flamingock.internal.core.configuration.core.CoreConfigurable; import io.flamingock.internal.core.event.EventPublisher; -import io.flamingock.internal.common.core.audit.AuditPersistence; import io.flamingock.internal.core.external.store.AuditStore; import io.flamingock.internal.core.external.targets.TargetSystemManager; import io.flamingock.internal.core.operation.audit.AuditFixArgs; import io.flamingock.internal.core.operation.audit.AuditFixOperation; import io.flamingock.internal.core.operation.audit.AuditFixResult; -import io.flamingock.internal.core.operation.audit.AuditListArgs; -import io.flamingock.internal.core.operation.audit.AuditListOperation; -import io.flamingock.internal.core.operation.audit.AuditListResult; import io.flamingock.internal.core.operation.execute.*; import io.flamingock.internal.core.operation.issue.IssueGetArgs; import io.flamingock.internal.core.operation.issue.IssueGetOperation; @@ -49,9 +45,6 @@ public class OperationResolver { - private static final String ARG_HISTORY = "flamingock.audit.history"; - private static final String ARG_SINCE = "flamingock.audit.since"; - private static final String ARG_EXTENDED = "flamingock.audit.extended"; private static final String ARG_CHANGE_ID = "flamingock.change-id"; private static final String ARG_RESOLUTION = "flamingock.resolution"; private static final String ARG_GUIDANCE = "flamingock.guidance"; @@ -104,8 +97,6 @@ public OperationResolver(RunnerId runnerId, return getExecuteApplyOperation(); case VALIDATE_APPLY: return getValidateApplyOperation(); - case AUDIT_LIST: - return getAuditListOperation(); case AUDIT_FIX: return getAuditFixOperation(); case ISSUE_LIST: @@ -117,14 +108,6 @@ public OperationResolver(RunnerId runnerId, } } - private RunnableOperation getAuditListOperation() { - boolean history = flamingockArgs.getBooleanOr(ARG_HISTORY, false); - java.time.LocalDateTime since = flamingockArgs.getDateTimeOr(ARG_SINCE, null); - boolean extended = flamingockArgs.getBooleanOr(ARG_EXTENDED, false); - AuditListOperation auditListOperation = new AuditListOperation(auditStore.getAuditReader()); - return new RunnableOperation<>(auditListOperation, new AuditListArgs(history, since, extended)); - } - private RunnableOperation getAuditFixOperation() { String changeId = flamingockArgs.getStringOrThrow(ARG_CHANGE_ID, "Change ID is required for AUDIT_FIX operation"); diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListArgs.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListArgs.java deleted file mode 100644 index 7e03c9a72..000000000 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListArgs.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2026 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.internal.core.operation.audit; - -import io.flamingock.internal.core.operation.OperationArgs; - -import java.time.LocalDateTime; - -public class AuditListArgs implements OperationArgs { - - private final boolean history; - private final LocalDateTime since; - private final boolean extended; - - public AuditListArgs() { - this(false, null, false); - } - - public AuditListArgs(boolean history, LocalDateTime since, boolean extended) { - this.history = history; - this.since = since; - this.extended = extended; - } - - public boolean isHistory() { - return history; - } - - public LocalDateTime getSince() { - return since; - } - - public boolean isExtended() { - return extended; - } -} diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListOperation.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListOperation.java deleted file mode 100644 index 8bfd6dab6..000000000 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListOperation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2026 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.internal.core.operation.audit; - -import io.flamingock.internal.common.core.audit.AuditEntry; -import io.flamingock.internal.common.core.audit.AuditReader; -import io.flamingock.internal.core.operation.Operation; - -import java.util.List; -import java.util.stream.Collectors; - -public class AuditListOperation implements Operation { - - private final AuditReader auditReader; - - public AuditListOperation(AuditReader auditReader) { - this.auditReader = auditReader; - } - - @Override - public AuditListResult execute(AuditListArgs args) { - // Step 1: Get base data based on --history flag - List entries = args.isHistory() - ? auditReader.getAuditHistory() - : auditReader.getAuditSnapshot(); - - // Step 2: Apply --since filter if present (works on both modes) - if (args.getSince() != null) { - entries = entries.stream() - .filter(e -> e.getCreatedAt() != null && !e.getCreatedAt().isBefore(args.getSince())) - .collect(Collectors.toList()); - } - - // Step 3: Return with extended flag - return new AuditListResult(entries, args.isExtended()); - } -} diff --git a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListResult.java b/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListResult.java deleted file mode 100644 index 51292ac15..000000000 --- a/core/flamingock-core/src/main/java/io/flamingock/internal/core/operation/audit/AuditListResult.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2026 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.internal.core.operation.audit; - -import io.flamingock.internal.common.core.audit.AuditEntry; -import io.flamingock.internal.common.core.response.data.AuditListResponseData; -import io.flamingock.internal.common.core.response.data.AuditListResponseData.AuditEntryDto; -import io.flamingock.internal.core.operation.AbstractOperationResult; - -import java.util.List; -import java.util.stream.Collectors; - -public class AuditListResult extends AbstractOperationResult { - private final List auditEntries; - private final boolean extended; - - public AuditListResult(List auditEntries) { - this(auditEntries, false); - } - - public AuditListResult(List auditEntries, boolean extended) { - this.auditEntries = auditEntries; - this.extended = extended; - } - - public List getAuditEntries() { - return auditEntries; - } - - public boolean isExtended() { - return extended; - } - - @Override - public Object toResponseData() { - List dtos = auditEntries.stream() - .map(this::toDto) - .collect(Collectors.toList()); - return new AuditListResponseData(dtos); - } - - private AuditEntryDto toDto(AuditEntry entry) { - if (extended) { - return new AuditEntryDto( - entry.getChangeId(), - entry.getAuthor(), - entry.getState() != null ? entry.getState().name() : null, - entry.getStageId(), - entry.getCreatedAt(), - entry.getExecutionMillis(), - entry.getExecutionId(), - entry.getClassName(), - entry.getMethodName(), - entry.getExecutionHostname(), - entry.getTargetSystemId() - ); - } else { - return new AuditEntryDto( - entry.getChangeId(), - entry.getAuthor(), - entry.getState() != null ? entry.getState().name() : null, - entry.getStageId(), - entry.getCreatedAt(), - entry.getExecutionMillis() - ); - } - } -} diff --git a/core/flamingock-core/src/test/java/io/flamingock/internal/core/builder/runner/DefaultRunnerTest.java b/core/flamingock-core/src/test/java/io/flamingock/internal/core/builder/runner/DefaultRunnerTest.java index e53da28d0..f25714a0f 100644 --- a/core/flamingock-core/src/test/java/io/flamingock/internal/core/builder/runner/DefaultRunnerTest.java +++ b/core/flamingock-core/src/test/java/io/flamingock/internal/core/builder/runner/DefaultRunnerTest.java @@ -15,8 +15,8 @@ */ package io.flamingock.internal.core.builder.runner; -import io.flamingock.internal.core.operation.audit.AuditListArgs; -import io.flamingock.internal.core.operation.audit.AuditListResult; +import io.flamingock.internal.core.operation.issue.IssueListArgs; +import io.flamingock.internal.core.operation.issue.IssueListResult; import io.flamingock.internal.core.operation.Operation; import io.flamingock.internal.core.operation.RunnableOperation; import io.flamingock.internal.util.id.RunnerId; @@ -34,20 +34,20 @@ class DefaultRunnerTest { @Mock - private Operation operation; + private Operation operation; @Mock private Runnable finalizer; private RunnerId runnerId; - private AuditListArgs args; - private RunnableOperation runnableOperation; + private IssueListArgs args; + private RunnableOperation runnableOperation; @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); runnerId = RunnerId.generate("test-service"); - args = new AuditListArgs(); + args = new IssueListArgs(); runnableOperation = new RunnableOperation<>(operation, args); } @@ -55,7 +55,7 @@ void setUp() { @DisplayName("Should execute operation when run is called") void shouldExecuteOperationWhenRunIsCalled() { // Given - when(operation.execute(args)).thenReturn(new AuditListResult(Collections.emptyList())); + when(operation.execute(args)).thenReturn(new IssueListResult(Collections.emptyList())); DefaultRunner runner = new DefaultRunner(runnerId, runnableOperation, finalizer); // When @@ -69,7 +69,7 @@ void shouldExecuteOperationWhenRunIsCalled() { @DisplayName("Should call finalizer after successful execution") void shouldCallFinalizerAfterSuccessfulExecution() { // Given - when(operation.execute(args)).thenReturn(new AuditListResult(Collections.emptyList())); + when(operation.execute(args)).thenReturn(new IssueListResult(Collections.emptyList())); DefaultRunner runner = new DefaultRunner(runnerId, runnableOperation, finalizer); // When @@ -108,7 +108,7 @@ void shouldRethrowExceptionFromOperation() { @DisplayName("Should pass correct args to operation") void shouldPassCorrectArgsToOperation() { // Given - when(operation.execute(any())).thenReturn(new AuditListResult(Collections.emptyList())); + when(operation.execute(any())).thenReturn(new IssueListResult(Collections.emptyList())); DefaultRunner runner = new DefaultRunner(runnerId, runnableOperation, finalizer); // When diff --git a/core/flamingock-core/src/test/java/io/flamingock/internal/core/operation/AuditListOperationTest.java b/core/flamingock-core/src/test/java/io/flamingock/internal/core/operation/AuditListOperationTest.java deleted file mode 100644 index f709dd01f..000000000 --- a/core/flamingock-core/src/test/java/io/flamingock/internal/core/operation/AuditListOperationTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2026 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.internal.core.operation; - -import io.flamingock.internal.common.core.audit.AuditEntry; -import io.flamingock.internal.common.core.audit.AuditPersistence; -import io.flamingock.internal.core.operation.audit.AuditListArgs; -import io.flamingock.internal.core.operation.audit.AuditListOperation; -import io.flamingock.internal.core.operation.audit.AuditListResult; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.*; - -class AuditListOperationTest { - - @Mock - private AuditPersistence persistence; - - private AuditListOperation operation; - - @BeforeEach - void setUp() { - MockitoAnnotations.openMocks(this); - operation = new AuditListOperation(persistence); - } - - @Test - @DisplayName("Should return empty list when no audit entries exist") - void shouldReturnEmptyListWhenNoAuditEntriesExist() { - // Given - default args (no history flag) uses snapshot - when(persistence.getAuditSnapshot()).thenReturn(Collections.emptyList()); - AuditListArgs args = new AuditListArgs(); - - // When - AuditListResult result = operation.execute(args); - - // Then - assertNotNull(result); - assertTrue(result.getAuditEntries().isEmpty()); - } - - @Test - @DisplayName("Should return audit entries from snapshot when no history flag") - void shouldReturnAuditEntriesFromSnapshotWhenNoHistoryFlag() { - // Given - AuditEntry entry1 = createAuditEntry("exec-1", "change-1"); - AuditEntry entry2 = createAuditEntry("exec-2", "change-2"); - List entries = Arrays.asList(entry1, entry2); - when(persistence.getAuditSnapshot()).thenReturn(entries); - AuditListArgs args = new AuditListArgs(); - - // When - AuditListResult result = operation.execute(args); - - // Then - assertNotNull(result); - assertEquals(2, result.getAuditEntries().size()); - assertEquals(entries, result.getAuditEntries()); - } - - @Test - @DisplayName("Should delegate to AuditPersistence getAuditSnapshot by default") - void shouldDelegateToAuditPersistenceGetAuditSnapshotByDefault() { - // Given - when(persistence.getAuditSnapshot()).thenReturn(Collections.emptyList()); - AuditListArgs args = new AuditListArgs(); - - // When - operation.execute(args); - - // Then - verify(persistence, times(1)).getAuditSnapshot(); - verify(persistence, never()).getAuditHistory(); - } - - @Test - @DisplayName("Should delegate to AuditPersistence getAuditHistory when history flag is set") - void shouldDelegateToAuditPersistenceGetAuditHistoryWhenHistoryFlagIsSet() { - // Given - when(persistence.getAuditHistory()).thenReturn(Collections.emptyList()); - AuditListArgs args = new AuditListArgs(true, null, false); - - // When - operation.execute(args); - - // Then - verify(persistence, times(1)).getAuditHistory(); - verify(persistence, never()).getAuditSnapshot(); - } - - @Test - @DisplayName("Should filter entries by since date") - void shouldFilterEntriesBySinceDate() { - // Given - LocalDateTime now = LocalDateTime.now(); - LocalDateTime yesterday = now.minusDays(1); - LocalDateTime twoDaysAgo = now.minusDays(2); - - AuditEntry oldEntry = createAuditEntryWithTime("exec-1", "change-1", twoDaysAgo); - AuditEntry newEntry = createAuditEntryWithTime("exec-2", "change-2", now); - List entries = Arrays.asList(oldEntry, newEntry); - when(persistence.getAuditSnapshot()).thenReturn(entries); - - AuditListArgs args = new AuditListArgs(false, yesterday, false); - - // When - AuditListResult result = operation.execute(args); - - // Then - assertNotNull(result); - assertEquals(1, result.getAuditEntries().size()); - assertEquals("change-2", result.getAuditEntries().get(0).getChangeId()); - } - - @Test - @DisplayName("Should set extended flag in result") - void shouldSetExtendedFlagInResult() { - // Given - when(persistence.getAuditSnapshot()).thenReturn(Collections.emptyList()); - AuditListArgs args = new AuditListArgs(false, null, true); - - // When - AuditListResult result = operation.execute(args); - - // Then - assertTrue(result.isExtended()); - } - - private AuditEntry createAuditEntry(String executionId, String changeId) { - return createAuditEntryWithTime(executionId, changeId, LocalDateTime.now()); - } - - private AuditEntry createAuditEntryWithTime(String executionId, String changeId, LocalDateTime time) { - return new AuditEntry( - executionId, - "stage-1", - changeId, - "test-author", - time, - AuditEntry.Status.APPLIED, - AuditEntry.ChangeType.STANDARD_CODE, - "TestClass", - "apply", - null, - 100L, - "localhost", - null, - false, - null - ); - } -}