1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.ruoyi.order.mapper;
 
import org.junit.jupiter.api.Test;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
 
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
class ChargingPeriodPaginationMapperTest {
 
    @Test
    void pagesOrdersBeforeLoadingAccountingSummaries() throws IOException {
        InputStream input = getClass().getClassLoader()
                .getResourceAsStream("mapper/order/TChargingOrderMapper.xml");
        assertNotNull(input);
 
        String mapper;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
            mapper = reader.lines().collect(Collectors.joining("\n"));
        }
 
        String pageQuery = mapper.substring(
                mapper.indexOf("<select id=\"chargingList1\""),
                mapper.indexOf("<select id=\"chargingListAccountingSummary\""));
        assertTrue(pageQuery.contains("from t_charging_order b"));
        assertFalse(pageQuery.contains("t_charging_order_accounting_strategy"));
        assertFalse(pageQuery.contains("group by charging_order_id"));
 
        int summaryStart = mapper.indexOf("<select id=\"chargingListAccountingSummary\"");
        assertTrue(summaryStart >= 0);
        String accountingQuery = mapper.substring(summaryStart, mapper.indexOf("<select id=\"chargingListSum\""));
        assertTrue(accountingQuery.contains("from t_charging_order_accounting_strategy"));
        assertTrue(accountingQuery.contains("where charging_order_id in"));
        assertTrue(accountingQuery.contains("group by charging_order_id"));
    }
}