diff --git a/src/main/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImpl.java b/src/main/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImpl.java index f8929a1e00c..044238ad2c6 100644 --- a/src/main/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImpl.java @@ -11,14 +11,14 @@ public class ArmLoggerServiceImpl implements ArmLoggerService { private static final String ARM_PUSH_SUCCESSFUL = "Successfully pushed object to ARM dropzone: eod_id={}"; - private static final String ARM_PUSHED_FAILED = "Failed to push object to ARM dropzone: eod_id={}"; - private static final String ARCHIVE_TO_ARM_SUCCESSFUL = "Successfully archived object to ARM: eod_id={}"; - private static final String ARCHIVE_TO_ARM_FAILED = "Failed to archive object to ARM: eod_id={}"; - - + private static final String ARM_RPO_SEARCH_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID = "ARM RPO Search - Successfully completed for execution Id = {}"; + private static final String ARM_RPO_SEARCH_FAILED_FOR_EXECUTION_ID = "ARM RPO Search - Failed for execution Id = {}"; + private static final String ARM_RPO_POLLING_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID = "ARM RPO Polling - Successfully completed for execution Id = {}"; + private static final String ARM_RPO_POLLING_FAILED_FOR_EXECUTION_ID = "ARM RPO Polling - Failed for execution Id = {}"; + @Override public void armPushSuccessful(Integer eodId) { log.info(ARM_PUSH_SUCCESSFUL, eodId); @@ -36,27 +36,27 @@ public void archiveToArmSuccessful(Integer eodId) { @Override public void archiveToArmFailed(Integer eodId) { - log.info(ARCHIVE_TO_ARM_FAILED, eodId); + log.error(ARCHIVE_TO_ARM_FAILED, eodId); } @Override public void armRpoSearchSuccessful(Integer executionId) { - log.info("ARM RPO Search - Successfully completed for execution Id = {}"); + log.info(ARM_RPO_SEARCH_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID, executionId); } @Override public void armRpoSearchFailed(Integer executionId) { - log.error("ARM RPO Search - Failed for execution Id = {}"); + log.error(ARM_RPO_SEARCH_FAILED_FOR_EXECUTION_ID, executionId); } @Override public void armRpoPollingSuccessful(Integer executionId) { - log.info("ARM RPO Polling - Successfully completed for execution Id = {}"); + log.info(ARM_RPO_POLLING_SUCCESSFULLY_COMPLETED_FOR_EXECUTION_ID, executionId); } @Override public void armRpoPollingFailed(Integer executionId) { - log.error("ARM RPO Polling - Failed for execution Id = {}"); + log.error(ARM_RPO_POLLING_FAILED_FOR_EXECUTION_ID, executionId); } - + } diff --git a/src/test/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImplTest.java b/src/test/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImplTest.java new file mode 100644 index 00000000000..254bc8eb164 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/darts/log/service/impl/ArmLoggerServiceImplTest.java @@ -0,0 +1,132 @@ +package uk.gov.hmcts.darts.log.service.impl; + +import nl.altindag.log.LogCaptor; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith({MockitoExtension.class}) +class ArmLoggerServiceImplTest { + + private static final Integer EOD_ID = 1; + private static final Integer EXECUTION_ID = 2; + private ArmLoggerServiceImpl armLoggerService; + private static LogCaptor logCaptor; + + @BeforeAll + public static void setupLogCaptor() { + logCaptor = LogCaptor.forClass(ArmLoggerServiceImpl.class); + logCaptor.setLogLevelToInfo(); + } + + @AfterEach + public void clearLogs() { + logCaptor.clearLogs(); + } + + @AfterAll + public static void tearDown() { + logCaptor.close(); + } + + @BeforeEach + void setUp() { + armLoggerService = new ArmLoggerServiceImpl(); + } + + @Test + void armPushSuccessful_shouldLogInfoWithEodId_whenProvidedWithEodId() { + armLoggerService.armPushSuccessful(EOD_ID); + + var logEntry = String.format("Successfully pushed object to ARM dropzone: eod_id=%s", EOD_ID); + + List infoLogs = logCaptor.getInfoLogs(); + assertEquals(1, infoLogs.size()); + assertEquals(logEntry, infoLogs.get(0)); + } + + @Test + void armPushFailed_shouldLogErrorWithEodId_whenProvidedWithEodId() { + armLoggerService.armPushFailed(EOD_ID); + + var logEntry = String.format("Failed to push object to ARM dropzone: eod_id=%s", EOD_ID); + + List errorLogs = logCaptor.getErrorLogs(); + assertEquals(1, errorLogs.size()); + assertEquals(logEntry, errorLogs.get(0)); + } + + @Test + void archiveToArmSuccessful_shouldLogInfoWithEodId_whenProvidedWithEodId() { + armLoggerService.archiveToArmSuccessful(EOD_ID); + + var logEntry = String.format("Successfully archived object to ARM: eod_id=%s", EOD_ID); + + List infoLogs = logCaptor.getInfoLogs(); + assertEquals(1, infoLogs.size()); + assertEquals(logEntry, infoLogs.get(0)); + } + + @Test + void archiveToArmFailed_shouldLogErrorWithEodId_whenProvidedWithEodId() { + armLoggerService.archiveToArmFailed(EOD_ID); + + var logEntry = String.format("Failed to archive object to ARM: eod_id=%s", EOD_ID); + + List errorLogs = logCaptor.getErrorLogs(); + assertEquals(1, errorLogs.size()); + assertEquals(logEntry, errorLogs.get(0)); + } + + @Test + void armRpoSearchSuccessful_shouldLogInfoWithEodId_whenProvidedWithExecutionId() { + armLoggerService.armRpoSearchSuccessful(EXECUTION_ID); + + var logEntry = String.format("ARM RPO Search - Successfully completed for execution Id = %s", EXECUTION_ID); + + List infoLogs = logCaptor.getInfoLogs(); + assertEquals(1, infoLogs.size()); + assertEquals(logEntry, infoLogs.get(0)); + } + + @Test + void armRpoSearchFailed_shouldLogErrorWithEodId_whenProvidedWithExecutionId() { + armLoggerService.armRpoSearchFailed(EXECUTION_ID); + + var logEntry = String.format("ARM RPO Search - Failed for execution Id = %s", EXECUTION_ID); + + List errorLogs = logCaptor.getErrorLogs(); + assertEquals(1, errorLogs.size()); + assertEquals(logEntry, errorLogs.get(0)); + } + + @Test + void armRpoPollingSuccessful_shouldLogInfoWithEodId_whenProvidedWithExecutionId() { + armLoggerService.armRpoPollingSuccessful(EXECUTION_ID); + + var logEntry = String.format("ARM RPO Polling - Successfully completed for execution Id = %s", EXECUTION_ID); + + List infoLogs = logCaptor.getInfoLogs(); + assertEquals(1, infoLogs.size()); + assertEquals(logEntry, infoLogs.get(0)); + } + + @Test + void armRpoPollingFailed_shouldLogErrorWithEodId_whenProvidedWithExecutionId() { + armLoggerService.armRpoPollingFailed(EXECUTION_ID); + + var logEntry = String.format("ARM RPO Polling - Failed for execution Id = %s", EXECUTION_ID); + + List errorLogs = logCaptor.getErrorLogs(); + assertEquals(1, errorLogs.size()); + assertEquals(logEntry, errorLogs.get(0)); + } +} \ No newline at end of file