| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | | * VIN 管理 Mapper 结构断言:列表与导出必须共用同一套筛选条件(含所属公司/车队),避免导出结果与列表不一致。 |
| | | * VIN 管理 Mapper 结构断言:列表与导出必须共用同一套筛选条件(含所属公司/车队/创建时间区间),避免导出结果与列表不一致。 |
| | | */ |
| | | class VinManagementMapperStructureTest { |
| | | |
| | | @Test |
| | | void pageListAndExportShareCompanyAndFleetFilters() throws IOException { |
| | | InputStream input = getClass().getClassLoader().getResourceAsStream("mapper/account/TVinManagementMapper.xml"); |
| | | assertNotNull(input); |
| | | String mapper; |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { |
| | | mapper = reader.lines().collect(Collectors.joining("\n")).toLowerCase(); |
| | | } |
| | | String mapper = loadMapper(); |
| | | assertTrue(mapper.contains("select id=\"selectpagelist\"")); |
| | | assertTrue(mapper.contains("select id=\"selectexportlist\"")); |
| | | assertEquals(2, occurrences(mapper, "and company_id = #{query.companyid}")); |
| | | assertEquals(2, occurrences(mapper, "and fleet_id = #{query.fleetid}")); |
| | | assertEquals(2, occurrences(mapper, "and create_time >= #{query.begintime}")); |
| | | assertEquals(2, occurrences(mapper, "and create_time <= #{query.endtime}")); |
| | | } |
| | | |
| | | @Test |
| | | void exportListSelectsAccountColumnsWithoutRemark() throws IOException { |
| | | String mapper = loadMapper(); |
| | | int start = mapper.indexOf("select id=\"selectexportlist\""); |
| | | int end = mapper.indexOf("</select>", start); |
| | | String exportSql = mapper.substring(start, end); |
| | | assertTrue(exportSql.contains("company_id as companyid")); |
| | | assertTrue(exportSql.contains("fleet_id as fleetid")); |
| | | assertTrue(exportSql.contains("balance")); |
| | | assertTrue(exportSql.contains("phone")); |
| | | assertTrue(exportSql.contains("status")); |
| | | assertFalse(exportSql.contains("remark")); |
| | | } |
| | | |
| | | private String loadMapper() throws IOException { |
| | | InputStream input = getClass().getClassLoader().getResourceAsStream("mapper/account/TVinManagementMapper.xml"); |
| | | assertNotNull(input); |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { |
| | | return reader.lines().collect(Collectors.joining("\n")).toLowerCase(); |
| | | } |
| | | } |
| | | |
| | | private int occurrences(String content, String keyword) { |