yeg
2026-09-05 90882aca0b60a5b39e127d30438752a774b3a7ac
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.battery.business.runtime;
 
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.jupiter.api.Test;
 
/** 测试数据列表必须通过测试级持久化查询,不得回读模拟器历史。 */
class TestPersistedDataQueryContractTest
{
    @Test
    void exposesTestScopedPersistedDataQueries()
    {
        String mapper = resource("mapper/battery/TTestMapper.xml");
        assertTrue(mapper.contains("id=\"selectPersistedFinalRealtimeRecords\""));
        assertTrue(mapper.contains("id=\"selectPersistedFinalStepRecords\""));
        assertTrue(mapper.contains("id=\"selectPersistedFinalCycleRecords\""));
        assertTrue(mapper.contains("where r.test_id = #{testId}"));
    }
 
    @Test
    void stepEndVoltageUsesPersistedDeviceStatistic()
    {
        String mapper = resource("mapper/battery/TTestMapper.xml");
        assertTrue(mapper.contains("r.voltage_v endVoltage"));
        assertTrue(mapper.contains("from t_test_step_record r"));
    }
 
    @Test
    void mapperXmlIsWellFormed()
    {
        try (InputStream stream = TestPersistedDataQueryContractTest.class.getClassLoader()
                .getResourceAsStream("mapper/battery/TTestMapper.xml"))
        {
            if (stream == null) throw new AssertionError("缺少资源 mapper/battery/TTestMapper.xml");
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            factory.newDocumentBuilder().parse(stream);
        }
        catch (Exception exception)
        {
            throw new AssertionError("TTestMapper.xml 必须是可解析的 XML", exception);
        }
    }
 
    private static String resource(String path)
    {
        try (InputStream stream = TestPersistedDataQueryContractTest.class.getClassLoader().getResourceAsStream(path))
        {
            if (stream == null) throw new AssertionError("缺少资源 " + path);
            return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
        }
        catch (Exception exception)
        {
            throw new AssertionError("无法读取资源 " + path, exception);
        }
    }
}