use of org.mycore.common.xml.MCRNodeBuilder in project mycore by MyCoRe-Org.
the class MCRTestMerger method test.
@Ignore
static void test(String xPathA, String xPathB, String xPathExpected) throws JaxenException, IOException {
Element a = new MCRNodeBuilder().buildElement("mods:mods" + xPathA, null, null);
Element b = new MCRNodeBuilder().buildElement("mods:mods" + xPathB, null, null);
Element e = new MCRNodeBuilder().buildElement("mods:mods" + xPathExpected, null, null);
MCRMergeTool.merge(a, b);
boolean asExpected = MCRXMLHelper.deepEqual(e, a);
if (!asExpected) {
System.out.println("actual result:");
logXML(a);
System.out.println("expected result:");
logXML(e);
}
assertTrue(asExpected);
}
use of org.mycore.common.xml.MCRNodeBuilder in project mycore by MyCoRe-Org.
the class MCREditorSubmissionTest method testSubmitSelectOptions.
@Test
public void testSubmitSelectOptions() throws JaxenException, JDOMException, IOException {
String template = "document[category='a'][category[2]='b'][category[3]='c']";
MCREditorSession session = new MCREditorSession();
session.setEditedXML(new Document(new MCRNodeBuilder().buildElement(template, null, null)));
session.getSubmission().mark2checkResubmission(new MCRBinding("/document/category", true, session.getRootBinding()));
session.getSubmission().emptyNotResubmittedNodes();
List<Element> categories = session.getEditedXML().getRootElement().getChildren("category");
assertEquals(3, categories.size());
assertEquals("", categories.get(0).getText());
assertEquals("", categories.get(1).getText());
assertEquals("", categories.get(2).getText());
session.getSubmission().mark2checkResubmission(new MCRBinding("/document/category", true, session.getRootBinding()));
Map<String, String[]> submittedValues = new HashMap<>();
submittedValues.put("/document/category", new String[] { "c", "d" });
session.getSubmission().setSubmittedValues(submittedValues);
session.getSubmission().emptyNotResubmittedNodes();
categories = session.getEditedXML().getRootElement().getChildren("category");
assertEquals(3, categories.size());
assertEquals("c", categories.get(0).getText());
assertEquals("d", categories.get(1).getText());
assertEquals("", categories.get(2).getText());
session.getSubmission().mark2checkResubmission(new MCRBinding("/document/category", true, session.getRootBinding()));
submittedValues.clear();
submittedValues.put("/document/category", new String[] { "a", "b", "c", "d" });
session.getSubmission().setSubmittedValues(submittedValues);
session.getSubmission().emptyNotResubmittedNodes();
categories = session.getEditedXML().getRootElement().getChildren("category");
assertEquals(4, categories.size());
assertEquals("a", categories.get(0).getText());
assertEquals("b", categories.get(1).getText());
assertEquals("c", categories.get(2).getText());
assertEquals("d", categories.get(3).getText());
}
use of org.mycore.common.xml.MCRNodeBuilder in project mycore by MyCoRe-Org.
the class MCRSwapInsertTargetTest method testBuildInsertParam.
@Test
public void testBuildInsertParam() throws JaxenException, JDOMException {
String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
Element template = new MCRNodeBuilder().buildElement(x, null, null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 2, 10, "build");
repeat.bindRepeatPosition();
String insertParam = MCRInsertTarget.getInsertParameter(repeat);
assertEquals("/mods:mods|1|build|mods:name[(@type = \"personal\")]", insertParam);
repeat.detach();
new MCRInsertTarget().handle(insertParam, root);
repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 1, 10, "build");
assertEquals(3, repeat.getBoundNodes().size());
assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
assertEquals("", ((Element) (repeat.getBoundNodes().get(1))).getText());
assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
}
use of org.mycore.common.xml.MCRNodeBuilder in project mycore by MyCoRe-Org.
the class MCRSwapInsertTargetTest method testCloneInsertParam.
@Test
public void testCloneInsertParam() throws JaxenException, JDOMException {
String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
Element template = new MCRNodeBuilder().buildElement(x, null, null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 2, 10, "clone");
repeat.bindRepeatPosition();
String insertParam = MCRInsertTarget.getInsertParameter(repeat);
assertEquals("/mods:mods|1|clone|mods:name[(@type = \"personal\")]", insertParam);
repeat.detach();
new MCRInsertTarget().handle(insertParam, root);
repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 1, 10, "build");
assertEquals(3, repeat.getBoundNodes().size());
assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
assertEquals("p1", ((Element) (repeat.getBoundNodes().get(1))).getText());
assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
}
use of org.mycore.common.xml.MCRNodeBuilder in project mycore by MyCoRe-Org.
the class MCRSwapInsertTargetTest method testSwapParameter.
@Test
public void testSwapParameter() throws JaxenException, JDOMException {
Element template = new MCRNodeBuilder().buildElement("parent[name='aa'][name='ab'][name='bc'][name='ac']", null, null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name[contains(text(),'a')]", root, 0, 0, "build");
assertEquals(3, repeat.getBoundNodes().size());
repeat.bindRepeatPosition();
repeat.bindRepeatPosition();
assertEquals("/parent|1|build|name[contains(text(), \"a\")]", MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_UP));
assertEquals("/parent|2|build|name[contains(text(), \"a\")]", MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN));
}
Aggregations