| | |
| | | |
| | | import com.ruoyi.account.api.feignClient.VinManagementClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.ChargingGunClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.ChargingPileClient; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | | import com.ruoyi.chargingPile.api.model.TChargingPile; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.integration.api.feignClient.SendMessageClient; |
| | | import com.ruoyi.integration.api.model.PlatformStopCharging; |
| | | import com.ruoyi.system.api.model.LoginUserApplet; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.model.TVinChargingOrder; |
| | |
| | | import java.util.Map; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertFalse; |
| | | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyList; |
| | | import static org.mockito.ArgumentMatchers.anyLong; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | |
| | | private SiteClient siteClient; |
| | | @Mock |
| | | private ChargingGunClient chargingGunClient; |
| | | @Mock |
| | | private ChargingPileClient chargingPileClient; |
| | | @Mock |
| | | private SendMessageClient sendMessageClient; |
| | | @Mock |
| | | private UploadRealTimeMonitoringDataService monitoringDataService; |
| | | |
| | |
| | | assertTrue(service.appletDetail(1001L).isEmpty()); |
| | | verify(mapper, never()).accountingStrategyList(1001L); |
| | | } |
| | | |
| | | @Test |
| | | void stopChargingByAppletStopsChargingOrderForBoundVinOwner() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.singletonList(11L))); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | order.setAppUserId(88L); |
| | | order.setStatus(3); |
| | | order.setChargingGunId(5); |
| | | order.setChargingPileId(7); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | TChargingGun gun = new TChargingGun(); |
| | | gun.setCode("GUN_5"); |
| | | when(chargingGunClient.getChargingGunById(5)).thenReturn(R.ok(gun)); |
| | | TChargingPile pile = new TChargingPile(); |
| | | pile.setCode("PILE_7"); |
| | | when(chargingPileClient.getChargingPileById(7)).thenReturn(R.ok(pile)); |
| | | when(mapper.updateById(order)).thenReturn(1); |
| | | |
| | | AjaxResult result = service.stopChargingByApplet("1001"); |
| | | |
| | | assertTrue(result.isSuccess()); |
| | | assertEquals(4, order.getStatus()); |
| | | assertEquals(1, order.getEndMode()); |
| | | assertNotNull(order.getEndTime()); |
| | | verify(sendMessageClient).platformStopCharging(any(PlatformStopCharging.class)); |
| | | } |
| | | |
| | | @Test |
| | | void stopChargingByAppletRejectsWhenVinNotBoundToCurrentUser() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.emptyList())); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | |
| | | AjaxResult result = service.stopChargingByApplet("1001"); |
| | | |
| | | assertFalse(result.isSuccess()); |
| | | verify(sendMessageClient, never()).platformStopCharging(any(PlatformStopCharging.class)); |
| | | verify(mapper, never()).updateById(any(TVinChargingOrder.class)); |
| | | } |
| | | |
| | | @Test |
| | | void stopChargingByAppletRejectsFinishedOrder() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.singletonList(11L))); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | order.setAppUserId(88L); |
| | | order.setStatus(5); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | |
| | | AjaxResult result = service.stopChargingByApplet("1001"); |
| | | |
| | | assertFalse(result.isSuccess()); |
| | | verify(sendMessageClient, never()).platformStopCharging(any(PlatformStopCharging.class)); |
| | | } |
| | | } |