use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl 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.ruleimplementation.TestSolutionHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa30Rule060304 method testTitleAttributeLink.
/**
*
* @param sspHandler
* @param el
* @param linkText
* @return
*/
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
// content identical to the link text, returns not applicable.
if (!el.hasAttr(TITLE_ATTR)) {
return TestSolution.NOT_APPLICABLE;
}
String attrValue = el.attr(TITLE_ATTR);
if (StringUtils.isBlank(attrValue)) {
return TestSolution.NOT_APPLICABLE;
}
if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
return TestSolution.NOT_APPLICABLE;
}
ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
return tsHandler.getTestSolution();
}
use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl in project Asqatasun by Asqatasun.
the class ElementPresenceCheckerTest method testCheckDefaultDetectedUnicityFailedOverrideSolutionResult1.
/**
* Test of doCheck method, of class ElementPresenceChecker.
* @throws java.io.IOException
*/
public void testCheckDefaultDetectedUnicityFailedOverrideSolutionResult1() throws IOException {
LOGGER.debug("elementPresenceChecker-check-default-detection-unicity-failed-override-solution-result1");
Document doc = Jsoup.parse(new File("src/test/resources/presenceChecker/presence-checker-unique-1.html"), Charset.defaultCharset().displayName());
ElementHandler<Element> elementHandler = new ElementHandlerImpl();
elementHandler.addAll(doc.select(HtmlElementStore.DIV_ELEMENT));
initMockContext((Elements) elementHandler.get(), TestSolution.NEED_MORE_INFO, "detected");
TestSolutionHandler testSolutionHandler = new TestSolutionHandlerImpl();
ElementPresenceChecker instance = new ElementPresenceChecker(true, TestSolution.NEED_MORE_INFO, TestSolution.NOT_APPLICABLE, "detected", "notDetected", null);
instance.check(mockSspHandler, elementHandler, testSolutionHandler);
assertEquals(TestSolution.NEED_MORE_INFO, testSolutionHandler.getTestSolution());
verifyMockContext();
}
use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa32016Rule060303 method testLink.
/**
*
* @param sspHandler
* @param el
* @return
*/
private TestSolution testLink(SSPHandler sspHandler, Element el) {
ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
// reset the service for each tested element. We use the collection
// handled by the service to feed the local collection of remarks
prs.resetService();
// check the pertinence of the link
getDecidableElementsChecker().check(sspHandler, elHandler, tsHandler);
// get the processRemark for eventually override it with the result
// returned by the title pertinence checker
ProcessRemark remark = prs.getRemarkList().iterator().next();
// to nmi but the inverse is impossible.
if (tsHandler.getTestSolution().equals(TestSolution.FAILED)) {
// check the pertinence of the title of the link
String linkText = getDecidableElementsChecker().getTextElementBuilder().buildTextFromElement(el);
if (testTitleAttributeLink(sspHandler, el, linkText).equals(TestSolution.NEED_MORE_INFO)) {
//override result (evidence element have already been collected
remark.setIssue(TestSolution.NEED_MORE_INFO);
remark.setMessageCode(CHECK_LINK_PERTINENCE_MSG);
remarks.add(remark);
return TestSolution.NEED_MORE_INFO;
}
}
remarks.add(remark);
return tsHandler.getTestSolution();
}
use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl in project Asqatasun by Asqatasun.
the class Rgaa32016Rule060303 method testTitleAttributeLink.
/**
*
* @param sspHandler
* @param el
* @param linkText
* @return
*/
private TestSolution testTitleAttributeLink(SSPHandler sspHandler, Element el, String linkText) {
// content identical to the link text, returns not applicable.
if (!el.hasAttr(TITLE_ATTR)) {
return TestSolution.NOT_APPLICABLE;
}
String attrValue = el.attr(TITLE_ATTR);
if (StringUtils.isBlank(attrValue)) {
return TestSolution.NOT_APPLICABLE;
}
if (StringUtils.equalsIgnoreCase(attrValue, linkText)) {
return TestSolution.NOT_APPLICABLE;
}
ElementHandler<Element> elHandler = new ElementHandlerImpl(el);
TestSolutionHandler tsHandler = new TestSolutionHandlerImpl();
titlePertinenceElementChecker.check(sspHandler, elHandler, tsHandler);
return tsHandler.getTestSolution();
}
Aggregations