use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.
the class MCRNodeBuilderTest method testExpressionsToIgnore.
@Test
public void testExpressionsToIgnore() throws JaxenException, JDOMException {
Element built = new MCRNodeBuilder().buildElement("element[2]", null, null);
assertNotNull(built);
assertEquals("element", built.getName());
built = new MCRNodeBuilder().buildElement("element[contains(.,'foo')]", null, null);
assertNotNull(built);
assertEquals("element", built.getName());
built = new MCRNodeBuilder().buildElement("foo|bar", null, null);
assertNull(built);
Attribute attribute = new MCRNodeBuilder().buildAttribute("@lang[preceding::*/foo='bar']", "value", null);
assertNotNull(attribute);
assertEquals("lang", attribute.getName());
assertEquals("value", attribute.getValue());
built = new MCRNodeBuilder().buildElement("parent/child/following::node/foo='bar'", null, null);
assertNotNull(built);
assertEquals("child", built.getName());
assertNotNull(built.getParentElement());
assertEquals("parent", built.getParentElement().getName());
assertEquals(0, built.getChildren().size());
assertEquals("", built.getText());
}
use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.
the class MCRNodeBuilderTest method testBuildingTrees.
@Test
public void testBuildingTrees() throws JaxenException, JDOMException {
Element root = new Element("root");
Attribute built = new MCRNodeBuilder().buildAttribute("parent/child/@attribute", null, root);
assertNotNull(built);
assertEquals("attribute", built.getName());
assertNotNull(built.getParent());
assertEquals("child", built.getParent().getName());
assertNotNull(built.getParent().getParentElement());
assertEquals("parent", built.getParent().getParentElement().getName());
assertNotNull(built.getParent().getParentElement().getParentElement());
assertEquals("root", built.getParent().getParentElement().getParentElement().getName());
}
use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.
the class MCRNodeBuilderTest method testBuildingAttributes.
@Test
public void testBuildingAttributes() throws JaxenException, JDOMException {
Attribute built = new MCRNodeBuilder().buildAttribute("@attribute", null, null);
assertNotNull(built);
assertEquals("attribute", built.getName());
assertTrue(built.getValue().isEmpty());
built = new MCRNodeBuilder().buildAttribute("@attribute", "value", null);
assertNotNull(built);
assertEquals("attribute", built.getName());
assertEquals("value", built.getValue());
Element parent = new Element("parent");
built = new MCRNodeBuilder().buildAttribute("@attribute", null, parent);
assertNotNull(built);
assertEquals("attribute", built.getName());
assertNotNull(built.getParent());
assertEquals("parent", built.getParent().getName());
}
use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.
the class MCRXPathBuilderTest method testXPath.
@Test
public void testXPath() {
Element root = new Element("root");
Element title1 = new Element("title");
Element title2 = new Element("title");
Element author = new Element("contributor");
Attribute role = new Attribute("role", "author");
Attribute lang = new Attribute("lang", "de", Namespace.XML_NAMESPACE);
author.setAttribute(role);
author.setAttribute(lang);
root.addContent(title1);
root.addContent(author);
root.addContent(title2);
new Document(root);
assertEquals("/root", MCRXPathBuilder.buildXPath(root));
assertEquals("/root/contributor", MCRXPathBuilder.buildXPath(author));
assertEquals("/root/title", MCRXPathBuilder.buildXPath(title1));
assertEquals("/root/title[2]", MCRXPathBuilder.buildXPath(title2));
assertEquals("/root/contributor/@role", MCRXPathBuilder.buildXPath(role));
assertEquals("/root/contributor/@xml:lang", MCRXPathBuilder.buildXPath(lang));
root.detach();
assertEquals("root", MCRXPathBuilder.buildXPath(root));
assertEquals("root/contributor", MCRXPathBuilder.buildXPath(author));
}
use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.
the class MCRChangeTrackerTest method testBreakpoint.
@Test
public void testBreakpoint() {
Element root = new Element("root");
Document doc = new Document(root);
MCRChangeTracker tracker = new MCRChangeTracker();
Element title = new Element("title");
root.addContent(title);
tracker.track(MCRAddedElement.added(title));
tracker.track(MCRBreakpoint.setBreakpoint(root, "Test"));
Attribute href = new Attribute("href", "foo", MCRConstants.XLINK_NAMESPACE);
root.setAttribute(href);
tracker.track(MCRAddedAttribute.added(href));
tracker.track(MCRSetAttributeValue.setValue(href, "bar"));
String label = tracker.undoLastBreakpoint(doc);
assertEquals("Test", label);
assertNull(root.getAttribute("href"));
assertEquals(1, tracker.getChangeCounter());
}
Aggregations