use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2_1IdentifiersTest method testWork.
/**
* <common:external-ids>
<common:external-id>
<common:external-id-type>agr</common:external-id-type>
<common:external-id-value>work:external-identifier-id</common:external-id-value>
<common:external-id-url>http://orcid.org</common:external-id-url>
<common:external-id-relationship>self</common:external-id-relationship>
</common:external-id>
</common:external-ids>
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testWork() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Work work = unmarshallFromPath("/record_2.1/samples/read_samples/work-2.1.xml", Work.class);
ExternalID id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("agr", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
Validator validator = getValidator("work");
validator.validate(marshall(Work.class, work));
validator.validate(marshallToDOM(Work.class, work));
work = unmarshallFromPath("/record_2.1/samples/read_samples/work-full-2.1.xml", Work.class);
id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("agr", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
validator.validate(marshall(Work.class, work));
validator.validate(marshallToDOM(Work.class, work));
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2_1IdentifiersTest method getValidator.
public Validator getValidator(String name) throws SAXException {
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(getClass().getResource("/record_2.1/" + name + "-2.1.xsd"));
Validator validator = schema.newValidator();
return validator;
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class OrcidValidationJaxbContextResolver method validate.
public void validate(Object toValidate) {
String apiVersion = getApiVersion();
String schemaFilenamePrefix = getSchemaFilenamePrefix(toValidate.getClass(), apiVersion);
try {
Schema schema = getSchema(schemaFilenamePrefix, apiVersion);
JAXBContext context = JAXBContext.newInstance(toValidate.getClass());
Source source = new JAXBSource(context, toValidate);
Validator validator = schema.newValidator();
validator.validate(source);
} catch (SAXException | JAXBException | IOException e) {
//Validation exceptions should return BAD_REQUEST status
throw new WebApplicationException(e, Status.BAD_REQUEST.getStatusCode());
}
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToOrcidProfileTest method validateAgainstSchema.
private void validateAgainstSchema(OrcidMessage orcidMessage) throws SAXException, IOException {
//We need to manually remove the visibility from the given and family names to match the schema
removeVisibilityAttributeFromNames(orcidMessage);
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(getClass().getResource("/orcid-message-" + OrcidMessage.DEFAULT_VERSION + ".xsd"));
Validator validator = schema.newValidator();
validator.validate(orcidMessage.toSource());
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2RC3Identifiers method testPerson.
/**
* <external-identifier:external-identifiers>
<external-identifier:external-identifier visibility="public" put-code="1">
<common:external-id-type>type-1</common:external-id-type>
<common:external-id-value>value-1</common:external-id-value>
<common:external-id-url>http://url.com/1</common:external-id-url>
<common:created-date>2001-12-31T12:00:00</common:created-date>
<common:last-modified-date>2001-12-31T12:00:00</common:last-modified-date>
<common:source>
<common:source-orcid>
<common:uri>http://orcid.org/8888-8888-8888-8880</common:uri>
<common:path>8888-8888-8888-8880</common:path>
<common:host>orcid.org</common:host>
</common:source-orcid>
<common:source-name />
</common:source>
</external-identifier:external-identifier>
</external-identifier:external-identifiers>
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testPerson() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Person person = unmarshallFromPath("/record_2.0_rc3/samples/person-2.0_rc3.xml", Person.class);
assertEquals("credit-name", person.getName().getCreditName().getContent());
assertEquals(1, person.getExternalIdentifiers().getExternalIdentifiers().size());
PersonExternalIdentifier id = person.getExternalIdentifiers().getExternalIdentifiers().get(0);
assertEquals("type-1", id.getType());
assertEquals("value-1", id.getValue());
assertEquals(new Url("http://url.com/1"), id.getUrl());
assertNull(id.getRelationship());
assertNotNull(id.getCreatedDate().getValue());
assertNotNull(id.getLastModifiedDate().getValue());
assertEquals(new Long(1), id.getPutCode());
assertEquals(Visibility.PUBLIC, id.getVisibility());
Validator validator = getValidator("person");
validator.validate(marshall(Person.class, person));
validator.validate(marshallToDOM(Person.class, person));
}
Aggregations