use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2RC1SamplesTest method validateSampleXML.
public void validateSampleXML(String name) throws SAXException, IOException {
Source source = getInputStream("/record_2.0_rc1/samples/" + name + "-2.0_rc1.xml");
Validator validator = getValidator(name);
validator.validate(source);
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest method testFunding.
@Test
public void testFunding() throws SAXException, IOException, JAXBException, ParserConfigurationException {
Funding funding = unmarshallFromPath("/record_2.0/samples/read_samples/funding-2.0.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));
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest 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.0/samples/read_samples/work-2.0.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.0/samples/read_samples/work-full-2.0.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 ValidateV2IdentifiersTest method testPeerReview.
/** Test both types of identifier here
*
* @throws SAXException
* @throws IOException
* @throws JAXBException
* @throws ParserConfigurationException
*/
@Test
public void testPeerReview() throws SAXException, IOException, JAXBException, ParserConfigurationException {
PeerReview peerReview = unmarshallFromPath("/record_2.0/samples/read_samples/peer-review-2.0.xml", PeerReview.class);
ExternalID id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
ExternalID subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
Validator validator = getValidator("peer-review");
validator.validate(marshall(PeerReview.class, peerReview));
validator.validate(marshallToDOM(PeerReview.class, peerReview));
//do the full record too
peerReview = unmarshallFromPath("/record_2.0/samples/read_samples/peer-review-full-2.0.xml", PeerReview.class);
id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
assertEquals("source-work-id", id.getType());
assertEquals("work:external-identifier-id", id.getValue());
assertEquals(new Url("http://orcid.org"), id.getUrl());
assertEquals(Relationship.SELF, id.getRelationship());
subjectid = peerReview.getSubjectExternalIdentifier();
assertEquals("doi", subjectid.getType());
assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
assertEquals(Relationship.SELF, subjectid.getRelationship());
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest 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.0/" + name + "-2.0.xsd"));
Validator validator = schema.newValidator();
return validator;
}
Aggregations