Search in sources :

Example 11 with TestSolutionHandlerImpl

use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl 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 TestSolutionHandlerImpl

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

the class ElementPresenceCheckerTest method testCheckDefaultDetectedUnicityFailedOverrideSolutionResult2.

/**
     * Test of doCheck method, of class ElementPresenceChecker.
     * @throws java.io.IOException
     */
public void testCheckDefaultDetectedUnicityFailedOverrideSolutionResult2() throws IOException {
    LOGGER.debug("elementPresenceChecker-check-default-detection-unicity-failed-override-solution-result2");
    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.A_ELEMENT));
    initMockContext(TestSolution.NOT_APPLICABLE, null);
    TestSolutionHandler testSolutionHandler = new TestSolutionHandlerImpl();
    ElementPresenceChecker instance = new ElementPresenceChecker(new ImmutablePair(TestSolution.NEED_MORE_INFO, "detected"), new ImmutablePair(TestSolution.NOT_APPLICABLE, ""));
    instance.check(mockSspHandler, elementHandler, testSolutionHandler);
    assertEquals(TestSolution.NOT_APPLICABLE, testSolutionHandler.getTestSolution());
    verifyMockContext();
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler) Document(org.jsoup.nodes.Document) File(java.io.File)

Example 13 with TestSolutionHandlerImpl

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

the class LangChangeChecker method checkLanguageRelevancyRecursively.

/**
     * 
     * @param sspHandler
     * @param element
     * @param checkCurrentElement
     * @return 
     */
private TestSolution checkLanguageRelevancyRecursively(SSPHandler sspHandler, Element element, @Nullable String currentLangRedefinitionValue) {
    String currentLangRedefinition = currentLangRedefinitionValue;
    TestSolutionHandler tsh = new TestSolutionHandlerImpl();
    // children have to be identical to the default one.
    if (isLangDefinedForElement(element)) {
        String langDefinition = extractLangDefinitionFromElement(element, sspHandler);
        String currentLang = extractEffectiveLang(langDefinition);
        if (!StringUtils.equalsIgnoreCase(defaultLang, currentLang)) {
            currentLangRedefinition = currentLang;
        } else {
            currentLangRedefinition = null;
        }
    }
    // we extract the textual content of the current element. If not empty 
    // we check the language relevancy 
    String extractedText = extractTextFromElement(element, false);
    if (isTextTestable(extractedText)) {
        newElementTested();
        if (StringUtils.isNotBlank(currentLangRedefinition)) {
            tsh.addTestSolution(checkLanguageDifferentFromDefault(element, extractedText, currentLangRedefinition));
        } else {
            tsh.addTestSolution(checkLanguageIdenticalToDefault(element, extractedText));
        }
    }
    for (Element el : element.children()) {
        tsh.addTestSolution(checkLanguageRelevancyRecursively(sspHandler, el, currentLangRedefinition));
    }
    return tsh.getTestSolution();
}
Also used : Element(org.jsoup.nodes.Element) TestSolutionHandlerImpl(org.asqatasun.ruleimplementation.TestSolutionHandlerImpl) TestSolutionHandler(org.asqatasun.ruleimplementation.TestSolutionHandler)

Example 14 with TestSolutionHandlerImpl

use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl 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
    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();
}
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 TestSolutionHandlerImpl

use of org.asqatasun.ruleimplementation.TestSolutionHandlerImpl 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)

Aggregations

TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)16 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 TestSolution (org.asqatasun.entity.audit.TestSolution)1