package com.tcm.training.admin.member.service;
|
|
import cn.idev.excel.FastExcel;
|
import com.tcm.training.admin.agent.service.ProvincialAgentAppService;
|
import com.tcm.training.admin.agent.vo.ProvincialAgentListItemVO;
|
import com.tcm.training.admin.common.PageResponse;
|
import org.junit.jupiter.api.Test;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import java.io.ByteArrayInputStream;
|
import java.util.Arrays;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Map;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.verify;
|
|
class ProvincialAgentExportTest {
|
private final ProvincialAgentAppService service =
|
spy(new ProvincialAgentAppService(null, null, null, null, null));
|
|
@Test
|
void shouldExportAllBatchesWithFiltersAndPlainPhone() throws Exception {
|
ProvincialAgentListItemVO item = new ProvincialAgentListItemVO();
|
item.setAgentName("省代测试");
|
item.setContactInfo("13800138000");
|
item.setRegionNames(Arrays.asList("广东省", "湖南省"));
|
item.setAddress("测试路88号");
|
item.setStatus(1);
|
item.setClinicCount(3L);
|
doReturn(PageResponse.of(Collections.nCopies(200, item), 201, 1, 200))
|
.when(service).page(1, 200, "44", "诊所", "138", 1);
|
doReturn(PageResponse.of(Collections.singletonList(item), 201, 2, 200))
|
.when(service).page(2, 200, "44", "诊所", "138", 1);
|
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
service.export("44", "诊所", "138", 1, response);
|
List<Map<Integer, String>> rows = readSheet(response);
|
|
assertEquals(202, rows.size());
|
assertEquals("负责人", rows.get(0).get(1));
|
assertEquals("详细地址", rows.get(0).get(4));
|
assertEquals("13800138000", rows.get(1).get(2));
|
assertEquals("广东省、湖南省", rows.get(1).get(3));
|
assertEquals("测试路88号", rows.get(1).get(4));
|
assertEquals("3", rows.get(1).get(5));
|
assertEquals("启用", rows.get(1).get(6));
|
assertEquals("201", rows.get(201).get(0));
|
verify(service).page(2, 200, "44", "诊所", "138", 1);
|
}
|
|
@Test
|
void shouldExportHeadersWhenNoMatches() throws Exception {
|
doReturn(PageResponse.of(Collections.emptyList(), 0, 1, 200))
|
.when(service).page(1, 200, null, null, null, null);
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
|
service.export(null, null, null, null, response);
|
|
List<Map<Integer, String>> rows = readSheet(response);
|
assertEquals(1, rows.size());
|
assertEquals(8, rows.get(0).size());
|
}
|
|
private List<Map<Integer, String>> readSheet(MockHttpServletResponse response) {
|
return FastExcel.read(new ByteArrayInputStream(response.getContentAsByteArray()))
|
.headRowNumber(0).sheet().doReadSync();
|
}
|
}
|