Search in sources :

Example 31 with TestSolution

use of org.asqatasun.entity.audit.TestSolution 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)

Example 32 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class AttributeWithValuePresenceChecker method checkAttributeWithValuePresence.

/**
     * This methods checks whether a given attribute is present for a set of
     * elements
     *
     * @param elements
     * @param testSolutionHandler
     */
private void checkAttributeWithValuePresence(Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = TestSolution.PASSED;
    for (Element el : elements) {
        if (!el.hasAttr(attributeName) || (el.hasAttr(attributeName) && !el.attr(attributeName).equals(attributeValue))) {
            testSolution = setTestSolution(testSolution, getFailureSolution());
            createSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
        } else if (StringUtils.isNotBlank(getSuccessMsgCode())) {
            testSolution = setTestSolution(testSolution, getSuccessSolution());
            createSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
        }
    }
    testSolutionHandler.addTestSolution(testSolution);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 33 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class IdUnicityChecker method checkIdUnicity.

/**
     * This methods checks whether a given id is unique for a set of 
     * elements
     * 
     * @param sspHandler
     * @param elements
     * @param testSolutionHandler
     */
private void checkIdUnicity(SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty() || !elements.hasAttr(ID_ATTR)) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = getSuccessSolution();
    for (Element el : elements) {
        if (el.hasAttr(ID_ATTR) && StringUtils.isNotBlank(el.id()) && getIdPresenceCounter(sspHandler, el.id()) > 1) {
            testSolution = getFailureSolution();
            addSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
        }
    }
    testSolutionHandler.addTestSolution(testSolution);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 34 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class TextEmptinessChecker method checkEmptiness.

/**
     * This methods checks whether a given attribute is empty for a set of
     * elements
     * 
     * @param elements
     * @param testSolutionHandler
     */
private void checkEmptiness(Elements elements, TestSolutionHandler testSolutionHandler) {
    if (elements.isEmpty()) {
        testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
        return;
    }
    TestSolution testSolution = TestSolution.NOT_APPLICABLE;
    String textElement;
    for (Element el : elements) {
        textElement = testableTextBuilder.buildTextFromElement(el);
        if (textElement == null) {
            testSolution = setTestSolution(testSolution, TestSolution.NOT_APPLICABLE);
        } else if (isElementEmpty(textElement)) {
            testSolution = setTestSolution(testSolution, getFailureSolution());
            addSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode());
        } else {
            testSolution = setTestSolution(testSolution, getSuccessSolution());
            addSourceCodeRemark(getSuccessSolution(), el, getSuccessMsgCode());
        }
    }
    testSolutionHandler.addTestSolution(testSolution);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution) Element(org.jsoup.nodes.Element)

Example 35 with TestSolution

use of org.asqatasun.entity.audit.TestSolution in project Asqatasun by Asqatasun.

the class LangChangeChecker method checkLanguageChange.

/**
     * 
     * @param element
     * @param sspHandler
     * @return 
     */
private TestSolution checkLanguageChange(Element element, SSPHandler sspHandler) {
    String langDefinition = extractLangDefinitionFromElement(element, sspHandler);
    defaultLang = extractEffectiveLang(langDefinition);
    TestSolution declarationValidity = checkLanguageDeclarationValidity(element, langDefinition, defaultLang, false);
    if (declarationValidity.equals(TestSolution.FAILED)) {
        return TestSolution.NOT_APPLICABLE;
    }
    // the handler may contain the html element or nothing
    return checkLanguageRelevancyRecursively(sspHandler, element, null);
}
Also used : TestSolution(org.asqatasun.entity.audit.TestSolution)

Aggregations

TestSolution (org.asqatasun.entity.audit.TestSolution)37 Node (org.w3c.dom.Node)13 Element (org.jsoup.nodes.Element)11 IncoherentValueDomainsException (org.asqatasun.exception.IncoherentValueDomainsException)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ProcessResult (org.asqatasun.entity.audit.ProcessResult)2 CriterionStatistics (org.asqatasun.entity.statistics.CriterionStatistics)2 ThemeStatistics (org.asqatasun.entity.statistics.ThemeStatistics)2 DomElement (org.asqatasun.rules.domelement.DomElement)2 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)2 NodeList (org.w3c.dom.NodeList)2 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NoResultException (javax.persistence.NoResultException)1 Query (javax.persistence.Query)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)1