| | |
| | | package com.flightfeather.uav.lightshare.service.impl |
| | | |
| | | import com.flightfeather.uav.biz.FactorFilter |
| | | import com.flightfeather.uav.biz.report.MissionReport |
| | | import com.flightfeather.uav.common.exception.BizException |
| | | import com.flightfeather.uav.domain.repository.MissionRep |
| | | import com.flightfeather.uav.lightshare.service.MissionService |
| | | import org.junit.Test |
| | | |
| | | import org.junit.Assert.* |
| | | import org.junit.runner.RunWith |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.boot.test.context.SpringBootTest |
| | | import org.springframework.test.context.junit4.SpringRunner |
| | | import javax.servlet.http.HttpServletResponse |
| | | |
| | | @RunWith(SpringRunner::class) |
| | | @SpringBootTest |
| | | import org.junit.jupiter.api.Assertions.* |
| | | import org.junit.jupiter.api.Test |
| | | import org.junit.jupiter.api.assertThrows |
| | | import org.junit.runner.RunWith |
| | | |
| | | import io.mockk.every |
| | | import io.mockk.mockk |
| | | import io.mockk.verify |
| | | |
| | | class MissionServiceImplTest { |
| | | |
| | | @Autowired |
| | | lateinit var missionService: MissionService |
| | | |
| | | private var missionRep: MissionRep = mockk() |
| | | |
| | | @Autowired |
| | | lateinit var missionReport: MissionReport |
| | | |
| | | @Test |
| | | fun getReport() { |
| | | missionReport.execute("SH-CN-20240514") |
| | | missionReport.execute("SH-CN-20240723-01", FactorFilter.default()) |
| | | missionReport.execute("SH-CN-20240723-02", FactorFilter.default()) |
| | | } |
| | | |
| | | @Test |
| | | fun `calMissionInfo should throw BizException when mission not found`() { |
| | | // Arrange |
| | | val missionCode = "M001" |
| | | every { missionRep.findOne(missionCode) } returns null |
| | | |
| | | // Act & Assert |
| | | val exception = assertThrows<BizException> { |
| | | missionService.calMissionInfo(missionCode) |
| | | } |
| | | assertEquals("走航任务不存在", exception.message) |
| | | } |
| | | |
| | | @Test |
| | | fun `calMissionInfo should calculate and update mission info successfully`() { |
| | | // Arrange |
| | | val missionCode = "M001" |
| | | val mission = Mission(missionCode) |
| | | val data = listOf<RealTimeData>() |
| | | |
| | | every { missionRep.findOne(missionCode) } returns mission |
| | | every { realTimeDataRep.fetchData(mission) } returns data |
| | | every { missionUtil.calKilometres(data) } returns 100.0 |
| | | every { missionUtil.calRegion(data) } returns "Center" |
| | | every { missionRep.updateMission(mission) } returns true |
| | | |
| | | // Act |
| | | val result = missionService.calMissionInfo(missionCode) |
| | | |
| | | // Assert |
| | | assertTrue(result) |
| | | assertEquals(100.0f, mission.kilometres) |
| | | assertEquals("Center", mission.region) |
| | | |
| | | verify { |
| | | missionRep.findOne(missionCode) |
| | | realTimeDataRep.fetchData(mission) |
| | | missionUtil.calKilometres(data) |
| | | missionUtil.calRegion(data) |
| | | missionRep.updateMission(mission) |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | fun `calMissionInfo should return false when update fails`() { |
| | | // Arrange |
| | | val missionCode = "M001" |
| | | val mission = Mission(missionCode) |
| | | val data = listOf<RealTimeData>() |
| | | |
| | | every { missionRep.findOne(missionCode) } returns mission |
| | | every { realTimeDataRep.fetchData(mission) } returns data |
| | | every { missionUtil.calKilometres(data) } returns 100.0 |
| | | every { missionUtil.calRegion(data) } returns "Center" |
| | | every { missionRep.updateMission(mission) } returns false |
| | | |
| | | // Act |
| | | val result = missionService.calMissionInfo(missionCode) |
| | | |
| | | // Assert |
| | | assertFalse(result) |
| | | } |
| | | } |