From 5c72f876509df2636c59249a7f9480d271395966 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Thu, 2 Jan 2025 12:25:12 +0100 Subject: [PATCH 1/7] tech: add log and unit test for all use cases --- .../domain/use_cases/amps/GetAllAMPsUTest.kt | 12 ++ .../authorization/DeleteUserUTest.kt | 12 ++ .../authorization/GetAuthorizedUserUTest.kt | 5 + .../use_cases/authorization/SaveUserUTest.kt | 5 + .../controlUnit/GetLegacyControlUnitsUTest.kt | 5 + .../BypassActionCheckAndDeleteMissionUTest.kt | 12 ++ .../missions/GetMissionsByIdsUTest.kt | 21 ++++ .../use_cases/missions/GetMissionsUTest.kt | 5 + .../use_cases/natinfs/GetAllNatinfsUTest.kt | 5 + .../GetAllRegulatoryAreasUTest.kt | 5 + .../GetRegulatoryAreaByIdUTest.kt | 12 ++ .../ArchiveOutdatedReportingsUTest.kt | 5 + .../reportings/ArchiveReportingsUTest.kt | 5 + .../reportings/DeleteReportingUTest.kt | 5 + .../reportings/DeleteReportingsUTest.kt | 31 ++++++ .../reportings/GetReportingByIdUTest.kt | 5 + .../reportings/GetReportingsUTest.kt | 5 + .../semaphores/GetAllSemaphoresUTest.kt | 19 ++++ .../semaphores/GetSemaphoreByIdUTest.kt | 32 ++++++ .../semaphores/fixtures/SemaphoreFixture.kt | 104 ++++++++++++++++++ .../ArchiveOutdatedVigilanceAreasUTest.kt | 29 +++++ 21 files changed, 339 insertions(+) create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt create mode 100644 backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt new file mode 100644 index 000000000..0b13b1a94 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt @@ -0,0 +1,12 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.amps + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* + +class GetAllAMPsUTest { + + @Test + fun execute() { + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt new file mode 100644 index 000000000..af02020b5 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt @@ -0,0 +1,12 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.authorization + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* + +class DeleteUserUTest { + + @Test + fun execute() { + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt new file mode 100644 index 000000000..21ca944b5 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.authorization + +import org.junit.jupiter.api.Assertions.* + +class GetAuthorizedUserUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt new file mode 100644 index 000000000..d27191057 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.authorization + +import org.junit.jupiter.api.Assertions.* + +class SaveUserTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt new file mode 100644 index 000000000..b17e452c3 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit + +import org.junit.jupiter.api.Assertions.* + +class GetLegacyControlUnitsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt new file mode 100644 index 000000000..bec4570e3 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt @@ -0,0 +1,12 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.missions + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* + +class BypassActionCheckAndDeleteMissionUTest { + + @Test + fun execute() { + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt new file mode 100644 index 000000000..4ba490f4b --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt @@ -0,0 +1,21 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.missions + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension + +@ExtendWith(OutputCaptureExtension::class) +class GetMissionsByIdsTest { + + + @Test + fun `execute should return a list of missions from its ids`(log: CapturedOutput) { + // Given + + // When + + // Then + + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt new file mode 100644 index 000000000..b9f9b7663 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.missions + +import org.junit.jupiter.api.Assertions.* + +class GetMissionsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt new file mode 100644 index 000000000..fc636a0e6 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.natinfs + +import org.junit.jupiter.api.Assertions.* + +class GetAllNatinfsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt new file mode 100644 index 000000000..0443acd25 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas + +import org.junit.jupiter.api.Assertions.* + +class GetAllRegulatoryAreasUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt new file mode 100644 index 000000000..1c5a3bff2 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt @@ -0,0 +1,12 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* + +class GetRegulatoryAreaByIdUTest { + + @Test + fun execute() { + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt new file mode 100644 index 000000000..7d77351ac --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import org.junit.jupiter.api.Assertions.* + +class ArchiveOutdatedReportingsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt new file mode 100644 index 000000000..edbe99e55 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import org.junit.jupiter.api.Assertions.* + +class ArchiveReportingsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt new file mode 100644 index 000000000..4b8b0aab5 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import org.junit.jupiter.api.Assertions.* + +class DeleteReportingUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt new file mode 100644 index 000000000..a260a1717 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt @@ -0,0 +1,31 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import com.nhaarman.mockitokotlin2.verify +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension + +@ExtendWith(OutputCaptureExtension::class) +class DeleteReportingUTest { + + private val reportingRepository: IReportingRepository = mock() + private val deleteReporting = DeleteReporting(reportingRepository) + + @Test + fun `execute should delete reporting`(log: CapturedOutput) { + // Given + val id = 1 + + // When + deleteReporting.execute(id) + + // Then + verify(reportingRepository).delete(id) + assertThat(log.out).contains("Attempt to DELETE reportings $id") + assertThat(log.out).contains("reportings $id deleted") + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt new file mode 100644 index 000000000..7415ce848 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import org.junit.jupiter.api.Assertions.* + +class GetReportingByIdUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt new file mode 100644 index 000000000..566af50a6 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt @@ -0,0 +1,5 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings + +import org.junit.jupiter.api.Assertions.* + +class GetReportingsUTest \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt new file mode 100644 index 000000000..74190c642 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt @@ -0,0 +1,19 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.semaphores + +import fr.gouv.cacem.monitorenv.domain.repositories.ISemaphoreRepository +import org.junit.jupiter.api.Test +import org.mockito.Mockito.mock + +class GetAllSemaphoresTest { + private val semaphoreRepository: ISemaphoreRepository = mock() + private val getAllSemaphores = GetAllSemaphores(semaphoreRepository) + + @Test + fun execute() { + // Given + + // When + + // Then + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt new file mode 100644 index 000000000..9cf59c6c9 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt @@ -0,0 +1,32 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.semaphores + +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.ISemaphoreRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.semaphores.fixtures.SemaphoreFixture.Companion.aSemaphore +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension + +@ExtendWith(OutputCaptureExtension::class) +class GetAllSemaphoresUTest { + private val semaphoreRepository: ISemaphoreRepository = mock() + private val getAllSemaphores = GetAllSemaphores(semaphoreRepository) + + @Test + fun `execute should get all semaphores`(log: CapturedOutput) { + // Given + val expectedSemaphores = listOf(aSemaphore(1), aSemaphore(2)) + given(semaphoreRepository.findAll()).willReturn(expectedSemaphores) + + // When + val semaphores = getAllSemaphores.execute() + + // Then + assertThat(semaphores).isEqualTo(expectedSemaphores) + assertThat(log.out).contains("Attempt to GET all semaphores") + assertThat(log.out).contains("Found ${semaphores.size} semaphores") + } +} \ No newline at end of file diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt new file mode 100644 index 000000000..c3f4b8c29 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt @@ -0,0 +1,104 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures + +import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum +import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingEntity +import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingSourceEntity +import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingTypeEnum +import fr.gouv.cacem.monitorenv.domain.entities.reporting.SourceTypeEnum +import fr.gouv.cacem.monitorenv.domain.entities.reporting.TargetTypeEnum +import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO +import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingSourceDTO +import org.locationtech.jts.geom.MultiPolygon +import org.locationtech.jts.io.WKTReader +import java.time.ZonedDateTime +import java.util.UUID + +class ReportingFixture { + companion object { + fun aReporting( + id: Int? = null, + reportingSources: List = listOf(), + missionId: Int? = null, + attachedToMissionAtUtc: ZonedDateTime? = null, + attachedEnvActionId: UUID? = null, + ): ReportingEntity { + val wktReader = WKTReader() + + val multipolygonString = + "MULTIPOLYGON(((-2.7335 47.6078, -2.7335 47.8452, -3.6297 47.8452, -3.6297 47.6078, -2.7335 47.6078)))" + val polygon = wktReader.read(multipolygonString) as MultiPolygon + + return ReportingEntity( + id = id, + targetType = TargetTypeEnum.VEHICLE, + reportingSources = reportingSources, + vehicleType = VehicleTypeEnum.VESSEL, + geom = polygon, + seaFront = "Facade 1", + description = "description", + reportType = ReportingTypeEnum.INFRACTION_SUSPICION, + themeId = 1, + subThemeIds = listOf(10, 11), + actionTaken = "actions effectuées ", + isControlRequired = true, + hasNoUnitAvailable = true, + createdAt = ZonedDateTime.parse("2022-01-15T04:50:09Z"), + validityTime = 10, + isArchived = false, + isDeleted = false, + updatedAtUtc = ZonedDateTime.now(), + openBy = "CDA", + isInfractionProven = true, + missionId = missionId, + attachedToMissionAtUtc = attachedToMissionAtUtc, + attachedEnvActionId = attachedEnvActionId + ) + } + + fun aReportingDTO( + id: Int? = 1, + attachedEnvActionId: UUID? = null, + reporting: ReportingEntity = aReporting(id, attachedEnvActionId = attachedEnvActionId), + ): ReportingDTO { + return ReportingDTO( + reporting = reporting, + reportingSources = + listOf( + ReportingSourceDTO( + reportingSource = aReportingSourceSemaphore(), + semaphore = null, + controlUnit = null, + ), + ), + ) + } + + fun aReportingSourceSemaphore( + reportingId: Int? = null, + semaphoreId: Int = 1, + ): ReportingSourceEntity { + return ReportingSourceEntity( + id = null, + reportingId = reportingId, + sourceType = SourceTypeEnum.SEMAPHORE, + semaphoreId = semaphoreId, + controlUnitId = null, + sourceName = null, + ) + } + + fun aReportingSourceControlUnit( + reportingId: Int? = null, + controlUnitId: Int = 1, + ): ReportingSourceEntity { + return ReportingSourceEntity( + id = null, + reportingId = reportingId, + sourceType = SourceTypeEnum.CONTROL_UNIT, + semaphoreId = null, + controlUnitId = controlUnitId, + sourceName = null, + ) + } + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt new file mode 100644 index 000000000..fae4d91a6 --- /dev/null +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt @@ -0,0 +1,29 @@ +package fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea + +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension + +@ExtendWith(OutputCaptureExtension::class) +class ArchiveOutdatedVigilanceAreasTest { + private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() + private val archiveOutdatedVigilanceAreas = ArchiveOutdatedVigilanceAreas(vigilanceAreaRepository) + + @Test + fun `execute should archive vigilance areas`(log: CapturedOutput) { + // Given + given(vigilanceAreaRepository.archiveOutdatedVigilanceAreas()).willReturn(2) + + // When + archiveOutdatedVigilanceAreas.execute() + + // Then + assertThat(log.out).contains("Attempt to ARCHIVE vigilance areas") + assertThat(log.out).contains("Archived 2 vigilance areas") + } +} \ No newline at end of file From bdfd500895d227bddd4748e441e6096677ee5f66 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Thu, 2 Jan 2025 12:27:47 +0100 Subject: [PATCH 2/7] tech: add log and unit test for all use cases --- backend/build.gradle.kts | 1 + .../use_cases/actions/PatchEnvAction.kt | 10 +- .../administration/ArchiveAdministration.kt | 6 +- .../CanArchiveAdministration.kt | 4 + .../administration/CanDeleteAdministration.kt | 4 + .../CreateOrUpdateAdministration.kt | 9 +- .../administration/DeleteAdministration.kt | 6 + .../administration/GetAdministrationById.kt | 4 + .../administration/GetAdministrations.kt | 1 + .../domain/use_cases/amps/GetAllAMPs.kt | 3 +- .../use_cases/authorization/DeleteUser.kt | 6 +- .../authorization/GetAuthorizedUser.kt | 2 + .../authorization/GetIsAuthorizedUser.kt | 1 + .../use_cases/authorization/SaveUser.kt | 5 + .../use_cases/controlPlan/GetControlPlans.kt | 4 +- .../controlPlan/GetControlPlansByYear.kt | 6 +- .../controlUnit/ArchiveControlUnit.kt | 7 +- .../controlUnit/ArchiveControlUnitResource.kt | 7 +- .../controlUnit/CanDeleteControlUnit.kt | 4 + .../CanDeleteControlUnitResource.kt | 4 + .../controlUnit/CreateOrUpdateControlUnit.kt | 9 +- .../CreateOrUpdateControlUnitContact.kt | 6 + .../CreateOrUpdateControlUnitResource.kt | 9 +- .../controlUnit/DeleteControlUnit.kt | 7 +- .../controlUnit/DeleteControlUnitContact.kt | 7 +- .../controlUnit/DeleteControlUnitResource.kt | 9 +- .../controlUnit/GetControlUnitById.kt | 5 + .../controlUnit/GetControlUnitContactById.kt | 5 + .../controlUnit/GetControlUnitContacts.kt | 4 +- .../controlUnit/GetControlUnitResourceById.kt | 8 +- .../controlUnit/GetControlUnitResources.kt | 4 +- .../use_cases/controlUnit/GetControlUnits.kt | 2 +- .../controlUnit/GetLegacyControlUnits.kt | 4 +- .../use_cases/dashboard/DeleteDashboard.kt | 4 +- .../domain/use_cases/dashboard/ExtractArea.kt | 4 + .../use_cases/dashboard/GetDashboard.kt | 3 +- .../use_cases/dashboard/GetDashboards.kt | 9 +- .../use_cases/dashboard/SaveDashboard.kt | 5 +- .../GetDepartmentAreaByInseeCode.kt | 4 + .../departmentArea/GetDepartmentAreas.kt | 4 +- .../BypassActionCheckAndDeleteMission.kt | 7 +- .../use_cases/missions/CanDeleteMission.kt | 6 +- .../missions/CreateOrUpdateEnvActions.kt | 8 ++ .../missions/CreateOrUpdateMission.kt | 3 + ...eMissionWithActionsAndAttachedReporting.kt | 6 +- .../use_cases/missions/DeleteMission.kt | 5 +- .../missions/GetEngagedControlUnits.kt | 4 +- .../use_cases/missions/GetFullMission.kt | 5 + ...FullMissionWithFishAndRapportNavActions.kt | 4 + .../use_cases/missions/GetFullMissions.kt | 3 +- .../domain/use_cases/missions/GetMission.kt | 4 + .../missions/GetMissionAndSourceAction.kt | 4 + .../GetMissionWithRapportNavActions.kt | 4 + .../domain/use_cases/missions/GetMissions.kt | 4 +- .../use_cases/missions/GetMissionsByIds.kt | 4 + .../domain/use_cases/missions/PatchMission.kt | 10 +- .../domain/use_cases/natinfs/GetAllNatinfs.kt | 1 + .../regulatoryAreas/GetAllRegulatoryAreas.kt | 5 +- .../regulatoryAreas/GetRegulatoryAreaById.kt | 4 +- .../reportings/ArchiveOutdatedReportings.kt | 4 +- .../use_cases/reportings/ArchiveReportings.kt | 8 +- .../reportings/CreateOrUpdateReporting.kt | 3 +- .../use_cases/reportings/DeleteReporting.kt | 8 +- .../use_cases/reportings/DeleteReportings.kt | 12 +- .../use_cases/reportings/GetReportingById.kt | 8 +- .../use_cases/reportings/GetReportings.kt | 9 +- .../reportings/GetReportingsByIds.kt | 4 + .../use_cases/semaphores/GetAllSemaphores.kt | 4 +- .../use_cases/semaphores/GetSemaphoreById.kt | 4 + .../use_cases/station/CanDeleteStation.kt | 4 + .../station/CreateOrUpdateStation.kt | 9 +- .../domain/use_cases/station/DeleteStation.kt | 6 +- .../use_cases/station/GetStationById.kt | 4 + .../domain/use_cases/station/GetStations.kt | 3 +- .../ArchiveOutdatedVigilanceAreas.kt | 4 +- .../CreateOrUpdateVigilanceArea.kt | 7 +- .../vigilanceArea/DeleteVigilanceArea.kt | 4 +- .../use_cases/vigilanceArea/GetTrigrams.kt | 9 +- .../vigilanceArea/GetVigilanceAreaById.kt | 4 + .../vigilanceArea/GetVigilanceAreas.kt | 8 +- .../database/model/MissionModel.kt | 21 +++- .../interfaces/IDBControlUnitRepository.kt | 2 +- .../interfaces/IDBVigilanceAreaRepository.kt | 1 + .../use_cases/actions/PatchEnvActionUTest.kt | 11 +- .../ArchiveAdministrationUTests.kt | 8 +- .../CanArchiveAdministrationUTests.kt | 6 +- .../CanDeleteAdministrationUTests.kt | 6 +- .../CreateOrUpdateAdministrationUTests.kt | 7 +- .../DeleteAdministrationUTests.kt | 8 +- .../GetAdministrationByIdUTests.kt | 6 +- .../GetAdministrationsUTests.kt | 7 +- .../domain/use_cases/amps/GetAllAMPsUTest.kt | 28 ++++- .../authorization/DeleteUserUTest.kt | 27 ++++- .../authorization/GetAuthorizedUserUTest.kt | 57 ++++++++- .../GetIsAuthorizedUserUTests.kt | 13 +- .../use_cases/authorization/SaveUserUTest.kt | 33 +++++- .../controlPlan/GetControlPlansByYearUTest.kt | 33 ++++-- .../controlPlan/GetControlPlansUTest.kt | 18 ++- .../ArchiveControlUnitResourceUTests.kt | 8 +- .../controlUnit/ArchiveControlUnitUTests.kt | 8 +- .../CanDeleteControlUnitResourceUTests.kt | 6 +- .../controlUnit/CanDeleteControlUnitUTests.kt | 8 +- .../CreateOrUpdateControlUnitContactUTests.kt | 7 +- ...CreateOrUpdateControlUnitResourceUTests.kt | 7 +- .../CreateOrUpdateControlUnitUTests.kt | 7 +- .../DeleteControlUnitContactUTests.kt | 8 +- .../DeleteControlUnitResourceUTests.kt | 10 +- .../controlUnit/DeleteControlUnitUTests.kt | 9 +- .../controlUnit/GetControlUnitByIdUTests.kt | 6 +- .../GetControlUnitContactByIdUTests.kt | 6 +- .../GetControlUnitContactsUTests.kt | 7 +- .../GetControlUnitResourceByIdUTests.kt | 6 +- .../GetControlUnitResourcesUTests.kt | 7 +- .../controlUnit/GetControlUnitsUTests.kt | 7 +- .../controlUnit/GetLegacyControlUnitsUTest.kt | 62 +++++++++- .../dashboard/DeleteDashboardUTest.kt | 9 +- .../use_cases/dashboard/ExtractAreaUTest.kt | 7 +- .../use_cases/dashboard/GetDashboardUTest.kt | 12 +- .../use_cases/dashboard/GetDashboardsUTest.kt | 9 +- .../use_cases/dashboard/SaveDashboardUTest.kt | 9 +- .../GetDepartmentAreaByInseeCodeUTests.kt | 6 +- .../GetDepartmentAreasUTests.kt | 8 +- .../BypassActionCheckAndDeleteMissionUTest.kt | 56 ++++++++- .../missions/CanDeleteMissionUTests.kt | 38 +++--- ...s.kt => CreateOrUpdateEnvActionsUTests.kt} | 15 ++- .../missions/CreateOrUpdateMissionUTests.kt | 9 +- ...onWithActionsAndAttachedReportingUTests.kt | 33 +++++- .../use_cases/missions/DeleteMissionUTests.kt | 8 +- .../missions/GetEngagedControlUnitsUTests.kt | 7 +- .../use_cases/missions/GetFullMissionUTest.kt | 7 +- ...issionWithFishAndRapportNavActionsUTest.kt | 10 +- .../GetMissionAndSourceActionUTest.kt | 8 +- .../use_cases/missions/GetMissionUTest.kt | 7 +- .../GetMissionWithRapportNavActionsUTests.kt | 7 +- .../missions/GetMissionsByIdsUTest.kt | 26 +++- .../use_cases/missions/GetMissionsUTest.kt | 50 +++++++- .../use_cases/missions/PatchMissionUTest.kt | 12 +- .../missions/fixtures/MissionFixture.kt | 8 ++ .../use_cases/natinfs/GetAllNatinfsUTest.kt | 41 ++++++- .../GetAllRegulatoryAreasUTest.kt | 31 ++++- .../GetRegulatoryAreaByIdUTest.kt | 28 ++++- .../ArchiveOutdatedReportingsUTest.kt | 28 ++++- .../reportings/ArchiveReportingsUTest.kt | 29 ++++- .../CreateOrUpdateReportingUTests.kt | 7 +- .../reportings/DeleteReportingUTest.kt | 29 ++++- .../reportings/DeleteReportingsUTest.kt | 17 ++- .../reportings/GetReportingByIdUTest.kt | 32 ++++- .../reportings/GetReportingsByIdsUTest.kt | 7 +- .../reportings/GetReportingsUTest.kt | 112 +++++++++++++++++- .../reportings/fixtures/ReportingFixture.kt | 11 +- .../semaphores/GetAllSemaphoresUTest.kt | 19 ++- .../semaphores/GetSemaphoreByIdUTest.kt | 18 +-- .../semaphores/fixtures/SemaphoreFixture.kt | 103 ++-------------- .../station/CanDeleteStationUTests.kt | 8 +- .../station/CreateOrUpdateStationUTests.kt | 7 +- .../use_cases/station/DeleteStationUTests.kt | 8 +- .../use_cases/station/GetStationByIdUTests.kt | 6 +- .../use_cases/station/GetStationsUTests.kt | 7 +- .../ArchiveOutdatedVigilanceAreasUTest.kt | 6 +- .../CreateOrUpdateVigilanceAreaUTests.kt | 12 +- .../DeleteVigilanceAreaUTests.kt | 9 +- .../vigilanceArea/GetTrigramsUTests.kt | 8 +- .../GetVigilanceAreaByIdUTests.kt | 7 +- .../vigilanceArea/GetVigilanceAreasUTests.kt | 13 +- .../JpaMissionRepositoryITests.kt | 4 +- backend/src/test/resources/log4j2-test.xml | 27 +++++ 166 files changed, 1529 insertions(+), 360 deletions(-) rename backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/{CreateOrPatchEnvActionsUTests.kt => CreateOrUpdateEnvActionsUTests.kt} (93%) create mode 100644 backend/src/test/resources/log4j2-test.xml diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 27093aeba..20e09ec68 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -88,6 +88,7 @@ dependencies { testImplementation("org.testcontainers:junit-jupiter:1.20.4") testImplementation("net.java.dev.jna:jna:5.16.0") testImplementation("net.ttddyy:datasource-proxy:1.10.1") + testImplementation("io.mockk:mockk:1.13.14") } group = "fr.gouv.cacem" diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvAction.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvAction.kt index 5b21c69e5..50210591e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvAction.kt @@ -7,20 +7,26 @@ import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.mappers.PatchEntity import fr.gouv.cacem.monitorenv.domain.repositories.IEnvActionRepository -import java.util.* +import org.slf4j.LoggerFactory +import java.util.UUID @UseCase class PatchEnvAction( private val envActionRepository: IEnvActionRepository, private val patchEnvAction: PatchEntity, ) { + private val logger = LoggerFactory.getLogger(PatchEnvAction::class.java) + fun execute( id: UUID, patchableEnvActionEntity: PatchableEnvActionEntity, ): EnvActionEntity { + logger.info("Attempt to PATCH envaction $id") envActionRepository.findById(id)?.let { patchEnvAction.execute(it, patchableEnvActionEntity) - return envActionRepository.save(it) + val patchedEnvAction = envActionRepository.save(it) + logger.info("envaction $id patched") + return patchedEnvAction } throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_FOUND, "envAction $id not found") } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministration.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministration.kt index 2cfed8dcf..ce7fa94c7 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministration.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministration.kt @@ -4,20 +4,24 @@ import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.slf4j.LoggerFactory @UseCase class ArchiveAdministration( private val administrationRepository: IAdministrationRepository, private val canArchiveAdministration: CanArchiveAdministration, ) { + private val logger = LoggerFactory.getLogger(ArchiveAdministration::class.java) + fun execute(administrationId: Int) { + logger.info("Attempt to ARCHIVE administration $administrationId") if (!canArchiveAdministration.execute(administrationId)) { throw BackendUsageException( BackendUsageErrorCode.UNARCHIVED_CHILD, "Cannot archive administration (ID=$administrationId) due to some of its control units not being archived.", ) } - administrationRepository.archiveById(administrationId) + logger.info("Administration $administrationId archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministration.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministration.kt index 17d756551..52a9e0d96 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministration.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministration.kt @@ -2,10 +2,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.administration import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.slf4j.LoggerFactory @UseCase class CanArchiveAdministration(private val administrationRepository: IAdministrationRepository) { + private val logger = LoggerFactory.getLogger(CanArchiveAdministration::class.java) + fun execute(administrationId: Int): Boolean { + logger.info("Can administration $administrationId be archived") val fullAdministration = administrationRepository.findById(administrationId) return fullAdministration.controlUnits.all { it.isArchived } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministration.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministration.kt index ad6bd7f3f..6eb29b50d 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministration.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministration.kt @@ -2,10 +2,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.administration import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.slf4j.LoggerFactory @UseCase class CanDeleteAdministration(private val administrationRepository: IAdministrationRepository) { + private val logger = LoggerFactory.getLogger(CanDeleteAdministration::class.java) + fun execute(administrationId: Int): Boolean { + logger.info("Can administration $administrationId be deleted") val fullAdministration = administrationRepository.findById(administrationId) return fullAdministration.controlUnits.isEmpty() diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministration.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministration.kt index 7d3288368..848e2f758 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministration.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministration.kt @@ -3,10 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.administration import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.administration.AdministrationEntity import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateAdministration(private val administrationRepository: IAdministrationRepository) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateAdministration::class.java) + fun execute(administration: AdministrationEntity): AdministrationEntity { - return administrationRepository.save(administration) + logger.info("Attempt to CREATE or UPDATE administration ${administration.id}") + val administrationEntity = administrationRepository.save(administration) + logger.info("Created or updated administration ${administrationEntity.id}") + + return administrationEntity } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministration.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministration.kt index d4aaf1233..464f40a12 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministration.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministration.kt @@ -3,13 +3,18 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.administration import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.slf4j.LoggerFactory @UseCase class DeleteAdministration( private val administrationRepository: IAdministrationRepository, private val canDeleteAdministration: CanDeleteAdministration, ) { + private val logger = LoggerFactory.getLogger(DeleteAdministration::class.java) + fun execute(administrationId: Int) { + logger.info("Attempt to DELETE administration $administrationId") + if (!canDeleteAdministration.execute(administrationId)) { throw CouldNotDeleteException( "Cannot delete administration (ID=$administrationId) due to existing relationships.", @@ -17,5 +22,6 @@ class DeleteAdministration( } administrationRepository.deleteById(administrationId) + logger.info("Administration $administrationId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationById.kt index 9c6b4c6a3..6c8ded6ff 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationById.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.administration import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO +import org.slf4j.LoggerFactory @UseCase class GetAdministrationById(private val administrationRepository: IAdministrationRepository) { + private val logger = LoggerFactory.getLogger(GetAdministrationById::class.java) + fun execute(administrationId: Int): FullAdministrationDTO { + logger.info("GET administration $administrationId") return administrationRepository.findById(administrationId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrations.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrations.kt index d88a9b2b2..16e357889 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrations.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrations.kt @@ -10,6 +10,7 @@ class GetAdministrations(private val administrationRepository: IAdministrationRe private val logger = LoggerFactory.getLogger(GetAdministrations::class.java) fun execute(): List { + logger.info("Attempt to GET all administrations") val fullAdministrations = administrationRepository.findAll() logger.info("Found ${fullAdministrations.size} administrations.") diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPs.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPs.kt index 6f548cc36..3b277c956 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPs.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPs.kt @@ -10,8 +10,9 @@ class GetAllAMPs(private val ampRepository: IAMPRepository) { private val logger = LoggerFactory.getLogger(GetAllAMPs::class.java) fun execute(): List { + logger.info("Attempt to GET all AMPs") val amps = ampRepository.findAll() - logger.info("Found ${amps.size} amps") + logger.info("Found ${amps.size} AMPs") return amps } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUser.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUser.kt index 8ca7b20cc..b83fc3e76 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUser.kt @@ -3,14 +3,18 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.hash import fr.gouv.cacem.monitorenv.domain.repositories.IUserAuthorizationRepository +import org.slf4j.LoggerFactory @UseCase class DeleteUser( private val userAuthorizationRepository: IUserAuthorizationRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteUser::class.java) + fun execute(email: String) { + logger.info("Attempt to DELETE user $email") val hashedEmail = hash(email) - userAuthorizationRepository.delete(hashedEmail) + logger.info("User $email deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUser.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUser.kt index 5a9c5b962..e16410a3d 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUser.kt @@ -14,10 +14,12 @@ class GetAuthorizedUser( fun execute(email: String): UserAuthorization { val hashedEmail = hash(email) + logger.info("Attempt to GET user $hashedEmail") val userAuthorization = userAuthorizationRepository.findByHashedEmail(hashedEmail) if (userAuthorization != null) { + logger.info("Found user $hashedEmail") return userAuthorization } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUser.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUser.kt index 7e89fc86c..b811a304d 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUser.kt @@ -25,6 +25,7 @@ class GetIsAuthorizedUser( * protected, reject */ val hashedEmail = hash(email) + logger.info("Is user $hashedEmail AUTHORIZED") return userAuthorizationRepository.findByHashedEmail(hashedEmail)?.isSuperUser ?: false } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUser.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUser.kt index b910b963b..ec425b3cc 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUser.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUser.kt @@ -3,12 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.authorization.UserAuthorization import fr.gouv.cacem.monitorenv.domain.repositories.IUserAuthorizationRepository +import org.slf4j.LoggerFactory @UseCase class SaveUser( private val userAuthorizationRepository: IUserAuthorizationRepository, ) { + private val logger = LoggerFactory.getLogger(SaveUser::class.java) + fun execute(userAuthorization: UserAuthorization) { + logger.info("Attempt to CREATE or UPDATE user ${userAuthorization.hashedEmail}") userAuthorizationRepository.save(userAuthorization) + logger.info("User ${userAuthorization.hashedEmail} created or updated") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlans.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlans.kt index e79360e7f..4e3970d9f 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlans.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlans.kt @@ -18,12 +18,14 @@ class GetControlPlans( private val logger = LoggerFactory.getLogger(GetControlPlans::class.java) fun execute(): ControlPlanThemes { + logger.info("Attempt to GET all control plans") val controlPlanThemes = controlPlanThemeRepository.findAll() val controlPlanSubThemes = controlPlanSubThemeRepository.findAll() val controlPlanTags = controlPlanTagRepository.findAll() logger.info( - "Found ${controlPlanThemes.size} control plan themes, ${controlPlanSubThemes.size} subthemes, and ${controlPlanTags.size} tags ", + "Found ${controlPlanThemes.size} control plan themes, ${controlPlanSubThemes.size} control plan subthemes and ${controlPlanTags.size} control plan tags", ) + return Triple(controlPlanThemes, controlPlanSubThemes, controlPlanTags) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYear.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYear.kt index ad03dcf76..3256a123b 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYear.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYear.kt @@ -18,10 +18,14 @@ class GetControlPlansByYear( private val logger = LoggerFactory.getLogger(GetControlPlansByYear::class.java) fun execute(year: Int): ControlPlanByYear { + logger.info("Attempt to GET all control plans for year $year") val controlPlanThemes = controlPlanThemeRepository.findByYear(year) val controlPlanSubThemes = controlPlanSubThemeRepository.findByYear(year) val controlPlanTags = controlPlanTagRepository.findByYear(year) - logger.info("Found ${controlPlanSubThemes.size} control plan subthemes for year $year") + logger.info( + "Found ${controlPlanThemes.size} control plan themes, ${controlPlanSubThemes.size} control plan subthemes and ${controlPlanTags.size} control plan tags for year $year", + ) + return Triple(controlPlanThemes, controlPlanSubThemes, controlPlanTags) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnit.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnit.kt index 2b5da6f4e..008424585 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnit.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnit.kt @@ -2,10 +2,15 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository +import org.slf4j.LoggerFactory @UseCase class ArchiveControlUnit(private val controlUnitRepository: IControlUnitRepository) { + private val logger = LoggerFactory.getLogger(ArchiveControlUnit::class.java) + fun execute(controlUnitId: Int) { - return controlUnitRepository.archiveById(controlUnitId) + logger.info("Attempt to ARCHIVE control unit $controlUnitId") + controlUnitRepository.archiveById(controlUnitId) + logger.info("Control unit $controlUnitId archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResource.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResource.kt index 565fa9da5..40c92857e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResource.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResource.kt @@ -2,10 +2,15 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository +import org.slf4j.LoggerFactory @UseCase class ArchiveControlUnitResource(private val controlUnitResourceRepository: IControlUnitResourceRepository) { + private val logger = LoggerFactory.getLogger(ArchiveControlUnitResource::class.java) + fun execute(controlUnitResourceId: Int) { - return controlUnitResourceRepository.archiveById(controlUnitResourceId) + logger.info("Attempt to ARCHIVE control unit resource $controlUnitResourceId") + controlUnitResourceRepository.archiveById(controlUnitResourceId) + logger.info("Control unit resource $controlUnitResourceId archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnit.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnit.kt index 8a9307375..d05d96661 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnit.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnit.kt @@ -3,13 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.slf4j.LoggerFactory @UseCase class CanDeleteControlUnit( private val missionRepository: IMissionRepository, private val reportingRepository: IReportingRepository, ) { + private val logger = LoggerFactory.getLogger(CanDeleteControlUnit::class.java) + fun execute(controlUnitId: Int): Boolean { + logger.info("Can control unit $controlUnitId be deleted") val nonDeletedMissions = missionRepository.findByControlUnitId(controlUnitId).filter { !it.isDeleted } val nonDeletedReportings = reportingRepository.findByControlUnitId(controlUnitId).filter { !it.isDeleted } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResource.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResource.kt index fe8c00008..14db96427 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResource.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResource.kt @@ -2,12 +2,16 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import org.slf4j.LoggerFactory @UseCase class CanDeleteControlUnitResource( private val missionRepository: IMissionRepository, ) { + private val logger = LoggerFactory.getLogger(CanDeleteControlUnitResource::class.java) + fun execute(controlUnitResourceId: Int): Boolean { + logger.info("Can control unit resource $controlUnitResourceId be deleted") val missions = missionRepository.findByControlUnitResourceId(controlUnitResourceId) return missions.isEmpty() diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnit.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnit.kt index e5d09e14f..a811acff5 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnit.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnit.kt @@ -3,10 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateControlUnit(private val controlUnitRepository: IControlUnitRepository) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateControlUnit::class.java) + fun execute(controlUnit: ControlUnitEntity): ControlUnitEntity { - return controlUnitRepository.save(controlUnit) + logger.info("Attempt to CREATE or UPDATE control unit ${controlUnit.id}") + val controlUnitEntity = controlUnitRepository.save(controlUnit) + logger.info("Control unit ${controlUnitEntity.id} created or updated") + + return controlUnitEntity } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContact.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContact.kt index ed0d87caf..3ae1e5345 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContact.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContact.kt @@ -6,13 +6,17 @@ import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitContactRepository import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateControlUnitContact( private val controlUnitRepository: IControlUnitRepository, private val controlUnitContactRepository: IControlUnitContactRepository, ) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateControlUnitContact::class.java) + fun execute(controlUnitContact: ControlUnitContactEntity): ControlUnitContactEntity { + logger.info("Attempt to CREATE or UPDATE control unit contact ${controlUnitContact.id}") val validControlUnitContact = validateSubscriptions(controlUnitContact) validatePhone(validControlUnitContact) @@ -28,6 +32,8 @@ class CreateOrUpdateControlUnitContact( createdOrUpdatedControlUnitContact.id, ) } + logger.info("Control unit contact ${createdOrUpdatedControlUnitContact.id} created or updated") + return createdOrUpdatedControlUnitContact } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResource.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResource.kt index d7d523c05..a14b8df98 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResource.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResource.kt @@ -3,10 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateControlUnitResource(private val controlUnitResourceRepository: IControlUnitResourceRepository) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateControlUnitResource::class.java) + fun execute(controlUnitResource: ControlUnitResourceEntity): ControlUnitResourceEntity { - return controlUnitResourceRepository.save(controlUnitResource) + logger.info("Attempt to CREATE or UPDATE control unit resource ${controlUnitResource.id}") + val controlUnitResourceEntity = controlUnitResourceRepository.save(controlUnitResource) + logger.info("Control unit resource ${controlUnitResourceEntity.id} created or updated") + + return controlUnitResourceEntity } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnit.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnit.kt index 674d99b60..0f90e0eed 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnit.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnit.kt @@ -6,6 +6,7 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingSourceRepository +import org.slf4j.LoggerFactory @UseCase class DeleteControlUnit( @@ -15,7 +16,10 @@ class DeleteControlUnit( private val reportingRepository: IReportingRepository, private val reportingSourceRepository: IReportingSourceRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteControlUnit::class.java) + fun execute(controlUnitId: Int) { + logger.info("Attempt to DELETE control unit $controlUnitId") if (!canDeleteControlUnit.execute(controlUnitId)) { throw CouldNotDeleteException( "Cannot delete control unit (ID=$controlUnitId) due to existing relationships.", @@ -44,6 +48,7 @@ class DeleteControlUnit( } } - return controlUnitRepository.deleteById(controlUnitId) + controlUnitRepository.deleteById(controlUnitId) + logger.info("Control unit $controlUnitId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContact.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContact.kt index 29f39ab49..a1d3d1ffa 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContact.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContact.kt @@ -2,10 +2,15 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitContactRepository +import org.slf4j.LoggerFactory @UseCase class DeleteControlUnitContact(private val controlUnitContactRepository: IControlUnitContactRepository) { + private val logger = LoggerFactory.getLogger(DeleteControlUnitContact::class.java) + fun execute(controlUnitContactId: Int) { - return controlUnitContactRepository.deleteById(controlUnitContactId) + logger.info("Attempt to DELETE control unit contact $controlUnitContactId") + controlUnitContactRepository.deleteById(controlUnitContactId) + logger.info("Control unit contact $controlUnitContactId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResource.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResource.kt index adbaf6329..336933779 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResource.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResource.kt @@ -3,19 +3,24 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository +import org.slf4j.LoggerFactory @UseCase class DeleteControlUnitResource( private val canDeleteControlUnitResource: CanDeleteControlUnitResource, private val controlUnitResourceRepository: IControlUnitResourceRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteControlUnitResource::class.java) + fun execute(controlUnitResourceId: Int) { + logger.info("Attempt to DELETE control unit resource $controlUnitResourceId") + if (!canDeleteControlUnitResource.execute(controlUnitResourceId)) { throw CouldNotDeleteException( "Cannot delete control unit resource (ID=$controlUnitResourceId) due to existing relationships.", ) } - - return controlUnitResourceRepository.deleteById(controlUnitResourceId) + controlUnitResourceRepository.deleteById(controlUnitResourceId) + logger.info("Control unit resource $controlUnitResourceId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitById.kt index a10ac0910..6556de12f 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitById.kt @@ -3,10 +3,15 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitDTO +import org.slf4j.LoggerFactory @UseCase class GetControlUnitById(private val controlUnitRepository: IControlUnitRepository) { + private val logger = LoggerFactory.getLogger(GetControlUnitById::class.java) + fun execute(controlUnitId: Int): FullControlUnitDTO { + logger.info("GET control unit $controlUnitId") + return controlUnitRepository.findById(controlUnitId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactById.kt index 59afb3bf9..eab0e8ebf 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactById.kt @@ -3,10 +3,15 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitContactRepository import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitContactDTO +import org.slf4j.LoggerFactory @UseCase class GetControlUnitContactById(private val controlUnitContactRepository: IControlUnitContactRepository) { + private val logger = LoggerFactory.getLogger(GetControlUnitById::class.java) + fun execute(controlUnitContactId: Int): FullControlUnitContactDTO { + logger.info("GET control unit contact $controlUnitContactId") + return controlUnitContactRepository.findById(controlUnitContactId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContacts.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContacts.kt index e12acee5d..c73c18cad 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContacts.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContacts.kt @@ -10,9 +10,9 @@ class GetControlUnitContacts(private val controlUnitContactRepository: IControlU private val logger = LoggerFactory.getLogger(GetControlUnitContacts::class.java) fun execute(): List { + logger.info("Attempt to GET all control unit contacts") val fullControlUnitContacts = controlUnitContactRepository.findAll() - - logger.info("Found ${fullControlUnitContacts.size} control unit contacts.") + logger.info("Found ${fullControlUnitContacts.size} control unit contacts") return fullControlUnitContacts } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceById.kt index 73ad74516..c375b6313 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceById.kt @@ -3,10 +3,16 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitResourceDTO +import org.slf4j.LoggerFactory @UseCase class GetControlUnitResourceById(private val controlUnitResourceRepository: IControlUnitResourceRepository) { + private val logger = LoggerFactory.getLogger(GetControlUnitById::class.java) + fun execute(controlUnitResourceId: Int): FullControlUnitResourceDTO { - return controlUnitResourceRepository.findById(controlUnitResourceId) + logger.info("GET control unit resource $controlUnitResourceId") + val controlUnitResourceDTO = controlUnitResourceRepository.findById(controlUnitResourceId) + + return controlUnitResourceDTO } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResources.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResources.kt index d609f78d5..867a7ce23 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResources.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResources.kt @@ -10,9 +10,9 @@ class GetControlUnitResources(private val controlUnitResourceRepository: IContro private val logger = LoggerFactory.getLogger(GetControlUnitResources::class.java) fun execute(): List { + logger.info("Attempt to GET all control unit resources") val fullControlUnitResources = controlUnitResourceRepository.findAll() - - logger.info("Found ${fullControlUnitResources.size} control unit resources.") + logger.info("Found ${fullControlUnitResources.size} control unit resources") return fullControlUnitResources } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnits.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnits.kt index 1ae718483..1c564f913 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnits.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnits.kt @@ -10,8 +10,8 @@ class GetControlUnits(private val controlUnitRepository: IControlUnitRepository) private val logger = LoggerFactory.getLogger(GetControlUnits::class.java) fun execute(): List { + logger.info("Attempt to GET all control units") val fullControlUnits = controlUnitRepository.findAll() - logger.info("Found ${fullControlUnits.size} control units.") return fullControlUnits diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnits.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnits.kt index 5dfb8c5cd..2cf8bdf6a 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnits.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnits.kt @@ -10,6 +10,8 @@ class GetLegacyControlUnits(private val controlUnitRepository: IControlUnitRepos private val logger = LoggerFactory.getLogger(GetLegacyControlUnits::class.java) fun execute(): List { + logger.info("Attempt to GET all legacy control units") + val controlUnits = controlUnitRepository.findAll() val controlUnitsWithActiveControlUnitResources = controlUnits.map { controlUnit -> @@ -20,7 +22,7 @@ class GetLegacyControlUnits(private val controlUnitRepository: IControlUnitRepos }, ) } - logger.info("Found ${controlUnitsWithActiveControlUnitResources.size} control units.") + logger.info("Found ${controlUnitsWithActiveControlUnitResources.size} legacy control units") return controlUnitsWithActiveControlUnitResources.map { it.toLegacyControlUnit() } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboard.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboard.kt index d76757fa3..e962ec931 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboard.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboard.kt @@ -12,8 +12,8 @@ class DeleteDashboard( private val logger = LoggerFactory.getLogger(DeleteDashboard::class.java) fun execute(id: UUID) { + logger.info("Attempt to DELETE dashboard $id") dashboardRepository.delete(id) - - logger.info("Deleted Dashboard: $id") + logger.info("Dashboard $id deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt index 9e12b6c4c..7dd0370c4 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt @@ -8,6 +8,7 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IRegulatoryAreaRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository import org.locationtech.jts.geom.Geometry +import org.slf4j.LoggerFactory @UseCase class ExtractArea( @@ -17,7 +18,10 @@ class ExtractArea( private val ampRepository: IAMPRepository, private val vigilanceAreaRepository: IVigilanceAreaRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteDashboard::class.java) + fun execute(geometry: Geometry): ExtractedAreaEntity { + logger.info("GET extracted area") val inseeCode = departmentAreaRepository.findDepartmentFromGeometry(geometry = geometry) val reportings = reportingRepository.findAllIdsByGeometry(geometry = geometry) val regulatoryAreas = regulatoryAreaRepository.findAllIdsByGeometry(geometry = geometry) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboard.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboard.kt index 2bead5a23..678690f5a 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboard.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboard.kt @@ -6,7 +6,7 @@ import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.repositories.IDashboardRepository import org.slf4j.LoggerFactory -import java.util.* +import java.util.UUID @UseCase class GetDashboard( @@ -15,6 +15,7 @@ class GetDashboard( private val logger = LoggerFactory.getLogger(GetDashboard::class.java) fun execute(id: UUID): DashboardEntity { + logger.info("GET dashboard $id") val dashboard = dashboardRepository.findById(id) if (dashboard == null) { diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboards.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboards.kt index 634f583b5..8954ced64 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboards.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboards.kt @@ -3,12 +3,19 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.dashboard import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.dashboard.DashboardEntity import fr.gouv.cacem.monitorenv.domain.repositories.IDashboardRepository +import org.slf4j.LoggerFactory @UseCase class GetDashboards( private val dashboardRepository: IDashboardRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteDashboard::class.java) + fun execute(): List { - return dashboardRepository.findAll() + logger.info("Attempt to GET all dashboards") + val dashboards = dashboardRepository.findAll() + logger.info("Found ${dashboards.size} dashboards") + + return dashboards } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboard.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboard.kt index 00713c878..6c8a93d93 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboard.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboard.kt @@ -16,9 +16,12 @@ class SaveDashboard( private val logger = LoggerFactory.getLogger(SaveDashboard::class.java) fun execute(dashboard: DashboardEntity): DashboardEntity { + logger.info("Attempt to CREATE or UPDATE dashboard ${dashboard.id}") try { val seaFront = facadeAreasRepository.findFacadeFromGeometry(dashboard.geom) - return dashboardRepository.save(dashboard.copy(seaFront = seaFront)) + val savedDashboard = dashboardRepository.save(dashboard.copy(seaFront = seaFront)) + logger.info("Dashboard ${savedDashboard.id} created or updated") + return savedDashboard } catch (e: Exception) { val errorMessage = "dashboard ${dashboard.id} couldn't be saved" logger.error(errorMessage, e) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCode.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCode.kt index eb8e0381a..607944f8c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCode.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCode.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.departmentArea import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.departmentArea.DepartmentAreaEntity import fr.gouv.cacem.monitorenv.domain.repositories.IDepartmentAreaRepository +import org.slf4j.LoggerFactory @UseCase class GetDepartmentAreaByInseeCode(private val departmentAreaRepository: IDepartmentAreaRepository) { + private val logger = LoggerFactory.getLogger(GetDepartmentAreaByInseeCode::class.java) + fun execute(departmentAreaInseeCode: String): DepartmentAreaEntity { + logger.info("GET department area from insee code $departmentAreaInseeCode") return departmentAreaRepository.findByInseeCode(departmentAreaInseeCode) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreas.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreas.kt index c8908701e..9b64f970f 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreas.kt @@ -10,9 +10,9 @@ class GetDepartmentAreas(private val departmentAreaRepository: IDepartmentAreaRe private val logger = LoggerFactory.getLogger(GetDepartmentAreas::class.java) fun execute(): List { + logger.info("Attempt to GET all department areas") val departmentAreas = departmentAreaRepository.findAll() - - logger.info("Found ${departmentAreas.size} departmentAreas.") + logger.info("Found ${departmentAreas.size} department areas") return departmentAreas } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMission.kt index ba2d88d3f..1b511a3cf 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMission.kt @@ -5,6 +5,7 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.slf4j.LoggerFactory import java.time.ZonedDateTime @UseCase @@ -13,7 +14,10 @@ class BypassActionCheckAndDeleteMission( private val missionRepository: IMissionRepository, private val reportingRepository: IReportingRepository, ) { + private val logger = LoggerFactory.getLogger(BypassActionCheckAndDeleteMission::class.java) + fun execute(missionId: Int) { + logger.info("Attempt to DELETE mission $missionId without checking actions") val missionToDelete = getFullMission.execute(missionId) missionToDelete.attachedReportingIds?.let { attachedReportingIds -> if (attachedReportingIds.isNotEmpty()) { @@ -37,7 +41,8 @@ class BypassActionCheckAndDeleteMission( reportingRepository.save(detachedReporting) } } - return missionRepository.delete(missionId) + missionRepository.delete(missionId) + logger.info("Mission $missionId deleted") } } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMission.kt index c21dcfc3d..986b2d77c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMission.kt @@ -21,7 +21,7 @@ class CanDeleteMission( missionId: Int, source: MissionSourceEnum, ): CanDeleteMissionResponse { - logger.info("Check if mission $missionId can be deleted") + logger.info("Can mission $missionId be deleted") if (source == MissionSourceEnum.MONITORFISH) { return canMonitorFishDeleteMission(missionId) @@ -85,9 +85,7 @@ class CanDeleteMission( ) } - if (fishActions.isNotEmpty() && - !rapportNavActions.containsActionsAddedByUnit - ) { + if (fishActions.isNotEmpty()) { return CanDeleteMissionResponse( canDelete = false, sources = listOf(MissionSourceEnum.MONITORFISH), diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActions.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActions.kt index e601e92d5..ede57e8af 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActions.kt @@ -11,6 +11,7 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IDepartmentAreaRepository import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IPostgisFunctionRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateEnvActions( @@ -19,11 +20,14 @@ class CreateOrUpdateEnvActions( private val missionRepository: IMissionRepository, private val postgisFunctionRepository: IPostgisFunctionRepository, ) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateEnvActions::class.java) + @Throws(IllegalArgumentException::class) fun execute( mission: MissionEntity, envActions: List?, ): MissionEntity { + logger.info("Attempt to CREATE or UPDATE mission ${mission.id} with envActions ${envActions?.map { it.id }}") val envActionsToSave = envActions?.map { when (it.actionType) { @@ -80,6 +84,10 @@ class CreateOrUpdateEnvActions( ) val savedMission = missionRepository.save(missionToSave) + logger.info( + "Mission ${savedMission.mission.id} with envActions ${envActions?.map { it.id }} created or updated", + ) + if (savedMission.mission.id == null) { throw IllegalArgumentException("Mission id is null") } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt index 4c3cef30d..5d4bf703e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt @@ -20,6 +20,8 @@ class CreateOrUpdateMission( @Throws(IllegalArgumentException::class) fun execute(mission: MissionEntity): MissionEntity { + logger.info("Attempt to CREATE or UPDATE mission ${mission.id}") + val normalizedMission = mission.geom?.let { nonNullGeom -> mission.copy(geom = postgisFunctionRepository.normalizeMultipolygon(nonNullGeom)) @@ -39,6 +41,7 @@ class CreateOrUpdateMission( ) val savedMission = missionRepository.save(missionToSave) + logger.info("Mission ${savedMission.mission.id} created or updated") if (savedMission.mission.id == null) { throw IllegalArgumentException("Mission id is null") } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReporting.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReporting.kt index 38eae101a..30b622e7a 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReporting.kt @@ -31,7 +31,7 @@ class CreateOrUpdateMissionWithActionsAndAttachedReporting( envActionsAttachedToReportingIds: List, ): Pair { logger.info( - "Create or update mission: ${mission.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: $envActionsAttachedToReportingIds", + "Attempt to CREATE or UPDATE mission: ${mission.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: $envActionsAttachedToReportingIds", ) if (mission.id != null) { reportingRepository.detachDanglingEnvActions( @@ -66,6 +66,10 @@ class CreateOrUpdateMissionWithActionsAndAttachedReporting( reportingRepository.attachEnvActionsToReportings(it.first, it.second) } + logger.info( + "Mission: ${mission.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: $envActionsAttachedToReportingIds created or updated", + ) + if (mission.id == null) { val newMission = getFullMission.execute(savedMission.id) return Pair(true, newMission.copy(fishActions = listOf(), hasRapportNavActions = null)) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMission.kt index 71899123c..8796fe109 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMission.kt @@ -26,7 +26,7 @@ class DeleteMission( ) { require(missionId != null) { "No mission to delete" } - logger.info("Delete mission $missionId") + logger.info("Attempt to delete mission $missionId") val missionToDelete = getFullMission.execute(missionId) @@ -73,6 +73,7 @@ class DeleteMission( ) } - return missionRepository.delete(missionId) + missionRepository.delete(missionId) + logger.info("Mission $missionId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnits.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnits.kt index 636f60370..2c91e7c29 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnits.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnits.kt @@ -14,6 +14,8 @@ class GetEngagedControlUnits(private val getFullMissions: GetFullMissions) { private val logger = LoggerFactory.getLogger(GetEngagedControlUnits::class.java) fun execute(): List { + logger.info("Attempt to GET all engaged control units") + val openedMissions = getFullMissions.execute( startedAfterDateTime = ZonedDateTime.now().minusMonths(2), @@ -54,7 +56,7 @@ class GetEngagedControlUnits(private val getFullMissions: GetFullMissions) { Pair(controlUnit, missionSources) } - logger.info("Found ${controlUnitToMissionSources.size} engaged control unit(s).") + logger.info("Found ${controlUnitToMissionSources.size} engaged control units") return controlUnitToMissionSources } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMission.kt index fecd5daa9..d7c482630 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMission.kt @@ -4,13 +4,18 @@ import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.dashboard.DeleteDashboard import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import org.slf4j.LoggerFactory @UseCase class GetFullMission( private val missionRepository: IMissionRepository, ) { + private val logger = LoggerFactory.getLogger(DeleteDashboard::class.java) + fun execute(missionId: Int): MissionDTO { + logger.info("GET full mission $missionId with fish and rapport nav action") missionRepository.findFullMissionById(missionId)?.let { return it } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActions.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActions.kt index 10bb37e93..11b83f156 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActions.kt @@ -4,6 +4,7 @@ import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IMonitorFishMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.repositories.IRapportNavMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import org.slf4j.LoggerFactory @UseCase class GetFullMissionWithFishAndRapportNavActions( @@ -11,7 +12,10 @@ class GetFullMissionWithFishAndRapportNavActions( private val monitorFishMissionActionsRepository: IMonitorFishMissionActionsRepository, private val rapportNavMissionActionsRepository: IRapportNavMissionActionsRepository, ) { + private val logger = LoggerFactory.getLogger(GetFullMissionWithFishAndRapportNavActions::class.java) + fun execute(missionId: Int): Pair { + logger.info("GET full mission $missionId with fish and rapport nav action") getFullMission.execute(missionId).let { try { val fishActions = monitorFishMissionActionsRepository.findFishMissionActionsById(missionId) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissions.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissions.kt index 320b1acc5..3edc9bb4a 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissions.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissions.kt @@ -24,6 +24,7 @@ class GetFullMissions( seaFronts: List?, searchQuery: String?, ): List { + logger.info("Attempt to GET all full missions") val missions = missionRepository.findAllFullMissions( startedAfter = @@ -43,7 +44,7 @@ class GetFullMissions( searchQuery = searchQuery, ) - logger.info("Found ${missions.size} mission(s)") + logger.info("Found ${missions.size} full mission(s)") return missions } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMission.kt index 60345a376..3f1bba4ce 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMission.kt @@ -5,12 +5,16 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import org.slf4j.LoggerFactory @UseCase class GetMission( private val missionRepository: IMissionRepository, ) { + private val logger = LoggerFactory.getLogger(GetMission::class.java) + fun execute(missionId: Int): MissionEntity { + logger.info("GET mission $missionId") missionRepository.findById(missionId)?.let { return it } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceAction.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceAction.kt index 3b0ad51eb..aa7924c2b 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceAction.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceAction.kt @@ -5,6 +5,7 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum import fr.gouv.cacem.monitorenv.domain.repositories.IMonitorFishMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.repositories.IRapportNavMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import org.slf4j.LoggerFactory @UseCase class GetMissionAndSourceAction( @@ -12,10 +13,13 @@ class GetMissionAndSourceAction( private val apiFishMissionActionsRepository: IMonitorFishMissionActionsRepository, private val apiRapportNavMissionActionsRepository: IRapportNavMissionActionsRepository, ) { + private val logger = LoggerFactory.getLogger(GetFullMissionWithFishAndRapportNavActions::class.java) + fun execute( missionId: Int, source: MissionSourceEnum?, ): MissionDTO { + logger.info("GET mission $missionId and source action") getMission.execute(missionId).let { when (source) { MissionSourceEnum.MONITORFISH -> return MissionDTO( diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActions.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActions.kt index 22d05aa2c..85da6ee67 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActions.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActions.kt @@ -3,13 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IRapportNavMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import org.slf4j.LoggerFactory @UseCase class GetMissionWithRapportNavActions( private val getMission: GetMission, private val rapportNavMissionActionsRepository: IRapportNavMissionActionsRepository, ) { + private val logger = LoggerFactory.getLogger(GetFullMissionWithFishAndRapportNavActions::class.java) + fun execute(missionId: Int): MissionDTO { + logger.info("GET mission $missionId with rapportNavActions") getMission.execute(missionId).let { try { val hasRapportNavActions = diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissions.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissions.kt index 498d4c488..aff49600b 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissions.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissions.kt @@ -26,6 +26,8 @@ class GetMissions(private val missionRepository: IMissionRepository) { startedBeforeDateTime: ZonedDateTime? = null, searchQuery: String? = null, ): List { + logger.info("Attempt to GET all missions") + val missions: List = missionRepository.findAll( controlUnitIds = controlUnitIds, @@ -47,7 +49,7 @@ class GetMissions(private val missionRepository: IMissionRepository) { searchQuery = searchQuery, ) - logger.info("Found ${missions.size} mission(s)") + logger.info("Found ${missions.size} missions") return missions } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIds.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIds.kt index 74b38ebc5..7ae69754f 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIds.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIds.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import org.slf4j.LoggerFactory @UseCase class GetMissionsByIds(private val missionRepository: IMissionRepository) { + private val logger = LoggerFactory.getLogger(GetMissions::class.java) + fun execute(ids: List): List { + logger.info("GET missions $ids") return missionRepository.findByIds(ids) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMission.kt index e38a2acd7..61812339c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMission.kt @@ -8,20 +8,26 @@ import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.mappers.PatchEntity import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import org.slf4j.LoggerFactory @UseCase class PatchMission( private val missionRepository: IMissionRepository, private val patchEntity: PatchEntity, ) { + private val logger = LoggerFactory.getLogger(GetFullMissionWithFishAndRapportNavActions::class.java) + fun execute( id: Int, patchableMissionEntity: PatchableMissionEntity, ): MissionDTO { + logger.info("Attempt to PATCH mission $id") missionRepository.findById(id)?.let { patchEntity.execute(it, patchableMissionEntity) - return missionRepository.save(it) + val patchedMission = missionRepository.save(it) + logger.info("Mission $id patched") + return patchedMission } - throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_FOUND, "mission $id not found") + throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_FOUND, "Mission $id not found") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfs.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfs.kt index 041c21633..4b4a99d25 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfs.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfs.kt @@ -12,6 +12,7 @@ class GetAllNatinfs(private val natinfRepository: INatinfRepository) { private val logger = LoggerFactory.getLogger(GetAllNatinfs::class.java) fun execute(): List { + logger.info("Attempt to GET all natinfs") val natinfs = natinfRepository.findAll() logger.info("Found ${natinfs.size} natinfs") diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreas.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreas.kt index b5e93acae..9d55b52ca 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreas.kt @@ -1,5 +1,3 @@ -@file:Suppress("ktlint:standard:package-name") - package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas import fr.gouv.cacem.monitorenv.config.UseCase @@ -12,8 +10,9 @@ class GetAllRegulatoryAreas(private val regulatoryAreaRepository: IRegulatoryAre private val logger = LoggerFactory.getLogger(GetAllRegulatoryAreas::class.java) fun execute(): List { + logger.info("Attempt to GET all regulatory areas") val regulatoryAreas = regulatoryAreaRepository.findAll() - logger.info("Found ${regulatoryAreas.size} regulatory areas ") + logger.info("Found ${regulatoryAreas.size} regulatory areas") return regulatoryAreas } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaById.kt index bf377951c..021312f74 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaById.kt @@ -12,8 +12,8 @@ class GetRegulatoryAreaById(private val regulatoryAreaRepository: IRegulatoryAre private val logger = LoggerFactory.getLogger(GetRegulatoryAreaById::class.java) fun execute(regulatoryAreaId: Int): RegulatoryAreaEntity { - val regulatoryArea = regulatoryAreaRepository.findById(regulatoryAreaId) + logger.info("GET regulatory area $regulatoryAreaId") - return regulatoryArea + return regulatoryAreaRepository.findById(regulatoryAreaId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportings.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportings.kt index c77581229..0dd0155de 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportings.kt @@ -15,8 +15,8 @@ class ArchiveOutdatedReportings( // At every 5 minutes, after 1 minute of initial delay @Scheduled(fixedDelay = 300000, initialDelay = 6000) fun execute() { - logger.info("Archiving reportings") + logger.info("Attempt to ARCHIVE reportings") val numberOfArchivedReportings = reportingRepository.archiveOutdatedReportings() - logger.info("Archived $numberOfArchivedReportings reportings") + logger.info("$numberOfArchivedReportings reportings archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportings.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportings.kt index 1153be55e..42216f999 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportings.kt @@ -11,11 +11,9 @@ class ArchiveReportings( ) { private val logger: Logger = LoggerFactory.getLogger(ArchiveReportings::class.java) - @Throws(IllegalArgumentException::class) fun execute(ids: List) { - logger.info("Archive reportings: $ids") - - require(ids.isNotEmpty()) { "No reportings to archive" } - return reportingRepository.archiveReportings(ids) + logger.info("Attempt to ARCHIVE reportings $ids") + reportingRepository.archiveReportings(ids) + logger.info("reportings $ids archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReporting.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReporting.kt index 4d6657a04..73db477c0 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReporting.kt @@ -21,7 +21,7 @@ class CreateOrUpdateReporting( @Throws(IllegalArgumentException::class) fun execute(reporting: ReportingEntity): ReportingDTO { - logger.info("Create or update reporting: $reporting.id") + logger.info("Attempt to CREATE or UPDATE reporting ${reporting.id}") reporting.validate() val reportingToSaveIsAttachedToMission = @@ -58,6 +58,7 @@ class CreateOrUpdateReporting( seaFront = seaFront, ), ) + logger.info("Reporting ${savedReporting.reporting.id} created or updated") logger.info("Sending CREATE/UPDATE event for reporting id ${savedReporting.reporting.id}.") eventPublisher.publishEvent( diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReporting.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReporting.kt index 4b9e394fe..9f565782e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReporting.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReporting.kt @@ -9,11 +9,9 @@ import org.slf4j.LoggerFactory class DeleteReporting(private val reportingRepository: IReportingRepository) { private val logger: Logger = LoggerFactory.getLogger(DeleteReporting::class.java) - @Throws(IllegalArgumentException::class) - fun execute(id: Int?) { - logger.info("Delete reporting: $id") - - require(id != null) { "No reporting to delete" } + fun execute(id: Int) { + logger.info("Attempt to DELETE reporting $id") reportingRepository.delete(id) + logger.info("reporting $id deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportings.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportings.kt index 0e5c29b0b..7366263dc 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportings.kt @@ -6,16 +6,12 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory @UseCase -class DeleteReportings( - private val reportingRepository: IReportingRepository, -) { +class DeleteReportings(private val reportingRepository: IReportingRepository) { private val logger: Logger = LoggerFactory.getLogger(DeleteReportings::class.java) - @Throws(IllegalArgumentException::class) fun execute(ids: List) { - logger.info("Delete reportings: $ids") - - require(ids.isNotEmpty()) { "No reportings to delete" } - return reportingRepository.deleteReportings(ids) + logger.info("Attempt to DELETE reportings $ids") + reportingRepository.deleteReportings(ids) + logger.info("reportings $ids deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingById.kt index 1a7b4ace4..073cc03ef 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingById.kt @@ -3,14 +3,18 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO +import org.slf4j.Logger +import org.slf4j.LoggerFactory @UseCase class GetReportingById( private val reportingRepository: IReportingRepository, ) { + private val logger: Logger = LoggerFactory.getLogger(DeleteReportings::class.java) + fun execute(id: Int): ReportingDTO { - val reporting = reportingRepository.findById(id) + logger.info("GET reporting $id") - return reporting + return reportingRepository.findById(id) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportings.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportings.kt index 56f529b83..9e334a80c 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportings.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportings.kt @@ -28,6 +28,8 @@ class GetReportings( isAttachedToMission: Boolean?, searchQuery: String?, ): List { + logger.info("Attempt to get reportings with criteria") + val now = ZonedDateTime.now() val reports = reportingRepository.findAll( reportingType = reportingType, @@ -35,7 +37,7 @@ class GetReportings( sourcesType = sourcesType, startedAfter = startedAfterDateTime?.toInstant() - ?: ZonedDateTime.now().minusDays(30).toInstant(), + ?: now.minusDays(30).toInstant(), startedBefore = startedBeforeDateTime?.toInstant(), status = status, targetTypes = targetTypes, @@ -44,10 +46,7 @@ class GetReportings( pageSize = pageSize, searchQuery = searchQuery, ) - - logger.info( - "Found ${reports.size} reporting(s)", - ) + logger.info("Found ${reports.size} reportings with criteria") return reports } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIds.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIds.kt index b3868cea5..5a6353405 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIds.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIds.kt @@ -3,12 +3,16 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO +import org.slf4j.LoggerFactory @UseCase class GetReportingsByIds( private val reportingRepository: IReportingRepository, ) { + private val logger = LoggerFactory.getLogger(GetReportingsByIds::class.java) + fun execute(ids: List): List { + logger.info("GET reportings $ids") val reportings = reportingRepository.findAllById(ids) return reportings diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphores.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphores.kt index 303b25319..b0742027e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphores.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphores.kt @@ -10,8 +10,10 @@ class GetAllSemaphores(private val semaphoreRepository: ISemaphoreRepository) { private val logger = LoggerFactory.getLogger(GetAllSemaphores::class.java) fun execute(): List { + logger.info("Attempt to GET all semaphores") val semaphores = semaphoreRepository.findAll() - logger.info("Found ${semaphores.size} semaphore(s)") + logger.info("Found ${semaphores.size} semaphores") + return semaphores } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreById.kt index 3083f8c18..1c929bb5e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreById.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.semaphores import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.semaphore.SemaphoreEntity import fr.gouv.cacem.monitorenv.domain.repositories.ISemaphoreRepository +import org.slf4j.LoggerFactory @UseCase class GetSemaphoreById(private val semaphoreRepository: ISemaphoreRepository) { + private val logger = LoggerFactory.getLogger(GetAllSemaphores::class.java) + fun execute(id: Int): SemaphoreEntity { + logger.info("GET semaphore $id") return semaphoreRepository.findById(id) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStation.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStation.kt index 38bf8a6f3..f32b11324 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStation.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStation.kt @@ -2,10 +2,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.station import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IStationRepository +import org.slf4j.LoggerFactory @UseCase class CanDeleteStation(private val stationRepository: IStationRepository) { + private val logger = LoggerFactory.getLogger(CanDeleteStation::class.java) + fun execute(stationId: Int): Boolean { + logger.info("Can station $stationId be deleted") val fullStation = stationRepository.findById(stationId) return fullStation.controlUnitResources.isEmpty() diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStation.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStation.kt index fd3bf0295..6b3b3f7df 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStation.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStation.kt @@ -3,10 +3,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.station import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.station.StationEntity import fr.gouv.cacem.monitorenv.domain.repositories.IStationRepository +import org.slf4j.LoggerFactory @UseCase class CreateOrUpdateStation(private val stationRepository: IStationRepository) { + private val logger = LoggerFactory.getLogger(CreateOrUpdateStation::class.java) + fun execute(station: StationEntity): StationEntity { - return stationRepository.save(station) + logger.info("Attempt to CREATE or UPDATE station ${station.id}") + val savedStation = stationRepository.save(station) + logger.info("Station ${savedStation.id} created or updated") + + return savedStation } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStation.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStation.kt index 137c77c93..8f068df65 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStation.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStation.kt @@ -3,19 +3,23 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.station import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IStationRepository +import org.slf4j.LoggerFactory @UseCase class DeleteStation( private val stationRepository: IStationRepository, private val canDeleteStation: CanDeleteStation, ) { + private val logger = LoggerFactory.getLogger(DeleteStation::class.java) + fun execute(stationId: Int) { + logger.info("Attempt to DELETE station $stationId") if (!canDeleteStation.execute(stationId)) { throw CouldNotDeleteException( "Cannot delete station (ID=$stationId) due to existing relationships.", ) } - stationRepository.deleteById(stationId) + logger.info("Station $stationId deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationById.kt index c5454b5f1..968ce4766 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationById.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.station import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IStationRepository import fr.gouv.cacem.monitorenv.domain.use_cases.station.dtos.FullStationDTO +import org.slf4j.LoggerFactory @UseCase class GetStationById(private val stationRepository: IStationRepository) { + private val logger = LoggerFactory.getLogger(GetStationById::class.java) + fun execute(stationId: Int): FullStationDTO { + logger.info("GET station $stationId") return stationRepository.findById(stationId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStations.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStations.kt index 285840999..770565cba 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStations.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStations.kt @@ -10,9 +10,10 @@ class GetStations(private val stationRepository: IStationRepository) { private val logger = LoggerFactory.getLogger(GetStations::class.java) fun execute(): List { + logger.info("Attempt to GET all stations") val fullStations = stationRepository.findAll() - logger.info("Found ${fullStations.size} stations.") + logger.info("Found ${fullStations.size} stations") return fullStations } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreas.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreas.kt index 341c4928f..67b70ff33 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreas.kt @@ -15,8 +15,8 @@ class ArchiveOutdatedVigilanceAreas( // At every 6 hours, after 1 minute of initial delay @Scheduled(fixedDelay = 21600000, initialDelay = 6000) fun execute() { - logger.info("Archiving vigilance areas") + logger.info("Attempt to ARCHIVE vigilance areas") val numberOfArchivedVigilanceAreas = vigilanceAreaRepository.archiveOutdatedVigilanceAreas() - logger.info("Archived $numberOfArchivedVigilanceAreas vigilance areas") + logger.info("$numberOfArchivedVigilanceAreas vigilance areas archived") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceArea.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceArea.kt index d49506c8a..5ad5e3ae4 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceArea.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceArea.kt @@ -17,15 +17,18 @@ class CreateOrUpdateVigilanceArea( private val logger = LoggerFactory.getLogger(SaveDashboard::class.java) fun execute(vigilanceArea: VigilanceAreaEntity): VigilanceAreaEntity { + logger.info("Attempt to CREATE or UPDATE vigilance area ${vigilanceArea.id}") try { val seaFront = vigilanceArea.geom?.let { nonNullGeom -> facadeAreasRepository.findFacadeFromGeometry(nonNullGeom) } - return vigilanceAreaRepository.save(vigilanceArea.copy(seaFront = seaFront)) + val savedVigilanceArea = vigilanceAreaRepository.save(vigilanceArea.copy(seaFront = seaFront)) + logger.info("Vigilance area ${savedVigilanceArea.id} created or updated") + return savedVigilanceArea } catch (e: Exception) { - val errorMessage = "dashboard ${vigilanceArea.id} couldn't be saved" + val errorMessage = "vigilance area ${vigilanceArea.id} couldn't be saved" logger.error(errorMessage, e) throw BackendUsageException(BackendUsageErrorCode.ENTITY_NOT_SAVED, message = errorMessage) } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceArea.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceArea.kt index 16941839b..6c57b71c9 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceArea.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceArea.kt @@ -10,8 +10,8 @@ class DeleteVigilanceArea(private val vigilanceAreaRepository: IVigilanceAreaRep private val logger: Logger = LoggerFactory.getLogger(DeleteVigilanceArea::class.java) fun execute(id: Int) { - logger.info("Delete vigilance area: $id") - + logger.info("Attempt to DELETE vigilance area $id") vigilanceAreaRepository.delete(id) + logger.info("Vigilance area $id deleted") } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigrams.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigrams.kt index 697b78d2d..6f1dce91e 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigrams.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigrams.kt @@ -2,10 +2,17 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository +import org.slf4j.LoggerFactory @UseCase class GetTrigrams(private val vigilanceAreaRepository: IVigilanceAreaRepository) { + private val logger = LoggerFactory.getLogger(GetTrigrams::class.java) + fun execute(): List { - return vigilanceAreaRepository.findAllTrigrams() + logger.info("Attempt to GET all vigilance areas creators trigrams") + val trigrams = vigilanceAreaRepository.findAllTrigrams() + logger.info("Found ${trigrams.size} trigrams") + + return trigrams } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaById.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaById.kt index eb60a2520..b598e05e3 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaById.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaById.kt @@ -3,10 +3,14 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VigilanceAreaEntity import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository +import org.slf4j.LoggerFactory @UseCase class GetVigilanceAreaById(private val vigilanceAreaRepository: IVigilanceAreaRepository) { + private val logger = LoggerFactory.getLogger(GetVigilanceAreas::class.java) + fun execute(vigilanceAreaId: Int): VigilanceAreaEntity? { + logger.info("GET vigilance area $vigilanceAreaId") return vigilanceAreaRepository.findById(vigilanceAreaId) } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreas.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreas.kt index d816aae1c..f601d4059 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreas.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreas.kt @@ -3,10 +3,16 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea import fr.gouv.cacem.monitorenv.config.UseCase import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VigilanceAreaEntity import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository +import org.slf4j.LoggerFactory @UseCase class GetVigilanceAreas(private val vigilanceAreaRepository: IVigilanceAreaRepository) { + private val logger = LoggerFactory.getLogger(GetVigilanceAreas::class.java) + fun execute(): List { - return vigilanceAreaRepository.findAll() + logger.info("Attempt to GET all vigilance areas") + val vigilanceAreas = vigilanceAreaRepository.findAll() + logger.info("Found ${vigilanceAreas.size} vigilance areas") + return vigilanceAreas } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt index 78ce922dd..e24796006 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt @@ -27,13 +27,13 @@ import jakarta.persistence.NamedEntityGraph import jakarta.persistence.NamedSubgraph import jakarta.persistence.OneToMany import jakarta.persistence.OrderBy +import jakarta.persistence.PrePersist +import jakarta.persistence.PreUpdate import jakarta.persistence.Table import org.hibernate.Hibernate -import org.hibernate.annotations.CreationTimestamp import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.JdbcType -import org.hibernate.annotations.UpdateTimestamp import org.hibernate.dialect.PostgreSQLEnumJdbcType import org.locationtech.jts.geom.MultiPolygon import org.n52.jackson.datatype.jts.GeometryDeserializer @@ -198,8 +198,7 @@ class MissionModel( val controlUnits: MutableSet? = LinkedHashSet(), @Column(name = "completed_by") val completedBy: String? = null, @Column(name = "created_at_utc", updatable = false) - @CreationTimestamp - val createdAtUtc: Instant? = null, + var createdAtUtc: Instant?, @OneToMany( mappedBy = "mission", cascade = [CascadeType.ALL], @@ -234,7 +233,7 @@ class MissionModel( @Column(name = "observations_cnsp") val observationsCnsp: String? = null, @Column(name = "open_by") val openBy: String? = null, @Column(name = "start_datetime_utc") val startDateTimeUtc: Instant, - @Column(name = "updated_at_utc") @UpdateTimestamp val updatedAtUtc: Instant? = null, + @Column(name = "updated_at_utc") var updatedAtUtc: Instant?, ) { fun toMissionEntity(objectMapper: ObjectMapper): MissionEntity { val mappedControlUnits = @@ -369,6 +368,8 @@ class MissionModel( observationsCnsp = mission.observationsCnsp, openBy = mission.openBy, startDateTimeUtc = mission.startDateTimeUtc.toInstant(), + createdAtUtc = mission.createdAtUtc?.toInstant(), + updatedAtUtc = mission.updatedAtUtc?.toInstant(), ) mission.envActions?.map { @@ -422,4 +423,14 @@ class MissionModel( } override fun hashCode(): Int = javaClass.hashCode() + + @PrePersist + private fun prePersist() { + this.createdAtUtc = Instant.now() + } + + @PreUpdate + private fun preUpdate() { + this.updatedAtUtc = Instant.now() + } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBControlUnitRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBControlUnitRepository.kt index 4f997e183..abbeb69e3 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBControlUnitRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBControlUnitRepository.kt @@ -23,7 +23,7 @@ interface IDBControlUnitRepository : JpaRepository { value = """ SELECT * FROM control_units - ORDER BY name ASC + ORDER BY name """, nativeQuery = true, ) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt index 2a8f09f71..fb10fc3ab 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBVigilanceAreaRepository.kt @@ -47,6 +47,7 @@ interface IDBVigilanceAreaRepository : JpaRepository { """ SELECT DISTINCT vigilanceArea.createdBy FROM VigilanceAreaModel vigilanceArea WHERE vigilanceArea.createdBy IS NOT NULL + ORDER BY vigilanceArea.createdBy """, ) fun findAllTrigrams(): List diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvActionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvActionUTest.kt index b76c3f44b..d7a5644c1 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvActionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/actions/PatchEnvActionUTest.kt @@ -12,10 +12,15 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.actions.fixtures.EnvActionFixtu import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import java.time.ZonedDateTime -import java.util.* +import java.util.Optional +import java.util.UUID +@ExtendWith(OutputCaptureExtension::class) class PatchEnvActionUTest { private val envActionRepository: IEnvActionRepository = mock() private val patchEntity: PatchEntity = PatchEntity() @@ -23,7 +28,7 @@ class PatchEnvActionUTest { private val objectMapper: ObjectMapper = ObjectMapper() @Test - fun `execute() should return the patched entity`() { + fun `execute() should return the patched entity`(log: CapturedOutput) { // Given val id = UUID.randomUUID() val today = ZonedDateTime.now() @@ -59,6 +64,8 @@ class PatchEnvActionUTest { assertThat(savedEnvAction.actionEndDateTimeUtc).isEqualTo(envActionPatched.actionEndDateTimeUtc) assertThat(savedEnvAction.observationsByUnit).isEqualTo(envActionPatched.observationsByUnit) verify(envActionRepository).save(envActionPatched) + assertThat(log.out).contains("Attempt to PATCH envaction $id") + assertThat(log.out).contains("envaction $id patched") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt index 833b09808..236f7c722 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt @@ -9,11 +9,14 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.mockito.Mock import org.mockito.Mockito.mock import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class ArchiveAdministrationUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @@ -22,7 +25,7 @@ class ArchiveAdministrationUTests { private val canArchiveAdministration: CanArchiveAdministration = mock() @Test - fun `execute should archive when canArchive returns true`() { + fun `execute should archive when canArchive returns true`(log: CapturedOutput) { val administrationId = 1 given(canArchiveAdministration.execute(administrationId)).willReturn(true) @@ -30,6 +33,9 @@ class ArchiveAdministrationUTests { ArchiveAdministration(administrationRepository, canArchiveAdministration).execute(administrationId) verify(administrationRepository).archiveById(administrationId) + + assertThat(log.out).contains("Attempt to ARCHIVE administration $administrationId") + assertThat(log.out).contains("Administration $administrationId archived") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt index 848cd33d5..ac352847b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanArchiveAdministrationUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @Test - fun `execute should return true when all control units are archived`() { + fun `execute should return true when all control units are archived`(log: CapturedOutput) { val administrationId = 1 val fullAdministration = FullAdministrationDTO( @@ -47,6 +50,7 @@ class CanArchiveAdministrationUTests { val result = CanArchiveAdministration(administrationRepository).execute(administrationId) assertThat(result).isTrue + assertThat(log.out).contains("Can administration $administrationId be archived") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministrationUTests.kt index 4d09bd1e8..bbeb9ba80 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministrationUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanDeleteAdministrationUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @Test - fun `execute should return true when control units are empty`() { + fun `execute should return true when control units are empty`(log: CapturedOutput) { val administrationId = 1 val fullAdministration = FullAdministrationDTO( @@ -36,6 +39,7 @@ class CanDeleteAdministrationUTests { val result = CanDeleteAdministration(administrationRepository).execute(administrationId) assertThat(result).isTrue + assertThat(log.out).contains("Can administration $administrationId be deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt index 3eb2045be..22553d79d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/CreateOrUpdateAdministrationUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateAdministrationUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @Test - fun `execute should return save result`() { + fun `execute should return save result`(log: CapturedOutput) { val newAdministration = AdministrationEntity( isArchived = false, @@ -33,5 +36,7 @@ class CreateOrUpdateAdministrationUTests { verify(administrationRepository, times(1)).save(newAdministration) assertThat(result).isEqualTo(expectedAdministration) + assertThat(log.out).contains("Attempt to CREATE or UPDATE administration ${newAdministration.id}") + assertThat(log.out).contains("Created or updated administration ${result.id}") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministrationUTests.kt index 54a638d9a..427d5b823 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministrationUTests.kt @@ -4,14 +4,18 @@ import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository +import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class DeleteAdministrationUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @@ -20,7 +24,7 @@ class DeleteAdministrationUTests { private val canDeleteAdministration: CanDeleteAdministration = mock() @Test - fun `execute should delete when canDeleteAdministration returns true`() { + fun `execute should delete when canDeleteAdministration returns true`(log: CapturedOutput) { val administrationId = 1 given(canDeleteAdministration.execute(administrationId)).willReturn(true) @@ -28,6 +32,8 @@ class DeleteAdministrationUTests { DeleteAdministration(administrationRepository, canDeleteAdministration).execute(administrationId) verify(administrationRepository).deleteById(administrationId) + assertThat(log.out).contains("Attempt to DELETE administration $administrationId") + assertThat(log.out).contains("Administration $administrationId deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationByIdUTests.kt index f93f833f0..675103468 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationByIdUTests.kt @@ -9,15 +9,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetAdministrationByIdUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @Test - fun `execute should return an administration by its ID`() { + fun `execute should return an administration by its ID`(log: CapturedOutput) { val administrationId = 1 val fullAdministration = FullAdministrationDTO( @@ -35,5 +38,6 @@ class GetAdministrationByIdUTests { val result = GetAdministrationById(administrationRepository).execute(administrationId) assertThat(result).isEqualTo(fullAdministration) + assertThat(log.out).contains("GET administration $administrationId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationsUTests.kt index a225f2d1b..daa948c0f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationsUTests.kt @@ -9,15 +9,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetAdministrationsUTests { @Mock private val administrationRepository: IAdministrationRepository = mock() @Test - fun `execute should return all administrations`() { + fun `execute should return all administrations`(log: CapturedOutput) { val fullAdministrations = listOf( FullAdministrationDTO( @@ -46,5 +49,7 @@ class GetAdministrationsUTests { assertThat(result.size).isEqualTo(2) assertThat(result).isEqualTo(fullAdministrations) + assertThat(log.out).contains("Attempt to GET all administrations") + assertThat(log.out).contains("Found ${result.size} administrations") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt index 0b13b1a94..9f26c3d6c 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/amps/GetAllAMPsUTest.kt @@ -1,12 +1,32 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.amps +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IAMPRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.amp.fixtures.AmpFixture.Companion.anAmp +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -import org.junit.jupiter.api.Assertions.* - +@ExtendWith(OutputCaptureExtension::class) class GetAllAMPsUTest { + private val ampRepository: IAMPRepository = mock() + private val getAllAMPs = GetAllAMPs(ampRepository) @Test - fun execute() { + fun `execute should return all amps`(log: CapturedOutput) { + // Given + val expectedAmps = listOf(anAmp(), anAmp()) + given(ampRepository.findAll()).willReturn(expectedAmps) + + // When + val amps = getAllAMPs.execute() + + // Then + assertThat(amps).isEqualTo(expectedAmps) + assertThat(log.out).contains("Attempt to GET all AMPs") + assertThat(log.out).contains("Found ${amps.size} AMPs") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt index af02020b5..9e05aad1f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/DeleteUserUTest.kt @@ -1,12 +1,31 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization +import com.nhaarman.mockitokotlin2.verify +import fr.gouv.cacem.monitorenv.domain.hash +import fr.gouv.cacem.monitorenv.domain.repositories.IUserAuthorizationRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -import org.junit.jupiter.api.Assertions.* - +@ExtendWith(OutputCaptureExtension::class) class DeleteUserUTest { + private val userAuthorizationRepository: IUserAuthorizationRepository = mock() + private val deleteUser = DeleteUser(userAuthorizationRepository) @Test - fun execute() { + fun `execute should delete user from email`(log: CapturedOutput) { + // Given + val email = "test@test.com" + + // When + deleteUser.execute(email) + + // Then + verify(userAuthorizationRepository).delete(hash(email)) + assertThat(log.out).contains("Attempt to DELETE user $email") + assertThat(log.out).contains("User $email deleted") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt index 21ca944b5..a9017f36b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetAuthorizedUserUTest.kt @@ -1,5 +1,58 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.entities.authorization.UserAuthorization +import fr.gouv.cacem.monitorenv.domain.hash +import fr.gouv.cacem.monitorenv.domain.repositories.IUserAuthorizationRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetAuthorizedUserUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetAuthorizedUserUTest { + private val userAuthorizationRepository: IUserAuthorizationRepository = mock() + private val getAuthorizedUser = GetAuthorizedUser(userAuthorizationRepository) + + @Test + fun `execute should return authorized user`(log: CapturedOutput) { + // Given + val email = "test@test.com" + val hashedEmail = hash(email) + val isSuperUser = true + given(userAuthorizationRepository.findByHashedEmail(hashedEmail)).willReturn( + UserAuthorization( + hashedEmail, + isSuperUser, + ), + ) + + // When + val user = getAuthorizedUser.execute(email) + + // Then + assertThat(user.hashedEmail).isEqualTo(hashedEmail) + assertThat(user.isSuperUser).isEqualTo(isSuperUser) + assertThat(log.out).contains("Attempt to GET user $hashedEmail") + assertThat(log.out).contains("Found user $hashedEmail") + } + + @Test + fun `execute should return authorized user with default rights when it does not exist`(log: CapturedOutput) { + // Given + val email = "test@test.com" + val hashedEmail = hash(email) + given(userAuthorizationRepository.findByHashedEmail(hashedEmail)).willReturn(null) + + // When + val user = getAuthorizedUser.execute(email) + + // Then + assertThat(user.hashedEmail).isEqualTo(hashedEmail) + assertThat(user.isSuperUser).isEqualTo(false) + assertThat(log.out).contains("Attempt to GET user $hashedEmail") + assertThat(log.out).contains("User $hashedEmail not found, defaulting to super-user=false") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt index 4179edc96..af6519023 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/GetIsAuthorizedUserUTests.kt @@ -2,6 +2,7 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization import com.nhaarman.mockitokotlin2.any import fr.gouv.cacem.monitorenv.domain.entities.authorization.UserAuthorization +import fr.gouv.cacem.monitorenv.domain.hash import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.JpaUserAuthorizationRepository import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -9,30 +10,38 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.BDDMockito.given import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetIsAuthorizedUserUTests { @Mock private val userAuthorizationRepository: JpaUserAuthorizationRepository = mock() @Test - fun `execute Should return true When the user is found and super-user When the path is super-user protected`() { + fun `execute Should return true When the user is found and super-user When the path is super-user protected`( + log: CapturedOutput, + ) { given(userAuthorizationRepository.findByHashedEmail(any())) .willReturn( UserAuthorization("58GE5S8VXE871FGGd2", true), ) // When + val email = "test@test.com" + val hashedEmail = hash(email) val isAuthorized = GetIsAuthorizedUser(userAuthorizationRepository) .execute( - "test", + email, true, ) // Then assertThat(isAuthorized).isTrue + assertThat(log.out).contains("Is user $hashedEmail AUTHORIZED") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt index d27191057..ec9722889 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/authorization/SaveUserUTest.kt @@ -1,5 +1,34 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.authorization -import org.junit.jupiter.api.Assertions.* +import fr.gouv.cacem.monitorenv.domain.entities.authorization.UserAuthorization +import fr.gouv.cacem.monitorenv.domain.hash +import fr.gouv.cacem.monitorenv.domain.repositories.IUserAuthorizationRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.mockito.Mockito.verify +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class SaveUserTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class SaveUserUTest { + private val userAuthorizationRepository: IUserAuthorizationRepository = mock() + private val saveUser = SaveUser(userAuthorizationRepository) + + @Test + fun `execute should save user`(log: CapturedOutput) { + // Given + val email = hash("test@test.com") + val isSuperUser = false + val userAuthorization = UserAuthorization(email, isSuperUser) + + // When + saveUser.execute(userAuthorization) + + // Then + verify(userAuthorizationRepository).save(userAuthorization) + assertThat(log.out).contains("Attempt to CREATE or UPDATE user $email") + assertThat(log.out).contains("User $email created or updated") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYearUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYearUTest.kt index 17a5e4cba..ebdd7d890 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYearUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansByYearUTest.kt @@ -8,12 +8,16 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanSubThemeReposito import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanTagRepository import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanThemeRepository import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlPlansByYearUTest { @Mock private val controlPlanSubThemeRepository: IControlPlanSubThemeRepository = mock() @@ -24,7 +28,11 @@ class GetControlPlansByYearUTest { @Mock private val controlPlanTagRepository: IControlPlanTagRepository = mock() - fun `execute should return all ControlPlanThemes, ControlPlanSubThemes and ControlPlanTags for the given year`() { + @Test + fun `execute should return all ControlPlanThemes, ControlPlanSubThemes and ControlPlanTags for the given year`( + log: CapturedOutput, + ) { + val year = 2023 val controlPlanThemes = listOf( ControlPlanThemeEntity( @@ -42,13 +50,13 @@ class GetControlPlansByYearUTest { id = 1, themeId = 1, subTheme = "ControlPlanSubTheme Name", - year = 2023, + year = year, ), ControlPlanSubThemeEntity( id = 2, themeId = 1, subTheme = "ControlPlanSubTheme Name 2", - year = 2023, + year = year, ), ) val controlPlanTags = @@ -65,9 +73,9 @@ class GetControlPlansByYearUTest { ), ) - given(controlPlanThemeRepository.findByYear(2023)).willReturn(controlPlanThemes) - given(controlPlanSubThemeRepository.findByYear(2023)).willReturn(controlPlanSubThemes) - given(controlPlanTagRepository.findByYear(2023)).willReturn(controlPlanTags) + given(controlPlanThemeRepository.findByYear(year)).willReturn(controlPlanThemes) + given(controlPlanSubThemeRepository.findByYear(year)).willReturn(controlPlanSubThemes) + given(controlPlanTagRepository.findByYear(year)).willReturn(controlPlanTags) val result = GetControlPlansByYear( @@ -75,9 +83,16 @@ class GetControlPlansByYearUTest { controlPlanSubThemeRepository = controlPlanSubThemeRepository, controlPlanTagRepository = controlPlanTagRepository, ) - .execute(2023) + .execute(year) - assertThat(result.first.size).isEqualTo(2) - assertThat(result).isEqualTo(controlPlanSubThemes) + assertThat(result.first).isEqualTo(controlPlanThemes) + assertThat(result.second).isEqualTo(controlPlanSubThemes) + assertThat(result.third).isEqualTo(controlPlanTags) + assertThat(log.out).contains("Attempt to GET all control plans for year $year") + assertThat( + log.out, + ).contains( + "Found ${controlPlanThemes.size} control plan themes, ${controlPlanSubThemes.size} control plan subthemes and ${controlPlanTags.size} control plan tags for year $year", + ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansUTest.kt index f56ac6576..2e627a3d1 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlPlan/GetControlPlansUTest.kt @@ -8,12 +8,16 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanSubThemeReposito import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanTagRepository import fr.gouv.cacem.monitorenv.domain.repositories.IControlPlanThemeRepository import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlPlansUTest { @Mock private val controlPlanSubThemeRepository: IControlPlanSubThemeRepository = mock() @@ -24,7 +28,8 @@ class GetControlPlansUTest { @Mock private val controlPlanTagRepository: IControlPlanTagRepository = mock() - fun `execute should return all ControlPlanThemes, ControlPlanSubThemes and ControlPlanTags`() { + @Test + fun `execute should return all ControlPlanThemes, ControlPlanSubThemes and ControlPlanTags`(log: CapturedOutput) { val controlPlanThemes = listOf( ControlPlanThemeEntity( @@ -76,7 +81,14 @@ class GetControlPlansUTest { controlPlanTagRepository = controlPlanTagRepository, ).execute() - assertThat(result.first.size).isEqualTo(2) - assertThat(result).isEqualTo(controlPlanSubThemes) + assertThat(result.first).isEqualTo(controlPlanThemes) + assertThat(result.second).isEqualTo(controlPlanSubThemes) + assertThat(result.third).isEqualTo(controlPlanTags) + assertThat(log.out).contains("Attempt to GET all control plans") + assertThat( + log.out, + ).contains( + "Found ${controlPlanThemes.size} control plan themes, ${controlPlanSubThemes.size} control plan subthemes and ${controlPlanTags.size} control plan tags", + ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResourceUTests.kt index 914a4ec03..8c884d005 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitResourceUTests.kt @@ -2,23 +2,29 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class ArchiveControlUnitResourceUTests { @Mock private val controlUnitResourceRepository: IControlUnitResourceRepository = mock() @Test - fun `execute should archive a control unit resource by its ID`() { + fun `execute should archive a control unit resource by its ID`(log: CapturedOutput) { val controlUnitResourceId = 1 ArchiveControlUnitResource(controlUnitResourceRepository).execute(controlUnitResourceId) verify(controlUnitResourceRepository).archiveById(controlUnitResourceId) + assertThat(log.out).contains("Attempt to ARCHIVE control unit resource $controlUnitResourceId") + assertThat(log.out).contains("Control unit resource $controlUnitResourceId archived") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitUTests.kt index bc853c2f7..820696e8d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/ArchiveControlUnitUTests.kt @@ -2,23 +2,29 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class ArchiveControlUnitUTests { @Mock private val controlUnitRepository: IControlUnitRepository = mock() @Test - fun `execute should archive a control unit by its ID`() { + fun `execute should archive a control unit by its ID`(log: CapturedOutput) { val controlUnitId = 1 ArchiveControlUnit(controlUnitRepository).execute(controlUnitId) verify(controlUnitRepository).archiveById(controlUnitId) + assertThat(log.out).contains("Attempt to ARCHIVE control unit $controlUnitId") + assertThat(log.out).contains("Control unit $controlUnitId archived") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt index 162cfd0df..72fa1b1e6 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt @@ -9,16 +9,19 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanDeleteControlUnitResourceUTests { @Mock private val missionRepository: IMissionRepository = mock() @Test - fun `execute should return true when missions are empty`() { + fun `execute should return true when missions are empty`(log: CapturedOutput) { val controlUnitResourceId = 1 given(missionRepository.findByControlUnitResourceId(controlUnitResourceId)) @@ -27,6 +30,7 @@ class CanDeleteControlUnitResourceUTests { val result = CanDeleteControlUnitResource(missionRepository).execute(controlUnitResourceId) assertThat(result).isTrue + assertThat(log.out).contains("Can control unit resource $controlUnitResourceId be deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitUTests.kt index 5162c81d7..bd42663c5 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitUTests.kt @@ -10,9 +10,12 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanDeleteControlUnitUTests { @Mock private val missionRepository: IMissionRepository = mock() @@ -21,7 +24,9 @@ class CanDeleteControlUnitUTests { private val reportingRepository: IReportingRepository = mock() @Test - fun `execute should return TRUE there are neither missions nor reportings attached to this control unit`() { + fun `execute should return TRUE there are neither missions nor reportings attached to this control unit`( + log: CapturedOutput, + ) { val controlUnitId = 1 given(missionRepository.findByControlUnitId(controlUnitId)).willReturn(listOf()) @@ -31,6 +36,7 @@ class CanDeleteControlUnitUTests { CanDeleteControlUnit(missionRepository, reportingRepository).execute(controlUnitId) assertThat(result).isTrue() + assertThat(log.out).contains("Can control unit $controlUnitId be deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt index 916d63991..d3dbaff91 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitContactUTests.kt @@ -19,9 +19,12 @@ import org.junit.jupiter.params.provider.ValueSource import org.mockito.BDDMockito import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateControlUnitContactUTests { @Mock private val controlUnitRepository: IControlUnitRepository = mock() @@ -30,7 +33,7 @@ class CreateOrUpdateControlUnitContactUTests { private val controlUnitContactRepository: IControlUnitContactRepository = mock() @Test - fun `execute should return the expected result`() { + fun `execute should return the expected result`(log: CapturedOutput) { // Given val newControlUnitContact = ControlUnitContactEntity( @@ -82,6 +85,8 @@ class CreateOrUpdateControlUnitContactUTests { BDDMockito.verify(controlUnitRepository).findById(repositoryOutputMock.controlUnitId) BDDMockito.verify(controlUnitContactRepository).save(newControlUnitContact) + assertThat(log.out).contains("Attempt to CREATE or UPDATE control unit contact ${newControlUnitContact.id}") + assertThat(log.out).contains("Control unit contact ${result.id} created or updated") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt index d75c09a89..5d4c633f1 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitResourceUTests.kt @@ -11,15 +11,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateControlUnitResourceUTests { @Mock private val controlUnitResourceRepository: IControlUnitResourceRepository = mock() @Test - fun `execute should return save() result`() { + fun `execute should return save() result`(log: CapturedOutput) { val newControlUnitResource = ControlUnitResourceEntity( controlUnitId = 3, @@ -39,5 +42,7 @@ class CreateOrUpdateControlUnitResourceUTests { verify(controlUnitResourceRepository, times(1)).save(newControlUnitResource) assertThat(result).isEqualTo(expectedControlUnitResource) + assertThat(log.out).contains("Attempt to CREATE or UPDATE control unit resource ${newControlUnitResource.id}") + assertThat(log.out).contains("Control unit resource ${result.id} created or updated") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt index e9cfa3278..04afe5699 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CreateOrUpdateControlUnitUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateControlUnitUTests { @Mock private val controlUnitRepository: IControlUnitRepository = mock() @Test - fun `execute should return save() result`() { + fun `execute should return save() result`(log: CapturedOutput) { val newControlUnit = ControlUnitEntity( administrationId = 2, @@ -40,5 +43,7 @@ class CreateOrUpdateControlUnitUTests { verify(controlUnitRepository, times(1)).save(newControlUnit) assertThat(result).isEqualTo(expectatedControlUnit) + assertThat(log.out).contains("Attempt to CREATE or UPDATE control unit ${newControlUnit.id}") + assertThat(log.out).contains("Control unit ${result.id} created or updated") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContactUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContactUTests.kt index 079c46a55..ad47f750d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContactUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitContactUTests.kt @@ -2,23 +2,29 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitContactRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class DeleteControlUnitContactUTests { @Mock private val controlUnitContactRepository: IControlUnitContactRepository = mock() @Test - fun `execute should delete control unit contact by its ID`() { + fun `execute should delete control unit contact by its ID`(log: CapturedOutput) { val controlUnitContactId = 1 DeleteControlUnitContact(controlUnitContactRepository).execute(controlUnitContactId) verify(controlUnitContactRepository).deleteById(controlUnitContactId) + assertThat(log.out).contains("Attempt to DELETE control unit contact $controlUnitContactId") + assertThat(log.out).contains("Control unit contact $controlUnitContactId deleted") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResourceUTests.kt index a2b88e609..95a98b5a9 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitResourceUTests.kt @@ -4,14 +4,18 @@ import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitResourceRepository +import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class DeleteControlUnitResourceUTests { @Mock private val controlUnitResourceRepository: IControlUnitResourceRepository = mock() @@ -20,7 +24,9 @@ class DeleteControlUnitResourceUTests { private val canDeleteControlUnitResource: CanDeleteControlUnitResource = mock() @Test - fun `execute should delete control unit resource when canDeleteControlUnitResource returns true`() { + fun `execute should delete control unit resource when canDeleteControlUnitResource returns true`( + log: CapturedOutput, + ) { val controlUnitResourceId = 1 given(canDeleteControlUnitResource.execute(controlUnitResourceId)).willReturn(true) @@ -30,6 +36,8 @@ class DeleteControlUnitResourceUTests { ) verify(controlUnitResourceRepository).deleteById(controlUnitResourceId) + assertThat(log.out).contains("Attempt to DELETE control unit resource $controlUnitResourceId") + assertThat(log.out).contains("Control unit resource $controlUnitResourceId deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitUTests.kt index d97655adb..8b2d69e63 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/DeleteControlUnitUTests.kt @@ -7,10 +7,15 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.repositories.IReportingSourceRepository +import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class DeleteControlUnitUTests { private val controlUnitRepository: IControlUnitRepository = mock() @@ -32,7 +37,7 @@ class DeleteControlUnitUTests { ) @Test - fun `execute should delete control unit when canDeleteControlUnit returns true`() { + fun `execute should delete control unit when canDeleteControlUnit returns true`(log: CapturedOutput) { val controlUnitId = 1 given(canDeleteControlUnit.execute(controlUnitId)).willReturn(true) @@ -40,6 +45,8 @@ class DeleteControlUnitUTests { deleteControlUnit.execute(controlUnitId) verify(controlUnitRepository).deleteById(controlUnitId) + assertThat(log.out).contains("Attempt to DELETE control unit $controlUnitId") + assertThat(log.out).contains("Control unit $controlUnitId deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitByIdUTests.kt index 907c10038..1be8f8446 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitByIdUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitByIdUTests { @Mock private val controlUnitRepository: IControlUnitRepository = mock() @Test - fun `execute should return a control unit by its ID`() { + fun `execute should return a control unit by its ID`(log: CapturedOutput) { val controlUnitId = 1 val fullControlUnit = FullControlUnitDTO( @@ -48,5 +51,6 @@ class GetControlUnitByIdUTests { val result = GetControlUnitById(controlUnitRepository).execute(controlUnitId) assertThat(result).isEqualTo(fullControlUnit) + assertThat(log.out).contains("GET control unit $controlUnitId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactByIdUTests.kt index 6981b4600..9bf8de14c 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactByIdUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitContactByIdUTests { @Mock private val controlUnitContactRepository: IControlUnitContactRepository = mock() @Test - fun `execute should return a control unit contact by its ID`() { + fun `execute should return a control unit contact by its ID`(log: CapturedOutput) { val controlUnitContactId = 1 val fullControlUnitContact = FullControlUnitContactDTO( @@ -49,5 +52,6 @@ class GetControlUnitContactByIdUTests { val result = GetControlUnitContactById(controlUnitContactRepository).execute(controlUnitContactId) assertThat(result).isEqualTo(fullControlUnitContact) + assertThat(log.out).contains("GET control unit contact $controlUnitContactId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactsUTests.kt index 6eb54070a..41522c6ca 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitContactsUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitContactsUTests { @Mock private val controlUnitContactRepository: IControlUnitContactRepository = mock() @Test - fun `execute should return all control unit contacts`() { + fun `execute should return all control unit contacts`(log: CapturedOutput) { val controlUnitContacts = listOf( FullControlUnitContactDTO( @@ -73,5 +76,7 @@ class GetControlUnitContactsUTests { assertThat(result).isEqualTo(controlUnitContacts) assertThat(result.size).isEqualTo(2) + assertThat(log.out).contains("Attempt to GET all control unit contacts") + assertThat(log.out).contains("Found ${result.size} control unit contacts") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceByIdUTests.kt index 52b5c6537..bd6334b50 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourceByIdUTests.kt @@ -12,15 +12,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitResourceByIdUTests { @Mock private val controlUnitResourceRepository: IControlUnitResourceRepository = mock() @Test - fun `execute should return a control unit resource by its ID`() { + fun `execute should return a control unit resource by its ID`(log: CapturedOutput) { val controlUnitResourceId = 1 val fullControlUnitResource = FullControlUnitResourceDTO( @@ -59,5 +62,6 @@ class GetControlUnitResourceByIdUTests { val result = GetControlUnitResourceById(controlUnitResourceRepository).execute(controlUnitResourceId) assertThat(result).isEqualTo(fullControlUnitResource) + assertThat(log.out).contains("GET control unit resource $controlUnitResourceId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourcesUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourcesUTests.kt index 9c847b48f..a11125031 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourcesUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitResourcesUTests.kt @@ -12,15 +12,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitResourcesUTests { @Mock private val controlUnitResourceRepository: IControlUnitResourceRepository = mock() @Test - fun `execute should return all control unit resources`() { + fun `execute should return all control unit resources`(log: CapturedOutput) { val controlUnitResources = listOf( FullControlUnitResourceDTO( @@ -91,5 +94,7 @@ class GetControlUnitResourcesUTests { assertThat(result).isEqualTo(controlUnitResources) assertThat(result.size).isEqualTo(2) + assertThat(log.out).contains("Attempt to GET all control unit resources") + assertThat(log.out).contains("Found ${result.size} control unit resources") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitsUTests.kt index b136c21d8..f09d5be44 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetControlUnitsUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetControlUnitsUTests { @Mock private val controlUnitRepository: IControlUnitRepository = mock() @Test - fun `execute should return all control units`() { + fun `execute should return all control units`(log: CapturedOutput) { val fullControlUnits = listOf( FullControlUnitDTO( @@ -71,5 +74,7 @@ class GetControlUnitsUTests { assertThat(result).isEqualTo(fullControlUnits) assertThat(result.size).isEqualTo(2) + assertThat(log.out).contains("Attempt to GET all control units") + assertThat(log.out).contains("Found ${result.size} control units") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt index b17e452c3..7d30f5319 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/GetLegacyControlUnitsUTest.kt @@ -1,5 +1,63 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.entities.administration.AdministrationEntity +import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity +import fr.gouv.cacem.monitorenv.domain.repositories.IControlUnitRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitDTO +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetLegacyControlUnitsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetLegacyControlUnitsUTest { + private val controlUnitRepository: IControlUnitRepository = mock() + private val getLegacyControlUnits = GetLegacyControlUnits(controlUnitRepository) + + @Test + fun `execute should return control unit`(log: CapturedOutput) { + // Given + val fullControlUnits = + listOf( + FullControlUnitDTO( + administration = + AdministrationEntity( + id = 0, + name = "Admin 1", + isArchived = false, + ), + controlUnit = + ControlUnitEntity( + id = 1, + administrationId = 0, + areaNote = "Area 1", + departmentAreaInseeCode = "A1", + isArchived = false, + name = "CU 1", + termsNote = "Terms 1", + ), + departmentArea = null, + controlUnitContacts = listOf(), + controlUnitResources = listOf(), + ), + ) + + given(controlUnitRepository.findAll()).willReturn(fullControlUnits) + + // When + val legacyControlUnits = getLegacyControlUnits.execute() + + // Then + assertThat(legacyControlUnits.size).isEqualTo(fullControlUnits.size) + assertThat(legacyControlUnits[0].id).isEqualTo(fullControlUnits[0].controlUnit.id) + assertThat(legacyControlUnits[0].name).isEqualTo(fullControlUnits[0].controlUnit.name) + assertThat(legacyControlUnits[0].administration).isEqualTo(fullControlUnits[0].administration.name) + assertThat(legacyControlUnits[0].isArchived).isEqualTo(fullControlUnits[0].controlUnit.isArchived) + assertThat(legacyControlUnits[0].resources).isEqualTo(fullControlUnits[0].controlUnitResources) + assertThat(log.out).contains("Attempt to GET all legacy control units") + assertThat(log.out).contains("Found ${legacyControlUnits.size} legacy control units") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboardUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboardUTest.kt index c1042d8ae..5c0bce73f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboardUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/DeleteDashboardUTest.kt @@ -2,16 +2,21 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.dashboard import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.repositories.IDashboardRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import java.util.UUID +@ExtendWith(OutputCaptureExtension::class) class DeleteDashboardUTest { private val dashboardRepository: IDashboardRepository = Mockito.mock() private val deleteDashboard = DeleteDashboard(dashboardRepository) @Test - fun `execute should delete dashboard`() { + fun `execute should delete dashboard`(log: CapturedOutput) { // Given val id = UUID.randomUUID() @@ -20,5 +25,7 @@ class DeleteDashboardUTest { // Then verify(dashboardRepository).delete(id) + assertThat(log.out).contains("Attempt to DELETE dashboard $id") + assertThat(log.out).contains("Dashboard $id deleted") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractAreaUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractAreaUTest.kt index 2da040a4d..c1d2b8508 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractAreaUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractAreaUTest.kt @@ -9,10 +9,14 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class ExtractAreaUTest { private val departementAreaRepository: IDepartmentAreaRepository = mock() private val reportingRepository: IReportingRepository = mock() @@ -30,7 +34,7 @@ class ExtractAreaUTest { ) @Test - fun `execute should return an ExtractedAreaEntity that does not intersect a different area`() { + fun `execute should return an ExtractedAreaEntity that does not intersect a different area`(log: CapturedOutput) { // Given val wktReader = WKTReader() @@ -59,6 +63,7 @@ class ExtractAreaUTest { assertThat(extractedAreaEntity.regulatoryAreaIds).isEmpty() assertThat(extractedAreaEntity.ampIds).isEmpty() assertThat(extractedAreaEntity.vigilanceAreaIds).isEmpty() + assertThat(log.out).contains("GET extracted area") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardUTest.kt index 6adee3cae..1829e9f18 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardUTest.kt @@ -4,16 +4,20 @@ import com.nhaarman.mockitokotlin2.given import fr.gouv.cacem.monitorenv.domain.repositories.IDashboardRepository import fr.gouv.cacem.monitorenv.domain.use_cases.dashboard.fixtures.DashboardFixture import org.assertj.core.api.Assertions.assertThat -import org.junit.Test +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito -import java.util.* +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +import java.util.UUID +@ExtendWith(OutputCaptureExtension::class) class GetDashboardUTest { private val dashboardRepository: IDashboardRepository = Mockito.mock() private val getDashboard = GetDashboard(dashboardRepository) @Test - fun `execute should return a dashboard`() { + fun `execute should return a dashboard`(log: CapturedOutput) { // Given val id = UUID.randomUUID() val dashboard = @@ -34,5 +38,7 @@ class GetDashboardUTest { // Then assertThat(dashboardResult).isEqualTo(dashboard) + + assertThat(log.out).contains("GET dashboard ${dashboard.id}") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardsUTest.kt index a066ff841..4fd839f2c 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/GetDashboardsUTest.kt @@ -7,15 +7,19 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.dashboard.fixtures.DashboardFix import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock import org.mockito.Mockito.verify +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetDashboardsUTest { private val dashboardRepository: IDashboardRepository = mock() private val getDashboards = GetDashboards(dashboardRepository) @Test - fun `execute should return all dashboards`() { + fun `execute should return all dashboards`(log: CapturedOutput) { // Given val dashboard1 = DashboardFixture.aDashboard( @@ -48,7 +52,8 @@ class GetDashboardsUTest { // Then assertThat(dashboardList.size).isEqualTo(2) - assertThat(dashboardList).isEqualTo(dashboards) + assertThat(log.out).contains("Attempt to GET all dashboards") + assertThat(log.out).contains("Found ${dashboardList.size} dashboards") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboardUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboardUTest.kt index 827cc8fb7..f4f5b9f27 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboardUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/SaveDashboardUTest.kt @@ -10,9 +10,13 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.dashboard.fixtures.DashboardFix import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import java.util.UUID +@ExtendWith(OutputCaptureExtension::class) class SaveDashboardUTest { private val dashboardRepository: IDashboardRepository = mock() private val facadeAreasRepository: IFacadeAreasRepository = mock() @@ -20,7 +24,7 @@ class SaveDashboardUTest { private val saveDashboard = SaveDashboard(dashboardRepository, facadeAreasRepository) @Test - fun `execute should find its sea front then save dashboard and return saved dashboard`() { + fun `execute should find its sea front then save dashboard and return saved dashboard`(log: CapturedOutput) { // Given val dashboard = aDashboard() val id = UUID.randomUUID() @@ -36,6 +40,9 @@ class SaveDashboardUTest { assertThat(savedDashboard.id).isEqualTo(id) verify(dashboardRepository).save(dashboardWithFacade) verify(facadeAreasRepository).findFacadeFromGeometry(dashboard.geom) + + assertThat(log.out).contains("Attempt to CREATE or UPDATE dashboard ${dashboard.id}") + assertThat(log.out).contains("Dashboard ${savedDashboard.id} created or updated") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCodeUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCodeUTests.kt index a7e164c00..41a648286 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCodeUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreaByInseeCodeUTests.kt @@ -8,15 +8,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetDepartmentAreaByInseeCodeUTests { @Mock private val departmentAreaRepository: IDepartmentAreaRepository = mock() @Test - fun `execute should return a department area by its INSEE Code`() { + fun `execute should return a department area by its INSEE Code`(log: CapturedOutput) { val departmentAreaId = "1" val departmentArea = DepartmentAreaEntity( @@ -30,5 +33,6 @@ class GetDepartmentAreaByInseeCodeUTests { val result = GetDepartmentAreaByInseeCode(departmentAreaRepository).execute(departmentAreaId) assertThat(result).isEqualTo(departmentArea) + assertThat(log.out).contains("GET department area from insee code $departmentAreaId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreasUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreasUTests.kt index ec8a82dad..66e6daf7d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreasUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/departmentArea/GetDepartmentAreasUTests.kt @@ -8,15 +8,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetDepartmentAreasUTests { @Mock private val departmentAreaRepository: IDepartmentAreaRepository = mock() @Test - fun `execute should return all department areas`() { + fun `execute should return all department areas`(log: CapturedOutput) { val departmentAreas = listOf( DepartmentAreaEntity( @@ -35,7 +38,8 @@ class GetDepartmentAreasUTests { val result = GetDepartmentAreas(departmentAreaRepository).execute() - assertThat(result.size).isEqualTo(2) assertThat(result).isEqualTo(departmentAreas) + assertThat(log.out).contains("Attempt to GET all department areas") + assertThat(log.out).contains("Found ${result.size} department areas") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt index bec4570e3..d7859c468 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/BypassActionCheckAndDeleteMissionUTest.kt @@ -1,12 +1,60 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.given +import com.nhaarman.mockitokotlin2.verify +import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture +import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures.ReportingFixture.Companion.aReportingDTO +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +import java.time.ZonedDateTime +import java.util.UUID -import org.junit.jupiter.api.Assertions.* - +@ExtendWith(OutputCaptureExtension::class) class BypassActionCheckAndDeleteMissionUTest { + private val getFullMission: GetFullMission = mock() + private val missionRepository: IMissionRepository = mock() + private val reportingRepository: IReportingRepository = mock() + private val bypassActionCheckAndDeleteMission = + BypassActionCheckAndDeleteMission(getFullMission, missionRepository, reportingRepository) @Test - fun execute() { + fun `execute should delete mission and detach env action from reporting`(log: CapturedOutput) { + // Given + val missionId = 1 + val attachedReportingIds = listOf(1) + given(getFullMission.execute(missionId)).willReturn( + MissionFixture.aMissionDTO(attachedReportingIds = attachedReportingIds), + ) + val attachedEnvActionId = UUID.randomUUID() + val aReportingDTO = aReportingDTO(id = 1, attachedEnvActionId = attachedEnvActionId) + given(reportingRepository.findById(attachedReportingIds[0])).willReturn(aReportingDTO) + val detachedFromMissionAtUtc = ZonedDateTime.now() + val savedReporting = + aReportingDTO( + reporting = + aReportingDTO.reporting.copy( + detachedFromMissionAtUtc = detachedFromMissionAtUtc, + attachedEnvActionId = null, + ), + ) + given(reportingRepository.save(any())).willReturn(savedReporting) + + // When + bypassActionCheckAndDeleteMission.execute(missionId) + + // Then + verify(reportingRepository).detachDanglingEnvActions(missionId, listOf(attachedEnvActionId)) + verify(missionRepository).delete(missionId) + assertThat(savedReporting.reporting.attachedEnvActionId).isNull() + assertThat(savedReporting.reporting.detachedFromMissionAtUtc).isEqualTo(detachedFromMissionAtUtc) + assertThat(log.out).contains("Attempt to DELETE mission $missionId without checking actions") + assertThat(log.out).contains("Mission $missionId deleted") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt index a09b1e360..1a4627c26 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt @@ -13,18 +13,21 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.rapportnav.RapportNavMis import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMonitorFishMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.repositories.IRapportNavMissionActionsRepository -import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime import java.util.UUID @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanDeleteMissionUTests { @Mock private val missionRepository: IMissionRepository = mock() @@ -36,7 +39,9 @@ class CanDeleteMissionUTests { private val rapportNavMissionActionsRepository: IRapportNavMissionActionsRepository = mock() @Test - fun `execute Should return true when haven't Env Actions and RapportNav Actions and request come from Fish`() { + fun `execute Should return true when haven't Env Actions and RapportNav Actions and request come from Fish`( + log: CapturedOutput, + ) { val missionId = 57 given(missionRepository.findById(missionId)) @@ -73,11 +78,14 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORFISH) - Assertions.assertThat(result).isEqualTo(CanDeleteMissionResponse(true, listOf())) + assertThat(result).isEqualTo(CanDeleteMissionResponse(true, listOf())) + assertThat(log.out).contains("Can mission $missionId be deleted") } @Test - fun `execute Should return a list when have Env Actions but no RapportNav Actions and request come from Fish`() { + fun `execute Should return a list when have Env Actions but no RapportNav Actions and request come from Fish`( + log: CapturedOutput, + ) { val missionId = 34 val wktReader = WKTReader() @@ -124,8 +132,8 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORFISH) - Assertions.assertThat(result) - .isEqualTo(CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORENV))) + assertThat(result).isEqualTo(CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORENV))) + assertThat(log.out).contains("Can mission $missionId be deleted") } @Test @@ -176,10 +184,9 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORFISH) - Assertions.assertThat(result) - .isEqualTo( - CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORENV, MissionSourceEnum.RAPPORT_NAV)), - ) + assertThat(result).isEqualTo( + CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORENV, MissionSourceEnum.RAPPORT_NAV)), + ) } @Test @@ -224,7 +231,7 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORENV) - Assertions.assertThat(result).isEqualTo(CanDeleteMissionResponse(true, listOf())) + assertThat(result).isEqualTo(CanDeleteMissionResponse(true, listOf())) } @Test @@ -284,7 +291,7 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORENV) - Assertions.assertThat(result).isEqualTo(CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORFISH))) + assertThat(result).isEqualTo(CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORFISH))) } @Test @@ -354,9 +361,8 @@ class CanDeleteMissionUTests { ) .execute(missionId, MissionSourceEnum.MONITORENV) - Assertions.assertThat(result) - .isEqualTo( - CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORFISH, MissionSourceEnum.RAPPORT_NAV)), - ) + assertThat(result).isEqualTo( + CanDeleteMissionResponse(false, listOf(MissionSourceEnum.MONITORFISH, MissionSourceEnum.RAPPORT_NAV)), + ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrPatchEnvActionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt similarity index 93% rename from backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrPatchEnvActionsUTests.kt rename to backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt index 0f2153d5d..d870fa981 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrPatchEnvActionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt @@ -1,5 +1,3 @@ -@file:Suppress("ktlint:standard:package-name") - package fr.gouv.cacem.monitorenv.domain.use_cases.missions import com.nhaarman.mockitokotlin2.anyOrNull @@ -26,11 +24,14 @@ import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime import java.util.UUID @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrPatchEnvActionsUTests { @Mock private val departmentRepository: IDepartmentAreaRepository = mock() @@ -45,7 +46,9 @@ class CreateOrPatchEnvActionsUTests { private val postgisFunctionRepository: IPostgisFunctionRepository = mock() @Test - fun `should return the mission to update with computed facade and department info for envActions`() { + fun `should return the mission to update with computed facade and department info for envActions`( + log: CapturedOutput, + ) { // Given val wktReader = WKTReader() @@ -202,5 +205,11 @@ class CreateOrPatchEnvActionsUTests { }, ) assertThat(createdMission).isEqualTo(expectedUpdatedMission) + assertThat(log.out).contains( + "Attempt to CREATE or UPDATE mission ${missionToUpdate.id} with envActions ${envActions.map { it.id }}", + ) + assertThat(log.out).contains( + "Mission ${missionToUpdate.id} with envActions ${envActions.map { it.id }} created or updated", + ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt index 7d0f65c37..c90a6d42d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt @@ -1,5 +1,3 @@ -@file:Suppress("ktlint:standard:package-name") - package fr.gouv.cacem.monitorenv.domain.use_cases.missions import com.nhaarman.mockitokotlin2.anyOrNull @@ -25,12 +23,15 @@ import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.context.ApplicationEventPublisher import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime import java.util.UUID @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateMissionUTests { @Mock private val missionRepository: IMissionRepository = mock() @@ -45,7 +46,7 @@ class CreateOrUpdateMissionUTests { private val applicationEventPublisher: ApplicationEventPublisher = mock() @Test - fun `should return the mission to update with computed facade and observationsByUnit`() { + fun `should return the mission to update with computed facade and observationsByUnit`(log: CapturedOutput) { // Given val wktReader = WKTReader() @@ -169,6 +170,8 @@ class CreateOrUpdateMissionUTests { }, ) assertThat(createdMission).isEqualTo(expectedCreatedMission) + assertThat(log.out).contains("Attempt to CREATE or UPDATE mission ${missionToUpdate.id}") + assertThat(log.out).contains("Mission ${missionToUpdate.id} created or updated") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt index a24a46726..8cb92ba0f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt @@ -1,5 +1,3 @@ -@file:Suppress("ktlint:standard:package-name") - package fr.gouv.cacem.monitorenv.domain.use_cases.missions import com.nhaarman.mockitokotlin2.* @@ -21,11 +19,14 @@ import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime import java.util.* @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { @Mock private val createOrUpdateMission: CreateOrUpdateMission = mock() @@ -52,7 +53,7 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { val polygon = wktReader.read(multipolygonString) as MultiPolygon @Test - fun `should attach mission to specified reportings`() { + fun `should attach mission to specified reportings`(log: CapturedOutput) { // Given val missionToCreate = MissionEntity( @@ -115,6 +116,16 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { // Then verify(reportingRepository, times(1)).attachReportingsToMission(attachedReportingIds, 100) assertThat(createdMissionDTO).isEqualTo(expectedCreatedMission) + assertThat( + log.out, + ).contains( + "Attempt to CREATE or UPDATE mission: ${missionToCreate.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: []", + ) + assertThat( + log.out, + ).contains( + "Mission: ${missionToCreate.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: [] created or updated", + ) } @Test @@ -155,7 +166,7 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { } @Test - fun `Should attach action to reporting`() { + fun `Should attach action to reporting`(log: CapturedOutput) { // Given val envActionControl = EnvActionControlEntity( @@ -243,6 +254,20 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { envActionAttachedToReportingIds.second, ) assertThat(createdMissionDTO).isEqualTo(expectedCreatedMission) + assertThat(log.out).contains( + "Attempt to CREATE or UPDATE mission: ${missionToCreate.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: ${ + listOf( + envActionAttachedToReportingIds, + ) + }", + ) + assertThat(log.out).contains( + "Mission: ${missionToCreate.id} with attached reporting ids: $attachedReportingIds and env actions attached to reporting ids: ${ + listOf( + envActionAttachedToReportingIds, + ) + } created or updated", + ) } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMissionUTests.kt index 84c3c489c..7955f932b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/DeleteMissionUTests.kt @@ -18,7 +18,11 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures.ReportingFi import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class DeleteMissionUTests { private val getFullMission: GetFullMission = mock() @@ -32,7 +36,7 @@ class DeleteMissionUTests { DeleteMission(getFullMission, missionRepository, reportingRepository, canDeleteMission) @Test - fun `execute Should detach reporting attached to mission and action attached to reporting`() { + fun `execute Should detach reporting attached to mission and action attached to reporting`(log: CapturedOutput) { val missionId = 100 val reporting = aReporting() val missionToDelete = aMissionEntity() @@ -68,6 +72,8 @@ class DeleteMissionUTests { } verify(missionRepository).delete(missionId) + assertThat(log.out).contains("Attempt to delete mission $missionId") + assertThat(log.out).contains("Mission $missionId deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt index 154152dd9..1b920cf69 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt @@ -12,16 +12,19 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetEngagedControlUnitsUTests { @Mock private val getFullMissions: GetFullMissions = mock() @Test - fun `execute() should return engaged control units`() { + fun `execute() should return engaged control units`(log: CapturedOutput) { val firstControlUnit = LegacyControlUnitEntity( id = 123, @@ -106,5 +109,7 @@ class GetEngagedControlUnitsUTests { assertThat(controlUnits.first().first.name).isEqualTo("Control Unit Name") assertThat(controlUnits.first().second.first()).isEqualTo(MissionSourceEnum.MONITORENV) assertThat(controlUnits.first().second.last()).isEqualTo(MissionSourceEnum.MONITORFISH) + assertThat(log.out).contains("Attempt to GET all engaged control units") + assertThat(log.out).contains("Found ${controlUnits.size} engaged control unit") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionUTest.kt index 75cf8ff60..c5d3bd1e6 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionUTest.kt @@ -9,9 +9,13 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixtur import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import kotlin.random.Random +@ExtendWith(OutputCaptureExtension::class) class GetFullMissionUTest { private val missionRepository: IMissionRepository = mock() private val getFullMission: GetFullMission = GetFullMission(missionRepository) @@ -31,7 +35,7 @@ class GetFullMissionUTest { } @Test - fun `execute should return a mission`() { + fun `execute should return a mission`(log: CapturedOutput) { // Given val missionId = Random.nextInt() val missionFromDatabase = MissionDTO(MissionFixture.aMissionEntity()) @@ -42,5 +46,6 @@ class GetFullMissionUTest { // Then assertThat(mission).isEqualTo(missionFromDatabase) + assertThat(log.out).contains("GET full mission $missionId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActionsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActionsUTest.kt index f3a4e8fef..8d95a4fb8 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActionsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetFullMissionWithFishAndRapportNavActionsUTest.kt @@ -9,8 +9,12 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetFullMissionWithFishAndRapportNavActionsUTest { private val getFullMission: GetFullMission = mock() @@ -26,7 +30,9 @@ class GetFullMissionWithFishAndRapportNavActionsUTest { ) @Test - fun `execute should return that api succeeded and a mission with fish and rapportnav information`() { + fun `execute should return that api succeeded and a mission with fish and rapportnav information`( + log: CapturedOutput, + ) { // Given val missionId = 100 @@ -47,6 +53,8 @@ class GetFullMissionWithFishAndRapportNavActionsUTest { assertThat(fullMission.second.mission).isEqualTo(missionFromDatabase.mission) assertThat(fullMission.second.fishActions).isEqualTo(fishActions) assertThat(fullMission.second.hasRapportNavActions?.containsActionsAddedByUnit).isEqualTo(true) + + assertThat(log.out).contains("GET full mission $missionId with fish and rapport nav action") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceActionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceActionUTest.kt index 11a511541..6dd2bbcdf 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceActionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionAndSourceActionUTest.kt @@ -9,10 +9,14 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.actions.fixtures.EnvActionFixtu import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock import org.mockito.Mockito.verifyNoInteractions +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import kotlin.random.Random +@ExtendWith(OutputCaptureExtension::class) class GetMissionAndSourceActionUTest { private val getMission: GetMission = mock() @@ -24,7 +28,7 @@ class GetMissionAndSourceActionUTest { GetMissionAndSourceAction(getMission, apiFishMissionActionsRepository, apiRapportNavMissionActionsRepository) @Test - fun `execute should return only the mission if source is not MONITORFISH or RAPPORTNAV`() { + fun `execute should return only the mission if source is not MONITORFISH or RAPPORTNAV`(log: CapturedOutput) { // Given val missionId = Random.nextInt() val source = null @@ -40,6 +44,8 @@ class GetMissionAndSourceActionUTest { assertThat(mission.mission).isEqualTo(missionFromDatabase) assertThat(mission.fishActions).isEmpty() assertThat(mission.hasRapportNavActions).isNull() + + assertThat(log.out).contains("GET mission $missionId and source action") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionUTest.kt index 0f1be1261..9f5c4daca 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionUTest.kt @@ -7,9 +7,13 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import kotlin.random.Random +@ExtendWith(OutputCaptureExtension::class) class GetMissionUTest { private val missionRepository: IMissionRepository = mock() private val getMission: GetMission = GetMission(missionRepository) @@ -30,7 +34,7 @@ class GetMissionUTest { } @Test - fun `execute should return a mission`() { + fun `execute should return a mission`(log: CapturedOutput) { // Given val missionId = Random.nextInt() val missionFromDatabase = aMissionEntity() @@ -41,5 +45,6 @@ class GetMissionUTest { // Then assertThat(mission).isEqualTo(missionFromDatabase) + assertThat(log.out).contains("GET mission $missionId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActionsUTests.kt index 2bdc7b199..c81d56595 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionWithRapportNavActionsUTests.kt @@ -7,8 +7,12 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetMissionWithRapportNavActionsUTests { private val getMission: GetMission = mock() @@ -18,7 +22,7 @@ class GetMissionWithRapportNavActionsUTests { GetMissionWithRapportNavActions(getMission, rapportNavMissionActionsRepository) @Test - fun `execute should return mission with rapportNavActions`() { + fun `execute should return mission with rapportNavActions`(log: CapturedOutput) { val missionId = 10 val missionEntity = aMissionEntity() @@ -37,6 +41,7 @@ class GetMissionWithRapportNavActionsUTests { val result = getMissionWithRapportNavActions.execute(missionId) assertThat(result).isEqualTo(mission.copy(hasRapportNavActions = rapportNavActions)) + assertThat(log.out).contains("GET mission $missionId with rapportNavActions") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt index 4ba490f4b..92bca9ef9 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsByIdsUTest.kt @@ -1,21 +1,39 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension @ExtendWith(OutputCaptureExtension::class) -class GetMissionsByIdsTest { - +class GetMissionsByIdsUTest { + private val missionRepository: IMissionRepository = mock() + private val getMissionsByIds = GetMissionsByIds(missionRepository) @Test fun `execute should return a list of missions from its ids`(log: CapturedOutput) { // Given + val ids = listOf(1, 2, 3) + val expectedMissions = + listOf( + aMissionEntity(id = 1), + aMissionEntity(id = 2), + aMissionEntity(id = 3), + ) + given(missionRepository.findByIds(ids)).willReturn( + expectedMissions, + ) // When + val missions = getMissionsByIds.execute(ids) // Then - + assertThat(missions).isEqualTo(expectedMissions) + assertThat(log.out).contains("GET missions $ids") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt index b9f9b7663..0670e1a04 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetMissionsUTest.kt @@ -1,5 +1,51 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum +import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +import java.time.ZonedDateTime -class GetMissionsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetMissionsUTest { + private val missionRepository: IMissionRepository = mock() + private val getMissions = GetMissions(missionRepository) + + @Test + fun `execute should return all missions`(log: CapturedOutput) { + // Given + val expectedMissions = listOf(MissionFixture.aMissionEntity()) + val startedAfter = ZonedDateTime.now() + given( + missionRepository.findAll( + null, + listOf( + MissionSourceEnum.MONITORENV, + MissionSourceEnum.MONITORFISH, + ), + null, + null, + null, + null, + null, + startedAfter.toInstant(), + null, + null, + ), + ).willReturn(expectedMissions) + + // When + val missions = getMissions.execute(startedAfterDateTime = startedAfter) + + // Then + assertThat(missions).isEqualTo(expectedMissions) + assertThat(log.out).contains("Attempt to GET all missions") + assertThat(log.out).contains("Found ${missions.size} missions") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMissionUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMissionUTest.kt index 4756a91d9..77261f45b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMissionUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/PatchMissionUTest.kt @@ -12,18 +12,22 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixtur import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import java.time.ZonedDateTime -import java.util.* +import java.util.Optional import kotlin.random.Random +@ExtendWith(OutputCaptureExtension::class) class PatchMissionUTest { private val missionRepository: IMissionRepository = mock() private val patchEntity: PatchEntity = PatchEntity() private val patchMission: PatchMission = PatchMission(missionRepository, patchEntity) @Test - fun `execute() should return the patched entity`() { + fun `execute() should return the patched entity`(log: CapturedOutput) { // Given val id = Random.nextInt() val today = ZonedDateTime.now() @@ -56,6 +60,8 @@ class PatchMissionUTest { assertThat(savedMission.mission.startDateTimeUtc).isEqualTo(missionPatched.startDateTimeUtc) assertThat(savedMission.mission.endDateTimeUtc).isEqualTo(missionPatched.endDateTimeUtc) verify(missionRepository).save(missionPatched) + assertThat(log.out).contains("Attempt to PATCH mission $id") + assertThat(log.out).contains("Mission $id patched") } @Test @@ -75,6 +81,6 @@ class PatchMissionUTest { val exception = assertThrows { patchMission.execute(id, patchableMission) } - assertThat(exception.message).isEqualTo("mission $id not found") + assertThat(exception.message).isEqualTo("Mission $id not found") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt index 19132025a..c6c47505e 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt @@ -3,6 +3,7 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import java.time.ZonedDateTime import kotlin.random.Random @@ -29,5 +30,12 @@ class MissionFixture { isGeometryComputedFromControls = false, ) } + + fun aMissionDTO( + missionEntity: MissionEntity = aMissionEntity(), + attachedReportingIds: List = listOf(), + ): MissionDTO { + return MissionDTO(mission = missionEntity, attachedReportingIds = attachedReportingIds) + } } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt index fc636a0e6..6cb2396f2 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/natinfs/GetAllNatinfsUTest.kt @@ -1,5 +1,42 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.natinfs -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.entities.natinf.NatinfEntity +import fr.gouv.cacem.monitorenv.domain.repositories.INatinfRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetAllNatinfsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetAllNatinfsUTest { + private val natinfRepository: INatinfRepository = mock() + private val getAllNatinfs = GetAllNatinfs(natinfRepository) + + @Test + fun `execute should return all NATINF`(log: CapturedOutput) { + // Given + val expectedNatinfs = + listOf( + NatinfEntity( + natinfCode = 1, + regulation = null, + infraction = null, + infractionCategory = null, + ), + ) + given(natinfRepository.findAll()).willReturn( + expectedNatinfs, + ) + + // When + val natinfs = getAllNatinfs.execute() + + // Then + assertThat(expectedNatinfs).isEqualTo(natinfs) + assertThat(log.out).contains("Attempt to GET all natinfs") + assertThat(log.out).contains("Found ${natinfs.size} natinfs") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt index 0443acd25..6a9c0687c 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetAllRegulatoryAreasUTest.kt @@ -1,5 +1,32 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IRegulatoryAreaRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryArea.fixtures.RegulatoryAreaFixture +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetAllRegulatoryAreasUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetAllRegulatoryAreasUTest { + private val regulatoryAreaRepository: IRegulatoryAreaRepository = mock() + private val getAllRegulatoryAreas = GetAllRegulatoryAreas(regulatoryAreaRepository) + + @Test + fun `execute should return all regulatory areas`(log: CapturedOutput) { + // Given + val expectedRegulatoryAreas = listOf(RegulatoryAreaFixture.aRegulatoryArea()) + given(regulatoryAreaRepository.findAll()).willReturn(expectedRegulatoryAreas) + + // When + val regulatoryAreas = getAllRegulatoryAreas.execute() + + // Then + assertThat(expectedRegulatoryAreas).isEqualTo(regulatoryAreas) + assertThat(log.out).contains("Attempt to GET all regulatory areas") + assertThat(log.out).contains("Found ${regulatoryAreas.size} regulatory areas") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt index 1c5a3bff2..34ccbb24e 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/regulatoryAreas/GetRegulatoryAreaByIdUTest.kt @@ -1,12 +1,32 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryAreas +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IRegulatoryAreaRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.regulatoryArea.fixtures.RegulatoryAreaFixture +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -import org.junit.jupiter.api.Assertions.* - +@ExtendWith(OutputCaptureExtension::class) class GetRegulatoryAreaByIdUTest { + private val regulatoryAreaRepository: IRegulatoryAreaRepository = mock() + private val getRegulatoryAreaById = GetRegulatoryAreaById(regulatoryAreaRepository) @Test - fun execute() { + fun `execute should return regulatory area by its id`(log: CapturedOutput) { + // Given + val id = 1 + val expectedRegulatoryArea = RegulatoryAreaFixture.aRegulatoryArea() + given(regulatoryAreaRepository.findById(id)).willReturn(expectedRegulatoryArea) + + // When + val regulatoryArea = getRegulatoryAreaById.execute(id) + + // Then + assertThat(expectedRegulatoryArea).isEqualTo(regulatoryArea) + assertThat(log.out).contains("GET regulatory area $id") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt index 7d77351ac..f561117da 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveOutdatedReportingsUTest.kt @@ -1,5 +1,29 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class ArchiveOutdatedReportingsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class ArchiveOutdatedReportingsUTest { + private val reportingRepository: IReportingRepository = mock() + private val archiveOutdatedReportings = ArchiveOutdatedReportings(reportingRepository) + + @Test + fun `execute should archive reportings`(log: CapturedOutput) { + // Given + given(reportingRepository.archiveOutdatedReportings()).willReturn(2) + + // When + archiveOutdatedReportings.execute() + + // Then + assertThat(log.out).contains("Attempt to ARCHIVE reportings") + assertThat(log.out).contains("2 reportings archived") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt index edbe99e55..4c145ab4d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/ArchiveReportingsUTest.kt @@ -1,5 +1,30 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.verify +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class ArchiveReportingsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class ArchiveReportingsUTest { + private val reportingRepository: IReportingRepository = mock() + private val archiveReportings = ArchiveReportings(reportingRepository) + + @Test + fun `execute should archive reportings`(log: CapturedOutput) { + // Given + val ids = listOf(1, 2) + + // When + archiveReportings.execute(ids) + + // Then + verify(reportingRepository).archiveReportings(ids) + assertThat(log.out).contains("Attempt to ARCHIVE reportings $ids") + assertThat(log.out).contains("reportings $ids archived") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt index 1e7e3479a..6f89d2afb 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt @@ -28,11 +28,14 @@ import org.junit.jupiter.api.extension.ExtendWith import org.locationtech.jts.geom.Point import org.locationtech.jts.io.WKTReader import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.context.ApplicationEventPublisher import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateReportingUTests { @MockBean private lateinit var reportingRepository: IReportingRepository @@ -56,7 +59,7 @@ class CreateOrUpdateReportingUTests { private lateinit var applicationEventPublisher: ApplicationEventPublisher @Test - fun `should return new or updated reporting`() { + fun `should return new or updated reporting`(log: CapturedOutput) { // Given val aReportingWithSemaphore = aReporting(reportingSources = listOf(aReportingSourceSemaphore())) val reportingWithSemaphoreDTO = @@ -136,6 +139,8 @@ class CreateOrUpdateReportingUTests { // Then verify(reportingRepository, times(1)).save(aReportingWithControlUnit) assertThat(createdReportingWithControlUnit).isEqualTo(reportingWithControlUnitDTO) + assertThat(log.out).contains("Attempt to CREATE or UPDATE reporting ${aReportingWithControlUnit.id}") + assertThat(log.out).contains("Reporting ${createdReportingWithControlUnit.reporting.id} created or updated") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt index 4b8b0aab5..7b96634c0 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingUTest.kt @@ -1,5 +1,30 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.verify +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class DeleteReportingUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class DeleteReportingUTest { + private val reportingRepository: IReportingRepository = mock() + private val deleteReporting = DeleteReporting(reportingRepository) + + @Test + fun `execute should delete reporting`(log: CapturedOutput) { + // Given + val id = 1 + + // When + deleteReporting.execute(id) + + // Then + verify(reportingRepository).delete(id) + assertThat(log.out).contains("Attempt to DELETE reporting $id") + assertThat(log.out).contains("reporting $id deleted") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt index a260a1717..d9b0d3066 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/DeleteReportingsUTest.kt @@ -10,22 +10,21 @@ import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension @ExtendWith(OutputCaptureExtension::class) -class DeleteReportingUTest { - +class DeleteReportingsUTest { private val reportingRepository: IReportingRepository = mock() - private val deleteReporting = DeleteReporting(reportingRepository) + private val deleteReportings = DeleteReportings(reportingRepository) @Test fun `execute should delete reporting`(log: CapturedOutput) { // Given - val id = 1 + val ids = listOf(1, 2) // When - deleteReporting.execute(id) + deleteReportings.execute(ids) // Then - verify(reportingRepository).delete(id) - assertThat(log.out).contains("Attempt to DELETE reportings $id") - assertThat(log.out).contains("reportings $id deleted") + verify(reportingRepository).deleteReportings(ids) + assertThat(log.out).contains("Attempt to DELETE reportings $ids") + assertThat(log.out).contains("reportings $ids deleted") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt index 7415ce848..03cf22ecd 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingByIdUTest.kt @@ -1,5 +1,33 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures.ReportingFixture.Companion.aReportingDTO +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetReportingByIdUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetReportingByIdUTest { + private val reportingRepository: IReportingRepository = mock() + + private val getReportingById = GetReportingById(reportingRepository) + + @Test + fun `execute should get reporting with given id`(log: CapturedOutput) { + // Given + val id = 1 + val expectedReportingDTO = aReportingDTO(id = id) + given(reportingRepository.findById(id)).willReturn(expectedReportingDTO) + + // When + val reportingDTO = getReportingById.execute(id) + + // Then + assertThat(expectedReportingDTO).isEqualTo(reportingDTO) + assertThat(log.out).contains("GET reporting $id") + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIdsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIdsUTest.kt index 5790fc2e5..228ee3b21 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIdsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsByIdsUTest.kt @@ -5,15 +5,19 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures.ReportingFixture.Companion.aReportingDTO import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetReportingsByIdsUTest { private val reportingRepository: IReportingRepository = mock() private val getReportingsByIds = GetReportingsByIds(reportingRepository) @Test - fun `execute should retrieve reportings that match ids`() { + fun `execute should retrieve reportings that match ids`(log: CapturedOutput) { // Given val ids = listOf(1, 2, 3) val reportings = listOf(aReportingDTO(id = 1), aReportingDTO(id = 2), aReportingDTO(id = 3)) @@ -24,6 +28,7 @@ class GetReportingsByIdsUTest { // Then assertThat(reportingDTOS).isEqualTo(reportings) + assertThat(log.out).contains("GET reportings $ids") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt index 566af50a6..e6b37a999 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/GetReportingsUTest.kt @@ -1,5 +1,113 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.reportings -import org.junit.jupiter.api.Assertions.* +import com.nhaarman.mockitokotlin2.given +import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures.ReportingFixture.Companion.aReportingDTO +import io.mockk.every +import io.mockk.mockkStatic +import io.mockk.unmockkStatic +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +import java.time.ZonedDateTime -class GetReportingsUTest \ No newline at end of file +@ExtendWith(OutputCaptureExtension::class) +class GetReportingsUTest { + private val reportingRepository: IReportingRepository = mock() + + private val getReportings = GetReportings(reportingRepository) + + @Test + fun `execute should retrieve all reportings with given criteria`(log: CapturedOutput) { + // Given + val now = ZonedDateTime.now() + val reportings = listOf(aReportingDTO(id = 1), aReportingDTO(id = 2), aReportingDTO(id = 3)) + given( + reportingRepository.findAll( + pageNumber = null, + pageSize = null, + reportingType = null, + seaFronts = null, + sourcesType = null, + startedAfter = now.toInstant(), + startedBefore = null, + status = null, + targetTypes = null, + isAttachedToMission = null, + searchQuery = null, + ), + ).willReturn(reportings) + + // When + val reportingDTOS = + getReportings.execute( + pageNumber = null, + pageSize = null, + reportingType = null, + seaFronts = null, + sourcesType = null, + startedAfterDateTime = now, + startedBeforeDateTime = null, + status = null, + targetTypes = null, + isAttachedToMission = null, + searchQuery = null, + ) + + // Then + assertThat(reportingDTOS).isEqualTo(reportings) + assertThat(log.out).contains("Attempt to get reportings with criteria") + assertThat(log.out).contains("Found ${reportings.size} reportings with criteria") + } + + @Test + fun `execute should retrieve all reportings within 30 days when there is no started date criteria`( + log: CapturedOutput, + ) { + // Given + val reportings = listOf(aReportingDTO(id = 1), aReportingDTO(id = 2), aReportingDTO(id = 3)) + + val now = ZonedDateTime.now() + mockkStatic(ZonedDateTime::class) + every { ZonedDateTime.now() } returns now + + given( + reportingRepository.findAll( + pageNumber = null, + pageSize = null, + reportingType = null, + seaFronts = null, + sourcesType = null, + startedAfter = now.minusDays(30).toInstant(), + startedBefore = null, + status = null, + targetTypes = null, + isAttachedToMission = null, + searchQuery = null, + ), + ).willReturn(reportings) + + // When + val reportingDTOS = + getReportings.execute( + pageNumber = null, + pageSize = null, + reportingType = null, + seaFronts = null, + sourcesType = null, + startedAfterDateTime = null, + startedBeforeDateTime = null, + status = null, + targetTypes = null, + isAttachedToMission = null, + searchQuery = null, + ) + + // Then + assertThat(reportingDTOS).isEqualTo(reportings) + unmockkStatic(ZonedDateTime::class) + } +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/fixtures/ReportingFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/fixtures/ReportingFixture.kt index 4ab95938f..5d9a4248f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/fixtures/ReportingFixture.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/fixtures/ReportingFixture.kt @@ -11,6 +11,7 @@ import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingSource import org.locationtech.jts.geom.MultiPolygon import org.locationtech.jts.io.WKTReader import java.time.ZonedDateTime +import java.util.UUID class ReportingFixture { companion object { @@ -19,6 +20,7 @@ class ReportingFixture { reportingSources: List = listOf(), missionId: Int? = null, attachedToMissionAtUtc: ZonedDateTime? = null, + attachedEnvActionId: UUID? = null, ): ReportingEntity { val wktReader = WKTReader() @@ -49,12 +51,17 @@ class ReportingFixture { isInfractionProven = true, missionId = missionId, attachedToMissionAtUtc = attachedToMissionAtUtc, + attachedEnvActionId = attachedEnvActionId, ) } - fun aReportingDTO(id: Int? = 1): ReportingDTO { + fun aReportingDTO( + id: Int? = 1, + attachedEnvActionId: UUID? = null, + reporting: ReportingEntity = aReporting(id, attachedEnvActionId = attachedEnvActionId), + ): ReportingDTO { return ReportingDTO( - reporting = aReporting(id), + reporting = reporting, reportingSources = listOf( ReportingSourceDTO( diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt index 74190c642..2815b43b9 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetAllSemaphoresUTest.kt @@ -1,19 +1,32 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.semaphores +import com.nhaarman.mockitokotlin2.given import fr.gouv.cacem.monitorenv.domain.repositories.ISemaphoreRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.semaphores.fixtures.SemaphoreFixture.Companion.aSemaphore +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension -class GetAllSemaphoresTest { +@ExtendWith(OutputCaptureExtension::class) +class GetAllSemaphoresUTest { private val semaphoreRepository: ISemaphoreRepository = mock() private val getAllSemaphores = GetAllSemaphores(semaphoreRepository) @Test - fun execute() { + fun `execute should get all semaphores`(log: CapturedOutput) { // Given + val expectedSemaphores = listOf(aSemaphore(1), aSemaphore(2)) + given(semaphoreRepository.findAll()).willReturn(expectedSemaphores) // When + val semaphores = getAllSemaphores.execute() // Then + assertThat(semaphores).isEqualTo(expectedSemaphores) + assertThat(log.out).contains("Attempt to GET all semaphores") + assertThat(log.out).contains("Found ${semaphores.size} semaphores") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt index 9cf59c6c9..6a3a3f655 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/GetSemaphoreByIdUTest.kt @@ -11,22 +11,22 @@ import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension @ExtendWith(OutputCaptureExtension::class) -class GetAllSemaphoresUTest { +class GetSemaphoreByIdUTest { private val semaphoreRepository: ISemaphoreRepository = mock() - private val getAllSemaphores = GetAllSemaphores(semaphoreRepository) + private val getSemaphoreById = GetSemaphoreById(semaphoreRepository) @Test fun `execute should get all semaphores`(log: CapturedOutput) { // Given - val expectedSemaphores = listOf(aSemaphore(1), aSemaphore(2)) - given(semaphoreRepository.findAll()).willReturn(expectedSemaphores) + val id = 1 + val expectedSemaphore = aSemaphore(id) + given(semaphoreRepository.findById(id)).willReturn(expectedSemaphore) // When - val semaphores = getAllSemaphores.execute() + val semaphores = getSemaphoreById.execute(id) // Then - assertThat(semaphores).isEqualTo(expectedSemaphores) - assertThat(log.out).contains("Attempt to GET all semaphores") - assertThat(log.out).contains("Found ${semaphores.size} semaphores") + assertThat(semaphores).isEqualTo(expectedSemaphore) + assertThat(log.out).contains("GET semaphore $id") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt index c3f4b8c29..5b8f74969 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/semaphores/fixtures/SemaphoreFixture.kt @@ -1,103 +1,22 @@ -package fr.gouv.cacem.monitorenv.domain.use_cases.reportings.fixtures +package fr.gouv.cacem.monitorenv.domain.use_cases.semaphores.fixtures -import fr.gouv.cacem.monitorenv.domain.entities.VehicleTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingEntity -import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingSourceEntity -import fr.gouv.cacem.monitorenv.domain.entities.reporting.ReportingTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.reporting.SourceTypeEnum -import fr.gouv.cacem.monitorenv.domain.entities.reporting.TargetTypeEnum -import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingDTO -import fr.gouv.cacem.monitorenv.domain.use_cases.reportings.dtos.ReportingSourceDTO -import org.locationtech.jts.geom.MultiPolygon +import fr.gouv.cacem.monitorenv.domain.entities.semaphore.SemaphoreEntity +import org.locationtech.jts.geom.Point import org.locationtech.jts.io.WKTReader -import java.time.ZonedDateTime -import java.util.UUID -class ReportingFixture { +class SemaphoreFixture { companion object { - fun aReporting( - id: Int? = null, - reportingSources: List = listOf(), - missionId: Int? = null, - attachedToMissionAtUtc: ZonedDateTime? = null, - attachedEnvActionId: UUID? = null, - ): ReportingEntity { + fun aSemaphore(id: Int = 1): SemaphoreEntity { val wktReader = WKTReader() - val multipolygonString = - "MULTIPOLYGON(((-2.7335 47.6078, -2.7335 47.8452, -3.6297 47.8452, -3.6297 47.6078, -2.7335 47.6078)))" - val polygon = wktReader.read(multipolygonString) as MultiPolygon + val pointString = + "POINT (-4.54877816747593 48.305559876971)\"" + val point = wktReader.read(pointString) as Point - return ReportingEntity( + return SemaphoreEntity( id = id, - targetType = TargetTypeEnum.VEHICLE, - reportingSources = reportingSources, - vehicleType = VehicleTypeEnum.VESSEL, - geom = polygon, - seaFront = "Facade 1", - description = "description", - reportType = ReportingTypeEnum.INFRACTION_SUSPICION, - themeId = 1, - subThemeIds = listOf(10, 11), - actionTaken = "actions effectuées ", - isControlRequired = true, - hasNoUnitAvailable = true, - createdAt = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - validityTime = 10, - isArchived = false, - isDeleted = false, - updatedAtUtc = ZonedDateTime.now(), - openBy = "CDA", - isInfractionProven = true, - missionId = missionId, - attachedToMissionAtUtc = attachedToMissionAtUtc, - attachedEnvActionId = attachedEnvActionId - ) - } - - fun aReportingDTO( - id: Int? = 1, - attachedEnvActionId: UUID? = null, - reporting: ReportingEntity = aReporting(id, attachedEnvActionId = attachedEnvActionId), - ): ReportingDTO { - return ReportingDTO( - reporting = reporting, - reportingSources = - listOf( - ReportingSourceDTO( - reportingSource = aReportingSourceSemaphore(), - semaphore = null, - controlUnit = null, - ), - ), - ) - } - - fun aReportingSourceSemaphore( - reportingId: Int? = null, - semaphoreId: Int = 1, - ): ReportingSourceEntity { - return ReportingSourceEntity( - id = null, - reportingId = reportingId, - sourceType = SourceTypeEnum.SEMAPHORE, - semaphoreId = semaphoreId, - controlUnitId = null, - sourceName = null, - ) - } - - fun aReportingSourceControlUnit( - reportingId: Int? = null, - controlUnitId: Int = 1, - ): ReportingSourceEntity { - return ReportingSourceEntity( - id = null, - reportingId = reportingId, - sourceType = SourceTypeEnum.CONTROL_UNIT, - semaphoreId = null, - controlUnitId = controlUnitId, - sourceName = null, + geom = point, + name = "Dummy semaphore", ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStationUTests.kt index e2110f948..16ae94ed5 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CanDeleteStationUTests.kt @@ -11,15 +11,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CanDeleteStationUTests { @Mock private val stationRepository: IStationRepository = mock() @Test - fun `execute should return true when control unit resources are empty`() { + fun `execute should return true when control unit resources are empty`(log: CapturedOutput) { val stationId = 1 val fullStation = FullStationDTO( @@ -37,7 +40,8 @@ class CanDeleteStationUTests { val result = CanDeleteStation(stationRepository).execute(stationId) - assertThat(result).isTrue + assertThat(result).isTrue() + assertThat(log.out).contains("Can station $stationId be deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStationUTests.kt index 6b7d57351..b4058846b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/CreateOrUpdateStationUTests.kt @@ -10,15 +10,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateStationUTests { @Mock private val stationRepository: IStationRepository = mock() @Test - fun `execute should return save() result`() { + fun `execute should return save() result`(log: CapturedOutput) { val newStation = StationEntity( latitude = 0.0, @@ -34,5 +37,7 @@ class CreateOrUpdateStationUTests { verify(stationRepository, times(1)).save(newStation) assertThat(result).isEqualTo(expectedStation) + assertThat(log.out).contains("Attempt to CREATE or UPDATE station ${newStation.id}") + assertThat(log.out).contains("Station ${result.id} created or updated") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStationUTests.kt index 3649f8ff9..ff032a6da 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/DeleteStationUTests.kt @@ -4,14 +4,18 @@ import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.exceptions.CouldNotDeleteException import fr.gouv.cacem.monitorenv.domain.repositories.IStationRepository +import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class DeleteStationUTests { @Mock private val stationRepository: IStationRepository = mock() @@ -20,7 +24,7 @@ class DeleteStationUTests { private val canDeleteStation: CanDeleteStation = mock() @Test - fun `execute should delete when canDeleteStation returns true`() { + fun `execute should delete when canDeleteStation returns true`(log: CapturedOutput) { val stationId = 1 given(canDeleteStation.execute(stationId)).willReturn(true) @@ -28,6 +32,8 @@ class DeleteStationUTests { DeleteStation(stationRepository, canDeleteStation).execute(stationId) verify(stationRepository).deleteById(stationId) + assertThat(log.out).contains("Attempt to DELETE station $stationId") + assertThat(log.out).contains("Station $stationId deleted") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationByIdUTests.kt index 533d966d2..b8cd150d7 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationByIdUTests.kt @@ -9,15 +9,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetStationByIdUTests { @Mock private val stationRepository: IStationRepository = mock() @Test - fun `execute should return a station by its ID`() { + fun `execute should return a station by its ID`(log: CapturedOutput) { val stationId = 1 val fullStation = FullStationDTO( @@ -36,5 +39,6 @@ class GetStationByIdUTests { val result = GetStationById(stationRepository).execute(stationId) assertThat(result).isEqualTo(fullStation) + assertThat(log.out).contains("GET station $stationId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationsUTests.kt index 03ff378b1..577ad34a3 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/station/GetStationsUTests.kt @@ -9,15 +9,18 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) +@ExtendWith(OutputCaptureExtension::class) class GetStationsUTests { @Mock private val stationRepository: IStationRepository = mock() @Test - fun `execute should return all stations`() { + fun `execute should return all stations`(log: CapturedOutput) { val stations = listOf( FullStationDTO( @@ -48,5 +51,7 @@ class GetStationsUTests { assertThat(result.size).isEqualTo(2) assertThat(result).isEqualTo(stations) + assertThat(log.out).contains("Attempt to GET all stations") + assertThat(log.out).contains("Found ${result.size} stations") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt index fae4d91a6..8279f7ac3 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/ArchiveOutdatedVigilanceAreasUTest.kt @@ -10,7 +10,7 @@ import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension @ExtendWith(OutputCaptureExtension::class) -class ArchiveOutdatedVigilanceAreasTest { +class ArchiveOutdatedVigilanceAreasUTest { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() private val archiveOutdatedVigilanceAreas = ArchiveOutdatedVigilanceAreas(vigilanceAreaRepository) @@ -24,6 +24,6 @@ class ArchiveOutdatedVigilanceAreasTest { // Then assertThat(log.out).contains("Attempt to ARCHIVE vigilance areas") - assertThat(log.out).contains("Archived 2 vigilance areas") + assertThat(log.out).contains("2 vigilance areas archived") } -} \ No newline at end of file +} diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceAreaUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceAreaUTests.kt index 4cd68c505..5809b8048 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceAreaUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/CreateOrUpdateVigilanceAreaUTests.kt @@ -8,9 +8,13 @@ import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.ImageEntity import fr.gouv.cacem.monitorenv.domain.entities.vigilanceArea.VigilanceAreaEntity import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository -import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateVigilanceAreaUTests { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() @@ -23,7 +27,7 @@ class CreateOrUpdateVigilanceAreaUTests { ) @Test - fun `execute should return save() result`() { + fun `execute should return save() result`(log: CapturedOutput) { val image = ImageEntity( id = 1, @@ -52,6 +56,8 @@ class CreateOrUpdateVigilanceAreaUTests { val result = createOrUpdateVigilanceArea.execute(newVigilanceArea) verify(vigilanceAreaRepository, times(1)).save(newVigilanceArea) - Assertions.assertThat(result).isEqualTo(expectedVigilanceArea) + assertThat(result).isEqualTo(expectedVigilanceArea) + assertThat(log.out).contains("Attempt to CREATE or UPDATE vigilance area ${newVigilanceArea.id}") + assertThat(log.out).contains("Vigilance area ${result.id} created or updated") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceAreaUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceAreaUTests.kt index 3e1843a9c..3be3b8281 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceAreaUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/DeleteVigilanceAreaUTests.kt @@ -3,17 +3,24 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class DeleteVigilanceAreaUTests { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() @Test - fun `execute should delete vigilanceArea`() { + fun `execute should delete vigilanceArea`(log: CapturedOutput) { val vigilanceAreaId = 1 DeleteVigilanceArea(vigilanceAreaRepository).execute(vigilanceAreaId) verify(vigilanceAreaRepository).delete(vigilanceAreaId) + assertThat(log.out).contains("Attempt to DELETE vigilance area $vigilanceAreaId") + assertThat(log.out).contains("Vigilance area $vigilanceAreaId deleted") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigramsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigramsUTests.kt index ecb8373e5..936a0d295 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigramsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetTrigramsUTests.kt @@ -5,12 +5,16 @@ import com.nhaarman.mockitokotlin2.mock import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetTrigramsUTests { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() @Test - fun `execute should return all trigrams`() { + fun `execute should return all trigrams`(log: CapturedOutput) { val trigrams = listOf("ABC", "DEF", "GHI") given(vigilanceAreaRepository.findAllTrigrams()).willReturn(trigrams) @@ -18,6 +22,8 @@ class GetTrigramsUTests { val result = GetTrigrams(vigilanceAreaRepository).execute() assertThat(trigrams).isEqualTo(result) + assertThat(log.out).contains("Attempt to GET all vigilance areas creators trigrams") + assertThat(log.out).contains("Found ${result.size} trigrams") } @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaByIdUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaByIdUTests.kt index 0431d1512..abc83c098 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaByIdUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreaByIdUTests.kt @@ -6,12 +6,16 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.fixtures.VigilanceAreaFixture import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetVigilanceAreaByIdUTests { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() @Test - fun `execute should return vigilance area entity`() { + fun `execute should return vigilance area entity`(log: CapturedOutput) { val vigilanceAreaId = 3 val expectedEntity = VigilanceAreaFixture.anArchivedVigilanceAreaEntity() @@ -20,5 +24,6 @@ class GetVigilanceAreaByIdUTests { val result = GetVigilanceAreaById(vigilanceAreaRepository).execute(vigilanceAreaId) assertThat(expectedEntity).isEqualTo(result) + assertThat(log.out).contains("GET vigilance area $vigilanceAreaId") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreasUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreasUTests.kt index a29b7804d..a1c83cd56 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreasUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/vigilanceArea/GetVigilanceAreasUTests.kt @@ -4,14 +4,18 @@ import com.nhaarman.mockitokotlin2.given import com.nhaarman.mockitokotlin2.mock import fr.gouv.cacem.monitorenv.domain.repositories.IVigilanceAreaRepository import fr.gouv.cacem.monitorenv.domain.use_cases.vigilanceArea.fixtures.VigilanceAreaFixture -import org.assertj.core.api.Assertions +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension +@ExtendWith(OutputCaptureExtension::class) class GetVigilanceAreasUTests { private val vigilanceAreaRepository: IVigilanceAreaRepository = mock() @Test - fun `execute should return all vigilance areas`() { + fun `execute should return all vigilance areas`(log: CapturedOutput) { val vigilancesAreas = listOf( VigilanceAreaFixture.aVigilanceAreaEntity(), @@ -22,7 +26,8 @@ class GetVigilanceAreasUTests { val result = GetVigilanceAreas(vigilanceAreaRepository).execute() - Assertions.assertThat(result.size).isEqualTo(2) - Assertions.assertThat(result).isEqualTo(vigilancesAreas) + assertThat(result).isEqualTo(vigilancesAreas) + assertThat(log.out).contains("Attempt to GET all vigilance areas") + assertThat(log.out).contains("Found ${result.size} vigilance areas") } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt index 08ec93a90..830ba07b0 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt @@ -625,7 +625,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { assertThat(newMissionCreated.mission.createdAtUtc) .isAfter(ZonedDateTime.now().minusMinutes(1)) assertThat(newMissionCreated.mission.updatedAtUtc) - .isAfter(ZonedDateTime.now().minusMinutes(1)) + .isNull() assertThat(newMissionCreated.mission.controlUnits).hasSize(1) assertThat(newMissionCreated.mission.controlUnits.first().id).isEqualTo(10121) assertThat(newMissionCreated.mission.controlUnits.first().name) @@ -773,7 +773,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { val updatedMission = jpaMissionRepository.save(nextMission!!) - assertThat(updatedMission.mission.createdAtUtc).isNull() + assertThat(updatedMission.mission.createdAtUtc).isNotNull() assertThat(updatedMission.mission.updatedAtUtc).isAfter(ZonedDateTime.now().minusMinutes(1)) assertThat(updatedMission.mission.controlUnits).hasSize(2) assertThat(updatedMission.mission.controlUnits.first().id).isEqualTo(10002) diff --git a/backend/src/test/resources/log4j2-test.xml b/backend/src/test/resources/log4j2-test.xml new file mode 100644 index 000000000..849ab92f6 --- /dev/null +++ b/backend/src/test/resources/log4j2-test.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + From 559a518c626c6d79455edde84d146c0d502aa13d Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Thu, 2 Jan 2025 13:03:23 +0100 Subject: [PATCH 3/7] tech: fix new year tests --- .../cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt index 7dd0370c4..3d4b34299 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/dashboard/ExtractArea.kt @@ -18,7 +18,7 @@ class ExtractArea( private val ampRepository: IAMPRepository, private val vigilanceAreaRepository: IVigilanceAreaRepository, ) { - private val logger = LoggerFactory.getLogger(DeleteDashboard::class.java) + private val logger = LoggerFactory.getLogger(ExtractArea::class.java) fun execute(geometry: Geometry): ExtractedAreaEntity { logger.info("GET extracted area") From 87ac8c04083d0c29b775050d008d974cfb41995e Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Mon, 6 Jan 2025 17:42:27 +0100 Subject: [PATCH 4/7] tech: add error log on use-case exception --- .../api/endpoints/ControllersExceptionHandler.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/ControllersExceptionHandler.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/ControllersExceptionHandler.kt index 260a2ba19..38ddf295d 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/ControllersExceptionHandler.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/ControllersExceptionHandler.kt @@ -5,7 +5,11 @@ import fr.gouv.cacem.monitorenv.domain.exceptions.BackendInternalException import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageErrorCode import fr.gouv.cacem.monitorenv.domain.exceptions.BackendUsageException import fr.gouv.cacem.monitorenv.domain.exceptions.ReportingAlreadyAttachedException -import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.* +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.ApiError +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.BackendInternalErrorDataOutput +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.BackendRequestErrorDataOutput +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.BackendUsageErrorDataOutput +import fr.gouv.cacem.monitorenv.infrastructure.api.adapters.bff.outputs.MissingParameterApiError import fr.gouv.cacem.monitorenv.infrastructure.exceptions.BackendRequestErrorCode import fr.gouv.cacem.monitorenv.infrastructure.exceptions.BackendRequestException import io.sentry.Sentry @@ -45,6 +49,7 @@ class ControllersExceptionHandler(val sentryConfig: SentryConfig) { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BackendUsageException::class) fun handleBackendUsageException(e: BackendUsageException): BackendUsageErrorDataOutput { + logger.error(e.message) return BackendUsageErrorDataOutput(code = e.code, data = e.data, message = null) } From 2b1a508f6c95d70692400e1432bee62a4da61cd0 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Mon, 13 Jan 2025 08:57:17 +0100 Subject: [PATCH 5/7] refacto: updating mission --- .../domain/entities/mission/MissionEntity.kt | 4 +- .../CreateOrUpdateMissionDataInput.kt | 13 +- .../inputs/CreateOrUpdateMissionDataInput.kt | 4 + .../CanDeleteControlUnitResourceUTests.kt | 28 +--- .../missions/CanDeleteMissionUTests.kt | 151 ++++-------------- .../CreateOrUpdateEnvActionsUTests.kt | 48 +++--- .../missions/CreateOrUpdateMissionUTests.kt | 24 +-- ...onWithActionsAndAttachedReportingUTests.kt | 133 +++------------ .../missions/GetEngagedControlUnitsUTests.kt | 4 + .../missions/fixtures/MissionFixture.kt | 5 + .../CreateOrUpdateReportingUTests.kt | 31 ++-- .../CreateOrUpdateMissionDataInputUTests.kt | 2 + .../api/endpoints/bff/v1/AmpsITests.kt | 4 +- .../api/endpoints/bff/v1/DashboardsITests.kt | 12 +- .../endpoints/bff/v1/DepartmentAreaITests.kt | 6 +- .../api/endpoints/bff/v1/MissionsITests.kt | 48 ++++-- .../api/endpoints/bff/v1/NatinfsITests.kt | 4 +- .../endpoints/bff/v1/RegulatoryAreasITests.kt | 6 +- .../api/endpoints/bff/v1/ReportingsITests.kt | 20 +-- .../api/endpoints/bff/v1/SemaphoresITests.kt | 6 +- .../endpoints/bff/v1/VigilanceAreasITests.kt | 14 +- .../publicapi/ApiLegacyMissionsITests.kt | 14 ++ .../JpaMissionRepositoryITests.kt | 30 +++- .../mission_form/delete_mission.spec.ts | 2 +- .../mission_form/main_form.spec.ts | 28 +++- .../MissionForm/FormikSyncMissionFields.tsx | 15 +- .../components/MissionForm/constants.ts | 2 - .../features/Mission/useCases/saveMission.ts | 8 +- 28 files changed, 277 insertions(+), 389 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/MissionEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/MissionEntity.kt index f0cd03dac..09457db29 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/MissionEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/mission/MissionEntity.kt @@ -22,8 +22,8 @@ data class MissionEntity( var startDateTimeUtc: ZonedDateTime, @Patchable var endDateTimeUtc: ZonedDateTime? = null, - val createdAtUtc: ZonedDateTime? = null, - val updatedAtUtc: ZonedDateTime? = null, + val createdAtUtc: ZonedDateTime?, + val updatedAtUtc: ZonedDateTime?, val envActions: List? = listOf(), val isDeleted: Boolean, val isGeometryComputedFromControls: Boolean, diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt index 51be8531a..2465fb1eb 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt @@ -28,10 +28,13 @@ data class CreateOrUpdateMissionDataInput( val startDateTimeUtc: ZonedDateTime, val endDateTimeUtc: ZonedDateTime? = null, val isGeometryComputedFromControls: Boolean, -) { + val createdAtUtc: ZonedDateTime?, + val updatedAtUtc: ZonedDateTime?, + + ) { fun toMissionEntity(): MissionEntity { - val hasMissionOrder = this.hasMissionOrder ?: false - val isUnderJdp = this.isUnderJdp ?: false + val hasMissionOrder = this.hasMissionOrder == true + val isUnderJdp = this.isUnderJdp == true return MissionEntity( id = this.id, @@ -51,6 +54,8 @@ data class CreateOrUpdateMissionDataInput( observationsCnsp = this.observationsCnsp, openBy = this.openBy, startDateTimeUtc = this.startDateTimeUtc, + createdAtUtc = createdAtUtc, + updatedAtUtc = updatedAtUtc, ) } @@ -58,7 +63,7 @@ data class CreateOrUpdateMissionDataInput( return this.envActions ?.filter { it.actionType == ActionTypeEnum.SURVEILLANCE || - it.actionType == ActionTypeEnum.CONTROL + it.actionType == ActionTypeEnum.CONTROL } ?.map { Pair(it.id, it.reportingIds.get()) } ?: listOf() diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateMissionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateMissionDataInput.kt index 8c1850c6a..9608a35ce 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateMissionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/publicapi/inputs/CreateOrUpdateMissionDataInput.kt @@ -23,6 +23,8 @@ data class CreateOrUpdateMissionDataInput( val hasMissionOrder: Boolean, val isUnderJdp: Boolean, val isGeometryComputedFromControls: Boolean, + val createdAtUtc: ZonedDateTime?, + val updatedAtUtc: ZonedDateTime?, ) { fun toMissionEntity(): MissionEntity { return MissionEntity( @@ -42,6 +44,8 @@ data class CreateOrUpdateMissionDataInput( hasMissionOrder = this.hasMissionOrder, isUnderJdp = this.isUnderJdp, isGeometryComputedFromControls = this.isGeometryComputedFromControls, + createdAtUtc = createdAtUtc, + updatedAtUtc = updatedAtUtc, ) } } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt index 72fa1b1e6..36d56e139 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/controlUnit/CanDeleteControlUnitResourceUTests.kt @@ -1,9 +1,8 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit import com.nhaarman.mockitokotlin2.given -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -12,7 +11,6 @@ import org.mockito.Mockito.mock import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension -import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) @ExtendWith(OutputCaptureExtension::class) @@ -38,29 +36,7 @@ class CanDeleteControlUnitResourceUTests { val controlUnitResourceId = 1 given(missionRepository.findByControlUnitResourceId(controlUnitResourceId)) - .willReturn( - listOf( - MissionEntity( - id = 1, - missionTypes = listOf(), - controlUnits = listOf(), - openBy = null, - completedBy = null, - observationsCacem = null, - observationsCnsp = null, - facade = null, - geom = null, - startDateTimeUtc = ZonedDateTime.now(), - endDateTimeUtc = null, - envActions = listOf(), - isDeleted = false, - isGeometryComputedFromControls = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - ), - ), - ) + .willReturn(listOf(aMissionEntity())) val result = CanDeleteControlUnitResource(missionRepository).execute(controlUnitResourceId) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt index 1a4627c26..3820ae44a 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt @@ -1,11 +1,10 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions +import com.fasterxml.jackson.databind.ObjectMapper import com.nhaarman.mockitokotlin2.given import fr.gouv.cacem.monitorenv.domain.entities.mission.ActionCompletionEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.CanDeleteMissionResponse -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum -import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.MonitorFishActionTypeEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionControl.EnvActionControlEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.monitorfish.MonitorFishMissionActionEntity @@ -13,6 +12,8 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.rapportnav.RapportNavMis import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMonitorFishMissionActionsRepository import fr.gouv.cacem.monitorenv.domain.repositories.IRapportNavMissionActionsRepository +import fr.gouv.cacem.monitorenv.domain.use_cases.actions.fixtures.EnvActionFixture.Companion.anEnvAction +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -23,7 +24,6 @@ import org.mockito.Mockito.mock import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension -import java.time.ZonedDateTime import java.util.UUID @ExtendWith(SpringExtension::class) @@ -45,22 +45,7 @@ class CanDeleteMissionUTests { val missionId = 57 given(missionRepository.findById(missionId)) - .willReturn( - MissionEntity( - id = 57, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(), - ), - ) + .willReturn(aMissionEntity()) given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId)) .willReturn( RapportNavMissionActionEntity( @@ -73,7 +58,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -87,33 +72,16 @@ class CanDeleteMissionUTests { log: CapturedOutput, ) { val missionId = 34 - - val wktReader = WKTReader() - - val multipolygonString = - "MULTIPOLYGON(((-2.7335 47.6078, -2.7335 47.8452, -3.6297 47.8452, -3.6297 47.6078, -2.7335 47.6078)))" - val polygon = wktReader.read(multipolygonString) as MultiPolygon - val envActionControl = - EnvActionControlEntity( - id = UUID.fromString("33310163-4e22-4d3d-b585-dac4431eb4b5"), - geom = polygon, - ) given(missionRepository.findById(missionId)) .willReturn( - MissionEntity( - id = 34, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(envActionControl), - ), + aMissionEntity( + envActions = listOf( + anEnvAction( + mapper = ObjectMapper(), + id = UUID.randomUUID() + ) + ) + ) ) given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId)) .willReturn( @@ -127,7 +95,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -140,32 +108,16 @@ class CanDeleteMissionUTests { fun `execute Should return a list when have Env actions and RapportNav actions and request come from Fish`() { val missionId = 53 - val wktReader = WKTReader() - - val multipolygonString = - "MULTIPOLYGON(((-2.7335 47.6078, -2.7335 47.8452, -3.6297 47.8452, -3.6297 47.6078, -2.7335 47.6078)))" - val polygon = wktReader.read(multipolygonString) as MultiPolygon - val envActionControl = - EnvActionControlEntity( - id = UUID.fromString("33310163-4e22-4d3d-b585-dac4431eb4b5"), - geom = polygon, - ) given(missionRepository.findById(missionId)) .willReturn( - MissionEntity( - id = 53, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(envActionControl), - ), + aMissionEntity( + envActions = listOf( + anEnvAction( + mapper = ObjectMapper(), + id = UUID.randomUUID() + ) + ) + ) ) given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId)) .willReturn( @@ -179,7 +131,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -194,22 +146,7 @@ class CanDeleteMissionUTests { val missionId = 57 given(missionRepository.findById(missionId)) - .willReturn( - MissionEntity( - id = 57, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(), - ), - ) + .willReturn(aMissionEntity()) given(monitorFishMissionActionsRepository.findFishMissionActionsById(missionId)) .willReturn(listOf()) @@ -226,7 +163,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) @@ -239,22 +176,7 @@ class CanDeleteMissionUTests { val missionId = 57 given(missionRepository.findById(missionId)) - .willReturn( - MissionEntity( - id = 57, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(), - ), - ) + .willReturn(aMissionEntity()) given(monitorFishMissionActionsRepository.findFishMissionActionsById(missionId)) .willReturn( @@ -286,7 +208,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) @@ -309,22 +231,7 @@ class CanDeleteMissionUTests { geom = polygon, ) given(missionRepository.findById(missionId)) - .willReturn( - MissionEntity( - id = 53, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = null, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(envActionControl), - ), - ) + .willReturn(aMissionEntity()) given(monitorFishMissionActionsRepository.findFishMissionActionsById(missionId)) .willReturn( @@ -356,7 +263,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt index d870fa981..8bf10bac9 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt @@ -131,6 +131,8 @@ class CreateOrPatchEnvActionsUTests { missionSource = MissionSourceEnum.MONITORENV, missionTypes = listOf(MissionTypeEnum.LAND), startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), + createdAtUtc = null, + updatedAtUtc = null, ) val expectedUpdatedMission = @@ -147,6 +149,8 @@ class CreateOrPatchEnvActionsUTests { missionSource = MissionSourceEnum.MONITORENV, missionTypes = listOf(MissionTypeEnum.LAND), startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), + createdAtUtc = null, + updatedAtUtc = null, ) given(postgisFunctionRepository.normalizeGeometry(point)).willReturn(point) @@ -180,28 +184,28 @@ class CreateOrPatchEnvActionsUTests { .save( argThat { this == - missionToUpdate.copy( - envActions = - missionToUpdate.envActions?.map { - when (it) { - is EnvActionControlEntity -> - it.copy( - facade = "La Face Ade", - department = - "Quequ'part", - ) - - is EnvActionSurveillanceEntity -> - it.copy( - facade = "La Face Ade", - department = - "Quequ'part", - ) - - else -> it - } - }, - ) + missionToUpdate.copy( + envActions = + missionToUpdate.envActions?.map { + when (it) { + is EnvActionControlEntity -> + it.copy( + facade = "La Face Ade", + department = + "Quequ'part", + ) + + is EnvActionSurveillanceEntity -> + it.copy( + facade = "La Face Ade", + department = + "Quequ'part", + ) + + else -> it + } + }, + ) }, ) assertThat(createdMission).isEqualTo(expectedUpdatedMission) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt index c90a6d42d..7731cf7ff 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt @@ -69,6 +69,8 @@ class CreateOrUpdateMissionUTests { isDeleted = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val existingEnvActions = @@ -132,11 +134,11 @@ class CreateOrUpdateMissionUTests { missionRepository.save( argThat { this == - missionToUpdate.copy( - facade = "La Face Ade", - envActions = existingEnvActions, - observationsByUnit = "observations", - ) + missionToUpdate.copy( + facade = "La Face Ade", + envActions = existingEnvActions, + observationsByUnit = "observations", + ) }, ), ) @@ -162,11 +164,11 @@ class CreateOrUpdateMissionUTests { .save( argThat { this == - missionToUpdate.copy( - facade = "La Face Ade", - envActions = existingEnvActions, - observationsByUnit = "observations", - ) + missionToUpdate.copy( + facade = "La Face Ade", + envActions = existingEnvActions, + observationsByUnit = "observations", + ) }, ) assertThat(createdMission).isEqualTo(expectedCreatedMission) @@ -190,6 +192,8 @@ class CreateOrUpdateMissionUTests { isDeleted = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val returnedSavedMission = diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt index 8cb92ba0f..08f061189 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionWithActionsAndAttachedReportingUTests.kt @@ -1,6 +1,10 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions -import com.nhaarman.mockitokotlin2.* +import com.nhaarman.mockitokotlin2.anyOrNull +import com.nhaarman.mockitokotlin2.given +import com.nhaarman.mockitokotlin2.times +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum @@ -11,6 +15,7 @@ import fr.gouv.cacem.monitorenv.domain.repositories.IReportingRepository import fr.gouv.cacem.monitorenv.domain.use_cases.missions.TestUtils.getReportingDTO import fr.gouv.cacem.monitorenv.domain.use_cases.missions.TestUtils.getReportingDTOWithAttachedMission import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO +import fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures.MissionFixture.Companion.aMissionEntity import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Test @@ -23,7 +28,7 @@ import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension import java.time.ZonedDateTime -import java.util.* +import java.util.UUID @ExtendWith(SpringExtension::class) @ExtendWith(OutputCaptureExtension::class) @@ -55,39 +60,12 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { @Test fun `should attach mission to specified reportings`(log: CapturedOutput) { // Given - val missionToCreate = - MissionEntity( - id = 100, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = polygon, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - ) + val missionToCreate = aMissionEntity() val attachedReportingIds = listOf(1, 2, 3) val expectedCreatedMission = MissionDTO( - mission = - MissionEntity( - id = 100, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - startDateTimeUtc = - ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = - ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - ), + mission = aMissionEntity(), attachedReportingIds = attachedReportingIds, ) @@ -130,19 +108,7 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { @Test fun `execute should throw ReportingAlreadyAttachedException when try to attach reporting that has already be attached`() { - val missionToCreate = - MissionEntity( - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = polygon, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - ) + val missionToCreate = aMissionEntity() val attachedReportingIds = listOf(5) given(createOrUpdateMission.execute(anyOrNull())).willReturn(missionToCreate.copy(id = 100)) given(reportingRepository.findById(5)).willReturn(getReportingDTOWithAttachedMission(5)) @@ -188,6 +154,8 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { isUnderJdp = false, isGeometryComputedFromControls = false, envActions = listOf(envActionControl), + createdAtUtc = null, + updatedAtUtc = null, ) val attachedReportingIds = listOf(1, 2, 3) @@ -207,6 +175,8 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), attachedReportingIds = attachedReportingIds, ) @@ -273,46 +243,9 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { @Test fun `Should return status 206 if fish api doesn't responds`() { // Given - val envActionControl = - EnvActionControlEntity( - id = UUID.fromString("33310163-4e22-4d3d-b585-dac4431eb4b5"), - geom = polygon, - ) - - val missionToCreate = - MissionEntity( - id = 100, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = polygon, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(envActionControl), - ) + val missionToCreate = aMissionEntity(id = 100) - val expectedCreatedMission = - MissionDTO( - mission = - MissionEntity( - id = 100, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - startDateTimeUtc = - ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = - ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - ), - ) + val expectedCreatedMission = MissionDTO(mission = aMissionEntity()) given(createOrUpdateMission.execute(anyOrNull())).willReturn(missionToCreate) given(missionRepository.save(anyOrNull())) @@ -341,39 +274,9 @@ class CreateOrUpdateMissionWithActionsAndAttachedReportingUTests { @Test fun `Should create a mission doesn't call getFullMissionWithFishAndRapportNavActions`() { - val missionToCreate = - MissionEntity( - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - geom = polygon, - startDateTimeUtc = ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - envActions = listOf(), - ) + val missionToCreate = aMissionEntity(id = null) - val expectedCreatedMission = - MissionDTO( - mission = - MissionEntity( - id = 100, - missionTypes = listOf(MissionTypeEnum.LAND), - facade = "Outre-Mer", - startDateTimeUtc = - ZonedDateTime.parse("2022-01-15T04:50:09Z"), - endDateTimeUtc = - ZonedDateTime.parse("2022-01-23T20:29:03Z"), - isDeleted = false, - missionSource = MissionSourceEnum.MONITORENV, - hasMissionOrder = false, - isUnderJdp = false, - isGeometryComputedFromControls = false, - ), - ) + val expectedCreatedMission = MissionDTO(aMissionEntity(100)) given(createOrUpdateMission.execute(anyOrNull())).willReturn(missionToCreate.copy(id = 100)) given(missionRepository.save(anyOrNull())) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt index 1b920cf69..ba2f6b662 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/GetEngagedControlUnitsUTests.kt @@ -60,6 +60,8 @@ class GetEngagedControlUnitsUTests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) val secondMission = @@ -81,6 +83,8 @@ class GetEngagedControlUnitsUTests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt index c6c47505e..b898e3023 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt @@ -3,6 +3,7 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions.fixtures import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionSourceEnum import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionTypeEnum +import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.EnvActionEntity import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO import java.time.ZonedDateTime import kotlin.random.Random @@ -14,11 +15,13 @@ class MissionFixture { startDateTimeUtc: ZonedDateTime = ZonedDateTime.parse("2022-01-15T04:50:09Z"), endDateTimeUtc: ZonedDateTime? = ZonedDateTime.parse("2022-01-23T20:29:03Z"), observationsByUnit: String? = null, + envActions: List = listOf(), ): MissionEntity { return MissionEntity( id = id, observationsByUnit = observationsByUnit, missionTypes = listOf(MissionTypeEnum.LAND), + envActions = envActions, facade = "Outre-Mer", geom = null, startDateTimeUtc = startDateTimeUtc, @@ -28,6 +31,8 @@ class MissionFixture { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + updatedAtUtc = null, + createdAtUtc = null ) } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt index 6f89d2afb..48922bd44 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/reportings/CreateOrUpdateReportingUTests.kt @@ -27,7 +27,8 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.locationtech.jts.geom.Point import org.locationtech.jts.io.WKTReader -import org.springframework.boot.test.mock.mockito.MockBean +import org.mockito.Mock +import org.mockito.Mockito.mock import org.springframework.boot.test.system.CapturedOutput import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.context.ApplicationEventPublisher @@ -37,26 +38,26 @@ import java.time.ZonedDateTime @ExtendWith(SpringExtension::class) @ExtendWith(OutputCaptureExtension::class) class CreateOrUpdateReportingUTests { - @MockBean - private lateinit var reportingRepository: IReportingRepository + @Mock + private val reportingRepository: IReportingRepository = mock() - @MockBean - private lateinit var controlUnitRepository: IControlUnitRepository + @Mock + private val controlUnitRepository: IControlUnitRepository = mock() - @MockBean - private lateinit var semaphoreRepository: ISemaphoreRepository + @Mock + private val semaphoreRepository: ISemaphoreRepository = mock() - @MockBean - private lateinit var facadeRepository: IFacadeAreasRepository + @Mock + private val facadeRepository: IFacadeAreasRepository = mock() - @MockBean - private lateinit var missionRepository: IMissionRepository + @Mock + private val missionRepository: IMissionRepository = mock() - @MockBean - private lateinit var postgisFunctionRepository: IPostgisFunctionRepository + @Mock + private val postgisFunctionRepository: IPostgisFunctionRepository = mock() - @MockBean - private lateinit var applicationEventPublisher: ApplicationEventPublisher + @Mock + private val applicationEventPublisher: ApplicationEventPublisher = mock() @Test fun `should return new or updated reporting`(log: CapturedOutput) { diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt index cb8dc967b..8aa709a3d 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt @@ -73,6 +73,8 @@ class CreateOrUpdateMissionDataInputUTests { attachedReportingIds = listOf(), envActions = listOf(envActionControl, envActionSurveillance, envActionNote), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) // when diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/AmpsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/AmpsITests.kt index 7426b07fe..81a64b6ef 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/AmpsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/AmpsITests.kt @@ -12,8 +12,8 @@ import org.locationtech.jts.io.WKTReader import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath @@ -26,7 +26,7 @@ class AmpsITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getAllAMPs: GetAllAMPs @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DashboardsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DashboardsITests.kt index 38e014993..34d9a58e5 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DashboardsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DashboardsITests.kt @@ -19,9 +19,9 @@ import org.locationtech.jts.io.WKTReader import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.http.MediaType +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -39,19 +39,19 @@ class DashboardsITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var extractArea: ExtractArea - @MockBean + @MockitoBean private lateinit var saveDashboard: SaveDashboard - @MockBean + @MockitoBean private lateinit var getDashboards: GetDashboards - @MockBean + @MockitoBean private lateinit var getDashboard: GetDashboard - @MockBean + @MockitoBean private lateinit var deleteDashboard: DeleteDashboard @Autowired diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DepartmentAreaITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DepartmentAreaITests.kt index 359d7fad3..93ce4797a 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DepartmentAreaITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/DepartmentAreaITests.kt @@ -12,8 +12,8 @@ import org.mockito.BDDMockito.given import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers @@ -26,10 +26,10 @@ class DepartmentAreaITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getDepartmentAreaByInseeCode: GetDepartmentAreaByInseeCode - @MockBean + @MockitoBean private lateinit var getDepartmentAreas: GetDepartmentAreas @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt index ad69944d3..42afe304f 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt @@ -41,9 +41,9 @@ import org.mockito.BDDMockito.verify import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.http.MediaType +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -59,32 +59,38 @@ import java.util.UUID @AutoConfigureMockMvc(addFilters = false) @WebMvcTest(value = [(Missions::class)]) class MissionsITests { - @Autowired private lateinit var mockMvc: MockMvc + @Autowired + private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var createOrUpdateMissionWithActionsAndAttachedReporting: - CreateOrUpdateMissionWithActionsAndAttachedReporting + CreateOrUpdateMissionWithActionsAndAttachedReporting - @MockBean private lateinit var getFullMissions: GetFullMissions + @MockitoBean + private lateinit var getFullMissions: GetFullMissions - @MockBean + @MockitoBean private lateinit var getFullMissionWithFishAndRapportNavActions: - GetFullMissionWithFishAndRapportNavActions + GetFullMissionWithFishAndRapportNavActions - @MockBean private lateinit var deleteMission: DeleteMission + @MockitoBean + private lateinit var deleteMission: DeleteMission - @MockBean private lateinit var canDeleteMission: CanDeleteMission + @MockitoBean + private lateinit var canDeleteMission: CanDeleteMission - @MockBean private lateinit var getEngagedControlUnits: GetEngagedControlUnits + @MockitoBean + private lateinit var getEngagedControlUnits: GetEngagedControlUnits - @Autowired private lateinit var objectMapper: ObjectMapper + @Autowired + private lateinit var objectMapper: ObjectMapper private val polygon = WKTReader() .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point @Test @@ -123,6 +129,8 @@ class MissionsITests { missionSource = MissionSourceEnum.MONITORENV, attachedReportingIds = listOf(), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val requestbody = objectMapper.writeValueAsString(newMissionRequest) given( @@ -164,6 +172,8 @@ class MissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) // we test only if the route is called with the right arg @@ -234,7 +244,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -258,6 +268,8 @@ class MissionsITests { isUnderJdp = false, isGeometryComputedFromControls = false, envActions = listOf(controlEnvAction), + createdAtUtc = null, + updatedAtUtc = null, ), attachedReportingIds = listOf(1), attachedReportings = @@ -509,7 +521,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -533,6 +545,8 @@ class MissionsITests { isUnderJdp = false, isGeometryComputedFromControls = false, envActions = listOf(controlEnvAction), + createdAtUtc = null, + updatedAtUtc = null, ), attachedReportingIds = listOf(1), attachedReportings = @@ -747,6 +761,8 @@ class MissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) val envAction = @@ -772,12 +788,14 @@ class MissionsITests { missionSource = MissionSourceEnum.MONITORENV, attachedReportingIds = listOf(1), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val envActionsAttachedToReportingIds = listOf( Pair(UUID.fromString("bf9f4062-83d3-4a85-b89b-76c0ded6473d"), listOf(1)), ) as - List + List given( createOrUpdateMissionWithActionsAndAttachedReporting.execute( mission = requestBody.toMissionEntity(), diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/NatinfsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/NatinfsITests.kt index dde279f7c..ee0f8213a 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/NatinfsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/NatinfsITests.kt @@ -10,8 +10,8 @@ import org.mockito.BDDMockito.given import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath @@ -24,7 +24,7 @@ class NatinfsITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getAllNatinfs: GetAllNatinfs @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/RegulatoryAreasITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/RegulatoryAreasITests.kt index eca0bc9b3..7fabc2b16 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/RegulatoryAreasITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/RegulatoryAreasITests.kt @@ -14,8 +14,8 @@ import org.mockito.BDDMockito.given import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -31,10 +31,10 @@ class RegulatoryAreasITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getAllRegulatoryAreas: GetAllRegulatoryAreas - @MockBean + @MockitoBean private lateinit var getRegulatoryAreaById: GetRegulatoryAreaById private val wktReader = WKTReader() diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt index 4ae0ff92e..6fc6e8a47 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt @@ -37,10 +37,10 @@ import org.mockito.Mockito import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.ApplicationEventPublisher import org.springframework.context.annotation.Import import org.springframework.http.MediaType +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -62,25 +62,25 @@ class ReportingsITests { @Autowired private lateinit var objectMapper: ObjectMapper - @MockBean + @MockitoBean private lateinit var createOrUpdateReporting: CreateOrUpdateReporting - @MockBean + @MockitoBean private lateinit var getReportings: GetReportings - @MockBean + @MockitoBean private lateinit var getReportingById: GetReportingById - @MockBean + @MockitoBean private lateinit var getReportingsByIds: GetReportingsByIds - @MockBean + @MockitoBean private lateinit var deleteReporting: DeleteReporting - @MockBean + @MockitoBean private lateinit var deleteReportings: DeleteReportings - @MockBean + @MockitoBean private lateinit var archiveReportings: ArchiveReportings @Autowired @@ -142,7 +142,7 @@ class ReportingsITests { .read( "POINT (-61.0 14.0)", ) as - Point, + Point, ), controlUnit = null, ), @@ -276,7 +276,7 @@ class ReportingsITests { .read( "POINT (-61.0 14.0)", ) as - Point, + Point, ), controlUnit = null, ), diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/SemaphoresITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/SemaphoresITests.kt index 95ed28e83..48bf30379 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/SemaphoresITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/SemaphoresITests.kt @@ -13,8 +13,8 @@ import org.mockito.BDDMockito.given import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath @@ -27,10 +27,10 @@ class SemaphoresITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getAllSemaphores: GetAllSemaphores - @MockBean + @MockitoBean private lateinit var getSemaphoreById: GetSemaphoreById @Test diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt index 4c91ea66e..d3e4481d6 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt @@ -24,9 +24,9 @@ import org.mockito.BDDMockito.given import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean import org.springframework.context.annotation.Import import org.springframework.http.MediaType +import org.springframework.test.context.bean.override.mockito.MockitoBean import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -46,19 +46,19 @@ class VigilanceAreasITests { @Autowired private lateinit var mockMvc: MockMvc - @MockBean + @MockitoBean private lateinit var getAllVigilanceAreas: GetVigilanceAreas - @MockBean + @MockitoBean private lateinit var getVigilanceAreaById: GetVigilanceAreaById - @MockBean + @MockitoBean private lateinit var createOrUpdateVigilanceArea: CreateOrUpdateVigilanceArea - @MockBean + @MockitoBean private lateinit var deleteVigilanceArea: DeleteVigilanceArea - @MockBean + @MockitoBean private lateinit var getTrigrams: GetTrigrams @Autowired @@ -69,7 +69,7 @@ class VigilanceAreasITests { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point private val vigilanceArea1 = diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyMissionsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyMissionsITests.kt index 935e59fff..980c030a2 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyMissionsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/publicapi/ApiLegacyMissionsITests.kt @@ -123,6 +123,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = true, isUnderJdp = true, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val requestBody = objectMapper.writeValueAsString(newMissionRequest) given( @@ -166,6 +168,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) given( getMissions.execute( @@ -212,6 +216,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) given( getMissionsByIds.execute(any()), @@ -243,6 +249,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) @@ -272,6 +280,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = true, isUnderJdp = true, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val requestBody = @@ -285,6 +295,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = true, isUnderJdp = true, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) given( createOrUpdateMission.execute( @@ -397,6 +409,8 @@ class ApiLegacyMissionsITests { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt index 830ba07b0..387789f88 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt @@ -63,7 +63,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point @Test @@ -452,21 +452,21 @@ class JpaMissionRepositoryITests : AbstractDBTests() { LegacyControlUnitResourceEntity( id = 3, controlUnitId = - 10002, + 10002, name = "Semi-rigide 1", ), LegacyControlUnitResourceEntity( id = 4, controlUnitId = - 10002, + 10002, name = "Semi-rigide 2", ), LegacyControlUnitResourceEntity( id = 5, controlUnitId = - 10002, + 10002, name = "Voiture", ), @@ -474,6 +474,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ), ), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) val mission = jpaMissionRepository.findFullMissionById(10) @@ -575,7 +577,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { isAdministrativeControl = true, isComplianceWithWaterRegulationsControl = true, isSafetyEquipmentAndStandardsComplianceControl = - true, + true, isSeafarersControl = true, ), EnvActionSurveillanceEntity( @@ -616,6 +618,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ), isGeometryComputedFromControls = false, observationsByUnit = noteObservationsByUnit, + createdAtUtc = null, + updatedAtUtc = null, ) // When @@ -687,6 +691,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ), ), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) jpaMissionRepository.save(newMission) @@ -706,14 +712,14 @@ class JpaMissionRepositoryITests : AbstractDBTests() { LegacyControlUnitResourceEntity( id = 3, controlUnitId = - 10002, + 10002, name = "Semi-rigide 1", ), LegacyControlUnitResourceEntity( id = 5, controlUnitId = - 10002, + 10002, name = "Voiture", ), ), @@ -818,6 +824,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ), ), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) // When @@ -849,6 +857,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ), ), isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) // When @@ -928,6 +938,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val expectedUpdatedMission = MissionDTO( @@ -951,6 +963,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ), ) // When @@ -1005,6 +1019,8 @@ class JpaMissionRepositoryITests : AbstractDBTests() { hasMissionOrder = false, isUnderJdp = false, isGeometryComputedFromControls = false, + createdAtUtc = null, + updatedAtUtc = null, ) val expectedUpdatedMission = MissionDTO( diff --git a/frontend/cypress/e2e/side_window/mission_form/delete_mission.spec.ts b/frontend/cypress/e2e/side_window/mission_form/delete_mission.spec.ts index 892f6bd51..e7a69d9d5 100644 --- a/frontend/cypress/e2e/side_window/mission_form/delete_mission.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/delete_mission.spec.ts @@ -11,8 +11,8 @@ context('Side Window > Mission Form > Delete Mission', () => { it('A mission should be deleted if no action created in MonitorFish', () => { // Given - visitSideWindow() cy.intercept('GET', '/bff/v1/missions*').as('getMissions') + visitSideWindow() cy.wait('@getMissions') cy.wait(600) // a first render with 0 missions is likely to happen cy.getDataCy('Missions-numberOfDisplayedMissions').then($el => { diff --git a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts index 6c3176934..f380a4b41 100644 --- a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts @@ -50,7 +50,8 @@ context('Side Window > Mission Form > Main Form', () => { cy.intercept('PUT', '/bff/v1/missions').as('createMission') cy.fill('Unité 1', 'Cross Etel') - cy.wait(200) + cy.wait(500) + cy.getDataCy('add-control-administration').contains('DIRM / DM') cy.getDataCy('add-control-unit').contains('Cross Etel') @@ -73,7 +74,32 @@ context('Side Window > Mission Form > Main Form', () => { ) .its('response.statusCode') .should('eq', 200) + cy.get('div').contains('Mission créée par le') + + cy.intercept('PUT', '/bff/v1/missions/*').as('updateMission') + cy.wait(3000) + + cy.get('[name="missionTypes2"]').click({ force: true }) + cy.waitForLastRequest( + '@updateMission', + { + body: { + controlUnits: [ + { + administration: 'DIRM / DM', + id: 10011, + name: 'Cross Etel' + } + ], + missionTypes: ['SEA', 'LAND', 'AIR'] + } + }, + 1 + ) + + cy.wait(3000) + cy.get('div').contains('Dernière modification enregistrée') cy.get('.Component-Banner').contains('La mission a bien été créée') cy.clickButton('Supprimer la mission') diff --git a/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx b/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx index 6dce4356c..4aa5bdfa8 100644 --- a/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx +++ b/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx @@ -3,7 +3,7 @@ import { useMissionEventContext } from 'context/mission/useMissionEventContext' import { diff } from 'deep-object-diff' import { useFormikContext } from 'formik' import { omit } from 'lodash' -import { useEffect } from 'react' +import { useEffect, useState } from 'react' import { MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM } from './constants' @@ -19,6 +19,7 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp const { setFieldValue, values } = useFormikContext() const { getMissionEventById, setMissionEventInContext } = useMissionEventContext() const missionEvent = getMissionEventById(missionId) + const [isUpdateEnded, setIsUpdateEnded] = useState(false) useEffect( () => { @@ -31,6 +32,7 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp omit(missionEvent, MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM) ) + setIsUpdateEnded(false) /** * We iterate and use `setFieldValue` on each diff key to avoid a global re-render of the component */ @@ -43,10 +45,7 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp setFieldValue(key, undefine(missionEvent[key])) }) - // we need to wait for the form to be updated before removing the mission event from the context - setTimeout(() => { - setMissionEventInContext(undefined) - }, 500) + setIsUpdateEnded(true) }, // We don't want to trigger infinite re-renders since `setFieldValue` changes after each rendering @@ -54,5 +53,11 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp [missionEvent] ) + useEffect(() => { + if (isUpdateEnded) { + setMissionEventInContext(undefined) + } + }, [isUpdateEnded, setMissionEventInContext]) + return <> } diff --git a/frontend/src/features/Mission/components/MissionForm/constants.ts b/frontend/src/features/Mission/components/MissionForm/constants.ts index 974b8a6e4..16a19f5fa 100644 --- a/frontend/src/features/Mission/components/MissionForm/constants.ts +++ b/frontend/src/features/Mission/components/MissionForm/constants.ts @@ -18,8 +18,6 @@ export const MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM = [ ...MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES, 'facade', // We do not update this field as it is not used by the form - 'updatedAtUtc', - // We do not update this field as it is not used by the form 'createdAtUtc' ] diff --git a/frontend/src/features/Mission/useCases/saveMission.ts b/frontend/src/features/Mission/useCases/saveMission.ts index 44913a538..56305b7da 100644 --- a/frontend/src/features/Mission/useCases/saveMission.ts +++ b/frontend/src/features/Mission/useCases/saveMission.ts @@ -33,7 +33,6 @@ export const saveMission = ]) const routeParams = getMissionPageRoute(currentPath) const missionIsNewMission = isMissionNew(routeParams?.params?.id) - await dispatch(missionFormsActions.setIsListeningToEvents(false)) const newOrNextMissionData = missionIsNewMission ? { ...valuesToSave, id: undefined } : valuesToSave const upsertMission = missionIsNewMission @@ -41,7 +40,8 @@ export const saveMission = : missionsAPI.endpoints.updateMission try { const response = await dispatch(upsertMission.initiate(newOrNextMissionData)) - if ('data' in response) { + + if (response.data) { const missionUpdated = response.data // We save the new properties : `id`, `createdAt`, `updatedAt` after a mission creation/update @@ -79,10 +79,6 @@ export const saveMission = ) } - setTimeout(async () => { - await dispatch(missionFormsActions.setIsListeningToEvents(true)) - }, 500) - if (reopen || !quitAfterSave) { return } From eb20599ce1a90ce105c91ca23456e39fae0dea18 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Mon, 13 Jan 2025 11:37:40 +0100 Subject: [PATCH 6/7] refacto: updating mission --- .../missions/CreateOrUpdateMission.kt | 10 +--- .../CreateOrUpdateMissionDataInput.kt | 5 +- .../database/model/MissionModel.kt | 3 +- .../ArchiveAdministrationUTests.kt | 4 +- .../missions/CanDeleteMissionUTests.kt | 42 ++++++++-------- .../CreateOrUpdateEnvActionsUTests.kt | 44 ++++++++--------- .../missions/CreateOrUpdateMissionUTests.kt | 22 ++++----- .../missions/fixtures/MissionFixture.kt | 2 +- .../api/endpoints/bff/v1/MissionsITests.kt | 12 ++--- .../api/endpoints/bff/v1/ReportingsITests.kt | 4 +- .../endpoints/bff/v1/VigilanceAreasITests.kt | 2 +- .../JpaMissionRepositoryITests.kt | 48 +++++++++---------- .../mission_form/main_form.spec.ts | 23 --------- 13 files changed, 97 insertions(+), 124 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt index 5d4bf703e..28e331463 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMission.kt @@ -1,7 +1,7 @@ package fr.gouv.cacem.monitorenv.domain.use_cases.missions import fr.gouv.cacem.monitorenv.config.UseCase -import fr.gouv.cacem.monitorenv.domain.entities.mission.* +import fr.gouv.cacem.monitorenv.domain.entities.mission.MissionEntity import fr.gouv.cacem.monitorenv.domain.repositories.IFacadeAreasRepository import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository import fr.gouv.cacem.monitorenv.domain.repositories.IPostgisFunctionRepository @@ -51,12 +51,6 @@ class CreateOrUpdateMission( UpdateMissionEvent(savedMission.mission), ) - /** - * TODO When doing an update, the `createdAtUtc` field is returned as null. - * To fix this, we return the stored `createdAtUtc` - */ - return savedMission.mission.copy( - createdAtUtc = savedMission.mission.createdAtUtc ?: storedMission?.createdAtUtc, - ) + return savedMission.mission } } diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt index 2465fb1eb..688e896bb 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt @@ -30,8 +30,7 @@ data class CreateOrUpdateMissionDataInput( val isGeometryComputedFromControls: Boolean, val createdAtUtc: ZonedDateTime?, val updatedAtUtc: ZonedDateTime?, - - ) { +) { fun toMissionEntity(): MissionEntity { val hasMissionOrder = this.hasMissionOrder == true val isUnderJdp = this.isUnderJdp == true @@ -63,7 +62,7 @@ data class CreateOrUpdateMissionDataInput( return this.envActions ?.filter { it.actionType == ActionTypeEnum.SURVEILLANCE || - it.actionType == ActionTypeEnum.CONTROL + it.actionType == ActionTypeEnum.CONTROL } ?.map { Pair(it.id, it.reportingIds.get()) } ?: listOf() diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt index e24796006..f3dda8464 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/MissionModel.kt @@ -34,6 +34,7 @@ import org.hibernate.Hibernate import org.hibernate.annotations.Fetch import org.hibernate.annotations.FetchMode import org.hibernate.annotations.JdbcType +import org.hibernate.annotations.UpdateTimestamp import org.hibernate.dialect.PostgreSQLEnumJdbcType import org.locationtech.jts.geom.MultiPolygon import org.n52.jackson.datatype.jts.GeometryDeserializer @@ -233,7 +234,7 @@ class MissionModel( @Column(name = "observations_cnsp") val observationsCnsp: String? = null, @Column(name = "open_by") val openBy: String? = null, @Column(name = "start_datetime_utc") val startDateTimeUtc: Instant, - @Column(name = "updated_at_utc") var updatedAtUtc: Instant?, + @Column(name = "updated_at_utc") @UpdateTimestamp var updatedAtUtc: Instant?, ) { fun toMissionEntity(objectMapper: ObjectMapper): MissionEntity { val mappedControlUnits = diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt index 236f7c722..dd0937c86 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt @@ -9,10 +9,10 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.extension.ExtendWith -import org.springframework.boot.test.system.CapturedOutput -import org.springframework.boot.test.system.OutputCaptureExtension import org.mockito.Mock import org.mockito.Mockito.mock +import org.springframework.boot.test.system.CapturedOutput +import org.springframework.boot.test.system.OutputCaptureExtension import org.springframework.test.context.junit.jupiter.SpringExtension @ExtendWith(SpringExtension::class) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt index 3820ae44a..e5c0a96f0 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CanDeleteMissionUTests.kt @@ -58,7 +58,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -75,13 +75,14 @@ class CanDeleteMissionUTests { given(missionRepository.findById(missionId)) .willReturn( aMissionEntity( - envActions = listOf( - anEnvAction( - mapper = ObjectMapper(), - id = UUID.randomUUID() - ) - ) - ) + envActions = + listOf( + anEnvAction( + mapper = ObjectMapper(), + id = UUID.randomUUID(), + ), + ), + ), ) given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId)) .willReturn( @@ -95,7 +96,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -111,13 +112,14 @@ class CanDeleteMissionUTests { given(missionRepository.findById(missionId)) .willReturn( aMissionEntity( - envActions = listOf( - anEnvAction( - mapper = ObjectMapper(), - id = UUID.randomUUID() - ) - ) - ) + envActions = + listOf( + anEnvAction( + mapper = ObjectMapper(), + id = UUID.randomUUID(), + ), + ), + ), ) given(rapportNavMissionActionsRepository.findRapportNavMissionActionsById(missionId)) .willReturn( @@ -131,7 +133,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORFISH) @@ -163,7 +165,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) @@ -208,7 +210,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) @@ -263,7 +265,7 @@ class CanDeleteMissionUTests { CanDeleteMission( missionRepository = missionRepository, monitorFishMissionActionsRepository = - monitorFishMissionActionsRepository, + monitorFishMissionActionsRepository, rapportNavMissionActionsRepository = rapportNavMissionActionsRepository, ) .execute(missionId, MissionSourceEnum.MONITORENV) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt index 8bf10bac9..24599a3a3 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateEnvActionsUTests.kt @@ -184,28 +184,28 @@ class CreateOrPatchEnvActionsUTests { .save( argThat { this == - missionToUpdate.copy( - envActions = - missionToUpdate.envActions?.map { - when (it) { - is EnvActionControlEntity -> - it.copy( - facade = "La Face Ade", - department = - "Quequ'part", - ) - - is EnvActionSurveillanceEntity -> - it.copy( - facade = "La Face Ade", - department = - "Quequ'part", - ) - - else -> it - } - }, - ) + missionToUpdate.copy( + envActions = + missionToUpdate.envActions?.map { + when (it) { + is EnvActionControlEntity -> + it.copy( + facade = "La Face Ade", + department = + "Quequ'part", + ) + + is EnvActionSurveillanceEntity -> + it.copy( + facade = "La Face Ade", + department = + "Quequ'part", + ) + + else -> it + } + }, + ) }, ) assertThat(createdMission).isEqualTo(expectedUpdatedMission) diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt index 7731cf7ff..a2689cda5 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/CreateOrUpdateMissionUTests.kt @@ -134,11 +134,11 @@ class CreateOrUpdateMissionUTests { missionRepository.save( argThat { this == - missionToUpdate.copy( - facade = "La Face Ade", - envActions = existingEnvActions, - observationsByUnit = "observations", - ) + missionToUpdate.copy( + facade = "La Face Ade", + envActions = existingEnvActions, + observationsByUnit = "observations", + ) }, ), ) @@ -164,11 +164,11 @@ class CreateOrUpdateMissionUTests { .save( argThat { this == - missionToUpdate.copy( - facade = "La Face Ade", - envActions = existingEnvActions, - observationsByUnit = "observations", - ) + missionToUpdate.copy( + facade = "La Face Ade", + envActions = existingEnvActions, + observationsByUnit = "observations", + ) }, ) assertThat(createdMission).isEqualTo(expectedCreatedMission) @@ -200,7 +200,7 @@ class CreateOrUpdateMissionUTests { MissionEntity( id = 100, endDateTimeUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), - createdAtUtc = null, + createdAtUtc = ZonedDateTime.parse("2022-01-23T20:29:03Z"), updatedAtUtc = ZonedDateTime.now(), facade = "La Face Ade", hasMissionOrder = false, diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt index b898e3023..9be7ce449 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/domain/use_cases/missions/fixtures/MissionFixture.kt @@ -32,7 +32,7 @@ class MissionFixture { isUnderJdp = false, isGeometryComputedFromControls = false, updatedAtUtc = null, - createdAtUtc = null + createdAtUtc = null, ) } diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt index 42afe304f..3bee4eaad 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt @@ -64,14 +64,14 @@ class MissionsITests { @MockitoBean private lateinit var createOrUpdateMissionWithActionsAndAttachedReporting: - CreateOrUpdateMissionWithActionsAndAttachedReporting + CreateOrUpdateMissionWithActionsAndAttachedReporting @MockitoBean private lateinit var getFullMissions: GetFullMissions @MockitoBean private lateinit var getFullMissionWithFishAndRapportNavActions: - GetFullMissionWithFishAndRapportNavActions + GetFullMissionWithFishAndRapportNavActions @MockitoBean private lateinit var deleteMission: DeleteMission @@ -90,7 +90,7 @@ class MissionsITests { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point @Test @@ -244,7 +244,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -521,7 +521,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -795,7 +795,7 @@ class MissionsITests { listOf( Pair(UUID.fromString("bf9f4062-83d3-4a85-b89b-76c0ded6473d"), listOf(1)), ) as - List + List given( createOrUpdateMissionWithActionsAndAttachedReporting.execute( mission = requestBody.toMissionEntity(), diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt index 6fc6e8a47..0ef9f1635 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/ReportingsITests.kt @@ -142,7 +142,7 @@ class ReportingsITests { .read( "POINT (-61.0 14.0)", ) as - Point, + Point, ), controlUnit = null, ), @@ -276,7 +276,7 @@ class ReportingsITests { .read( "POINT (-61.0 14.0)", ) as - Point, + Point, ), controlUnit = null, ), diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt index d3e4481d6..edfaaa564 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/VigilanceAreasITests.kt @@ -69,7 +69,7 @@ class VigilanceAreasITests { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point private val vigilanceArea1 = diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt index 387789f88..eb6b65207 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/JpaMissionRepositoryITests.kt @@ -63,7 +63,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point @Test @@ -452,21 +452,21 @@ class JpaMissionRepositoryITests : AbstractDBTests() { LegacyControlUnitResourceEntity( id = 3, controlUnitId = - 10002, + 10002, name = "Semi-rigide 1", ), LegacyControlUnitResourceEntity( id = 4, controlUnitId = - 10002, + 10002, name = "Semi-rigide 2", ), LegacyControlUnitResourceEntity( id = 5, controlUnitId = - 10002, + 10002, name = "Voiture", ), @@ -577,7 +577,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { isAdministrativeControl = true, isComplianceWithWaterRegulationsControl = true, isSafetyEquipmentAndStandardsComplianceControl = - true, + true, isSeafarersControl = true, ), EnvActionSurveillanceEntity( @@ -629,7 +629,7 @@ class JpaMissionRepositoryITests : AbstractDBTests() { assertThat(newMissionCreated.mission.createdAtUtc) .isAfter(ZonedDateTime.now().minusMinutes(1)) assertThat(newMissionCreated.mission.updatedAtUtc) - .isNull() + .isAfter(ZonedDateTime.now().minusMinutes(1)) assertThat(newMissionCreated.mission.controlUnits).hasSize(1) assertThat(newMissionCreated.mission.controlUnits.first().id).isEqualTo(10121) assertThat(newMissionCreated.mission.controlUnits.first().name) @@ -694,32 +694,32 @@ class JpaMissionRepositoryITests : AbstractDBTests() { createdAtUtc = null, updatedAtUtc = null, ) - jpaMissionRepository.save(newMission) + val createdMission = jpaMissionRepository.save(newMission) // When - val newMissionUpdated = + val updatedMission = jpaMissionRepository.save( - newMission.copy( + createdMission.mission.copy( controlUnits = listOf( LegacyControlUnitEntity( id = 10002, name = "DML 2A", - administration = "DIRM / DM", + administration = "DDTM", isArchived = false, resources = listOf( LegacyControlUnitResourceEntity( id = 3, controlUnitId = - 10002, + 10002, name = "Semi-rigide 1", ), LegacyControlUnitResourceEntity( id = 5, controlUnitId = - 10002, + 10002, name = "Voiture", ), ), @@ -729,21 +729,21 @@ class JpaMissionRepositoryITests : AbstractDBTests() { ) // Then - assertThat(newMissionUpdated.mission.controlUnits).hasSize(1) - assertThat(newMissionUpdated.mission.controlUnits.first().id).isEqualTo(10002) - assertThat(newMissionUpdated.mission.controlUnits.first().name).isEqualTo("DML 2A") - assertThat(newMissionUpdated.mission.controlUnits.first().administration) - .isEqualTo("DIRM / DM") - assertThat(newMissionUpdated.mission.controlUnits.first().resources).hasSize(2) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().id).isEqualTo(3) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().controlUnitId) + assertThat(updatedMission.mission.controlUnits).hasSize(1) + assertThat(updatedMission.mission.controlUnits.first().id).isEqualTo(10002) + assertThat(updatedMission.mission.controlUnits.first().name).isEqualTo("DML 2A") + assertThat(updatedMission.mission.controlUnits.first().administration) + .isEqualTo("DDTM") + assertThat(updatedMission.mission.controlUnits.first().resources).hasSize(2) + assertThat(updatedMission.mission.controlUnits.first().resources.first().id).isEqualTo(3) + assertThat(updatedMission.mission.controlUnits.first().resources.first().controlUnitId) .isEqualTo(10002) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.first().name) + assertThat(updatedMission.mission.controlUnits.first().resources.first().name) .isEqualTo("Semi-rigide 1") - assertThat(newMissionUpdated.mission.controlUnits.first().resources.last().id).isEqualTo(5) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.last().controlUnitId) + assertThat(updatedMission.mission.controlUnits.first().resources.last().id).isEqualTo(5) + assertThat(updatedMission.mission.controlUnits.first().resources.last().controlUnitId) .isEqualTo(10002) - assertThat(newMissionUpdated.mission.controlUnits.first().resources.last().name) + assertThat(updatedMission.mission.controlUnits.first().resources.last().name) .isEqualTo("Voiture") } diff --git a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts index f380a4b41..f95759371 100644 --- a/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts +++ b/frontend/cypress/e2e/side_window/mission_form/main_form.spec.ts @@ -77,29 +77,6 @@ context('Side Window > Mission Form > Main Form', () => { cy.get('div').contains('Mission créée par le') - cy.intercept('PUT', '/bff/v1/missions/*').as('updateMission') - cy.wait(3000) - - cy.get('[name="missionTypes2"]').click({ force: true }) - cy.waitForLastRequest( - '@updateMission', - { - body: { - controlUnits: [ - { - administration: 'DIRM / DM', - id: 10011, - name: 'Cross Etel' - } - ], - missionTypes: ['SEA', 'LAND', 'AIR'] - } - }, - 1 - ) - - cy.wait(3000) - cy.get('div').contains('Dernière modification enregistrée') cy.get('.Component-Banner').contains('La mission a bien été créée') cy.clickButton('Supprimer la mission') From b6f14db68e3235b169699bc40575bd0bb9e1fd25 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Thu, 16 Jan 2025 11:04:06 +0100 Subject: [PATCH 7/7] revert update mission modifications --- .../CreateOrUpdateMissionDataInput.kt | 8 +-- .../CreateOrUpdateMissionDataInputUTests.kt | 2 - .../api/endpoints/bff/v1/MissionsITests.kt | 16 ++--- frontend/.env.frontend.example | 2 +- frontend/package-lock.json | 58 +++++++++++-------- .../MissionForm/FormikSyncMissionFields.tsx | 15 ++--- .../components/MissionForm/constants.ts | 2 + .../features/Mission/useCases/saveMission.ts | 5 ++ 8 files changed, 57 insertions(+), 51 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt index 688e896bb..d7964dd87 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/inputs/missions/CreateOrUpdateMissionDataInput.kt @@ -28,8 +28,6 @@ data class CreateOrUpdateMissionDataInput( val startDateTimeUtc: ZonedDateTime, val endDateTimeUtc: ZonedDateTime? = null, val isGeometryComputedFromControls: Boolean, - val createdAtUtc: ZonedDateTime?, - val updatedAtUtc: ZonedDateTime?, ) { fun toMissionEntity(): MissionEntity { val hasMissionOrder = this.hasMissionOrder == true @@ -53,8 +51,8 @@ data class CreateOrUpdateMissionDataInput( observationsCnsp = this.observationsCnsp, openBy = this.openBy, startDateTimeUtc = this.startDateTimeUtc, - createdAtUtc = createdAtUtc, - updatedAtUtc = updatedAtUtc, + createdAtUtc = null, + updatedAtUtc = null, ) } @@ -62,7 +60,7 @@ data class CreateOrUpdateMissionDataInput( return this.envActions ?.filter { it.actionType == ActionTypeEnum.SURVEILLANCE || - it.actionType == ActionTypeEnum.CONTROL + it.actionType == ActionTypeEnum.CONTROL } ?.map { Pair(it.id, it.reportingIds.get()) } ?: listOf() diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt index 8aa709a3d..cb8dc967b 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/missions/CreateOrUpdateMissionDataInputUTests.kt @@ -73,8 +73,6 @@ class CreateOrUpdateMissionDataInputUTests { attachedReportingIds = listOf(), envActions = listOf(envActionControl, envActionSurveillance, envActionNote), isGeometryComputedFromControls = false, - createdAtUtc = null, - updatedAtUtc = null, ) // when diff --git a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt index 3bee4eaad..8088d0a29 100644 --- a/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt +++ b/backend/src/test/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/endpoints/bff/v1/MissionsITests.kt @@ -64,14 +64,14 @@ class MissionsITests { @MockitoBean private lateinit var createOrUpdateMissionWithActionsAndAttachedReporting: - CreateOrUpdateMissionWithActionsAndAttachedReporting + CreateOrUpdateMissionWithActionsAndAttachedReporting @MockitoBean private lateinit var getFullMissions: GetFullMissions @MockitoBean private lateinit var getFullMissionWithFishAndRapportNavActions: - GetFullMissionWithFishAndRapportNavActions + GetFullMissionWithFishAndRapportNavActions @MockitoBean private lateinit var deleteMission: DeleteMission @@ -90,7 +90,7 @@ class MissionsITests { .read( "MULTIPOLYGON (((-4.54877817 48.30555988, -4.54997332 48.30597601, -4.54998501 48.30718823, -4.5487929 48.30677461, -4.54877817 48.30555988)))", ) as - MultiPolygon + MultiPolygon private val point = WKTReader().read("POINT (-4.54877816747593 48.305559876971)") as Point @Test @@ -129,8 +129,6 @@ class MissionsITests { missionSource = MissionSourceEnum.MONITORENV, attachedReportingIds = listOf(), isGeometryComputedFromControls = false, - createdAtUtc = null, - updatedAtUtc = null, ) val requestbody = objectMapper.writeValueAsString(newMissionRequest) given( @@ -244,7 +242,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -521,7 +519,7 @@ class MissionsITests { LegacyControlUnitResourceEntity( id = 2, controlUnitId = - 1, + 1, name = "Ressource 2", ), @@ -788,14 +786,12 @@ class MissionsITests { missionSource = MissionSourceEnum.MONITORENV, attachedReportingIds = listOf(1), isGeometryComputedFromControls = false, - createdAtUtc = null, - updatedAtUtc = null, ) val envActionsAttachedToReportingIds = listOf( Pair(UUID.fromString("bf9f4062-83d3-4a85-b89b-76c0ded6473d"), listOf(1)), ) as - List + List given( createOrUpdateMissionWithActionsAndAttachedReporting.execute( mission = requestBody.toMissionEntity(), diff --git a/frontend/.env.frontend.example b/frontend/.env.frontend.example index 0bcbf79f8..797e4bc7a 100644 --- a/frontend/.env.frontend.example +++ b/frontend/.env.frontend.example @@ -54,7 +54,7 @@ FRONTEND_METABASE_URL= FRONTEND_OIDC_AUTHORITY= FRONTEND_OIDC_CLIENT_ID= -FRONTEND_OIDC_ENABLED= +FRONTEND_OIDC_ENABLED=true FRONTEND_OIDC_REDIRECT_URI= ################################################################################ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 8ebae1e4c..3fc3d8031 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1177,9 +1177,9 @@ } }, "node_modules/@babel/plugin-transform-nullish-coalescing-operator": { - "version": "7.26.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.26.5.tgz", - "integrity": "sha512-OHqczNm4NTQlW1ghrVY43FPoiRzbmzNVbcgVnMKZN/RQYezHUSdjACjaX50CD3B7UIAjv39+MlsrVDb3v741FA==", + "version": "7.26.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.26.6.tgz", + "integrity": "sha512-CKW8Vu+uUZneQCPtXmSBUC6NCAUdya26hWCElAWh5mVSlSRsmiCPUUDKb3Z0szng1hiAJa098Hkhg9o4SE35Qw==", "dependencies": { "@babel/helper-plugin-utils": "^7.26.5" }, @@ -6690,13 +6690,25 @@ } }, "node_modules/bare-stream": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.6.1.tgz", - "integrity": "sha512-eVZbtKM+4uehzrsj49KtCy3Pbg7kO1pJ3SKZ1SFrIH/0pnj9scuGGgUlNDf/7qS8WKtGdiJY5Kyhs/ivYPTB/g==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.6.4.tgz", + "integrity": "sha512-G6i3A74FjNq4nVrrSTUz5h3vgXzBJnjmWAVlBWaZETkgu+LgKd7AiyOml3EDJY1AHlIbBHKDXE+TUT53Ff8OaA==", "dev": true, "optional": true, "dependencies": { "streamx": "^2.21.0" + }, + "peerDependencies": { + "bare-buffer": "*", + "bare-events": "*" + }, + "peerDependenciesMeta": { + "bare-buffer": { + "optional": true + }, + "bare-events": { + "optional": true + } } }, "node_modules/base64-arraybuffer": { @@ -8374,9 +8386,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.80", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.80.tgz", - "integrity": "sha512-LTrKpW0AqIuHwmlVNV+cjFYTnXtM9K37OGhpe0ZI10ScPSxqVSryZHIY3WnCS5NSYbBODRTZyhRMS2h5FAEqAw==" + "version": "1.5.83", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.83.tgz", + "integrity": "sha512-LcUDPqSt+V0QmI47XLzZrz5OqILSMGsPFkDYus22rIbgorSvBYEFqq854ltTmUdHkY92FSdAAvsh4jWEULMdfQ==" }, "node_modules/emittery": { "version": "0.13.1", @@ -8715,9 +8727,9 @@ "peer": true }, "node_modules/es-object-atoms": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz", - "integrity": "sha512-MZ4iQ6JwHOBQjahnjwaC1ZtIBH+2ohjamzAO3oaHcXYup7qxjF2fixyH+Q71voWHeOkI2q/TnJao/KfXYIZWbw==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "dependencies": { "es-errors": "^1.3.0" }, @@ -17249,20 +17261,20 @@ "dev": true }, "node_modules/tldts": { - "version": "6.1.71", - "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.71.tgz", - "integrity": "sha512-LQIHmHnuzfZgZWAf2HzL83TIIrD8NhhI0DVxqo9/FdOd4ilec+NTNZOlDZf7EwrTNoutccbsHjvWHYXLAtvxjw==", + "version": "6.1.72", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.72.tgz", + "integrity": "sha512-QNtgIqSUb9o2CoUjX9T5TwaIvUUJFU1+12PJkgt42DFV2yf9J6549yTF2uGloQsJ/JOC8X+gIB81ind97hRiIQ==", "dependencies": { - "tldts-core": "^6.1.71" + "tldts-core": "^6.1.72" }, "bin": { "tldts": "bin/cli.js" } }, "node_modules/tldts-core": { - "version": "6.1.71", - "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.71.tgz", - "integrity": "sha512-LRbChn2YRpic1KxY+ldL1pGXN/oVvKfCVufwfVzEQdFYNo39uF7AJa/WXdo+gYO7PTvdfkCPCed6Hkvz/kR7jg==" + "version": "6.1.72", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.72.tgz", + "integrity": "sha512-FW3H9aCaGTJ8l8RVCR3EX8GxsxDbQXuwetwwgXA2chYdsX+NY1ytCBl61narjjehWmCw92tc1AxlcY3668CU8g==" }, "node_modules/tmp": { "version": "0.2.3", @@ -18170,9 +18182,9 @@ } }, "node_modules/vite/node_modules/postcss": { - "version": "8.4.49", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.49.tgz", - "integrity": "sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.1.tgz", + "integrity": "sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ==", "dev": true, "funding": [ { @@ -18189,7 +18201,7 @@ } ], "dependencies": { - "nanoid": "^3.3.7", + "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" }, diff --git a/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx b/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx index 4aa5bdfa8..6dce4356c 100644 --- a/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx +++ b/frontend/src/features/Mission/components/MissionForm/FormikSyncMissionFields.tsx @@ -3,7 +3,7 @@ import { useMissionEventContext } from 'context/mission/useMissionEventContext' import { diff } from 'deep-object-diff' import { useFormikContext } from 'formik' import { omit } from 'lodash' -import { useEffect, useState } from 'react' +import { useEffect } from 'react' import { MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM } from './constants' @@ -19,7 +19,6 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp const { setFieldValue, values } = useFormikContext() const { getMissionEventById, setMissionEventInContext } = useMissionEventContext() const missionEvent = getMissionEventById(missionId) - const [isUpdateEnded, setIsUpdateEnded] = useState(false) useEffect( () => { @@ -32,7 +31,6 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp omit(missionEvent, MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM) ) - setIsUpdateEnded(false) /** * We iterate and use `setFieldValue` on each diff key to avoid a global re-render of the component */ @@ -45,7 +43,10 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp setFieldValue(key, undefine(missionEvent[key])) }) - setIsUpdateEnded(true) + // we need to wait for the form to be updated before removing the mission event from the context + setTimeout(() => { + setMissionEventInContext(undefined) + }, 500) }, // We don't want to trigger infinite re-renders since `setFieldValue` changes after each rendering @@ -53,11 +54,5 @@ export function FormikSyncMissionFields({ missionId }: FormikSyncMissionFormProp [missionEvent] ) - useEffect(() => { - if (isUpdateEnded) { - setMissionEventInContext(undefined) - } - }, [isUpdateEnded, setMissionEventInContext]) - return <> } diff --git a/frontend/src/features/Mission/components/MissionForm/constants.ts b/frontend/src/features/Mission/components/MissionForm/constants.ts index 16a19f5fa..974b8a6e4 100644 --- a/frontend/src/features/Mission/components/MissionForm/constants.ts +++ b/frontend/src/features/Mission/components/MissionForm/constants.ts @@ -18,6 +18,8 @@ export const MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM = [ ...MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES, 'facade', // We do not update this field as it is not used by the form + 'updatedAtUtc', + // We do not update this field as it is not used by the form 'createdAtUtc' ] diff --git a/frontend/src/features/Mission/useCases/saveMission.ts b/frontend/src/features/Mission/useCases/saveMission.ts index 56305b7da..d17704203 100644 --- a/frontend/src/features/Mission/useCases/saveMission.ts +++ b/frontend/src/features/Mission/useCases/saveMission.ts @@ -33,6 +33,7 @@ export const saveMission = ]) const routeParams = getMissionPageRoute(currentPath) const missionIsNewMission = isMissionNew(routeParams?.params?.id) + await dispatch(missionFormsActions.setIsListeningToEvents(false)) const newOrNextMissionData = missionIsNewMission ? { ...valuesToSave, id: undefined } : valuesToSave const upsertMission = missionIsNewMission @@ -79,6 +80,10 @@ export const saveMission = ) } + setTimeout(async () => { + await dispatch(missionFormsActions.setIsListeningToEvents(true)) + }, 500) + if (reopen || !quitAfterSave) { return }