improved test

This commit is contained in:
Luca Frosini 2023-03-16 17:40:59 +01:00
parent 39e3112016
commit 97ff99ce46
1 changed files with 18 additions and 5 deletions

View File

@ -51,19 +51,31 @@ public class ProfileTest {
return new File(resourcesDirectory, "profile_schemas"); return new File(resourcesDirectory, "profile_schemas");
} }
protected File getSchemaFile() throws Exception { protected File getGRSFSchemaFile() throws Exception {
File schemaDirectory = getSchemaDirectory(); File schemaDirectory = getSchemaDirectory();
return new File(schemaDirectory, "grsf_profile.xsd"); return new File(schemaDirectory, "grsf_profile.xsd");
} }
protected File getGcatSchemaFile() throws Exception {
File schemaDirectory = getSchemaDirectory();
return new File(schemaDirectory, "profile5.xsd");
}
@Test @Test
public void validateAgainstXSD() throws Exception { public void validateAgainstXSD() throws Exception {
File profilesDirectory = getProfilesDirectory(); File profilesDirectory = getProfilesDirectory();
File schemaFile = getSchemaFile(); File grsfSchemaFile = getGRSFSchemaFile();
File gcatSchemaFile = getGcatSchemaFile();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(schemaFile.toURI().toURL());
Validator validator = schema.newValidator(); Schema grsfSchema = factory.newSchema(grsfSchemaFile.toURI().toURL());
Validator grsfValidator = grsfSchema.newValidator();
Schema gcatSchema = factory.newSchema(gcatSchemaFile.toURI().toURL());
Validator gcatValidator = gcatSchema.newValidator();
for(File profileFile : profilesDirectory.listFiles()) { for(File profileFile : profilesDirectory.listFiles()) {
@ -74,7 +86,8 @@ public class ProfileTest {
DOMSource xml = new DOMSource(doc); DOMSource xml = new DOMSource(doc);
try { try {
validator.validate(xml); grsfValidator.validate(xml);
gcatValidator.validate(xml);
logger.info("File {} has been successfuly validated against schema.", profileFile.getName()); logger.info("File {} has been successfuly validated against schema.", profileFile.getName());
}catch (Exception e) { }catch (Exception e) {
logger.error("Error while validating file {}", profileFile.getName()); logger.error("Error while validating file {}", profileFile.getName());