-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add controllers into public_api for vessel search and port
- Loading branch information
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
...rc/main/kotlin/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/VesselController.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,35 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api | ||
|
||
import fr.gouv.cnsp.monitorfish.domain.use_cases.vessel.SearchVessels | ||
import fr.gouv.cnsp.monitorfish.infrastructure.api.outputs.VesselIdentityDataOutput | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/vessels") | ||
@Tag(name = "APIs for Vessels") | ||
class PublicVesselController( | ||
private val searchVessels: SearchVessels, | ||
) { | ||
|
||
@GetMapping("/search") | ||
@Operation(summary = "Search vessels") | ||
fun searchVessel( | ||
@Parameter( | ||
description = | ||
"Vessel internal reference number (CFR), external marker, IRCS, MMSI, name or beacon number", | ||
required = true, | ||
) | ||
@RequestParam(name = "searched") | ||
searched: String, | ||
): List<VesselIdentityDataOutput> { | ||
return searchVessels.execute(searched).map { | ||
VesselIdentityDataOutput.fromVesselAndBeacon(it) | ||
} | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...in/fr/gouv/cnsp/monitorfish/infrastructure/api/public_api/PublicVesselControllerITests.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,87 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.api.public_api | ||
|
||
import com.neovisionaries.i18n.CountryCode | ||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.anyOrNull | ||
import com.nhaarman.mockitokotlin2.eq | ||
import fr.gouv.cnsp.monitorfish.config.SentryConfig | ||
import fr.gouv.cnsp.monitorfish.domain.entities.alerts.type.ThreeMilesTrawlingAlert | ||
import fr.gouv.cnsp.monitorfish.domain.entities.vessel.* | ||
import fr.gouv.cnsp.monitorfish.domain.use_cases.TestUtils | ||
import fr.gouv.cnsp.monitorfish.domain.use_cases.vessel.* | ||
import fr.gouv.cnsp.monitorfish.domain.entities.beacon_malfunctions.* | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.BDDMockito | ||
import org.mockito.BDDMockito.given | ||
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.annotation.Import | ||
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 | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
@Import(SentryConfig::class) | ||
@AutoConfigureMockMvc(addFilters = false) | ||
@WebMvcTest(value = [(PublicVesselController::class)]) | ||
class PublicVesselControllerITests { | ||
@Autowired | ||
private lateinit var api: MockMvc | ||
|
||
@MockBean | ||
private lateinit var searchVessels: SearchVessels | ||
|
||
@Test | ||
fun `Should search for a vessel`() { | ||
// Given | ||
given(this.searchVessels.execute(any())).willReturn( | ||
listOf( | ||
VesselAndBeacon( | ||
vessel = | ||
Vessel( | ||
id = 1, | ||
internalReferenceNumber = "FR224226850", | ||
vesselName = "MY AWESOME VESSEL", | ||
flagState = CountryCode.FR, | ||
declaredFishingGears = listOf("Trémails"), | ||
vesselType = "Fishing", | ||
hasLogbookEsacapt = false, | ||
), | ||
beacon = Beacon(beaconNumber = "123456", vesselId = 1), | ||
), | ||
VesselAndBeacon( | ||
vessel = | ||
Vessel( | ||
id = 2, | ||
internalReferenceNumber = "GBR21555445", | ||
vesselName = "ANOTHER VESSEL", | ||
flagState = CountryCode.GB, | ||
declaredFishingGears = listOf("Trémails"), | ||
vesselType = "Fishing", | ||
hasLogbookEsacapt = false, | ||
), | ||
beacon = null, | ||
), | ||
), | ||
) | ||
|
||
// When | ||
api.perform(get("/api/v1/vessels/search?searched=VESSEL")) | ||
// Then | ||
.andExpect(status().isOk) | ||
.andExpect(jsonPath("$.length()", equalTo(2))) | ||
.andExpect(jsonPath("$[0].flagState", equalTo("FR"))) | ||
.andExpect(jsonPath("$[0].vesselName", equalTo("MY AWESOME VESSEL"))) | ||
.andExpect(jsonPath("$[0].internalReferenceNumber", equalTo("FR224226850"))) | ||
.andExpect(jsonPath("$[0].beaconNumber", equalTo("123456"))) | ||
.andExpect(jsonPath("$[1].flagState", equalTo("GB"))) | ||
.andExpect(jsonPath("$[1].vesselName", equalTo("ANOTHER VESSEL"))) | ||
.andExpect(jsonPath("$[1].internalReferenceNumber", equalTo("GBR21555445"))) | ||
|
||
Mockito.verify(searchVessels).execute("VESSEL") | ||
} | ||
} |