Init
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package space.nstart.pcp.tle_monitoring_service
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class TleMonitoringServiceApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package space.nstart.pcp.tle_monitoring_service.service
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import space.nstart.pcp.tle_monitoring_service.configuration.TlePollingProperties
|
||||
|
||||
class CelesTrakServiceTest {
|
||||
|
||||
@Test
|
||||
fun `findExpired does not access satellite source when polling is disabled`() {
|
||||
val pollingSettingsService = TlePollingSettingsService(
|
||||
TlePollingProperties(enabled = false, timeoutSeconds = 30),
|
||||
)
|
||||
val service = CelesTrakService(WebClient.builder().build(), pollingSettingsService)
|
||||
|
||||
val result = service.findExpired().collectList().block().orEmpty()
|
||||
|
||||
assertTrue(result.isEmpty())
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package space.nstart.pcp.tle_monitoring_service.service
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import space.nstart.pcp.tle_monitoring_service.repository.TLERepository
|
||||
|
||||
class SatelliteDeletedServiceTest {
|
||||
|
||||
@Test
|
||||
fun `deleteSatelliteData removes TLE rows`() {
|
||||
val tleRepository = mock(TLERepository::class.java)
|
||||
val service = SatelliteDeletedService(tleRepository)
|
||||
|
||||
`when`(tleRepository.countBySatelliteId(56756L)).thenReturn(4L)
|
||||
`when`(tleRepository.deleteAllBySatelliteId(56756L)).thenReturn(4L)
|
||||
|
||||
val deleted = service.deleteSatelliteData(56756L)
|
||||
|
||||
assertEquals(4L, deleted)
|
||||
verify(tleRepository).countBySatelliteId(56756L)
|
||||
verify(tleRepository).deleteAllBySatelliteId(56756L)
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package space.nstart.pcp.tle_monitoring_service.service
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import space.nstart.pcp.tle_monitoring_service.configuration.CustomValidationException
|
||||
import space.nstart.pcp.tle_monitoring_service.configuration.TlePollingProperties
|
||||
import java.time.Instant
|
||||
|
||||
class TlePollingSettingsServiceTest {
|
||||
|
||||
@Test
|
||||
fun `initializes settings from properties`() {
|
||||
val service = TlePollingSettingsService(
|
||||
TlePollingProperties(enabled = false, timeoutSeconds = 45),
|
||||
)
|
||||
|
||||
val settings = service.current()
|
||||
|
||||
assertFalse(settings.enabled)
|
||||
assertEquals(45, settings.timeoutSeconds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `polling is disabled by default`() {
|
||||
val service = TlePollingSettingsService(TlePollingProperties())
|
||||
|
||||
val settings = service.current()
|
||||
|
||||
assertFalse(settings.enabled)
|
||||
assertFalse(service.shouldStartPolling())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `updates polling settings`() {
|
||||
val service = TlePollingSettingsService(TlePollingProperties())
|
||||
|
||||
val settings = service.update(
|
||||
UpdateTlePollingSettingsRequest(enabled = false, timeoutSeconds = 60),
|
||||
)
|
||||
|
||||
assertFalse(settings.enabled)
|
||||
assertEquals(60, settings.timeoutSeconds)
|
||||
assertFalse(service.shouldStartPolling())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `uses timeout between polling cycles`() {
|
||||
val service = TlePollingSettingsService(
|
||||
TlePollingProperties(enabled = true, timeoutSeconds = 30),
|
||||
)
|
||||
val startedAt = Instant.parse("2026-05-13T10:00:00Z")
|
||||
|
||||
assertTrue(service.shouldStartPolling(startedAt))
|
||||
|
||||
service.markPollingStarted(startedAt)
|
||||
|
||||
assertFalse(service.shouldStartPolling(startedAt.plusSeconds(29)))
|
||||
assertTrue(service.shouldStartPolling(startedAt.plusSeconds(30)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `rejects invalid timeout`() {
|
||||
val service = TlePollingSettingsService(TlePollingProperties())
|
||||
|
||||
assertThrows(CustomValidationException::class.java) {
|
||||
service.update(UpdateTlePollingSettingsRequest(enabled = true, timeoutSeconds = 0))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `starts immediately after polling is enabled`() {
|
||||
val service = TlePollingSettingsService(
|
||||
TlePollingProperties(enabled = true, timeoutSeconds = 30),
|
||||
)
|
||||
val startedAt = Instant.parse("2026-05-13T10:00:00Z")
|
||||
|
||||
service.markPollingStarted(startedAt)
|
||||
service.update(UpdateTlePollingSettingsRequest(enabled = false, timeoutSeconds = 30))
|
||||
service.update(UpdateTlePollingSettingsRequest(enabled = true, timeoutSeconds = 30))
|
||||
|
||||
assertTrue(service.shouldStartPolling(startedAt.plusSeconds(1)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
spring:
|
||||
application:
|
||||
name: tle-monitoring-service
|
||||
cloud:
|
||||
config:
|
||||
enabled: false
|
||||
kafka:
|
||||
bootstrap-servers: 192.168.60.68:29092
|
||||
consumer:
|
||||
group-id: pcp
|
||||
auto-offset-reset: earliest
|
||||
template:
|
||||
default-topic: pcp.tle
|
||||
datasource:
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: jdbc:postgresql://192.168.60.68:5432/pcp_tle
|
||||
username: postgres
|
||||
password: password
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
properties:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.PostgreSQLDialect
|
||||
jdbc:
|
||||
lob:
|
||||
non_contextual_creation: true
|
||||
flyway:
|
||||
enabled: true
|
||||
baseline-on-migrate: true
|
||||
locations: classpath:db/migration
|
||||
lifecycle.timeout-per-shutdown-phase: 40s
|
||||
jackson:
|
||||
default-property-inclusion: non_null
|
||||
codec:
|
||||
max-in-memory-size: 20MB
|
||||
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
layout: BaseLayout
|
||||
path: /swagger/ui
|
||||
api-docs:
|
||||
enabled: true
|
||||
path: /api-docs
|
||||
|
||||
logging:
|
||||
level:
|
||||
.: ERROR
|
||||
file:
|
||||
name: ./logs/application.log
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: "*"
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
info:
|
||||
enabled: true
|
||||
|
||||
settings:
|
||||
complex-mission-service: http://192.168.60.68:7002
|
||||
|
||||
tle:
|
||||
polling:
|
||||
enabled: false
|
||||
timeout-seconds: 10800
|
||||
|
||||
server:
|
||||
port: 7001
|
||||
Reference in New Issue
Block a user