Search in sources :

Example 6 with MCREditorSession

use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method testMaxDateRule.

@Test
public void testMaxDateRule() throws JaxenException, JDOMException {
    MCREditorSession session = buildSession("document[year='2017'][year='2117'][year[3]]");
    addRule(session, "/document/year", "max", "2017", "type", "date", "format", "yyyy");
    assertFalse(session.getValidator().isValid());
    assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/year", MCRValidationResults.MARKER_SUCCESS);
    checkResult(session, "/document/year[2]", MCRValidationResults.MARKER_ERROR);
    checkResult(session, "/document/year[3]", MCRValidationResults.MARKER_DEFAULT);
}
Also used : MCREditorSession(org.mycore.frontend.xeditor.MCREditorSession) Test(org.junit.Test)

Example 7 with MCREditorSession

use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method testDateFormatRule.

@Test
public void testDateFormatRule() throws JaxenException, JDOMException {
    MCREditorSession session = buildSession("document[date]");
    addRule(session, "/document", "xpath", "//date", "type", "date", "format", "yyyy-MM-dd");
    assertTrue(session.getValidator().isValid());
    assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/date", MCRValidationResults.MARKER_DEFAULT);
    session = buildSession("document[date='2017-04-28']");
    addRule(session, "/document", "xpath", "//date", "type", "date", "format", "yyyy-MM-dd");
    assertTrue(session.getValidator().isValid());
    assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/date", MCRValidationResults.MARKER_SUCCESS);
    session = buildSession("document[date='28.04.2017']");
    addRule(session, "/document", "xpath", "//date", "type", "date", "format", "yyyy-MM-dd");
    assertFalse(session.getValidator().isValid());
    assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/date", MCRValidationResults.MARKER_ERROR);
    session = buildSession("document[date='28.04.2017'][date[2]='2017-04-28']");
    addRule(session, "/document", "xpath", "//date", "type", "date", "format", "yyyy-MM-dd;dd.MM.yyyy");
    assertTrue(session.getValidator().isValid());
    assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/date[1]", MCRValidationResults.MARKER_SUCCESS);
    checkResult(session, "/document/date[2]", MCRValidationResults.MARKER_SUCCESS);
}
Also used : MCREditorSession(org.mycore.frontend.xeditor.MCREditorSession) Test(org.junit.Test)

Example 8 with MCREditorSession

use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method testGlobalRules.

@Test
public void testGlobalRules() throws JaxenException, JDOMException {
    MCREditorSession session = buildSession("document[year='1899']");
    addRule(session, "/", "xpath", "//year", "min", "2000", "type", "integer");
    assertFalse(session.getValidator().isValid());
    assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/year", MCRValidationResults.MARKER_ERROR);
}
Also used : MCREditorSession(org.mycore.frontend.xeditor.MCREditorSession) Test(org.junit.Test)

Example 9 with MCREditorSession

use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method testMinIntegerRule.

@Test
public void testMinIntegerRule() throws JaxenException, JDOMException {
    MCREditorSession session = buildSession("document[year='1899'][year='2013'][year[3]]");
    addRule(session, "/document/year", "min", "2000", "type", "integer");
    assertFalse(session.getValidator().isValid());
    assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/year", MCRValidationResults.MARKER_ERROR);
    checkResult(session, "/document/year[2]", MCRValidationResults.MARKER_SUCCESS);
    checkResult(session, "/document/year[3]", MCRValidationResults.MARKER_DEFAULT);
}
Also used : MCREditorSession(org.mycore.frontend.xeditor.MCREditorSession) Test(org.junit.Test)

Example 10 with MCREditorSession

use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method testRequiredRule.

@Test
public void testRequiredRule() throws JDOMException, JaxenException {
    MCREditorSession session = buildSession("document[title]");
    addRule(session, "/document/title", "required", "true");
    assertFalse(session.getValidator().isValid());
    assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/title", MCRValidationResults.MARKER_ERROR);
    session = buildSession("document[title='foo']");
    addRule(session, "/document/title", "required", "true");
    assertTrue(session.getValidator().isValid());
    assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/title", MCRValidationResults.MARKER_SUCCESS);
    session = buildSession("document[title][title[2]='foo']");
    addRule(session, "/document/title", "required", "true");
    assertTrue(session.getValidator().isValid());
    assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
    checkResult(session, "/document/title", MCRValidationResults.MARKER_SUCCESS);
}
Also used : MCREditorSession(org.mycore.frontend.xeditor.MCREditorSession) Test(org.junit.Test)

Aggregations

MCREditorSession (org.mycore.frontend.xeditor.MCREditorSession)13 Test (org.junit.Test)12 Document (org.jdom2.Document)1 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)1