-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing administration use cases tests
- Loading branch information
1 parent
541b729
commit 94bf685
Showing
11 changed files
with
350 additions
and
5 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...n/fr/gouv/cacem/monitorenv/domain/use_cases/administration/ArchiveAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
import com.nhaarman.mockitokotlin2.given | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.exceptions.UnarchivedChildException | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class ArchiveAdministrationUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@MockBean | ||
private lateinit var canArchiveAdministration: CanArchiveAdministration | ||
|
||
@Test | ||
fun `execute should archive when canArchive returns true`() { | ||
val administrationId = 1 | ||
|
||
given(canArchiveAdministration.execute(administrationId)).willReturn(true) | ||
|
||
ArchiveAdministration(administrationRepository, canArchiveAdministration).execute(administrationId) | ||
|
||
verify(administrationRepository).archiveById(administrationId) | ||
} | ||
|
||
@Test | ||
fun `execute should throw UnarchivedChildException when canArchive() returns false`() { | ||
val administrationId = 1 | ||
|
||
given(canArchiveAdministration.execute(administrationId)).willReturn(false) | ||
|
||
assertThatThrownBy { | ||
ArchiveAdministration(administrationRepository, canArchiveAdministration).execute(administrationId) | ||
} | ||
.isInstanceOf(UnarchivedChildException::class.java) | ||
|
||
verifyNoMoreInteractions(administrationRepository) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...r/gouv/cacem/monitorenv/domain/use_cases/administration/CanArchiveAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
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.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO | ||
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.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class CanArchiveAdministrationUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@Test | ||
fun `execute should return true when all control units are archived`() { | ||
val administrationId = 1 | ||
val fullAdministration = FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 1, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = true, | ||
name = "Control Unit Name", | ||
termsNote = null, | ||
), | ||
), | ||
) | ||
|
||
given(administrationRepository.findById(administrationId)).willReturn(fullAdministration) | ||
|
||
val result = CanArchiveAdministration(administrationRepository).execute(administrationId) | ||
|
||
assertThat(result).isTrue | ||
} | ||
|
||
@Test | ||
fun `execute should return false when some control units are not archived`() { | ||
val administrationId = 1 | ||
val fullAdministration = FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 1, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = false, | ||
name = "Control Unit Name", | ||
termsNote = null, | ||
), | ||
), | ||
) | ||
|
||
given(administrationRepository.findById(administrationId)).willReturn(fullAdministration) | ||
|
||
val result = CanArchiveAdministration(administrationRepository).execute(administrationId) | ||
|
||
assertThat(result).isFalse | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...fr/gouv/cacem/monitorenv/domain/use_cases/administration/CanDeleteAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
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.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class CanDeleteAdministrationUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@Test | ||
fun `execute should return true when control units are empty`() { | ||
val administrationId = 1 | ||
val fullAdministration = FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf(), | ||
) | ||
|
||
given(administrationRepository.findById(administrationId)).willReturn(fullAdministration) | ||
|
||
val result = CanDeleteAdministration(administrationRepository).execute(administrationId) | ||
|
||
assertThat(result).isTrue | ||
} | ||
|
||
@Test | ||
fun `execute should return false when control units are not empty`() { | ||
val administrationId = 1 | ||
val fullAdministration = FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 1, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = true, | ||
name = "Control Unit Name", | ||
termsNote = null, | ||
), | ||
), | ||
) | ||
|
||
given(administrationRepository.findById(administrationId)).willReturn(fullAdministration) | ||
|
||
val result = CanDeleteAdministration(administrationRepository).execute(administrationId) | ||
|
||
assertThat(result).isFalse | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...in/fr/gouv/cacem/monitorenv/domain/use_cases/administration/DeleteAdministrationUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
import com.nhaarman.mockitokotlin2.given | ||
import com.nhaarman.mockitokotlin2.verify | ||
import fr.gouv.cacem.monitorenv.domain.repositories.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.exceptions.ForeignKeyConstraintException | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class DeleteAdministrationUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@MockBean | ||
private lateinit var canDeleteAdministration: CanDeleteAdministration | ||
|
||
@Test | ||
fun `execute should delete when canDeleteAdministration returns true`() { | ||
val administrationId = 1 | ||
|
||
given(canDeleteAdministration.execute(administrationId)).willReturn(true) | ||
|
||
DeleteAdministration(administrationRepository, canDeleteAdministration).execute(administrationId) | ||
|
||
verify(administrationRepository).deleteById(administrationId) | ||
} | ||
|
||
@Test | ||
fun `execute should throw ForeignKeyConstraintException when canDeleteAdministration returns false`() { | ||
val administrationId = 1 | ||
|
||
given(canDeleteAdministration.execute(administrationId)).willReturn(false) | ||
|
||
assertThatThrownBy { | ||
DeleteAdministration(administrationRepository, canDeleteAdministration).execute(administrationId) | ||
} | ||
.isInstanceOf(ForeignKeyConstraintException::class.java) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...n/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationByIdUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
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.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class GetAdministrationByIdUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@Test | ||
fun `execute should return administration by ID`() { | ||
val administrationId = 1 | ||
val fullAdministration = FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 1, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = true, | ||
name = "Control Unit Name", | ||
termsNote = null, | ||
), | ||
), | ||
) | ||
|
||
given(administrationRepository.findById(administrationId)).willReturn(fullAdministration) | ||
|
||
val result = GetAdministrationById(administrationRepository).execute(administrationId) | ||
|
||
assertThat(result).isEqualTo(fullAdministration) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...tlin/fr/gouv/cacem/monitorenv/domain/use_cases/administration/GetAdministrationsUTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package fr.gouv.cacem.monitorenv.domain.use_cases.administration | ||
|
||
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.IAdministrationRepository | ||
import fr.gouv.cacem.monitorenv.domain.use_cases.administration.dtos.FullAdministrationDTO | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class GetAdministrationsUTests { | ||
@MockBean | ||
private lateinit var administrationRepository: IAdministrationRepository | ||
|
||
@Test | ||
fun `execute should return all administrations`() { | ||
val administrations = listOf( | ||
FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 1, | ||
name = "Administration Name", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 1, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = true, | ||
name = "Control Unit Name", | ||
termsNote = null, | ||
), | ||
), | ||
), | ||
FullAdministrationDTO( | ||
administration = AdministrationEntity( | ||
id = 2, | ||
name = "Administration Name 2", | ||
isArchived = false, | ||
), | ||
controlUnits = listOf( | ||
ControlUnitEntity( | ||
id = 0, | ||
administrationId = 2, | ||
areaNote = null, | ||
departmentAreaInseeCode = null, | ||
isArchived = true, | ||
name = "Control Unit Name 2", | ||
termsNote = null, | ||
), | ||
), | ||
), | ||
) | ||
|
||
given(administrationRepository.findAll()).willReturn(administrations) | ||
|
||
val result = GetAdministrations(administrationRepository).execute() | ||
|
||
assertThat(result.size).isEqualTo(1) | ||
assertThat(result).isEqualTo(administrations) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters