use of javax.xml.validation.Validator in project graphhopper by graphhopper.
the class InstructionListTest method verifyGPX.
public void verifyGPX(String gpx) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = null;
try {
Source schemaFile = new StreamSource(getClass().getResourceAsStream("gpx-schema.xsd"));
schema = schemaFactory.newSchema(schemaFile);
// using more schemas: http://stackoverflow.com/q/1094893/194609
} catch (SAXException e1) {
throw new IllegalStateException("There was a problem with the schema supplied for validation. Message:" + e1.getMessage());
}
Validator validator = schema.newValidator();
try {
validator.validate(new StreamSource(new StringReader(gpx)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.xml.validation.Validator in project hazelcast by hazelcast.
the class DiscoverySpiTest method testSchema.
@Test
public void testSchema() throws Exception {
String xmlFileName = "test-hazelcast-discovery-spi.xml";
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaResource = DiscoverySpiTest.class.getClassLoader().getResource("hazelcast-config-3.9.xsd");
assertNotNull(schemaResource);
InputStream xmlResource = DiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Source source = new StreamSource(xmlResource);
Schema schema = factory.newSchema(schemaResource);
Validator validator = schema.newValidator();
validator.validate(source);
}
use of javax.xml.validation.Validator in project midpoint by Evolveum.
the class TestExtraSchema method testUserExtensionSchemaParseUser.
@Test
public void testUserExtensionSchemaParseUser() throws SAXException, IOException, SchemaException {
System.out.println("===[ testUserExtensionSchemaParseUser ]===");
Document dataDoc = DOMUtil.parseFile(USER_JACK_FILE_XML);
PrismContext context = constructPrismContext();
SchemaRegistryImpl reg = (SchemaRegistryImpl) context.getSchemaRegistry();
reg.registerPrismSchemasFromDirectory(EXTRA_SCHEMA_DIR);
context.initialize();
// Parsing user
// items from user extension are not correctly defined in the schema
PrismObject<UserType> user = context.parserFor(DOMUtil.getFirstChildElement(dataDoc)).compat().parse();
assertNotNull("No definition for user", user.getDefinition());
System.out.println("Parsed root object:");
System.out.println(user.debugDump());
// TODO: assert user
// Try javax schemas by validating a XML file
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(dataDoc), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.validation.Validator in project midpoint by Evolveum.
the class TestSchemaRegistry method testBasic.
/**
* Test whether the midpoint prism context was constructed OK and if it can validate
* ordinary user object.
*/
@Test
public void testBasic() throws SAXException, IOException, SchemaException {
MidPointPrismContextFactory factory = getContextFactory();
PrismContext context = factory.createInitializedPrismContext();
SchemaRegistry reg = context.getSchemaRegistry();
Schema javaxSchema = reg.getJavaxSchema();
assertNotNull(javaxSchema);
// Try to use the schema to validate Jack
// PrismObject<UserType> user = context.parseObject(new File("src/test/resources/common/user-jack.xml"));
// Element document = context.serializeToDom(user);
Document document = DOMUtil.parseFile("src/test/resources/common/user-jack.xml");
Validator validator = javaxSchema.newValidator();
DOMResult validationResult = new DOMResult();
validator.validate(new DOMSource(document), validationResult);
// System.out.println("Validation result:");
// System.out.println(DOMUtil.serializeDOMToString(validationResult.getNode()));
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2_1IdentifiersTest method testFunding.
@Test
public void testFunding() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Funding funding = unmarshallFromPath("/record_2.1/samples/read_samples/funding-2.1.xml", Funding.class);
assertEquals("funding:organization-defined-type", funding.getOrganizationDefinedType().getContent());
assertNotNull(funding.getExternalIdentifiers());
assertNotNull(funding.getExternalIdentifiers().getExternalIdentifier());
Assert.notEmpty(funding.getExternalIdentifiers().getExternalIdentifier());
assertEquals("grant_number", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
assertEquals("funding:external-identifier-value", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
assertEquals(new Url("http://tempuri.org"), funding.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl());
assertEquals(Relationship.SELF, funding.getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
Validator validator = getValidator("funding");
validator.validate(marshall(Funding.class, funding));
validator.validate(marshallToDOM(Funding.class, funding));
}
Aggregations