Skip to content

Commit 7648ca2

Browse files
jabrenaclaude
andcommitted
test(skills-generator): cache remote schema across parameterized cases
RemoteSchemaValidationTest fetched and parsed the remote pml.xsd on every parameterized invocation (199 XML files), causing redundant network calls and flakiness risk. Load the Schema once in @BeforeAll and reuse it, creating a fresh Validator per case. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent dd03896 commit 7648ca2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

plinth-skills-generator/src/test/java/info/jab/pml/RemoteSchemaValidationTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.xml.validation.Schema;
1111
import javax.xml.validation.SchemaFactory;
1212
import javax.xml.validation.Validator;
13+
import org.junit.jupiter.api.BeforeAll;
1314
import org.junit.jupiter.params.ParameterizedTest;
1415
import org.junit.jupiter.params.provider.MethodSource;
1516

@@ -20,6 +21,17 @@ class RemoteSchemaValidationTest {
2021
//TODO: Use maven-central ASAP
2122
private static final String REMOTE_XSD = "https://jabrena.github.io/pml/schemas/0.8.0/pml.xsd";
2223

24+
private static Schema schema;
25+
26+
@BeforeAll
27+
static void loadRemoteSchema() throws Exception {
28+
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
29+
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "all");
30+
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "all");
31+
32+
schema = schemaFactory.newSchema(URI.create(REMOTE_XSD).toURL());
33+
}
34+
2335
private static Stream<String> provideXmlFileNames() {
2436
return SkillReferences.xmlFilenames();
2537
}
@@ -33,11 +45,6 @@ void xmlFilesAreValidAgainstRemoteSchema(String fileName) throws Exception {
3345
throw new IllegalStateException("Test resource not found: " + resourcePath);
3446
}
3547

36-
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
37-
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "all");
38-
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "all");
39-
40-
Schema schema = schemaFactory.newSchema(URI.create(REMOTE_XSD).toURL());
4148
Validator validator = schema.newValidator();
4249

4350
Source source = new StreamSource(xml);

0 commit comments

Comments
 (0)