Search in sources :

Example 11 with TestSolutionHandler

use of org.asqatasun.ruleimplementation.TestSolutionHandler in project Asqatasun by Asqatasun.

the class Aw22Rule06031 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();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 12 with TestSolutionHandler

use of org.asqatasun.ruleimplementation.TestSolutionHandler in project Asqatasun by Asqatasun.

the class Rgaa30Rule060304 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
    decidableElementsChecker.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 = decidableElementsChecker.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();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) ProcessRemark(org.asqatasun.entity.audit.ProcessRemark)

Example 13 with TestSolutionHandler

use of org.asqatasun.ruleimplementation.TestSolutionHandler in project Asqatasun by Asqatasun.

the class Rgaa30Rule060301 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();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 14 with TestSolutionHandler

use of org.asqatasun.ruleimplementation.TestSolutionHandler in project Asqatasun by Asqatasun.

the class Rgaa30Rule060301 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
    decidableElementsChecker.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 = decidableElementsChecker.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();
}
Also used : Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) ProcessRemark(org.asqatasun.entity.audit.ProcessRemark)

Example 15 with TestSolutionHandler

use of org.asqatasun.ruleimplementation.TestSolutionHandler in project Asqatasun by Asqatasun.

the class DoctypeHtml5CheckerTest method testChecker.

/**
 * @param doctype
 * @param result
 * @param remark
 */
private void testChecker(String doctype, TestSolution result, String remark) {
    ProcessRemarkService processRemarkService = createMock(ProcessRemarkService.class);
    SSP ssp = createMock(SSP.class);
    SSPHandler sspHandler = createMock(SSPHandler.class);
    expect(sspHandler.getSSP()).andReturn(ssp);
    expect(ssp.getDoctype()).andReturn(doctype);
    if (StringUtils.isNotBlank(remark)) {
        processRemarkService.addProcessRemark(result, remark);
        expectLastCall();
    }
    // Elements not used in this implementation
    Elements elements = null;
    TestSolutionHandler testSolutionHandler = createMock(TestSolutionHandler.class);
    testSolutionHandler.addTestSolution(result);
    expectLastCall();
    replay(ssp, sspHandler, processRemarkService, testSolutionHandler);
    DoctypeHtml5Checker instance = new DoctypeHtml5Checker();
    instance.setProcessRemarkService(processRemarkService);
    instance.doCheck(sspHandler, elements, testSolutionHandler);
    verify(ssp, sspHandler, processRemarkService, testSolutionHandler);
}
Also used : SSP(org.asqatasun.entity.audit.SSP) SSPHandler(org.asqatasun.processor.SSPHandler) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) Elements(org.jsoup.select.Elements) ProcessRemarkService(org.asqatasun.service.ProcessRemarkService)

Aggregations

TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)17 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)16 Element (org.jsoup.nodes.Element)15 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)14 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)6 File (java.io.File)2 Document (org.jsoup.nodes.Document)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 SSP (org.asqatasun.entity.audit.SSP)1 TestSolution (org.asqatasun.entity.audit.TestSolution)1 SSPHandler (org.asqatasun.processor.SSPHandler)1 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)1 Elements (org.jsoup.select.Elements)1