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=\"selectTestSampleContentHash\""));
|
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);
|
}
|
}
|
}
|