Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positions VMS - Lorque le type de réseau est GSM, la position n'est pas traitée #3569

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package fr.gouv.cnsp.monitorfish.domain.entities.position

enum class NetworkType(val code: String) {
CELLULAR("CEL"),
SATELLITE("SAT"),
import org.slf4j.Logger
import org.slf4j.LoggerFactory

enum class NetworkType(val codes: List<String>) {
CELLULAR(listOf("CEL", "GSM")),
SATELLITE(listOf("SAT")),
;

companion object {
infix fun from(code: String): NetworkType {
private val logger: Logger = LoggerFactory.getLogger(NetworkType::class.java)

infix fun from(code: String): NetworkType? {
return try {
NetworkType.entries.first { it.code == code }
NetworkType.entries.first { it.codes.contains(code) }
} catch (e: NoSuchElementException) {
throw NoSuchElementException("NetworkType $code not found.", e)
logger.error("NAF Message parsing : NetworkType $code not found.", e)

null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.gouv.cnsp.monitorfish.domain.entities.position

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
class CountryCodeUTests {

@Test
fun `from Should return null if not found`() {
// When
val result = NetworkType.from("INCORRECT")

// Then
assertThat(result).isNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,16 @@ internal class NAFMessageMapperUTests {
// Then
assertThat(position.networkType).isEqualTo(NetworkType.SATELLITE)
}

@Test
internal fun `init Should not throw Whe nthe network type is incorrect`() {
// Given
val naf = "//SR//TM/POS//IR/FRA000123456//NA/MANUEL//RC/FT6951//FS/FRA//XR/TL326095//DA/20200814//TI/0911//LT/+43.0789//LG/+006.1549//SP/000//CO/0//FR/FRA//RD/20200814//RT/0912//MS/INCORRECT//ER//"

// When
val position = NAFMessageMapper(naf).toPosition()

// Then
assertThat(position.networkType).isNull()
}
}
Loading