Search in sources :

Example 46 with ElementHandlerImpl

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

the class Aw22Rule11011 method select.

@Override
protected void select(SSPHandler sspHandler) {
    // Selection of all the input form elements of the page
    ElementSelector elementSelector = new SimpleElementSelector(FORM_ELEMENT_CSS_LIKE_QUERY);
    elementSelector.selectElements(sspHandler, inputFormHandler);
    // the selection of the input form elements without label is initialised
    // with all the elements of the page, some elements will be removed later
    inputFormWithoutLabelHandler.addAll(inputFormHandler.get());
    // selection of the input form elements with explicit label
    ElementHandler<Element> inputFormLabelHandler = new ElementHandlerImpl();
    ElementSelector explicitLabelSelector = new InputFormElementWithExplicitLabelSelector(inputFormHandler);
    explicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
    // remove all the input form elements with explicit label from 
    // the selection of the input form elements without label
    inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
    // selection of the input form with inplicit label
    ElementSelector inplicitLabelSelector = new InputFormElementWithInplicitLabelSelector(inputFormHandler);
    inplicitLabelSelector.selectElements(sspHandler, inputFormLabelHandler);
    // remove all the input form elements with inplicit label from 
    // the selection of the input form elements without label
    inputFormWithoutLabelHandler.removeAll(inputFormLabelHandler.get());
}
Also used : InputFormElementWithExplicitLabelSelector(org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector) InputFormElementWithInplicitLabelSelector(org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector) ElementSelector(org.asqatasun.rules.elementselector.ElementSelector) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Example 47 with ElementHandlerImpl

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

the class Aw22Rule11013 method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    if (explicitLabelElements.isEmpty() && innerControlLabelElements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    // if all the label are explicitely defined, the test is passed
    if (innerControlLabelElements.isEmpty()) {
        // add the explicit label element to main handler for counter
        // purpose
        innerControlLabelElements.addAll(explicitLabelElements.get());
        testSolutionHandler.addTestSolution(TestSolution.PASSED);
        return;
    }
    ElementHandler<Element> labelOnError = new ElementHandlerImpl();
    for (Element el : innerControlLabelElements.get()) {
        if (!isForAttributeOfLabelEqualsToIdAttributeOfFormField(el, el.attr(FOR_ATTR))) {
            labelOnError.add(el);
        }
    }
    // use this checker to create sourceCodeRemark when needed
    ElementChecker checker = new ElementPresenceChecker(new ImmutablePair(TestSolution.FAILED, INVALID_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, ""));
    checker.check(sspHandler, labelOnError, testSolutionHandler);
}
Also used : ElementPresenceChecker(org.asqatasun.rules.elementchecker.element.ElementPresenceChecker) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) ElementChecker(org.asqatasun.rules.elementchecker.ElementChecker)

Example 48 with ElementHandlerImpl

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

the class Aw22Rule06034 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 49 with ElementHandlerImpl

use of org.asqatasun.ruleimplementation.ElementHandlerImpl 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 50 with ElementHandlerImpl

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

the class AbstractDownloadableLinkRuleImplementation method check.

@Override
protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) {
    // invoke getElementChecker instead of super.check() to use local
    // collection of elements
    setServicesToChecker(getElementChecker());
    getElementChecker().check(sspHandler, linkWithSimpleExtension, testSolutionHandler);
    TestSolution checkerSolution = testSolutionHandler.getTestSolution();
    if (checkerSolution.equals(TestSolution.NOT_APPLICABLE) && !getElements().isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
        sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
        return;
    }
    if (checkerSolution.equals(TestSolution.PASSED)) {
        // the test result is NMI
        if (getElements().get().size() > linkWithSimpleExtension.get().size()) {
            testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
            sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_MANUALLY_LINK_WITHOUT_EXT_MSG, this.getTest().getCode()));
            return;
        }
        // we search whether the page contains form, if yes, the result 
        // is nmi, if not, the test is not applicable
        ElementHandler<Element> formHandler = new ElementHandlerImpl();
        new SimpleElementSelector(FORM_ELEMENT).selectElements(sspHandler, formHandler);
        if (formHandler.isEmpty()) {
            testSolutionHandler.cleanTestSolutions();
            testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        } else {
            testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
            sspHandler.getProcessRemarkService().addProcessRemark(TestSolution.NEED_MORE_INFO, RuleCheckHelper.specifyMessageToRule(CHECK_DOWNLOADABLE_DOCUMENT_FROM_FORM_MSG, this.getTest().getCode()));
        }
    }
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element) ElementHandlerImpl(org.asqatasun.ruleimplementation.ElementHandlerImpl) SimpleElementSelector(org.asqatasun.rules.elementselector.SimpleElementSelector)

Aggregations

ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)88 Element (org.jsoup.nodes.Element)87 Document (org.jsoup.nodes.Document)51 File (java.io.File)49 IOException (java.io.IOException)44 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)14 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)14 SimpleElementSelector (org.asqatasun.rules.elementselector.SimpleElementSelector)9 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)5 Nomenclature (org.asqatasun.entity.reference.Nomenclature)4 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)4 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)4 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TextEmptinessChecker (org.asqatasun.rules.elementchecker.text.TextEmptinessChecker)3 InputFormElementWithExplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector)3 InputFormElementWithInplicitLabelSelector (org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector)3