use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class CompositeChecker method callCheckers.
/**
* Check the pertinence of a text by calling recursively the checkers
* loaded by the instance. If no checker returns failed, a sourceCodeRemark
* is created with a manual check message. To respect the ElementChecker
* interface, the check method is called with an elementHandler instance as
* argument. This instance only contains the current checked element.
*
* @param sspHandler
* @param elementHandler
* @return the solution of the pertinence check
*/
protected TestSolution callCheckers(SSPHandler sspHandler, ElementHandler<Element> elementHandler) {
TestSolutionHandler globalTestSolutionHandler = new TestSolutionHandlerImpl();
for (ElementChecker ec : checkers) {
TestSolutionHandler testSolutionHandler = new TestSolutionHandlerImpl();
ec.check(sspHandler, elementHandler, testSolutionHandler);
TestSolution checkerSolution = testSolutionHandler.getTestSolution();
Logger.getLogger(this.getClass()).debug("Checker " + ec.getClass() + " returned " + checkerSolution);
if (isOrCombinaison && (checkerSolution.equals(ec.getFailureSolution()) || checkerSolution.equals(TestSolution.NOT_APPLICABLE))) {
return checkerSolution;
}
globalTestSolutionHandler.addTestSolution(checkerSolution);
}
return createSolutionFromCheckersResult(globalTestSolutionHandler.getTestSolution(), elementHandler);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class AttributeOnChildElementPresenceChecker method checkChildElementWithAttributePresence.
/**
* This methods checks whether elements have a child element of with a given
* attribute.
*
* @param elements
* @param testSolutionHandler
*/
private void checkChildElementWithAttributePresence(Elements elements, TestSolutionHandler testSolutionHandler) {
if (elements.isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
TestSolution testSolution = TestSolution.PASSED;
for (Element el : elements) {
if (!el.getElementsByAttribute(attributeName).isEmpty()) {
testSolution = setTestSolution(testSolution, getSuccessSolution());
addSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
} else {
testSolution = setTestSolution(testSolution, getFailureSolution());
addSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
}
}
testSolutionHandler.addTestSolution(testSolution);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class AttributePresenceChecker method checkAttributePresence.
/**
* This methods checks whether a given attribute is present for a set of
* elements
*
* @param elements
* @param testSolutionHandler
*/
private void checkAttributePresence(Elements elements, TestSolutionHandler testSolutionHandler) {
if (elements.isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
TestSolution testSolution = TestSolution.PASSED;
for (Element el : elements) {
if (!el.hasAttr(attributeName)) {
testSolution = setTestSolution(testSolution, getFailureSolution());
createSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
} else {
testSolution = setTestSolution(testSolution, getSuccessSolution());
createSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
}
}
testSolutionHandler.addTestSolution(testSolution);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class ElementPresenceChecker method checkElementPresence.
/**
* This methods checks whether a given element is present on the page.
*
* @param elements
* @param testSolutionHandler
*/
private void checkElementPresence(Elements elements, TestSolutionHandler testSolutionHandler) {
TestSolution checkResult = getFailureSolution();
if (!elements.isEmpty() && ((!checkUnicity) || (checkUnicity && elements.size() == 1))) {
checkResult = getSuccessSolution();
for (Element el : elements) {
createSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
}
} else if (checkUnicity && elements.size() > 1 && StringUtils.isNotBlank(messageCodeOnMultipleElements)) {
for (Element el : elements) {
addSourceCodeRemark(getFailureSolution(), el, messageCodeOnMultipleElements);
}
} else if (StringUtils.isNotBlank(getFailureMsgCode())) {
getProcessRemarkService().addProcessRemark(getFailureSolution(), getFailureMsgCode());
}
testSolutionHandler.addTestSolution(checkResult);
}
use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.
the class HeadingsHierarchyChecker method checkHeadingsHierarchy.
/**
* This methods checks whether the headings hierarchy is well-structured
*
* @param elements
* @param testSolutionHandler
*/
private void checkHeadingsHierarchy(Elements elements, TestSolutionHandler testSolutionHandler) {
if (elements.isEmpty()) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
TestSolution checkResult = TestSolution.PASSED;
Iterator<Element> iter = elements.iterator();
// we get the index of the first element for further test
Element element = iter.next();
int indexOfReference = getHeaderIndex(element);
int currentIndex;
int previousIndex = indexOfReference;
Element elementOfReference = element;
Element previousElement = element;
while (iter.hasNext()) {
element = iter.next();
currentIndex = getHeaderIndex(element);
if (currentIndex != -1) {
if (currentIndex - previousIndex >= 2) {
checkResult = TestSolution.FAILED;
addSourceCodeRemark(TestSolution.FAILED, element, HEADER_NOT_HIERARCHICALLY_WELL_DEFINED_MSG, getEvidenceElement(PREVIOUS_H_TAG_INDEX_EE, getEvidenceElementMsg(previousIndex, previousElement)));
} else if (currentIndex < indexOfReference) {
checkResult = TestSolution.FAILED;
addSourceCodeRemark(TestSolution.FAILED, element, HEADER_NOT_HIERARCHICALLY_WELL_DEFINED_MSG, getEvidenceElement(FIRST_H_TAG_INDEX_EE, getEvidenceElementMsg(indexOfReference, elementOfReference)));
}
previousIndex = currentIndex;
previousElement = element;
}
}
testSolutionHandler.addTestSolution(checkResult);
}
Aggregations