Skip to content

Commit a6340e4

Browse files
committed
wip
1 parent 153081d commit a6340e4

File tree

7 files changed

+576
-46
lines changed

7 files changed

+576
-46
lines changed

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/MonitorFishApplication.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ import org.slf4j.Logger
55
import org.slf4j.LoggerFactory
66
import org.springframework.boot.autoconfigure.SpringBootApplication
77
import org.springframework.boot.runApplication
8+
import org.springframework.context.annotation.ComponentScan
89

910
@SpringBootApplication
11+
@ComponentScan(
12+
basePackages = [
13+
"fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification",
14+
"fr.gouv.cnsp.monitorfish.domain.repositories",
15+
"fr.gouv.cnsp.monitorfish.infrastructure.database.repositories",
16+
],
17+
)
1018
class MonitorFishApplication
1119

1220
fun main(args: Array<String>) {

backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/bff/PriorNotificationController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class PriorNotificationController(
297297
.fromPriorNotification(getPriorNotification.execute(reportId, operationDate, isManuallyCreated))
298298
}
299299

300-
@PostMapping("/{reportId}/verify_and_send")
300+
@PutMapping("/{reportId}/verify_and_send")
301301
@Operation(summary = "Verify and send a prior notification by its `reportId`")
302302
fun verifyAndSend(
303303
@PathParam("Logbook message `reportId`")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
package fr.gouv.cnsp.monitorfish.domain.use_cases.prior_notification
2+
3+
import fr.gouv.cnsp.monitorfish.config.MapperConfiguration
4+
import fr.gouv.cnsp.monitorfish.domain.entities.prior_notification.PriorNotificationState
5+
import fr.gouv.cnsp.monitorfish.domain.repositories.LogbookReportRepository
6+
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.AbstractDBTests
7+
import fr.gouv.cnsp.monitorfish.utils.CustomZonedDateTime
8+
import org.assertj.core.api.Assertions.assertThat
9+
import org.junit.jupiter.api.Test
10+
import org.junit.jupiter.api.extension.ExtendWith
11+
import org.springframework.beans.factory.annotation.Autowired
12+
import org.springframework.boot.test.context.SpringBootTest
13+
import org.springframework.context.annotation.Import
14+
import org.springframework.test.context.junit.jupiter.SpringExtension
15+
import org.springframework.transaction.annotation.Transactional
16+
17+
@ExtendWith(SpringExtension::class)
18+
@Import(MapperConfiguration::class)
19+
@SpringBootTest
20+
class VerifyAndSendPriorNotificationITests : AbstractDBTests() {
21+
@Autowired
22+
private lateinit var verifyAndSendPriorNotification: VerifyAndSendPriorNotification
23+
24+
@Autowired
25+
private lateinit var logbookReportRepository: LogbookReportRepository
26+
27+
// @Autowired
28+
// private lateinit var manualPriorNotificationRepository: ManualPriorNotificationRepository
29+
30+
// @Autowired
31+
// private lateinit var getPriorNotification: GetPriorNotification
32+
33+
private data class TestCase(
34+
val reportId: String,
35+
val expectedBeforeStateRepresentation: String,
36+
val expectedBeforeState: PriorNotificationState,
37+
val expectedAfterStateRepresentation: String,
38+
val expectedAfterState: PriorNotificationState,
39+
)
40+
41+
@Test
42+
@Transactional
43+
fun `Should transition prior notification states as expected`() {
44+
// Given
45+
val testCases = listOf(
46+
// Logbook prior notifications
47+
48+
/*TestCase(
49+
"???",
50+
"00000",
51+
PriorNotificationState.OUT_OF_VERIFICATION_SCOPE,
52+
"00101",
53+
PriorNotificationState.PENDING_SEND,
54+
),
55+
TestCase(
56+
"???",
57+
"00001",
58+
PriorNotificationState.PENDING_AUTO_SEND,
59+
"00101",
60+
PriorNotificationState.PENDING_SEND,
61+
),
62+
TestCase(
63+
"???",
64+
"00010",
65+
PriorNotificationState.AUTO_SEND_DONE,
66+
"00101",
67+
PriorNotificationState.PENDING_SEND,
68+
),
69+
TestCase(
70+
"???",
71+
"00100",
72+
PriorNotificationState.FAILED_SEND,
73+
"00101",
74+
PriorNotificationState.PENDING_SEND,
75+
),
76+
TestCase(
77+
"???",
78+
"00101",
79+
PriorNotificationState.PENDING_SEND,
80+
"00101",
81+
PriorNotificationState.PENDING_SEND,
82+
),
83+
TestCase(
84+
"???",
85+
"00110",
86+
PriorNotificationState.VERIFIED_AND_SENT,
87+
"00101",
88+
PriorNotificationState.PENDING_SEND,
89+
),
90+
TestCase(
91+
"???",
92+
"01000",
93+
PriorNotificationState.PENDING_VERIFICATION,
94+
"01101",
95+
PriorNotificationState.PENDING_SEND,
96+
),
97+
TestCase(
98+
"???",
99+
"01100",
100+
PriorNotificationState.FAILED_SEND,
101+
"01101",
102+
PriorNotificationState.PENDING_SEND,
103+
),
104+
TestCase(
105+
"???",
106+
"01101",
107+
PriorNotificationState.PENDING_SEND,
108+
"01101",
109+
PriorNotificationState.PENDING_SEND,
110+
),
111+
TestCase(
112+
"???",
113+
"01110",
114+
PriorNotificationState.VERIFIED_AND_SENT,
115+
"01101",
116+
PriorNotificationState.PENDING_SEND,
117+
),*/
118+
119+
// Manual prior notifications
120+
121+
TestCase(
122+
"00000000-0000-4000-0000-000000000001",
123+
"10000",
124+
PriorNotificationState.OUT_OF_VERIFICATION_SCOPE,
125+
"10101",
126+
PriorNotificationState.PENDING_SEND,
127+
),
128+
TestCase(
129+
"00000000-0000-4000-0000-000000000002",
130+
"10001",
131+
PriorNotificationState.PENDING_AUTO_SEND,
132+
"10101",
133+
PriorNotificationState.PENDING_SEND,
134+
),
135+
TestCase(
136+
"00000000-0000-4000-0000-000000000003",
137+
"10010",
138+
PriorNotificationState.AUTO_SEND_DONE,
139+
"10101",
140+
PriorNotificationState.PENDING_SEND,
141+
),
142+
TestCase(
143+
"00000000-0000-4000-0000-000000000004",
144+
"10100",
145+
PriorNotificationState.FAILED_SEND,
146+
"10101",
147+
PriorNotificationState.PENDING_SEND,
148+
),
149+
TestCase(
150+
"00000000-0000-4000-0000-000000000005",
151+
"10101",
152+
PriorNotificationState.PENDING_SEND,
153+
"10101",
154+
PriorNotificationState.PENDING_SEND,
155+
),
156+
TestCase(
157+
"00000000-0000-4000-0000-000000000006",
158+
"10110",
159+
PriorNotificationState.VERIFIED_AND_SENT,
160+
"10101",
161+
PriorNotificationState.PENDING_SEND,
162+
),
163+
TestCase(
164+
"00000000-0000-4000-0000-000000000007",
165+
"11000",
166+
PriorNotificationState.PENDING_VERIFICATION,
167+
"11101",
168+
PriorNotificationState.PENDING_SEND,
169+
),
170+
TestCase(
171+
"00000000-0000-4000-0000-000000000008",
172+
"11100",
173+
PriorNotificationState.FAILED_SEND,
174+
"11101",
175+
PriorNotificationState.PENDING_SEND,
176+
),
177+
TestCase(
178+
"00000000-0000-4000-0000-000000000009",
179+
"11101",
180+
PriorNotificationState.PENDING_SEND,
181+
"11101",
182+
PriorNotificationState.PENDING_SEND,
183+
),
184+
TestCase(
185+
"00000000-0000-4000-0000-000000000010",
186+
"11110",
187+
PriorNotificationState.VERIFIED_AND_SENT,
188+
"11101",
189+
PriorNotificationState.PENDING_SEND,
190+
),
191+
)
192+
193+
testCases.forEach { testCase ->
194+
val isManuallyCreated = testCase.expectedBeforeStateRepresentation[0] == '1'
195+
196+
// When
197+
val result = verifyAndSendPriorNotification.execute(
198+
testCase.reportId,
199+
CustomZonedDateTime.now().toZonedDateTime(),
200+
isManuallyCreated,
201+
)
202+
203+
// Then
204+
val pnoValue = result.logbookMessageAndValue.value
205+
assertThat(result.reportId).isEqualTo(testCase.reportId)
206+
assertThat(result.isManuallyCreated).isEqualTo(testCase.expectedAfterStateRepresentation[0] == '1')
207+
assertThat(pnoValue.isInVerificationScope).isEqualTo(testCase.expectedAfterStateRepresentation[1] == '1')
208+
assertThat(pnoValue.isVerified).isEqualTo(testCase.expectedAfterStateRepresentation[2] == '1')
209+
assertThat(pnoValue.isSent).isEqualTo(testCase.expectedAfterStateRepresentation[3] == '1')
210+
assertThat(pnoValue.isBeingSent).isEqualTo(testCase.expectedAfterStateRepresentation[4] == '1')
211+
assertThat(result.state).isEqualTo(testCase.expectedBeforeState)
212+
}
213+
}
214+
215+
// @ParameterizedTest
216+
// @MethodSource("getArguments")
217+
// fun `verifyAndSend Should get a list of prior notifications`(state: PriorNotificationState) {
218+
// println("state: $state")
219+
//
220+
// assertThat(true).isTrue()
221+
// }
222+
//
223+
// companion object {
224+
// @JvmStatic
225+
// private fun getArguments(): Stream<Arguments> {
226+
// return Stream.of(PriorNotificationState.values()).map { state -> arguments(state) }
227+
// }
228+
// }
229+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fr.gouv.cnsp.monitorfish.infrastructure
2+
3+
import fr.gouv.cnsp.monitorfish.config.SentryConfig
4+
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.AbstractDBTests
5+
import org.junit.jupiter.api.extension.ExtendWith
6+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration
7+
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration
8+
import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
9+
import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
10+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
11+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc
12+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTypeExcludeFilter
13+
import org.springframework.context.annotation.Import
14+
import org.springframework.test.context.junit.jupiter.SpringExtension
15+
16+
17+
@ExtendWith(SpringExtension::class)
18+
@OverrideAutoConfiguration(enabled = false)
19+
@TypeExcludeFilters(WebMvcTypeExcludeFilter::class)
20+
@AutoConfigureCache
21+
@AutoConfigureWebMvc
22+
@AutoConfigureMockMvc
23+
@ImportAutoConfiguration
24+
@Import(SentryConfig::class)
25+
abstract class EndToEndTests : AbstractDBTests()

0 commit comments

Comments
 (0)