yeg
2026-09-02 74f55db1acd945f4860b2d0b4bae48e2b918b32b
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
package com.ruoyi.config;
 
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/system/TTestMapper.xml");
        assertTrue(mapper.contains("id=\"selectPersistedRecords\""));
        assertTrue(mapper.contains("id=\"selectPersistedSteps\""));
        assertTrue(mapper.contains("id=\"selectPersistedCycles\""));
        assertTrue(mapper.contains("id=\"selectBtsSampleContentHash\""));
        assertTrue(mapper.contains("sample.step_name"));
        assertTrue(mapper.contains("where sample.test_id = #{testId}"));
        assertTrue(mapper.contains("from t_test_sample sample"));
    }
 
    @Test
    void mapperXmlIsWellFormed()
    {
        try (InputStream stream = TestPersistedDataQueryContractTest.class.getClassLoader()
                .getResourceAsStream("mapper/system/TTestMapper.xml"))
        {
            if (stream == null) throw new AssertionError("缺少资源 mapper/system/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);
        }
    }
}