| | |
| | | |
| | | 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.domain.entity.Mission |
| | | import com.flightfeather.uav.domain.mapper.MissionMapper |
| | | import com.flightfeather.uav.lightshare.service.MissionService |
| | | |
| | | import org.junit.Test |
| | | 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 |
| | | import tk.mybatis.mapper.entity.Example |
| | | |
| | | 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 |
| | | |
| | | @RunWith(SpringRunner::class) |
| | | @SpringBootTest |
| | | class MissionServiceImplTest { |
| | | |
| | | @Autowired |
| | | lateinit var missionService: MissionService |
| | | |
| | | private var missionRep: MissionRep = mockk() |
| | | @Autowired |
| | | lateinit var missionMapper: MissionMapper |
| | | |
| | | @Autowired |
| | | lateinit var missionReport: MissionReport |
| | |
| | | } |
| | | |
| | | @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) |
| | | fun calMissionInfo() { |
| | | missionMapper.selectByExample(Example(Mission::class.java).apply { |
| | | createCriteria().andGreaterThanOrEqualTo("startTime", "2025-08-08 08:30:00") |
| | | }).forEach {mission -> |
| | | mission?.let { missionService.calMissionInfo(it.missionCode) } |
| | | Thread.sleep(1000) |
| | | } |
| | | 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) |
| | | } |
| | | } |