Search in sources :

Example 1 with MCRNodeBuilder

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);
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) Element(org.jdom2.Element) Ignore(org.junit.Ignore)

Example 2 with MCRNodeBuilder

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());
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) HashMap(java.util.HashMap) Element(org.jdom2.Element) Document(org.jdom2.Document) Test(org.junit.Test)

Example 3 with MCRNodeBuilder

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());
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRRepeatBinding(org.mycore.frontend.xeditor.MCRRepeatBinding) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Example 4 with MCRNodeBuilder

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());
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRRepeatBinding(org.mycore.frontend.xeditor.MCRRepeatBinding) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Example 5 with MCRNodeBuilder

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));
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRRepeatBinding(org.mycore.frontend.xeditor.MCRRepeatBinding) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Aggregations

MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)27 Document (org.jdom2.Document)24 Test (org.junit.Test)20 Element (org.jdom2.Element)19 MCRBinding (org.mycore.frontend.xeditor.MCRBinding)8 Attribute (org.jdom2.Attribute)6 MCRRepeatBinding (org.mycore.frontend.xeditor.MCRRepeatBinding)6 HashMap (java.util.HashMap)4 MCRAddedElement (org.mycore.frontend.xeditor.tracker.MCRAddedElement)2 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 MCRException (org.mycore.common.MCRException)1 MCRXPathEvaluator (org.mycore.common.xml.MCRXPathEvaluator)1 MCRBase (org.mycore.datamodel.metadata.MCRBase)1 MCRObject (org.mycore.datamodel.metadata.MCRObject)1 MCREditorSession (org.mycore.frontend.xeditor.MCREditorSession)1 MCRAddedAttribute (org.mycore.frontend.xeditor.tracker.MCRAddedAttribute)1 MCRRemoveAttribute (org.mycore.frontend.xeditor.tracker.MCRRemoveAttribute)1 MCRRemoveElement (org.mycore.frontend.xeditor.tracker.MCRRemoveElement)1 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)1