Skip to content

Commit

Permalink
Positions VMS - Lorque le type de réseau est GSM, la position n'est p…
Browse files Browse the repository at this point in the history
…as traitée (#3569)

## Linked issues

- Resolve #3568

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron committed Aug 22, 2024
2 parents da2653a + ebbf4d6 commit 1e2d1ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
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()
}
}

0 comments on commit 1e2d1ce

Please sign in to comment.