Search in sources :

Example 91 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)91 Element (org.jsoup.nodes.Element)90 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)11 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)6 ElementHandler (org.asqatasun.ruleimplementation.ElementHandler)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Nomenclature (org.asqatasun.entity.reference.Nomenclature)5 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)5 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)4 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)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