use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method testMaxDecimalRule.
@Test
public void testMaxDecimalRule() throws JaxenException, JDOMException {
MCREditorSession session = buildSession("document[price='10.99'][price='20.00'][price[3]]");
addRule(session, "/document/price", "max", "15.0", "type", "decimal", "locale", "en");
assertFalse(session.getValidator().isValid());
assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/price", MCRValidationResults.MARKER_SUCCESS);
checkResult(session, "/document/price[2]", MCRValidationResults.MARKER_ERROR);
checkResult(session, "/document/price[3]", MCRValidationResults.MARKER_DEFAULT);
}
use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method testLengthRule.
@Test
public void testLengthRule() throws JaxenException, JDOMException {
MCREditorSession session = buildSession("document[text='12345']");
addRule(session, "/document", "xpath", "//text", "minLength", "3", "maxLength", "5");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/text", MCRValidationResults.MARKER_SUCCESS);
session = buildSession("document[text='12345']");
addRule(session, "/document", "xpath", "//text", "maxLength", "4");
assertFalse(session.getValidator().isValid());
assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/text", MCRValidationResults.MARKER_ERROR);
}
use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method testXPathTestRule.
@Test
public void testXPathTestRule() throws JaxenException, JDOMException {
MCREditorSession session = buildSession("document[author='Jim'][author='Charles'][author='John']");
addRule(session, "/document/author", "test", "contains(.,'J')");
assertFalse(session.getValidator().isValid());
assertEquals("true", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
checkResult(session, "/document/author[1]", MCRValidationResults.MARKER_SUCCESS);
checkResult(session, "/document/author[2]", MCRValidationResults.MARKER_ERROR);
checkResult(session, "/document/author[3]", MCRValidationResults.MARKER_SUCCESS);
session = buildSession("document[validFrom='2011'][validTo='2009']");
addRule(session, "/document/validTo", "test", "(string-length(.) = 0) or (number(.) >= number(../validFrom))");
assertFalse(session.getValidator().isValid());
checkResult(session, "/document/validFrom", MCRValidationResults.MARKER_DEFAULT);
checkResult(session, "/document/validTo", MCRValidationResults.MARKER_ERROR);
session = buildSession("document[validFrom='2011'][validTo]");
addRule(session, "/document/validTo", "test", "(string-length(.) = 0) or (number(.) >= number(../validFrom))");
assertTrue(session.getValidator().isValid());
session = buildSession("document[password='secret'][passwordRepeated='sacred']");
addRule(session, "/document", "test", "password = passwordRepeated");
assertFalse(session.getValidator().isValid());
session = buildSession("document[password='secret'][passwordRepeated='secret']");
addRule(session, "/document", "test", "password = passwordRepeated");
assertTrue(session.getValidator().isValid());
session = buildSession("document[service='printOnDemand']");
session.getVariables().put("allowedServices", "oai rss");
addRule(session, "/document/service", "test", "contains($allowedServices,.)");
assertFalse(session.getValidator().isValid());
checkResult(session, "/document/service", MCRValidationResults.MARKER_ERROR);
session = buildSession("document[service='oai']");
session.getVariables().put("allowedServices", "oai rss");
addRule(session, "/document/service", "test", "contains($allowedServices,.)");
assertTrue(session.getValidator().isValid());
checkResult(session, "/document/service", MCRValidationResults.MARKER_SUCCESS);
}
use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method testInvalidation.
@Test
public void testInvalidation() throws JaxenException, JDOMException {
MCREditorSession session = buildSession("document[year='1899']");
addRule(session, "/document/year", "min", "2000", "type", "integer");
addRule(session, "/document/*", "max", "2010", "type", "integer");
assertFalse(session.getValidator().isValid());
checkResult(session, "/document/year", MCRValidationResults.MARKER_ERROR);
}
use of org.mycore.frontend.xeditor.MCREditorSession in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method testNoValidationRules.
@Test
public void testNoValidationRules() throws JDOMException, JaxenException {
MCREditorSession session = buildSession("document");
assertTrue(session.getValidator().isValid());
assertEquals("false", session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_FAILED));
}
Aggregations