| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.chargingPile.dto.BatchSetSiteAccountingStrategyDTO; |
| | | import com.ruoyi.chargingPile.service.ISiteService; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | |
| | | assertTrue(result.getData().isEmpty()); |
| | | verify(siteService, never()).list(any(Wrapper.class)); |
| | | } |
| | | |
| | | @Test |
| | | void batchSetAccountingStrategyUsesJsonRequestBody() throws NoSuchMethodException { |
| | | SiteController controller = new SiteController(); |
| | | ISiteService siteService = mock(ISiteService.class); |
| | | ReflectionTestUtils.setField(controller, "siteService", siteService); |
| | | BatchSetSiteAccountingStrategyDTO request = new BatchSetSiteAccountingStrategyDTO(); |
| | | request.setIds(Arrays.asList(11, 12)); |
| | | request.setAccountingStrategyId(23); |
| | | |
| | | controller.batchSetAccountingStrategy(request); |
| | | |
| | | assertNotNull(SiteController.class |
| | | .getMethod("batchSetAccountingStrategy", BatchSetSiteAccountingStrategyDTO.class) |
| | | .getParameters()[0] |
| | | .getAnnotation(RequestBody.class)); |
| | | verify(siteService).batchSetAccountingStrategy(Arrays.asList(11, 12), 23); |
| | | } |
| | | |
| | | @Test |
| | | void batchSetAccountingStrategyRejectsEmptySiteSelection() { |
| | | SiteController controller = new SiteController(); |
| | | ISiteService siteService = mock(ISiteService.class); |
| | | ReflectionTestUtils.setField(controller, "siteService", siteService); |
| | | BatchSetSiteAccountingStrategyDTO request = new BatchSetSiteAccountingStrategyDTO(); |
| | | request.setIds(Collections.emptyList()); |
| | | request.setAccountingStrategyId(23); |
| | | |
| | | AjaxResult result = controller.batchSetAccountingStrategy(request); |
| | | |
| | | assertTrue(result.isError()); |
| | | verify(siteService, never()).batchSetAccountingStrategy(any(), any()); |
| | | } |
| | | } |