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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations