Search in sources :

Example 1 with XPathBuilder

use of org.jdom2.xpath.XPathBuilder in project mycore by MyCoRe-Org.

the class MCRMODSLinkedMetadataTest method testUpdate.

@Test
public void testUpdate() throws IOException, URISyntaxException, MCRPersistenceException, MCRActiveLinkException, JDOMException, SAXException, MCRAccessException {
    MCRObject seriesNew = new MCRObject(getResourceAsURL(seriesID + "-updated.xml").toURI());
    MCRMetadataManager.update(seriesNew);
    Document bookNew = MCRXMLMetadataManager.instance().retrieveXML(bookID);
    XPathBuilder<Element> builder = new XPathBuilder<>("/mycoreobject/metadata/def.modsContainer/modsContainer/mods:mods/mods:relatedItem/mods:titleInfo/mods:title", Filters.element());
    builder.setNamespace(MCRConstants.MODS_NAMESPACE);
    XPathExpression<Element> seriesTitlePath = builder.compileWith(XPathFactory.instance());
    Element titleElement = seriesTitlePath.evaluateFirst(bookNew);
    Assert.assertNotNull("No title element in related item: " + new XMLOutputter(Format.getPrettyFormat()).outputString(bookNew), titleElement);
    Assert.assertEquals("Title update from series was not promoted to book of series.", "Updated series title", titleElement.getText());
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) XPathBuilder(org.jdom2.xpath.XPathBuilder) Document(org.jdom2.Document) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 XMLOutputter (org.jdom2.output.XMLOutputter)1 XPathBuilder (org.jdom2.xpath.XPathBuilder)1 Test (org.junit.Test)1 MCRObject (org.mycore.datamodel.metadata.MCRObject)1